1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # missing:
|
---|
4 | # vferify of files
|
---|
5 | # only treat file if it is there
|
---|
6 |
|
---|
7 | # mjd of 1970-01-01
|
---|
8 | # needed in this script as for 1 day the mjd in the aux files are inconsistent
|
---|
9 | # mjdref=40587
|
---|
10 |
|
---|
11 | # known:
|
---|
12 | # 2011/11/22 MJDREF in DRIVE empty, Time > 55000
|
---|
13 | # 2011/11/23 MJDREF in DRIVE not empty, Time > 55000
|
---|
14 | # 2011/11/24 MJDREF in DRIVE not empty, Time > 15000
|
---|
15 | # raw files
|
---|
16 | # 2011/11/21 no MJDREF
|
---|
17 | # 2011/11/22 MJDREF
|
---|
18 | # further things: https://www.fact-project.org/logbook/showthread.php?tid=67
|
---|
19 |
|
---|
20 | # trigger rate has as first value -1, but with using the median it should be fine
|
---|
21 |
|
---|
22 | # option
|
---|
23 | doupdate="yes" # update all entries (needed when new fields have been added)
|
---|
24 | doupdate="no" # fill only entries which are not yet existing (default)
|
---|
25 |
|
---|
26 | source `dirname $0`/Sourcefile.sh
|
---|
27 | printprocesslog "INFO starting $0 with option doupdate="$doupdate
|
---|
28 |
|
---|
29 | logfile=$runlogpath"/FillAuxLP-"$datetime".log"
|
---|
30 | date >> $logfile
|
---|
31 |
|
---|
32 | function getfitsstatistics()
|
---|
33 | {
|
---|
34 | # $1 filename
|
---|
35 | # $2 colname
|
---|
36 | # $3 tstart
|
---|
37 | # $4 tstop
|
---|
38 | good=
|
---|
39 | min=
|
---|
40 | mean=
|
---|
41 | median=
|
---|
42 | max=
|
---|
43 | tmpfile=`dirname $0`/`basename $1`.tmp
|
---|
44 | echo "ftcopy $1'[col Time]' - | ftstat - | grep 'mean' | grep -E -o [0-9]+[.] | sed -e 's/[.]//g'" >> $logfile
|
---|
45 | timefromfile=`ftcopy $1'[col Time]' - 2>>$logfile | ftstat - 2>>$logfile | grep 'mean' | grep -E -o [0-9]+[.] | sed -e 's/[.]//g'`
|
---|
46 | if [ $timefromfile -gt 30000 ]
|
---|
47 | then
|
---|
48 | echo "ftcopy $1'[Time - 40587> '${3}' && Time - 40587< '${4}' ][col '${2}';Time]' - | ftcopy -'[col '${2}']' - | ftstat -" >> $logfile
|
---|
49 | #ftcopy $1'[Time - 40587> '${3}' && Time - 40587< '${4}' ][col '${2}';Time]' - | ftcopy -'[col '${2}']' - | ftstat -
|
---|
50 | ftcopy $1'[Time - 40587> '${3}' && Time - 40587< '${4}' ][col '${2}';Time]' - 2>>$logfile | ftcopy -'[col '${2}']' - 2>>$logfile | ftstat - 2>>$logfile > $tmpfile
|
---|
51 | else
|
---|
52 | echo "ftcopy $1'[Time> '${3}' && Time< '${4}' ][col '${2}';Time]' - | ftcopy -'[col '${2}']' - | ftstat -" >> $logfile
|
---|
53 | #ftcopy $1'[Time> '${3}' && Time< '${4}' ][col '${2}';Time]' - | ftcopy -'[col '${2}']' - | ftstat -
|
---|
54 | ftcopy $1'[Time> '${3}' && Time< '${4}' ][col '${2}';Time]' - 2>>$logfile | ftcopy -'[col '${2}']' - 2>>$logfile | ftstat - 2>>$logfile > $tmpfile
|
---|
55 | fi
|
---|
56 | good=`cat $tmpfile | grep 'good' | grep -E -o '[-]?[0-9]+[.]?[0-9]*'`
|
---|
57 | min=`cat $tmpfile | grep 'min' | grep -E -o '[-]?[0-9]+[.]?[0-9]*'`
|
---|
58 | mean=`cat $tmpfile | grep 'mean' | grep -E -o '[-]?[0-9]+[.]?[0-9]*'`
|
---|
59 | median=`cat $tmpfile | grep 'median' | grep -E -o '[-]?[0-9]+[.]?[0-9]*'`
|
---|
60 | max=`cat $tmpfile | grep 'max' | grep -E -o '[-]?[0-9]+[.]?[0-9]*'`
|
---|
61 | if [ "$good" = "" ]
|
---|
62 | then
|
---|
63 | printprocesslog "WARN couldn't get statistics from file $1 for run $date $file"
|
---|
64 | rm $tmpfile
|
---|
65 | finish
|
---|
66 | fi
|
---|
67 | #echo "good: "$good
|
---|
68 | #echo "min: "$min
|
---|
69 | #echo "max: "$max
|
---|
70 | #echo "mean: "$max
|
---|
71 | #echo "median: "$max
|
---|
72 | rm $tmpfile
|
---|
73 | }
|
---|
74 |
|
---|
75 | # setup to use ftools
|
---|
76 | source $HEADAS/headas-init.sh
|
---|
77 |
|
---|
78 | # check if software is available
|
---|
79 | if ! ls $factpath/fitsdump >/dev/null 2>&1
|
---|
80 | then
|
---|
81 | printprocesslog "ERROR "$factpath"/fitsdump is not available."
|
---|
82 | finish
|
---|
83 | fi
|
---|
84 |
|
---|
85 |
|
---|
86 | # get last 3 nights
|
---|
87 | dates=( `date +%Y/%m/%d --date="-12hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-60hour"` )
|
---|
88 | #dates=( `find $ziprawdata -mindepth 3 -type d | sort | sed "s/\${ziprawdata_for_sed}//g" | sed -e 's/^\///'` ) #all available dates in /loc_data/zipraw
|
---|
89 | printprocesslog "INFO processing the following night(s): "${dates[@]}
|
---|
90 | echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
|
---|
91 |
|
---|
92 | # do filling of aux data
|
---|
93 | for date in ${dates[@]}
|
---|
94 | do
|
---|
95 | auxdir=$auxdata/$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 | # get file numbers from DB
|
---|
108 | # but only for not-corrupted files
|
---|
109 | query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
|
---|
110 | printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
|
---|
111 | filenumbers=( `sendquery $query` )
|
---|
112 | if [ ${#filenumbers} -eq 0 ]
|
---|
113 | then
|
---|
114 | printprocesslog "INFO No files found in the DB for night "$date
|
---|
115 | continue
|
---|
116 | fi
|
---|
117 |
|
---|
118 | # get daily fits files
|
---|
119 | trackingfile=$auxdir/$runnumber.DRIVE_CONTROL_TRACKING_POSITION.fits
|
---|
120 | if ! [ -e $trackingfile ]
|
---|
121 | then
|
---|
122 | printprocesslog "WARN "$trackingfile" not found."
|
---|
123 | else
|
---|
124 | tracknumerrors=`fverify $trackingfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
---|
125 | if [ $tracknumerrors -gt 0 ]
|
---|
126 | then
|
---|
127 | printprocesslog "WARN for $trackingfile fverify returned "$tracknumerrors" error(s)."
|
---|
128 | fi
|
---|
129 | fi
|
---|
130 |
|
---|
131 | triggerratefile=$auxdir/$runnumber.FTM_CONTROL_TRIGGER_RATES.fits
|
---|
132 | if ! [ -e $triggerratefile ]
|
---|
133 | then
|
---|
134 | printprocesslog "WARN "$triggerratefile" not found."
|
---|
135 | else
|
---|
136 | trignumerrors=`fverify $triggerratefile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
---|
137 | if [ $trignumerrors -gt 0 ]
|
---|
138 | then
|
---|
139 | printprocesslog "WARN for $triggerratefile fverify returned "$trignumerrors" error(s)."
|
---|
140 | fi
|
---|
141 | fi
|
---|
142 |
|
---|
143 | thresholdfile=$auxdir/$runnumber.FTM_CONTROL_STATIC_DATA.fits
|
---|
144 | if ! [ -e $thresholdfile ]
|
---|
145 | then
|
---|
146 | printprocesslog "WARN "$thresholdfile" not found."
|
---|
147 | else
|
---|
148 | treshnumerrors=`fverify $thresholdfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
---|
149 | if [ $treshnumerrors -gt 0 ]
|
---|
150 | then
|
---|
151 | printprocesslog "WARN for $thresholdfile fverify returned "$treshnumerrors" error(s)."
|
---|
152 | fi
|
---|
153 | fi
|
---|
154 |
|
---|
155 | biasvoltagefile=$auxdir/$runnumber.BIAS_CONTROL_VOLTAGE.fits
|
---|
156 | if ! [ -e $biasvoltagefile ]
|
---|
157 | then
|
---|
158 | printprocesslog "WARN "$biasvoltagefile" not found."
|
---|
159 | else
|
---|
160 | biasnumerrors=`fverify $biasvoltagefile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
---|
161 | if [ $biasnumerrors -gt 0 ]
|
---|
162 | then
|
---|
163 | printprocesslog "WARN for $biasvoltagefile fverify returned "$biasnumerrors" error(s)."
|
---|
164 | fi
|
---|
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 | # get information from rawfile
|
---|
173 | rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.gz
|
---|
174 | if ! [ -e $rawfile ]
|
---|
175 | then
|
---|
176 | printprocesslog "ERROR: "$rawfile" not found."
|
---|
177 | continue
|
---|
178 | fi
|
---|
179 | #checkfitsfile=`fverify $rawfile 2>/dev/null | grep '0 error(s)'`
|
---|
180 | #if [ "$checkfitsfile" == "" ]
|
---|
181 | #then
|
---|
182 | # numfitserrors=1
|
---|
183 | # printprocesslog "WARN: "$rawfile" probably corrupted."
|
---|
184 | # continue
|
---|
185 | #fi
|
---|
186 | runtype=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
|
---|
187 | mjdrefraw=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
|
---|
188 | tstarti=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
|
---|
189 | tstartf=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
|
---|
190 | tstopi=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
|
---|
191 | tstopf=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '0[.][0-9]+'`
|
---|
192 | if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
|
---|
193 | then
|
---|
194 | printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
|
---|
195 | continue
|
---|
196 | fi
|
---|
197 | # assuming that at least TSTARTI and TSTOPI are consistent
|
---|
198 | #echo $rawfile
|
---|
199 | #echo $tstarti
|
---|
200 | #echo $tstopi
|
---|
201 | #echo $tstartf
|
---|
202 | #echo $tstopf
|
---|
203 | if [ $tstarti -gt 30000 ]
|
---|
204 | then
|
---|
205 | tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
|
---|
206 | tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
|
---|
207 | #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
|
---|
208 | tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
|
---|
209 | else
|
---|
210 | tstart=`echo " $tstarti + $tstartf " | bc -l`
|
---|
211 | tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
|
---|
212 | #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
|
---|
213 | tstop=`echo " $tstopi + $tstopf " | bc -l`
|
---|
214 | fi
|
---|
215 | #echo $tstart
|
---|
216 | #echo $tstop
|
---|
217 | #if [ $runnumber -eq 20111123 ]
|
---|
218 | #then
|
---|
219 | # # add mjdref for days were aux files were inconsistent
|
---|
220 | # tstart=`echo " $tstart + $mjdref " | bc -l`
|
---|
221 | # tstart2=`echo " $tstart2 + $mjdref " | bc -l`
|
---|
222 | # tstop=`echo " $tstop + $mjdref " | bc -l`
|
---|
223 | #fi
|
---|
224 |
|
---|
225 | # build query to update runinfo in DB
|
---|
226 | query="UPDATE RunInfo SET "
|
---|
227 |
|
---|
228 | # get information from tracking
|
---|
229 | if [ -e $trackingfile ] && [ $tracknumerrors -eq 0 ]
|
---|
230 | then
|
---|
231 | # RA
|
---|
232 | getfitsstatistics $trackingfile "Ra" $tstart $tstop
|
---|
233 | if [ "$min" == "$max" ] && [ $good -gt 0 ]
|
---|
234 | then
|
---|
235 | query=$query" fRightAscension="$mean
|
---|
236 | else
|
---|
237 | query=$query" fRightAscension=NULL"
|
---|
238 | if [ $good -gt 0 ]
|
---|
239 | then
|
---|
240 | printprocesslog "WARN for $rawfile RA changes within run (min: "$min", max: "$max")."
|
---|
241 | fi
|
---|
242 | fi
|
---|
243 | # Declination
|
---|
244 | getfitsstatistics $trackingfile "Dec" $tstart $tstop
|
---|
245 | if [ "$decmin" == "$decmax" ] && [ $good -gt 0 ]
|
---|
246 | then
|
---|
247 | query=$query", fDeclination="$mean
|
---|
248 | else
|
---|
249 | query=$query", fDeclination=NULL"
|
---|
250 | if [ $good -gt 0 ]
|
---|
251 | then
|
---|
252 | printprocesslog "WARN for $rawfile declination changes within run (min: "$min", max: "$max")."
|
---|
253 | fi
|
---|
254 | fi
|
---|
255 | # Zd
|
---|
256 | getfitsstatistics $trackingfile "Zd" $tstart $tstop
|
---|
257 | if [ $good -gt 0 ]
|
---|
258 | then
|
---|
259 | query=$query", fZenithDistanceMin="$min
|
---|
260 | query=$query", fZenithDistanceMean="$mean
|
---|
261 | query=$query", fZenithDistanceMax="$max
|
---|
262 | else
|
---|
263 | query=$query", fZenithDistanceMin=NULL"
|
---|
264 | query=$query", fZenithDistanceMean=NULL"
|
---|
265 | query=$query", fZenithDistanceMax=NULL"
|
---|
266 | fi
|
---|
267 | # Az
|
---|
268 | getfitsstatistics $trackingfile "Az" $tstart $tstop
|
---|
269 | if [ $good -gt 0 ]
|
---|
270 | then
|
---|
271 | query=$query", fAzimuthMin="$min
|
---|
272 | query=$query", fAzimuthMean="$mean
|
---|
273 | query=$query", fAzimuthMax="$max
|
---|
274 | else
|
---|
275 | query=$query", fAzimuthMin=NULL"
|
---|
276 | query=$query", fAzimuthMean=NULL"
|
---|
277 | query=$query", fAzimuthMax=NULL"
|
---|
278 | fi
|
---|
279 | else
|
---|
280 | query=$query" fRightAscension=NULL"
|
---|
281 | query=$query", fDeclination=NULL"
|
---|
282 | query=$query", fZenithDistanceMin=NULL"
|
---|
283 | query=$query", fZenithDistanceMean=NULL"
|
---|
284 | query=$query", fZenithDistanceMax=NULL"
|
---|
285 | query=$query", fAzimuthMin=NULL"
|
---|
286 | query=$query", fAzimuthMean=NULL"
|
---|
287 | query=$query", fAzimuthMax=NULL"
|
---|
288 | fi
|
---|
289 |
|
---|
290 | # get information from trigger
|
---|
291 | if [ -e $triggerratefile ] && [ $trignumerrors -eq 0 ]
|
---|
292 | then
|
---|
293 | #echo " $triggerratefile TriggerRate $tstart $tstop"
|
---|
294 | getfitsstatistics $triggerratefile "TriggerRate" $tstart $tstop
|
---|
295 | # if [ "$mjdreftrig" == "" ]
|
---|
296 | # then
|
---|
297 | # ratemin=`ftcopy $triggerratefile'[Time> '${tstart}' && Time< '${tstop}' && TriggerRate!=-1][col TriggerRate;Time]' - | ftcopy -'[col TriggerRate]' - | ftstat - | grep 'min' | grep -E -o '[0-9]+[.]?[0-9]*'`
|
---|
298 | # ratemax=`ftcopy $triggerratefile'[Time> '${tstart}' && Time< '${tstop}' && TriggerRate!=-1][col TriggerRate;Time]' - | ftcopy -'[col TriggerRate]' - | ftstat - | grep 'max' | grep -E -o '[0-9]+[.]?[0-9]*'`
|
---|
299 | # ratemean=`ftcopy $triggerratefile'[Time> '${tstart}' && Time< '${tstop}' && TriggerRate!=-1][col TriggerRate;Time]' - | ftcopy -'[col TriggerRate]' - | ftstat - | grep 'mean' | grep -E -o '[0-9]+[.]?[0-9]*'`
|
---|
300 | # ratemedian=`ftcopy $triggerratefile'[Time> '${tstart}' && Time< '${tstop}' && TriggerRate!=-1][col TriggerRate;Time]' - | ftcopy -'[col TriggerRate]' - | ftstat - | grep 'median' | grep -E -o '[0-9]+[.]?[0-9]*'`
|
---|
301 | # else
|
---|
302 | # ratemin=`ftcopy $triggerratefile'[Time> '${tstart}' && Time< '${tstop}' && TriggerRate!=-1][col TriggerRate;Time]' - | ftcopy -'[col TriggerRate]' - | ftstat - | grep 'min' | grep -E -o '[0-9]+[.]?[0-9]*'`
|
---|
303 | # ratemax=`ftcopy $triggerratefile'[Time> '${tstart}' && Time< '${tstop}' && TriggerRate!=-1][col TriggerRate;Time]' - | ftcopy -'[col TriggerRate]' - | ftstat - | grep 'max' | grep -E -o '[0-9]+[.]?[0-9]*'`
|
---|
304 | # ratemean=`ftcopy $triggerratefile'[Time> '${tstart}' && Time< '${tstop}' && TriggerRate!=-1][col TriggerRate;Time]' - | ftcopy -'[col TriggerRate]' - | ftstat - | grep 'mean' | grep -E -o '[0-9]+[.]?[0-9]*'`
|
---|
305 | # ratemedian=`ftcopy $triggerratefile'[Time> '${tstart}' && Time< '${tstop}' && TriggerRate!=-1][col TriggerRate;Time]' - | ftcopy -'[col TriggerRate]' - | ftstat - | grep 'median' | grep -E -o '[0-9]+[.]?[0-9]*'`
|
---|
306 | # fi
|
---|
307 | if [ $good -gt 0 ]
|
---|
308 | then
|
---|
309 | query=$query", fTriggerRateMedian="$median
|
---|
310 | else
|
---|
311 | query=$query", fTriggerRateMedian=NULL"
|
---|
312 | fi
|
---|
313 | else
|
---|
314 | query=$query", fTriggerRateMedian=NULL"
|
---|
315 | fi
|
---|
316 |
|
---|
317 | # get information from thresholds
|
---|
318 | if [ -e $thresholdfile ] && [ $treshnumerrors -eq 0 ]
|
---|
319 | then
|
---|
320 | getfitsstatistics $thresholdfile "PatchThresh" $tstart $tstop
|
---|
321 | if [ $good -eq 0 ]
|
---|
322 | then
|
---|
323 | getfitsstatistics $thresholdfile "PatchThresh" $tstart2 $tstop
|
---|
324 | fi
|
---|
325 | if [ $good -gt 0 ]
|
---|
326 | then
|
---|
327 | query=$query", fThresholdMedian="$median
|
---|
328 | else
|
---|
329 | query=$query", fThresholdMedian=NULL"
|
---|
330 | fi
|
---|
331 | else
|
---|
332 | query=$query", fThresholdMedian=NULL"
|
---|
333 | fi
|
---|
334 |
|
---|
335 | # get information from bias: U
|
---|
336 | if [ -e $biasvoltagefile ] && [ $biasnumerrors -eq 0 ]
|
---|
337 | then
|
---|
338 | getfitsstatistics $biasvoltagefile "U" $tstart $tstop
|
---|
339 | if [ $good -eq 0 ]
|
---|
340 | then
|
---|
341 | getfitsstatistics $biasvoltagefile "U" $tstart2 $tstop
|
---|
342 | fi
|
---|
343 | if [ $good -gt 0 ]
|
---|
344 | then
|
---|
345 | query=$query", fBiasVoltageMedian="$median
|
---|
346 | else
|
---|
347 | query=$query", fBiasVoltageMedian=NULL"
|
---|
348 | fi
|
---|
349 | else
|
---|
350 | query=$query", fBiasVoltageMedian=NULL"
|
---|
351 | fi
|
---|
352 |
|
---|
353 | # add where condition
|
---|
354 | query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
|
---|
355 |
|
---|
356 | # send query to DB
|
---|
357 | sendquery >/dev/null
|
---|
358 | done
|
---|
359 | done
|
---|
360 |
|
---|
361 | finish
|
---|
362 |
|
---|
363 |
|
---|