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