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 | pwfile=`dirname $0`/.pw
|
---|
79 | password=`cat $pwfile 2>/dev/null`
|
---|
80 | if [ "$password" == "" ]
|
---|
81 | then
|
---|
82 | echo "please insert password in $pwfile"
|
---|
83 | printprocesslog "ERROR password for DB access in $pwfile missing"
|
---|
84 | finish
|
---|
85 | fi
|
---|
86 |
|
---|
87 | # check if software is available
|
---|
88 | if ! ls $factpath/fitsdump >/dev/null 2>&1
|
---|
89 | then
|
---|
90 | printprocesslog "ERROR "$factpath"/fitsdump is not available."
|
---|
91 | finish
|
---|
92 | fi
|
---|
93 |
|
---|
94 |
|
---|
95 | # get last 3 nights
|
---|
96 | dates=( `date +%Y/%m/%d --date="-12hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-60hour"` )
|
---|
97 | #dates=( `find $ziprawdata -mindepth 3 -type d | sort | sed "s/\${ziprawdata_for_sed}//g" | sed -e 's/^\///'` ) #all available dates in /loc_data/zipraw
|
---|
98 | printprocesslog "INFO processing the following night(s): "${dates[@]}
|
---|
99 | echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
|
---|
100 |
|
---|
101 | # do filling of aux data
|
---|
102 | for date in ${dates[@]}
|
---|
103 | do
|
---|
104 | auxdir=$auxdata/$date
|
---|
105 | runnumber=`echo $date | sed -e 's/\///g'`
|
---|
106 |
|
---|
107 | # check if aux files are available from that night
|
---|
108 | if ! [ -d $auxdir ]
|
---|
109 | then
|
---|
110 | printprocesslog "INFO no data available in "$auxdir
|
---|
111 | continue
|
---|
112 | else
|
---|
113 | printprocesslog "INFO processing files in "$auxdir
|
---|
114 | fi
|
---|
115 |
|
---|
116 | # get file numbers from DB
|
---|
117 | # but only for not-corrupted files
|
---|
118 | query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
|
---|
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 | else
|
---|
133 | tracknumerrors=`fverify $trackingfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
---|
134 | if [ $tracknumerrors -gt 0 ]
|
---|
135 | then
|
---|
136 | printprocesslog "WARN for $trackingfile fverify returned "$tracknumerrors" error(s)."
|
---|
137 | fi
|
---|
138 | fi
|
---|
139 |
|
---|
140 | triggerratefile=$auxdir/$runnumber.FTM_CONTROL_TRIGGER_RATES.fits
|
---|
141 | if ! [ -e $triggerratefile ]
|
---|
142 | then
|
---|
143 | printprocesslog "WARN "$triggerratefile" not found."
|
---|
144 | else
|
---|
145 | trignumerrors=`fverify $triggerratefile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
---|
146 | if [ $trignumerrors -gt 0 ]
|
---|
147 | then
|
---|
148 | printprocesslog "WARN for $triggerratefile fverify returned "$trignumerrors" error(s)."
|
---|
149 | fi
|
---|
150 | fi
|
---|
151 |
|
---|
152 | thresholdfile=$auxdir/$runnumber.FTM_CONTROL_STATIC_DATA.fits
|
---|
153 | if ! [ -e $thresholdfile ]
|
---|
154 | then
|
---|
155 | printprocesslog "WARN "$thresholdfile" not found."
|
---|
156 | else
|
---|
157 | treshnumerrors=`fverify $thresholdfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
---|
158 | if [ $treshnumerrors -gt 0 ]
|
---|
159 | then
|
---|
160 | printprocesslog "WARN for $thresholdfile fverify returned "$treshnumerrors" error(s)."
|
---|
161 | fi
|
---|
162 | fi
|
---|
163 |
|
---|
164 | biasvoltagefile=$auxdir/$runnumber.BIAS_CONTROL_VOLTAGE.fits
|
---|
165 | if ! [ -e $biasvoltagefile ]
|
---|
166 | then
|
---|
167 | printprocesslog "WARN "$biasvoltagefile" not found."
|
---|
168 | else
|
---|
169 | biasnumerrors=`fverify $biasvoltagefile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
---|
170 | if [ $biasnumerrors -gt 0 ]
|
---|
171 | then
|
---|
172 | printprocesslog "WARN for $biasvoltagefile fverify returned "$biasnumerrors" error(s)."
|
---|
173 | fi
|
---|
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 | # get information from rawfile
|
---|
182 | rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.gz
|
---|
183 | if ! [ -e $rawfile ]
|
---|
184 | then
|
---|
185 | printprocesslog "ERROR: "$rawfile" not found."
|
---|
186 | continue
|
---|
187 | fi
|
---|
188 | #checkfitsfile=`fverify $rawfile 2>/dev/null | grep '0 error(s)'`
|
---|
189 | #if [ "$checkfitsfile" == "" ]
|
---|
190 | #then
|
---|
191 | # numfitserrors=1
|
---|
192 | # printprocesslog "WARN: "$rawfile" probably corrupted."
|
---|
193 | # continue
|
---|
194 | #fi
|
---|
195 | runtype=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
|
---|
196 | mjdrefraw=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
|
---|
197 | tstarti=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
|
---|
198 | tstartf=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
|
---|
199 | tstopi=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
|
---|
200 | tstopf=`$factpath/fitsdump -h -t Events $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '0[.][0-9]+'`
|
---|
201 | if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
|
---|
202 | then
|
---|
203 | printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
|
---|
204 | continue
|
---|
205 | fi
|
---|
206 | # assuming that at least TSTARTI and TSTOPI are consistent
|
---|
207 | #echo $rawfile
|
---|
208 | #echo $tstarti
|
---|
209 | #echo $tstopi
|
---|
210 | #echo $tstartf
|
---|
211 | #echo $tstopf
|
---|
212 | if [ $tstarti -gt 30000 ]
|
---|
213 | then
|
---|
214 | tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
|
---|
215 | tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
|
---|
216 | #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
|
---|
217 | tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
|
---|
218 | else
|
---|
219 | tstart=`echo " $tstarti + $tstartf " | bc -l`
|
---|
220 | tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
|
---|
221 | #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
|
---|
222 | tstop=`echo " $tstopi + $tstopf " | bc -l`
|
---|
223 | fi
|
---|
224 | #echo $tstart
|
---|
225 | #echo $tstop
|
---|
226 | #if [ $runnumber -eq 20111123 ]
|
---|
227 | #then
|
---|
228 | # # add mjdref for days were aux files were inconsistent
|
---|
229 | # tstart=`echo " $tstart + $mjdref " | bc -l`
|
---|
230 | # tstart2=`echo " $tstart2 + $mjdref " | bc -l`
|
---|
231 | # tstop=`echo " $tstop + $mjdref " | bc -l`
|
---|
232 | #fi
|
---|
233 |
|
---|
234 | # build query to update runinfo in DB
|
---|
235 | query="UPDATE RunInfo SET "
|
---|
236 |
|
---|
237 | # get information from tracking
|
---|
238 | if [ -e $trackingfile ] && [ $tracknumerrors -eq 0 ]
|
---|
239 | then
|
---|
240 | # RA
|
---|
241 | getfitsstatistics $trackingfile "Ra" $tstart $tstop
|
---|
242 | if [ "$min" == "$max" ] && [ $good -gt 0 ]
|
---|
243 | then
|
---|
244 | query=$query" fRightAscension="$mean
|
---|
245 | else
|
---|
246 | query=$query" fRightAscension=NULL"
|
---|
247 | if [ $good -gt 0 ]
|
---|
248 | then
|
---|
249 | printprocesslog "WARN for $rawfile RA changes within run (min: "$min", max: "$max")."
|
---|
250 | fi
|
---|
251 | fi
|
---|
252 | # Declination
|
---|
253 | getfitsstatistics $trackingfile "Dec" $tstart $tstop
|
---|
254 | if [ "$decmin" == "$decmax" ] && [ $good -gt 0 ]
|
---|
255 | then
|
---|
256 | query=$query", fDeclination="$mean
|
---|
257 | else
|
---|
258 | query=$query", fDeclination=NULL"
|
---|
259 | if [ $good -gt 0 ]
|
---|
260 | then
|
---|
261 | printprocesslog "WARN for $rawfile declination changes within run (min: "$min", max: "$max")."
|
---|
262 | fi
|
---|
263 | fi
|
---|
264 | # Zd
|
---|
265 | getfitsstatistics $trackingfile "Zd" $tstart $tstop
|
---|
266 | if [ $good -gt 0 ]
|
---|
267 | then
|
---|
268 | query=$query", fZenithDistanceMin="$min
|
---|
269 | query=$query", fZenithDistanceMean="$mean
|
---|
270 | query=$query", fZenithDistanceMax="$max
|
---|
271 | else
|
---|
272 | query=$query", fZenithDistanceMin=NULL"
|
---|
273 | query=$query", fZenithDistanceMean=NULL"
|
---|
274 | query=$query", fZenithDistanceMax=NULL"
|
---|
275 | fi
|
---|
276 | # Az
|
---|
277 | getfitsstatistics $trackingfile "Az" $tstart $tstop
|
---|
278 | if [ $good -gt 0 ]
|
---|
279 | then
|
---|
280 | query=$query", fAzimuthMin="$min
|
---|
281 | query=$query", fAzimuthMean="$mean
|
---|
282 | query=$query", fAzimuthMax="$max
|
---|
283 | else
|
---|
284 | query=$query", fAzimuthMin=NULL"
|
---|
285 | query=$query", fAzimuthMean=NULL"
|
---|
286 | query=$query", fAzimuthMax=NULL"
|
---|
287 | fi
|
---|
288 | else
|
---|
289 | query=$query" fRightAscension=NULL"
|
---|
290 | query=$query", fDeclination=NULL"
|
---|
291 | query=$query", fZenithDistanceMin=NULL"
|
---|
292 | query=$query", fZenithDistanceMean=NULL"
|
---|
293 | query=$query", fZenithDistanceMax=NULL"
|
---|
294 | query=$query", fAzimuthMin=NULL"
|
---|
295 | query=$query", fAzimuthMean=NULL"
|
---|
296 | query=$query", fAzimuthMax=NULL"
|
---|
297 | fi
|
---|
298 |
|
---|
299 | # get information from trigger
|
---|
300 | if [ -e $triggerratefile ] && [ $trignumerrors -eq 0 ]
|
---|
301 | then
|
---|
302 | #echo " $triggerratefile TriggerRate $tstart $tstop"
|
---|
303 | getfitsstatistics $triggerratefile "TriggerRate" $tstart $tstop
|
---|
304 | # if [ "$mjdreftrig" == "" ]
|
---|
305 | # then
|
---|
306 | # 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]*'`
|
---|
307 | # 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]*'`
|
---|
308 | # 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]*'`
|
---|
309 | # 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]*'`
|
---|
310 | # else
|
---|
311 | # 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]*'`
|
---|
312 | # 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]*'`
|
---|
313 | # 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]*'`
|
---|
314 | # 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]*'`
|
---|
315 | # fi
|
---|
316 | if [ $good -gt 0 ]
|
---|
317 | then
|
---|
318 | query=$query", fTriggerRateMedian="$median
|
---|
319 | else
|
---|
320 | query=$query", fTriggerRateMedian=NULL"
|
---|
321 | fi
|
---|
322 | else
|
---|
323 | query=$query", fTriggerRateMedian=NULL"
|
---|
324 | fi
|
---|
325 |
|
---|
326 | # get information from thresholds
|
---|
327 | if [ -e $thresholdfile ] && [ $treshnumerrors -eq 0 ]
|
---|
328 | then
|
---|
329 | getfitsstatistics $thresholdfile "PatchThresh" $tstart $tstop
|
---|
330 | if [ $good -eq 0 ]
|
---|
331 | then
|
---|
332 | getfitsstatistics $thresholdfile "PatchThresh" $tstart2 $tstop
|
---|
333 | fi
|
---|
334 | if [ $good -gt 0 ]
|
---|
335 | then
|
---|
336 | query=$query", fThresholdMedian="$median
|
---|
337 | else
|
---|
338 | query=$query", fThresholdMedian=NULL"
|
---|
339 | fi
|
---|
340 | else
|
---|
341 | query=$query", fThresholdMedian=NULL"
|
---|
342 | fi
|
---|
343 |
|
---|
344 | # get information from bias: U
|
---|
345 | if [ -e $biasvoltagefile ] && [ $biasnumerrors -eq 0 ]
|
---|
346 | then
|
---|
347 | getfitsstatistics $biasvoltagefile "U" $tstart $tstop
|
---|
348 | if [ $good -eq 0 ]
|
---|
349 | then
|
---|
350 | getfitsstatistics $biasvoltagefile "U" $tstart2 $tstop
|
---|
351 | fi
|
---|
352 | if [ $good -gt 0 ]
|
---|
353 | then
|
---|
354 | query=$query", fBiasVoltageMedian="$median
|
---|
355 | else
|
---|
356 | query=$query", fBiasVoltageMedian=NULL"
|
---|
357 | fi
|
---|
358 | else
|
---|
359 | query=$query", fBiasVoltageMedian=NULL"
|
---|
360 | fi
|
---|
361 |
|
---|
362 | # add where condition
|
---|
363 | query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
|
---|
364 |
|
---|
365 | # send query to DB
|
---|
366 | sendquery >/dev/null
|
---|
367 | done
|
---|
368 | done
|
---|
369 |
|
---|
370 | finish
|
---|
371 |
|
---|
372 |
|
---|