source: trunk/DataCheck/Processing/FillAuxData.sh@ 18770

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