1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # option whether to fill all row or only those where information is missing
|
---|
4 | # $doupdate might be given as environment variable
|
---|
5 | if [ "$doupdate" = "" ]
|
---|
6 | then
|
---|
7 | doupdate="yes" # update all entries (needed when new fields have been added)
|
---|
8 | doupdate="no" # fill only entries which are not yet existing (default)
|
---|
9 | fi
|
---|
10 |
|
---|
11 | source `dirname $0`/../Sourcefile.sh
|
---|
12 | printprocesslog "INFO starting $0 with option doupdate="$doupdate
|
---|
13 |
|
---|
14 | logfile=$runlogpath"/EffectiveOn-"$datetime".log"
|
---|
15 | date >> $logfile
|
---|
16 |
|
---|
17 | # setup to use ftools
|
---|
18 | source $HEADAS/headas-init.sh
|
---|
19 |
|
---|
20 | # check if software is available
|
---|
21 | if ! ls $factpath/fitsdump >/dev/null 2>&1
|
---|
22 | then
|
---|
23 | printprocesslog "ERROR "$factpath"/fitsdump is not available."
|
---|
24 | finish
|
---|
25 | fi
|
---|
26 |
|
---|
27 | # get dates
|
---|
28 | if [ "$certaindate" != "" ]
|
---|
29 | then
|
---|
30 | getdates $certaindate
|
---|
31 | else
|
---|
32 | # get all night
|
---|
33 | #getdates "all"
|
---|
34 | # get last 6 nights
|
---|
35 | getdates 6
|
---|
36 | fi
|
---|
37 |
|
---|
38 |
|
---|
39 | printprocesslog "INFO processing the following night(s): "${dates[@]}
|
---|
40 | echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
|
---|
41 |
|
---|
42 | cd $mars
|
---|
43 |
|
---|
44 | # do filling of aux data
|
---|
45 | for date in ${dates[@]}
|
---|
46 | do
|
---|
47 | auxdir=$auxdata/$date
|
---|
48 | runnumber=`echo $date | sed -e 's/\///g'`
|
---|
49 |
|
---|
50 | # if [ $runnumber -lt 20130301 ]
|
---|
51 | # then
|
---|
52 | # continue
|
---|
53 | # fi
|
---|
54 | # echo $auxdir" @ "`date`
|
---|
55 |
|
---|
56 | # check if aux files are available from that night
|
---|
57 | if ! [ -d $auxdir ]
|
---|
58 | then
|
---|
59 | printprocesslog "INFO no data available in "$auxdir
|
---|
60 | continue
|
---|
61 | else
|
---|
62 | printprocesslog "INFO processing files in "$auxdir
|
---|
63 | fi
|
---|
64 |
|
---|
65 | ftmcontrolfile=$auxdir/$runnumber.FTM_CONTROL_TRIGGER_RATES.fits
|
---|
66 | if ! [ -e $ftmcontrolfile ]
|
---|
67 | then
|
---|
68 | printprocesslog "WARN "$ftmcontrolfile" not found."
|
---|
69 | continue
|
---|
70 | else
|
---|
71 | ftmnumerrors=`fverify $ftmcontrolfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
---|
72 | if [ $ftmnumerrors -gt 0 ]
|
---|
73 | then
|
---|
74 | printprocesslog "WARN for $ftmcontrolfile fverify returned "$ftmnumerrors" error(s)."
|
---|
75 | fi
|
---|
76 | fi
|
---|
77 |
|
---|
78 | # get file numbers from DB
|
---|
79 | # but only for not-corrupted files
|
---|
80 | query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
|
---|
81 | if [ "$doupdate" = "no" ]
|
---|
82 | then
|
---|
83 | query=$query" AND ISNULL(fEffectiveOn) "
|
---|
84 | fi
|
---|
85 |
|
---|
86 | printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
|
---|
87 | filenumbers=( `sendquery $query` )
|
---|
88 | if [ ${#filenumbers} -eq 0 ]
|
---|
89 | then
|
---|
90 | printprocesslog "INFO No files found in the DB for night "$date
|
---|
91 | continue
|
---|
92 | fi
|
---|
93 |
|
---|
94 | # fill auxiliary information for files
|
---|
95 | for filenum in ${filenumbers[@]}
|
---|
96 | do
|
---|
97 | printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
|
---|
98 | echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
|
---|
99 | # get information from rawfile
|
---|
100 | rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.gz
|
---|
101 | if ! [ -e $rawfile ]
|
---|
102 | then
|
---|
103 | printprocesslog "ERROR: "$rawfile" not found."
|
---|
104 | continue
|
---|
105 | fi
|
---|
106 | runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
|
---|
107 | mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
|
---|
108 | tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
|
---|
109 | tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
|
---|
110 | tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
|
---|
111 | tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '0[.][0-9]+'`
|
---|
112 | if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
|
---|
113 | then
|
---|
114 | printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
|
---|
115 | continue
|
---|
116 | fi
|
---|
117 | # assuming that at least TSTARTI and TSTOPI are consistent
|
---|
118 | #echo $rawfile
|
---|
119 | #echo $tstarti
|
---|
120 | #echo $tstopi
|
---|
121 | #echo $tstartf
|
---|
122 | #echo $tstopf
|
---|
123 | if [ $tstarti -gt 30000 ]
|
---|
124 | then
|
---|
125 | tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
|
---|
126 | tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
|
---|
127 | #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
|
---|
128 | tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
|
---|
129 | else
|
---|
130 | tstart=`echo " $tstarti + $tstartf " | bc -l`
|
---|
131 | tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
|
---|
132 | #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
|
---|
133 | tstop=`echo " $tstopi + $tstopf " | bc -l`
|
---|
134 | fi
|
---|
135 |
|
---|
136 | # build query to update runinfo in DB
|
---|
137 | query="UPDATE RunInfo SET "
|
---|
138 |
|
---|
139 | # get information from fsc: T[31]
|
---|
140 | if [ -e $ftmcontrolfile ] && [ $ftmnumerrors -eq 0 ]
|
---|
141 | then
|
---|
142 | effectiveon=( `root -q -b -l fact/processing/ontime.C\("\"$ftmcontrolfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
|
---|
143 | if [ "${effectiveon[0]}" == "" ]
|
---|
144 | then
|
---|
145 | query=$query"fEffectiveOn=NULL"
|
---|
146 | else
|
---|
147 | query=$query"fEffectiveOn="${effectiveon[0]}
|
---|
148 | fi
|
---|
149 | if [ "${effectiveon[1]}" == "" ]
|
---|
150 | then
|
---|
151 | query=$query", fEffectiveOnRms=NULL"
|
---|
152 | else
|
---|
153 | query=$query", fEffectiveOnRms="${effectiveon[1]}
|
---|
154 | fi
|
---|
155 | if [ "${effectiveon[2]}" == "" ]
|
---|
156 | then
|
---|
157 | query=$query", fOnTime=NULL"
|
---|
158 | else
|
---|
159 | query=$query", fOnTime="${effectiveon[2]}
|
---|
160 | fi
|
---|
161 | if [ "${effectiveon[3]}" == "" ]
|
---|
162 | then
|
---|
163 | query=$query", fTriggerRateTimeOver100=NULL"
|
---|
164 | else
|
---|
165 | query=$query", fTriggerRateTimeOver100="${effectiveon[3]}
|
---|
166 | fi
|
---|
167 | if [ "${effectiveon[4]}" == "" ]
|
---|
168 | then
|
---|
169 | query=$query", fTriggerRateTimeOver125=NULL"
|
---|
170 | else
|
---|
171 | query=$query", fTriggerRateTimeOver125="${effectiveon[4]}
|
---|
172 | fi
|
---|
173 | if [ "${effectiveon[5]}" == "" ]
|
---|
174 | then
|
---|
175 | query=$query", fTriggerRateTimeOver150=NULL"
|
---|
176 | else
|
---|
177 | query=$query", fTriggerRateTimeOver150="${effectiveon[5]}
|
---|
178 | fi
|
---|
179 | if [ "${effectiveon[6]}" == "" ]
|
---|
180 | then
|
---|
181 | query=$query", fTriggerRateTimeOver175=NULL"
|
---|
182 | else
|
---|
183 | query=$query", fTriggerRateTimeOver175="${effectiveon[6]}
|
---|
184 | fi
|
---|
185 | if [ "${effectiveon[7]}" == "" ]
|
---|
186 | then
|
---|
187 | query=$query", fTriggerRateRms=NULL"
|
---|
188 | else
|
---|
189 | query=$query", fTriggerRateRms="${effectiveon[7]}
|
---|
190 | fi
|
---|
191 | else
|
---|
192 | query=$query" fEffectiveOn=NULL"
|
---|
193 | query=$query", fEffectiveOnRms=NULL"
|
---|
194 | query=$query", fOnTime=NULL"
|
---|
195 | query=$query", fTriggerRateTimeOver100=NULL"
|
---|
196 | query=$query", fTriggerRateTimeOver125=NULL"
|
---|
197 | query=$query", fTriggerRateTimeOver150=NULL"
|
---|
198 | query=$query", fTriggerRateTimeOver175=NULL"
|
---|
199 | query=$query", fTriggerRateRms=NULL"
|
---|
200 |
|
---|
201 | fi
|
---|
202 |
|
---|
203 | # add where condition
|
---|
204 | query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
|
---|
205 |
|
---|
206 | #send query to DB
|
---|
207 | sendquery >/dev/null
|
---|
208 |
|
---|
209 | done
|
---|
210 | done
|
---|
211 |
|
---|
212 | finish
|
---|
213 |
|
---|
214 |
|
---|