source: trunk/DataCheck/Processing/FillAuxTemp.sh@ 18752

Last change on this file since 18752 was 18708, checked in by Daniela Dorner, 8 years ago
avoid warnings for missing files for the first few days; fixed bug in finding start and stop time; improved logging
  • Property svn:executable set to *
File size: 7.3 KB
Line 
1#!/bin/bash
2
3# option whether to fill all row or only those where information is missing
4# $doupdate might be given as environment variable
5if [ "$doupdate" = "" ]
6then
7 doupdate="yes" # update all entries (needed when new fields have been added)
8 doupdate="no" # fill only entries which are not yet existing (default)
9fi
10
11source `dirname $0`/../Sourcefile.sh
12printprocesslog "INFO starting $0 with option doupdate="$doupdate
13
14logfile=$runlogpath"/FillAuxTemp-"$datetime".log"
15date >> $logfile
16
17# setup to use ftools
18source $HEADAS/headas-init.sh
19
20# check if software is available
21if ! ls $factpath/fitsdump >/dev/null 2>&1
22then
23 printprocesslog "ERROR "$factpath"/fitsdump is not available."
24 finish
25fi
26
27# get dates
28if [ "$certaindate" != "" ]
29then
30 getdates $certaindate
31else
32 # get all night
33 #getdates "all"
34 # get last 6 nights
35 getdates 6
36fi
37
38
39
40printprocesslog "INFO processing the following night(s): "${dates[@]}
41echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
42
43cd $mars
44
45# do filling of aux data
46for date in ${dates[@]}
47do
48 auxdir=$auxdata/$date
49 runnumber=`echo $date | sed -e 's/\///g'`
50 if [ $runnumber -lt 20120328 ]
51 then
52 continue
53 fi
54
55 # check if aux files are available from that night
56 if ! [ -d $auxdir ]
57 then
58 printprocesslog "INFO no data available in "$auxdir
59 continue
60 else
61 printprocesslog "INFO processing files in "$auxdir
62 fi
63
64 # get file numbers from DB
65 # but only for not-corrupted files
66 query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
67 if [ "$doupdate" = "no" ]
68 then
69 query=$query" AND ISNULL(fCameraTempMean) "
70 fi
71 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
72 filenumbers=( `sendquery $query` )
73 # proceed only if there are files available
74 if [ ${#filenumbers} -eq 0 ]
75 then
76 printprocesslog "INFO No files found in the DB for night "$date
77 continue
78 fi
79
80 magicweatherfile=$auxdir/$runnumber.MAGIC_WEATHER_DATA.fits
81 if ! [ -e $magicweatherfile ]
82 then
83 printprocesslog "WARN "$magicweatherfile" not found."
84 else
85 weathernumerrors=`fverify $magicweatherfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
86 if [ $weathernumerrors -gt 0 ]
87 then
88 printprocesslog "WARN for $magicweatherfile fverify returned "$weathernumerrors" error(s)."
89 fi
90 fi
91
92 fsctempfile=$auxdir/$runnumber.FSC_CONTROL_TEMPERATURE.fits
93 if ! [ -e $fsctempfile ]
94 then
95 printprocesslog "WARN "$fsctempfile" not found."
96 else
97 tempnumerrors=`fverify $fsctempfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
98 if [ $tempnumerrors -gt 0 ]
99 then
100 printprocesslog "WARN for $fsctempfile fverify returned "$tempnumerrors" error(s)."
101 fi
102 fi
103
104 # fill auxiliary information for files
105 for filenum in ${filenumbers[@]}
106 do
107 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
108 echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
109 # get information from rawfile
110 rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.fz
111 if ! [ -e $rawfile ]
112 then
113 if [ $runnumber -lt $checknight ]
114 then
115 printprocesslog "WARN "$rawfile" not found."
116 else
117 printprocesslog "INFO "$rawfile" not found."
118 fi
119 continue
120 fi
121 #checkfitsfile=`fverify $rawfile 2>/dev/null | grep '0 error(s)'`
122 #if [ "$checkfitsfile" == "" ]
123 #then
124 # numfitserrors=1
125 # printprocesslog "WARN: "$rawfile" probably corrupted."
126 # continue
127 #fi
128 runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
129 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
130 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
131 tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '[0-9][.][0-9]+([E][\-][0-9][0-9])?' | sed -e 's/[E]+*/\\*10\\^/'`
132 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
133 tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '[0-9][.][0-9]+([E][\-][0-9][0-9])?' | sed -e 's/[E]+*/\\*10\\^/'`
134 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
135 then
136 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
137 continue
138 fi
139 # assuming that at least TSTARTI and TSTOPI are consistent
140 if [ $tstarti -gt 30000 ]
141 then
142 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
143 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
144 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
145 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
146 else
147 tstart=`echo " $tstarti + $tstartf " | bc -l`
148 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
149 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
150 tstop=`echo " $tstopi + $tstopf " | bc -l`
151 fi
152
153 # build query to update runinfo in DB
154 query="UPDATE RunInfo SET "
155
156 # get information from fsc: T[31]
157 if [ -e $fsctempfile ] && [ $tempnumerrors -eq 0 ]
158 then
159 fsctemps=( `root -q -b -l fact/processing/camtemp.C\("\"$fsctempfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
160 if [ "${fsctemps[0]}" == "" ]
161 then
162 query=$query"fCameraTempMean=NULL"
163 else
164 query=$query"fCameraTempMean="${fsctemps[0]}
165 fi
166 if [ "${fsctemps[1]}" == "" ]
167 then
168 query=$query", fCameraTempRms=NULL"
169 else
170 query=$query", fCameraTempRms="${fsctemps[1]}
171 fi
172 if [ "${fsctemps[2]}" == "" ]
173 then
174 query=$query", fCameraTempRmsMean=NULL"
175 else
176 query=$query", fCameraTempRmsMean="${fsctemps[2]}
177 fi
178 else
179 query=$query" fCameraTempMean=NULL"
180 query=$query", fCameraTempRms=NULL"
181 query=$query", fCameraTempRmsMean=NULL"
182 fi
183 #fCameraTempMeanRms: mean of rms of single sensors
184
185 # get information from weather: T
186 if [ -e $magicweatherfile ] && [ $weathernumerrors -eq 0 ]
187 then
188 mtemps=( `root -q -b -l fact/processing/magictemp.C\("\"$magicweatherfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
189 if [ "${mtemps[0]}" == "" ]
190 then
191 query=$query", fOutsideTempMean=NULL"
192 else
193 query=$query", fOutsideTempMean="${mtemps[0]}
194 fi
195 if [ "${mtemps[1]}" == "" ]
196 then
197 query=$query", fOutsideTempRms=NULL"
198 else
199 query=$query", fOutsideTempRms="${mtemps[1]}
200 fi
201 else
202 query=$query", fOutsideTempMean=NULL"
203 query=$query", fOutsideTempRms=NULL"
204 fi
205
206 # add where condition
207 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
208
209 # send query to DB
210 sendquery >/dev/null
211 done
212done
213
214finish
215
216
Note: See TracBrowser for help on using the repository browser.