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

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