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

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