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

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