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

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