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

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