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