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