1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # new version of the script to run on newdaq
|
---|
4 | # but can be also used at ISDC
|
---|
5 |
|
---|
6 | # option whether to fill all row or only those where information is missing
|
---|
7 | # $doupdate might be given as environment variable
|
---|
8 | if [ "$doupdate" = "" ]
|
---|
9 | then
|
---|
10 | # doupdate="yes" # update all entries (needed when new fields have been added)
|
---|
11 | # doupdate="force" # needed when something with insert in La Palma did not work (adds more information)
|
---|
12 | doupdate="no" # fill only entries which are not yet existing (default)
|
---|
13 | fi
|
---|
14 |
|
---|
15 | source `dirname $0`/../Sourcefile.sh
|
---|
16 | printprocesslog "INFO starting $0 with option doupdate="$doupdate
|
---|
17 |
|
---|
18 | logfile=$runlogpath"/FillAuxData-"$datetime".log"
|
---|
19 | date >> $logfile
|
---|
20 |
|
---|
21 | # check if software is available
|
---|
22 | if ! ls $factpath/fitsdump >/dev/null 2>&1
|
---|
23 | then
|
---|
24 | printprocesslog "ERROR "$factpath"/fitsdump is not available."
|
---|
25 | finish
|
---|
26 | fi
|
---|
27 |
|
---|
28 | # get dates
|
---|
29 | if [ "$certaindate" != "" ]
|
---|
30 | then
|
---|
31 | getdates $certaindate
|
---|
32 | else
|
---|
33 | # get all night
|
---|
34 | #getdates "all"
|
---|
35 | # get last 3 nights if hour between 7 and 19h, else only current night
|
---|
36 | getdates 3 7 19
|
---|
37 | fi
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 | printprocesslog "INFO processing the following night(s): "${dates[@]}
|
---|
42 | echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
|
---|
43 |
|
---|
44 | # mjd of 1970-01-01
|
---|
45 | # needed in this script as for 1 day the mjd in the aux files are inconsistent
|
---|
46 | # mjdref=40587
|
---|
47 |
|
---|
48 | # known:
|
---|
49 | # 2011/11/22 MJDREF in DRIVE empty, Time > 55000
|
---|
50 | # 2011/11/23 MJDREF in DRIVE not empty, Time > 55000
|
---|
51 | # 2011/11/24 MJDREF in DRIVE not empty, Time > 15000
|
---|
52 | # raw files
|
---|
53 | # 2011/11/21 no MJDREF
|
---|
54 | # 2011/11/22 MJDREF
|
---|
55 | # further things: https://www.fact-project.org/logbook/showthread.php?tid=67
|
---|
56 |
|
---|
57 | # trigger rate has as first value -1, but with using the median it should be fine
|
---|
58 |
|
---|
59 |
|
---|
60 | function evaluatestatistics()
|
---|
61 | {
|
---|
62 | # $1 variable name
|
---|
63 | # $@ statistics
|
---|
64 | if [ "$2" = "" ]
|
---|
65 | then
|
---|
66 | printprocesslog "WARN couldn't get statistics from file $1 for run "$date" "$rawfile
|
---|
67 | continue
|
---|
68 | fi
|
---|
69 | min=
|
---|
70 | mean=
|
---|
71 | med=
|
---|
72 | max=
|
---|
73 | rms=
|
---|
74 | evaluation=`echo $@ | grep -E -o '\['${1}':0[:]?[0-9]*\]\ Min:\ [-]?[0-9]+[.]?[0-9]*\ Max:\ [-]?[0-9]+[.]?[0-9]*\ Med:\ [-]?[0-9]+[.]?[0-9]*\ Avg:\ [-]?[0-9]+[.]?[0-9]*\ Rms:\ [-]?[0-9]+[.]?[0-9]*[e]?[-]?[0-9]*'`
|
---|
75 | if [ "$evaluation" = "" ]
|
---|
76 | then
|
---|
77 | printprocesslog "DEBUG empty evaluation of statistic ("$@") for run "$date" file "$rawfile
|
---|
78 | # if [ $runtypekey -eq 1 ] || [ $runtypekey -eq 18 ] #|| [ $sourcekey -gt 0 ] #doesn't work as sourcekey can be empty
|
---|
79 | # then
|
---|
80 | # printprocesslog "WARN empty evaluation of statistic ("$@") for run "$date" file "$rawfile
|
---|
81 | # else
|
---|
82 | # printprocesslog "DEBUG empty evaluation of statistic ("$@") for run "$date" file "$rawfile
|
---|
83 | # fi
|
---|
84 | fi
|
---|
85 | min=`echo $evaluation | grep -E -o 'Min:\ [-]?[0-9]+[.]?[0-9]*' | sed -e 's/Min:\ //'`
|
---|
86 | max=`echo $evaluation | grep -E -o 'Max:\ [-]?[0-9]+[.]?[0-9]*' | sed -e 's/Max:\ //'`
|
---|
87 | med=`echo $evaluation | grep -E -o 'Med:\ [-]?[0-9]+[.]?[0-9]*' | sed -e 's/Med:\ //'`
|
---|
88 | mean=`echo $evaluation | grep -E -o 'Avg:\ [-]?[0-9]+[.]?[0-9]*' | sed -e 's/Avg:\ //'`
|
---|
89 | rms=`echo $evaluation | grep -E -o 'Rms:\ [-]?[0-9]+[.]?[0-9]*[e]?[-]?[0-9]+' | sed -e 's/Rms:\ //'`
|
---|
90 | }
|
---|
91 |
|
---|
92 | # do filling of aux data
|
---|
93 | for date in ${dates[@]}
|
---|
94 | do
|
---|
95 | auxdir=$auxdata/$date
|
---|
96 | rawdir=$rawdata/$date
|
---|
97 | runnumber=`echo $date | sed -e 's/\///g'`
|
---|
98 |
|
---|
99 | # check if aux files are available from that night
|
---|
100 | if ! [ -d $auxdir ]
|
---|
101 | then
|
---|
102 | printprocesslog "INFO no data available in "$auxdir
|
---|
103 | continue
|
---|
104 | else
|
---|
105 | printprocesslog "INFO processing files in "$auxdir
|
---|
106 | fi
|
---|
107 |
|
---|
108 | # check if raw files are available from that night
|
---|
109 | # only needed to get start/stop time
|
---|
110 | # might be removed once the start/stop time comes from the DB
|
---|
111 | if ! [ -d $rawdir ]
|
---|
112 | then
|
---|
113 | printprocesslog "INFO no data available in "$rawdir" -> continue"
|
---|
114 | continue
|
---|
115 | fi
|
---|
116 |
|
---|
117 | # get file numbers from DB
|
---|
118 | # but only for not-corrupted files
|
---|
119 | # as aux files are written only once a minute, select only files which are older than 1.5 minutes
|
---|
120 | query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 AND NOT ISNULL(fRunStop) AND fRunStop < SUBTIME(UTC_TIMESTAMP(), \"00:01:30\")"
|
---|
121 | # only runs which are not yet filled
|
---|
122 | if [ "$doupdate" = "no" ]
|
---|
123 | then
|
---|
124 | query=$query" AND (ISNULL(fRightAscension) OR (ISNULL(fSourceKey) AND fRunTypeKey=1)) "
|
---|
125 | fi
|
---|
126 | printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
|
---|
127 | filenumbers=( `sendquery $query` )
|
---|
128 | if [ ${#filenumbers} -eq 0 ]
|
---|
129 | then
|
---|
130 | printprocesslog "INFO No files found in the DB for night "$date
|
---|
131 | continue
|
---|
132 | fi
|
---|
133 |
|
---|
134 | # get daily fits files
|
---|
135 | trackingfile=$auxdir/$runnumber.DRIVE_CONTROL_TRACKING_POSITION.fits
|
---|
136 | check_file_avail $trackingfile
|
---|
137 |
|
---|
138 | sourceposfile=$auxdir/$runnumber.DRIVE_CONTROL_SOURCE_POSITION.fits
|
---|
139 | if check_file_avail $sourceposfile
|
---|
140 | then
|
---|
141 | sourceposfiletstarti=`$factpath/fitsdump -h $sourceposfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
|
---|
142 | sourceposfiletstartf=`$factpath/fitsdump -h $sourceposfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
|
---|
143 | if [ $sourceposfiletstarti -gt 30000 ]
|
---|
144 | then
|
---|
145 | sourceposfiletstart=`echo " $sourceposfiletstarti + $sourceposfiletstartf - 40587 " | bc -l`
|
---|
146 | else
|
---|
147 | sourceposfiletstart=`echo " $sourceposfiletstarti + $sourceposfiletstartf " | bc -l`
|
---|
148 | fi
|
---|
149 | fi
|
---|
150 |
|
---|
151 | triggerratefile=$auxdir/$runnumber.FTM_CONTROL_TRIGGER_RATES.fits
|
---|
152 | check_file_avail $triggerratefile
|
---|
153 |
|
---|
154 | thresholdfile=$auxdir/$runnumber.FTM_CONTROL_STATIC_DATA.fits
|
---|
155 | check_file_avail $thresholdfile
|
---|
156 |
|
---|
157 | biasvoltagefile=$auxdir/$runnumber.BIAS_CONTROL_VOLTAGE.fits
|
---|
158 | check_file_avail $biasvoltagefile
|
---|
159 |
|
---|
160 | # fill auxiliary information for files
|
---|
161 | for filenum in ${filenumbers[@]}
|
---|
162 | do
|
---|
163 | printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
|
---|
164 | echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
|
---|
165 | if [ "$certaindate" != "" ]
|
---|
166 | then
|
---|
167 | echo `date`": processing file number "$runnumber"_"`printf %03d $filenum`
|
---|
168 | fi
|
---|
169 |
|
---|
170 | # get information from rawfile
|
---|
171 | rawfile=`ls $rawdir/$runnumber"_"\`printf %03d $filenum\`.fits* 2>/dev/null`
|
---|
172 | if [ "$rawfile" = "" ]
|
---|
173 | then
|
---|
174 | if [ $runnumber -le $checknight ]
|
---|
175 | then
|
---|
176 | printprocesslog "WARN no raw file found for "$runnumber"_"`printf %03d $filenum`
|
---|
177 | else
|
---|
178 | printprocesslog "INFO no raw file found for "$runnumber"_"`printf %03d $filenum`
|
---|
179 | fi
|
---|
180 | continue
|
---|
181 | fi
|
---|
182 | # this check is obsolete
|
---|
183 | # find a way to check raw files also with general function
|
---|
184 | if ! check_file_avail $rawfile
|
---|
185 | then
|
---|
186 | continue
|
---|
187 | fi
|
---|
188 |
|
---|
189 | runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
|
---|
190 | #mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
|
---|
191 | tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
|
---|
192 | 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\\^/'`
|
---|
193 | tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
|
---|
194 | 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\\^/'`
|
---|
195 | if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
|
---|
196 | then
|
---|
197 | printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF ("$filenum"/"$date")"
|
---|
198 | #echo "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF ("$filenum"/"$date")"
|
---|
199 | continue
|
---|
200 | fi
|
---|
201 | #echo $rawfile" "$tstarti" "$tstartf" "$tstopi" "$tstopf
|
---|
202 | printprocesslog "DEBUG "$rawfile" "$tstarti" "$tstartf" "$tstopi" "$tstopf
|
---|
203 | # assuming that at least TSTARTI and TSTOPI are consistent
|
---|
204 | if [ $tstarti -gt 30000 ]
|
---|
205 | then
|
---|
206 | tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
|
---|
207 | tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
|
---|
208 | #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
|
---|
209 | tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
|
---|
210 | else
|
---|
211 | tstart=`echo " $tstarti + $tstartf " | bc -l`
|
---|
212 | tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
|
---|
213 | #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
|
---|
214 | tstop=`echo " $tstopi + $tstopf " | bc -l`
|
---|
215 | fi
|
---|
216 | #echo $rawfile" "$tstart" "$tstop
|
---|
217 | printprocesslog "DEBUG "$rawfile" "$tstart" "$tstop
|
---|
218 | # code for very old data
|
---|
219 | #if [ $runnumber -eq 20111123 ]
|
---|
220 | #then
|
---|
221 | # # add mjdref for days were aux files were inconsistent
|
---|
222 | # tstart=`echo " $tstart + $mjdref " | bc -l`
|
---|
223 | # tstart2=`echo " $tstart2 + $mjdref " | bc -l`
|
---|
224 | # tstop=`echo " $tstop + $mjdref " | bc -l`
|
---|
225 | #fi
|
---|
226 |
|
---|
227 | # get information from source_pos file
|
---|
228 | if [ -e $sourceposfile ]
|
---|
229 | then
|
---|
230 | sourcename=`$factpath/fitsdump ${sourceposfile} -c Time -c Name --filter='[1]<'${tstop}' && [1]>'${sourceposfiletstart} 2>/dev/null | tail -1 2>&1 | grep -o -E "['][a-zA-Z0-9\#\_\ \.\+\-]+[']" | sed -e "s/'//g"`
|
---|
231 | printprocesslog "DEBUG $factpath/fitsdump ${sourceposfile} -c Time -c Name --filter='[1]<'${tstop}' && [1]>'${sourceposfiletstart} 2>/dev/null | tail -1 2>&1 | grep -o -E \"['][a-zA-Z0-9\#\_\ \.\+\-]+[']\" | sed -e \"s/'//g\" "
|
---|
232 | if [ "$sourcename" == "" ]
|
---|
233 | then
|
---|
234 | printprocesslog "INFO couldn't get sourcename ("$sourcename") from "$sourceposfile" for "$runnumber"_"$filenum
|
---|
235 | else
|
---|
236 | query="SELECT fSourceKey FROM Source WHERE fSourceName='"$sourcename"'"
|
---|
237 | sourcekey=`sendquery`
|
---|
238 | if [ "$sourcename" == "" ]
|
---|
239 | then
|
---|
240 | printprocesslog "WARN couldn't get sourcekey for source "$sourcename" from DB for "$runnumber"_"$filenum
|
---|
241 | fi
|
---|
242 | fi
|
---|
243 | fi
|
---|
244 | # set runtype to 'unknown', if no runtype could be retrieved from file
|
---|
245 | if [ "$runtype" == "" ]
|
---|
246 | then
|
---|
247 | runtype="n/a"
|
---|
248 | fi
|
---|
249 | # on 15.11.2011 the runtypes had different names
|
---|
250 | if [ "$date" == "2011/11/15" ]
|
---|
251 | then
|
---|
252 | if [ "$runtype" == "drs-calib" ]
|
---|
253 | then
|
---|
254 | runtype="drs-gain"
|
---|
255 | fi
|
---|
256 | if [ "$runtype" == "drs-time-calib" ]
|
---|
257 | then
|
---|
258 | runtype="drs-time"
|
---|
259 | fi
|
---|
260 | if [ "$runtype" == "pedestal" ]
|
---|
261 | then
|
---|
262 | runtype="drs-pedestal"
|
---|
263 | fi
|
---|
264 | if [ "$runtype" == "light-pulser" ]
|
---|
265 | then
|
---|
266 | runtype="light-pulser-ext"
|
---|
267 | fi
|
---|
268 | if [ "$runtype" == "pedestal-on" ]
|
---|
269 | then
|
---|
270 | runtype="pedestal"
|
---|
271 | fi
|
---|
272 | fi
|
---|
273 | # get runtype
|
---|
274 | query="SELECT fRunTypeKEY FROM RunType WHERE fRunTypeName='"$runtype"'"
|
---|
275 | result2=( `sendquery` )
|
---|
276 | if [ ${#result2} -eq 0 ]
|
---|
277 | then
|
---|
278 | printprocesslog "ERROR "$numberfromname": Could not query fRunTypeKey for runtype "$runtype" ."
|
---|
279 | continue
|
---|
280 | fi
|
---|
281 | runtypekey=${result2[0]}
|
---|
282 |
|
---|
283 | if [ "$doupdate" == "force" ]
|
---|
284 | then
|
---|
285 | # in newest data start time is in DATE-OBS
|
---|
286 | # in older data start time is in TSTART
|
---|
287 | # in the beginning TSTART was empty
|
---|
288 | #runstart=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep DATE-OBS | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
|
---|
289 | runstart=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep DATE-OBS | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
|
---|
290 | #runstart2=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep TSTART | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
|
---|
291 | runstart2=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep TSTART | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
|
---|
292 | if [ "$runstart" == "" ]
|
---|
293 | then
|
---|
294 | if [ "$runstart2" == "" ]
|
---|
295 | then
|
---|
296 | #runstart=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep DATE | grep -v 'DATE-' | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
|
---|
297 | runstart=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep DATE | grep -v 'DATE-' | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
|
---|
298 | else
|
---|
299 | runstart=$runstart2
|
---|
300 | fi
|
---|
301 | fi
|
---|
302 | # in newest data start time is in DATE-END
|
---|
303 | # in older data start time is in TSTOP
|
---|
304 | # in the beginning TSTOP was empty
|
---|
305 | #runstop=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep DATE-END | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
|
---|
306 | runstop=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep DATE-END | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
|
---|
307 | #runstop2=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep TSTOP | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
|
---|
308 | runstop2=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep TSTOP | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
|
---|
309 | if [ "$runstop" == "" ]
|
---|
310 | then
|
---|
311 | if [ "$runstop2" == "" ]
|
---|
312 | then
|
---|
313 | runstop=`stat $rawfile 2>/dev/null | grep Modify | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9][ ][0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{9}'`
|
---|
314 | else
|
---|
315 | runstop=$runstop2
|
---|
316 | fi
|
---|
317 | fi
|
---|
318 |
|
---|
319 | #numevents=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep Events | grep -E -o '[0-9]+'`
|
---|
320 | numevents=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep Events | grep -E -o '[0-9]+'`
|
---|
321 | #roi=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep NROI | grep -v NROITM | grep -E -o '[0-9]{1,4}'`
|
---|
322 | roi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep NROI | grep -v NROITM | grep -E -o '[0-9]{1,4}'`
|
---|
323 | #roitm=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep NROITM | grep -E -o '[0-9]{1,4}'`
|
---|
324 | roitm=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep NROITM | grep -E -o '[0-9]{1,4}'`
|
---|
325 | #numphys=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'NTRG ' | grep -E -o '[0-9]+'`
|
---|
326 | numphys=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'NTRG ' | grep -E -o '[0-9]+'`
|
---|
327 | #numext1=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'NTRGEXT1' | grep -E -o '[ ][0-9]+[ ]' | sed -e 's/\ //g'`
|
---|
328 | numext1=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'NTRGEXT1' | grep -E -o '[ ][0-9]+[ ]' | sed -e 's/\ //g'`
|
---|
329 | #numext2=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'NTRGEXT2' | grep -E -o '[ ][0-9]+[ ]' | sed -e 's/\ //g'`
|
---|
330 | numext2=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'NTRGEXT2' | grep -E -o '[ ][0-9]+[ ]' | sed -e 's/\ //g'`
|
---|
331 | #numelp=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'NTRGLPE' | grep -E -o '[0-9]+'`
|
---|
332 | numelp=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'NTRGLPE' | grep -E -o '[0-9]+'`
|
---|
333 | #numilp=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'NTRGLPI' | grep -E -o '[0-9]+'`
|
---|
334 | numilp=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'NTRGLPI' | grep -E -o '[0-9]+'`
|
---|
335 | #numoth=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'NTRGMISC' | grep -E -o '[0-9]+'`
|
---|
336 | numoth=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'NTRGMISC' | grep -E -o '[0-9]+'`
|
---|
337 | #numped=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'NTRGPED' | grep -E -o '[0-9]+'`
|
---|
338 | numped=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'NTRGPED' | grep -E -o '[0-9]+'`
|
---|
339 | #numtime=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'NTRGTIM' | grep -E -o '[0-9]+'`
|
---|
340 | numtime=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'NTRGTIM' | grep -E -o '[0-9]+'`
|
---|
341 | #compiled=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'COMPILED' | grep -E -o "['][a-zA-Z]+[ ][ 12][0-9][ ]20[0-9][0-9][ ][0-2][0-9]:[0-5][0-9]:[0-5][0-9][']" | sed -e "s/'//g"`
|
---|
342 | compiled=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'COMPILED' | grep -E -o "['][a-zA-Z]+[ ][ 12][0-9][ ]20[0-9][0-9][ ][0-2][0-9]:[0-5][0-9]:[0-5][0-9][']" | sed -e "s/'//g"`
|
---|
343 | if ! [ "$compiled" == "" ]
|
---|
344 | then
|
---|
345 | compiletime=`date +'%F %H:%M:%S' --date="${compiled}" `
|
---|
346 | else
|
---|
347 | compiletime=
|
---|
348 | fi
|
---|
349 | #revnum=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'REVISION' | grep -E -o "['][0-9]+[:]?[0-9]*[MSP]*[']" | sed -e "s/'//g"`
|
---|
350 | revnum=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'REVISION' | grep -E -o "['][0-9]+[:]?[0-9]*[MSP]*[']" | sed -e "s/'//g"`
|
---|
351 | # get checksums from header
|
---|
352 | #checksum=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep CHECKSUM | grep -E -o '[a-zA-Z0-9]{16}'`
|
---|
353 | checksum=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep CHECKSUM | grep -E -o '[a-zA-Z0-9]{16}'`
|
---|
354 | if [ "$checksum" == "" ]
|
---|
355 | then
|
---|
356 | printprocesslog "WARN checksum for file "$rawfile" is empty."
|
---|
357 | fi
|
---|
358 | #datasum=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep DATASUM | grep -E -o '[0-9]{1,10}'`
|
---|
359 | datasum=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep DATASUM | grep -E -o '[0-9]{1,10}'`
|
---|
360 | if [ "$datasum" == "" ]
|
---|
361 | then
|
---|
362 | printprocesslog "WARN datasum for file "$rawfile" is empty."
|
---|
363 | fi
|
---|
364 | # check if this run has drs file
|
---|
365 | # in case file is available, get STEP from header
|
---|
366 | # in the very beginning only drs-files were existing
|
---|
367 | # in the beginning the keywords DRSCALIB and STEP were not existing
|
---|
368 | drsfile=`echo $rawfile | sed -e 's/fits/drs.fits/'`
|
---|
369 | numdrsfiles=`ls $drsfile 2>/dev/null | wc -l`
|
---|
370 | #drscalib=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep DRSCALIB | grep -E -o "['][TF][']" | sed -e "s/'//g"`
|
---|
371 | drscalib=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep DRSCALIB | grep -E -o "[\ ][TF][\ ]" | sed -e "s/\ //g"`
|
---|
372 | if [ "$drscalib" == "T" ]
|
---|
373 | then
|
---|
374 | #step=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep DRSSTEP | grep -E -o "['][012][']" | sed -e "s/'//g"`
|
---|
375 | step=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep DRSSTEP | grep -E -o "[\ ][012][\ ]" | sed -e "s/\ //g"`
|
---|
376 | #stepfromdrs=`$factpath/fitsdump -h -t Events $drsfile 2>/dev/null | grep STEP | grep -E -o "['][012][']" | sed -e "s/'//g"`
|
---|
377 | stepfromdrs=`$factpath/fitsdump -h $drsfile 2>/dev/null | grep STEP | grep -E -o "[\ ][012][\ ]?" | sed -e "s/\ //g"`
|
---|
378 | if [ "$stepfromdrs" != "$step" ]
|
---|
379 | then
|
---|
380 | printprocesslog "ERROR for file "$rawfile" step from drsfile ("$stepfromdrs") and from file ("$step") do not agree."
|
---|
381 | if [ "$stepfromdrsfile" != "" ] && [ "$step" == "" ]
|
---|
382 | then
|
---|
383 | step=$stepfromdrsfile
|
---|
384 | printprocesslog "WARN setting drsstep from drsfile ("$stepfromdrs") although value differs from the one in file "$rawfile"."
|
---|
385 | fi
|
---|
386 | fi
|
---|
387 | if ! [ $numdrsfiles -eq 1 ]
|
---|
388 | then
|
---|
389 | printprocesslog "ERROR for file "$rawfile" number of drsfiles ("$numdrsfiles") and information from header ("$drscalib") don't agree."
|
---|
390 | fi
|
---|
391 | if [ "$step" = "" ]
|
---|
392 | then
|
---|
393 | printprocesslog "ERROR file "$rawfile" has drsfiles ("$numdrsfiles"), but step ("$step") is empty."
|
---|
394 | fi
|
---|
395 | else
|
---|
396 | if ! [ "$drscalib" == "F" ]
|
---|
397 | then
|
---|
398 | printprocesslog "WARN for file "$rawfile" DRSCALIB is neither T nor F."
|
---|
399 | fi
|
---|
400 | fi
|
---|
401 | fi
|
---|
402 |
|
---|
403 | # build query to update runinfo in DB
|
---|
404 | query="UPDATE RunInfo SET "
|
---|
405 |
|
---|
406 | # fill source key only if available
|
---|
407 | if ! [ "$sourcekey" = "" ]
|
---|
408 | then
|
---|
409 | query=$query" fSourceKey="$sourcekey", "
|
---|
410 | else
|
---|
411 | query=$query" fSourceKey=NULL, "
|
---|
412 | fi
|
---|
413 |
|
---|
414 | # get information from tracking
|
---|
415 | if [ -e $trackingfile ]
|
---|
416 | then
|
---|
417 | # get statistics
|
---|
418 | trackingstats=`$factpath/fitsdump $trackingfile -s -c Time -c Ra -c Dec -c Zd -c Az --filter='[1]<'${tstop}' && [1]>'${tstart} 2>/dev/null`
|
---|
419 | # RA
|
---|
420 | evaluatestatistics "Ra" $trackingstats
|
---|
421 | if [ "$evaluation" != "" ]
|
---|
422 | then
|
---|
423 | if [ "$min" == "$max" ]
|
---|
424 | then
|
---|
425 | query=$query" fRightAscension="$mean
|
---|
426 | else
|
---|
427 | query=$query" fRightAscension=NULL"
|
---|
428 | printprocesslog "WARN for $rawfile RA changes within run (min: "$min", max: "$max")."
|
---|
429 | fi
|
---|
430 | # Declination
|
---|
431 | evaluatestatistics "Dec" $trackingstats
|
---|
432 | if [ "$decmin" == "$decmax" ]
|
---|
433 | then
|
---|
434 | query=$query", fDeclination="$mean
|
---|
435 | else
|
---|
436 | query=$query", fDeclination=NULL"
|
---|
437 | printprocesslog "WARN for $rawfile declination changes within run (min: "$min", max: "$max")."
|
---|
438 | fi
|
---|
439 | else
|
---|
440 | query=$query" fRightAscension=NULL"
|
---|
441 | query=$query", fDeclination=NULL"
|
---|
442 | fi
|
---|
443 | # Zd
|
---|
444 | evaluatestatistics "Zd" $trackingstats
|
---|
445 | if [ "$evaluation" != "" ]
|
---|
446 | then
|
---|
447 | query=$query", fZenithDistanceMin="$min
|
---|
448 | query=$query", fZenithDistanceMean="$mean
|
---|
449 | query=$query", fZenithDistanceMax="$max
|
---|
450 | else
|
---|
451 | query=$query", fZenithDistanceMin=NULL"
|
---|
452 | query=$query", fZenithDistanceMean=NULL"
|
---|
453 | query=$query", fZenithDistanceMax=NULL"
|
---|
454 | fi
|
---|
455 | # Az
|
---|
456 | evaluatestatistics "Az" $trackingstats
|
---|
457 | if [ "$evaluation" != "" ]
|
---|
458 | then
|
---|
459 | query=$query", fAzimuthMin="$min
|
---|
460 | query=$query", fAzimuthMean="$mean
|
---|
461 | query=$query", fAzimuthMax="$max
|
---|
462 | else
|
---|
463 | query=$query", fAzimuthMin=NULL"
|
---|
464 | query=$query", fAzimuthMean=NULL"
|
---|
465 | query=$query", fAzimuthMax=NULL"
|
---|
466 | fi
|
---|
467 | else
|
---|
468 | query=$query" fRightAscension=NULL"
|
---|
469 | query=$query", fDeclination=NULL"
|
---|
470 | query=$query", fZenithDistanceMin=NULL"
|
---|
471 | query=$query", fZenithDistanceMean=NULL"
|
---|
472 | query=$query", fZenithDistanceMax=NULL"
|
---|
473 | query=$query", fAzimuthMin=NULL"
|
---|
474 | query=$query", fAzimuthMean=NULL"
|
---|
475 | query=$query", fAzimuthMax=NULL"
|
---|
476 | fi
|
---|
477 |
|
---|
478 | # get information from trigger
|
---|
479 | if [ -e $triggerratefile ]
|
---|
480 | then
|
---|
481 | # get statistics
|
---|
482 | triggerstats=`$factpath/fitsdump $triggerratefile -s -c Time -c TriggerRate --filter='[1]<'${tstop}' && [1]>'${tstart} 2>/dev/null`
|
---|
483 | evaluatestatistics "TriggerRate" $triggerstats
|
---|
484 | if [ "$evaluation" != "" ]
|
---|
485 | then
|
---|
486 | query=$query", fTriggerRateMedian="$med
|
---|
487 | else
|
---|
488 | query=$query", fTriggerRateMedian=NULL"
|
---|
489 | fi
|
---|
490 | else
|
---|
491 | query=$query", fTriggerRateMedian=NULL"
|
---|
492 | fi
|
---|
493 |
|
---|
494 | # get information from thresholds
|
---|
495 | if [ -e $thresholdfile ]
|
---|
496 | then
|
---|
497 | # get statistics
|
---|
498 | thresholdstats=`$factpath/fitsdump $thresholdfile -s -c Time -c PatchThresh --filter='[1]<'${tstop}' && [1]>'${tstart} 2>/dev/null`
|
---|
499 | evaluatestatistics "PatchThresh" $thresholdstats
|
---|
500 | if [ "$evaluation" = "" ]
|
---|
501 | then
|
---|
502 | thresholdstats=`$factpath/fitsdump $thresholdfile -s -c Time -c PatchThresh --filter='[1]<'${tstop}' && [1]>'${tstart2} 2>/dev/null`
|
---|
503 | #echo "$factpath/fitsdump $thresholdfile -s -c Time -c PatchThresh --filter='[1]<'${tstop}' && [1]>'${tstart2} 2>/dev/null"
|
---|
504 | evaluatestatistics "PatchThresh" $thresholdstats
|
---|
505 | fi
|
---|
506 | if [ "$evaluation" != "" ]
|
---|
507 | then
|
---|
508 | query=$query", fThresholdMedian="$med
|
---|
509 | else
|
---|
510 | query=$query", fThresholdMedian=NULL"
|
---|
511 | fi
|
---|
512 | else
|
---|
513 | query=$query", fThresholdMedian=NULL"
|
---|
514 | fi
|
---|
515 |
|
---|
516 | # get information from bias: U
|
---|
517 | if [ -e $biasvoltagefile ]
|
---|
518 | then
|
---|
519 | if [ $runnumber -gt 20120324 ]
|
---|
520 | then
|
---|
521 | biasstats=`$factpath/fitsdump $biasvoltagefile -s -c Time -c Uout --filter='[1]<'${tstop}' && [1]>'${tstart} 2>/dev/null`
|
---|
522 | evaluatestatistics "Uout" $biasstats
|
---|
523 | if [ "$evaluation" = "" ]
|
---|
524 | then
|
---|
525 | biasstats=`$factpath/fitsdump $biasvoltagefile -s -c Time -c Uout --filter='[1]<'${tstop}' && [1]>'${tstart2} 2>/dev/null`
|
---|
526 | evaluatestatistics "Uout" $biasstats
|
---|
527 | fi
|
---|
528 | else
|
---|
529 | biasstats=`$factpath/fitsdump $biasvoltagefile -s -c Time -c U --filter='[1]<'${tstop}' && [1]>'${tstart} 2>/dev/null`
|
---|
530 | evaluatestatistics "U" $biasstats
|
---|
531 | if [ "$evaluation" = "" ]
|
---|
532 | then
|
---|
533 | biasstats=`$factpath/fitsdump $biasvoltagefile -s -c Time -c U --filter='[1]<'${tstop}' && [1]>'${tstart2} 2>/dev/null`
|
---|
534 | evaluatestatistics "U" $biasstats
|
---|
535 | fi
|
---|
536 | fi
|
---|
537 | if [ "$evaluation" != "" ]
|
---|
538 | then
|
---|
539 | query=$query", fBiasVoltageMedian="$med
|
---|
540 | else
|
---|
541 | query=$query", fBiasVoltageMedian=NULL"
|
---|
542 | fi
|
---|
543 | else
|
---|
544 | query=$query", fBiasVoltageMedian=NULL"
|
---|
545 | fi
|
---|
546 | if [ "$doupdate" == "force" ]
|
---|
547 | then
|
---|
548 | query=$query", fRunStart='"$runstart"', fRunStop='"$runstop"'"
|
---|
549 | query=$query", fRunTypeKey="$runtypekey
|
---|
550 | if [ "$numevents" != "" ]
|
---|
551 | then
|
---|
552 | query=$query", fNumEvents="$numevents
|
---|
553 | fi
|
---|
554 | if [ "$roi" != "" ]
|
---|
555 | then
|
---|
556 | query=$query", fROI="$roi
|
---|
557 | fi
|
---|
558 | if [ "$roitm" != "" ]
|
---|
559 | then
|
---|
560 | query=$query", fROITimeMarker="$roitm
|
---|
561 | fi
|
---|
562 | if [ "$numphys" != "" ]
|
---|
563 | then
|
---|
564 | query=$query", fNumPhysicsTrigger="$numphys
|
---|
565 | fi
|
---|
566 | if [ "$numext1" != "" ]
|
---|
567 | then
|
---|
568 | query=$query", fNumExt1Trigger="$numext1
|
---|
569 | fi
|
---|
570 | if [ "$numext2" != "" ]
|
---|
571 | then
|
---|
572 | query=$query", fNumExt2Trigger="$numext2
|
---|
573 | fi
|
---|
574 | if [ "$numelp" != "" ]
|
---|
575 | then
|
---|
576 | query=$query", fNumELPTrigger="$numelp
|
---|
577 | fi
|
---|
578 | if [ "$numilp" != "" ]
|
---|
579 | then
|
---|
580 | query=$query", fNumILPTrigger="$numilp
|
---|
581 | fi
|
---|
582 | if [ "$numped" != "" ]
|
---|
583 | then
|
---|
584 | query=$query", fNumPedestalTrigger="$numped
|
---|
585 | fi
|
---|
586 | if [ "$numtime" != "" ]
|
---|
587 | then
|
---|
588 | query=$query", fNumTimeTrigger="$numtime
|
---|
589 | fi
|
---|
590 | if [ "$numoth" != "" ]
|
---|
591 | then
|
---|
592 | query=$query", fNumOtherTrigger="$numoth
|
---|
593 | fi
|
---|
594 | if [ "$checksum" != "" ]
|
---|
595 | then
|
---|
596 | query=$query", fCheckSum='"$checksum"'"
|
---|
597 | fi
|
---|
598 | if [ "$datasum" != "" ]
|
---|
599 | then
|
---|
600 | query=$query", fDataSum='"$datasum"'"
|
---|
601 | fi
|
---|
602 | if [ "$numdrsfiles" != "" ]
|
---|
603 | then
|
---|
604 | query=$query", fHasDrsFile="$numdrsfiles
|
---|
605 | fi
|
---|
606 | if [ "$step" != "" ]
|
---|
607 | then
|
---|
608 | query=$query", fDrsStep="$step
|
---|
609 | fi
|
---|
610 | if [ "$compiletime" != "" ]
|
---|
611 | then
|
---|
612 | query=$query", fCompileTime='"$compiletime"'"
|
---|
613 | fi
|
---|
614 | if [ "$revnum" != "" ]
|
---|
615 | then
|
---|
616 | query=$query", fRevisionNumber='"$revnum"'"
|
---|
617 | fi
|
---|
618 | fi
|
---|
619 |
|
---|
620 |
|
---|
621 | # add where condition
|
---|
622 | query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
|
---|
623 |
|
---|
624 | # send query to DB
|
---|
625 | sendquery >/dev/null
|
---|
626 | done
|
---|
627 | done
|
---|
628 |
|
---|
629 | finish
|
---|
630 |
|
---|
631 |
|
---|