source: branches/trigger_burst_research/Processing/FillAuxData.sh@ 19344

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