source: trunk/DataCheck/Processing/FillAuxCurrents.sh@ 19042

Last change on this file since 19042 was 18708, checked in by Daniela Dorner, 8 years ago
avoid warnings for missing files for the first few days; fixed bug in finding start and stop time; improved logging
  • Property svn:executable set to *
File size: 9.7 KB
Line 
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
5if [ "$doupdate" = "" ]
6then
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)
9fi
10
11source `dirname $0`/../Sourcefile.sh
12printprocesslog "INFO starting $0 with option doupdate="$doupdate
13
14logfile=$runlogpath"/FillCurrents-"$datetime".log"
15date >> $logfile
16
17# setup to use ftools
18source $HEADAS/headas-init.sh
19
20# check if software is available
21if ! ls $factpath/fitsdump >/dev/null 2>&1
22then
23 printprocesslog "ERROR "$factpath"/fitsdump is not available."
24 finish
25fi
26
27# get dates
28if [ "$certaindate" != "" ]
29then
30 getdates $certaindate
31else
32 # get all night
33 #getdates "all"
34 # get last 6 nights
35 getdates 6
36fi
37
38
39
40printprocesslog "INFO processing the following night(s): "${dates[@]}
41echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
42
43cd $mars
44
45# do filling of aux data
46for date in ${dates[@]}
47do
48 auxdir=$auxdata/$date
49 runnumber=`echo $date | sed -e 's/\///g'`
50
51 #if [ $runnumber -lt 20130301 ]
52 #then
53 # continue
54 #fi
55
56 # get file numbers from DB
57 # but only for not-corrupted files
58 query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
59 if [ "$doupdate" = "no" ]
60 then
61 query=$query" AND ISNULL(fCurrentsMedMean) "
62 fi
63 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
64 filenumbers=( `sendquery $query` )
65 # proceed only if there are files available
66 if [ ${#filenumbers} -eq 0 ]
67 then
68 printprocesslog "INFO No files found in the DB for night "$date
69 continue
70 fi
71
72 # check if aux files are available from that night
73 if ! [ -d $auxdir ]
74 then
75 printprocesslog "INFO no data available in "$auxdir
76 continue
77 else
78 printprocesslog "INFO processing files in "$auxdir
79 fi
80
81 biasvoltagefile=$auxdir/$runnumber.BIAS_CONTROL_VOLTAGE.fits
82 if ! [ -e $biasvoltagefile ]
83 then
84 printprocesslog "WARN "$biasvoltagefile" not found."
85 continue
86 else
87 biasnumerrors=`fverify $biasvoltagefile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
88 if [ $biasnumerrors -gt 0 ]
89 then
90 printprocesslog "WARN for $biasvoltagefile fverify returned "$biasnumerrors" error(s)."
91 fi
92 fi
93
94 biascurrentfile=$auxdir/$runnumber.BIAS_CONTROL_CURRENT.fits
95 if ! [ -e $biascurrentfile ]
96 then
97 printprocesslog "WARN "$biascurrentfile" not found."
98 continue
99 else
100 biascurrnumerrors=`fverify $biascurrentfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
101 if [ $biascurrnumerrors -gt 0 ]
102 then
103 printprocesslog "WARN for $biascurrentfile fverify returned "$biascurrnumerrors" error(s)."
104 fi
105 fi
106
107 # this file is needed for the calibration of the currents
108 feedbackcalfile=$auxdir/$runnumber.FEEDBACK_CALIBRATION.fits
109 if ! [ -e $feedbackcalfile ]
110 then
111 printprocesslog "WARN "$feedbackcalfile" not found."
112 continue
113 else
114 feedbacknumerrors=`fverify $feedbackcalfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
115 if [ $feedbacknumerrors -gt 0 ]
116 then
117 printprocesslog "WARN for $feedbackcalfile fverify returned "$feedbacknumerrors" error(s)."
118 fi
119 fi
120
121 calcurrentsfile=$auxdir/$runnumber.FEEDBACK_CALIBRATED_CURRENTS.fits
122 if ! [ -e $calcurrentsfile ]
123 then
124 calcurrentsfile=/gpfs/scratch/fact/calibrated_currents/$runnumber.CALIBRATED_CURRENTS.fits
125 if ! [ -e $calcurrentsfile ]
126 then
127 printprocesslog "INFO run calibrate.C for night "$runnumber >> $logfile 2>&1
128 root -q -b -l fact/processing/calibrate.C\($runnumber\)
129 fi
130 fi
131 printprocesslog "INFO using calibrated currents from file "$calcurrentsfile
132
133 #calcurrentsfile=$auxdir/$runnumber.FEEDBACK_CALIBRATED_CURRENTS.fits
134 #calcurrentsfile=/scratch_nfs/calibrated_currents/$runnumber.CALIBRATED_CURRENTS.fits
135 #calcurrentsfile=/gpfs/scratch/fact/calibrated_currents/$runnumber.CALIBRATED_CURRENTS.fits
136 if ! [ -e $calcurrentsfile ]
137 then
138 printprocesslog "WARN "$calcurrentsfile" not found."
139 continue
140 else
141 calnumerrors=`fverify $calcurrentsfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
142 if [ $calnumerrors -gt 0 ]
143 then
144 printprocesslog "WARN for $calcurrentsfile fverify returned "$calnumerrors" error(s)."
145 fi
146 fi
147
148 # fill auxiliary information for files
149 for filenum in ${filenumbers[@]}
150 do
151 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
152 echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
153 # get information from rawfile
154 rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.fz
155 if ! [ -e $rawfile ]
156 then
157 if [ $runnumber -lt $checknight ]
158 then
159 printprocesslog "WARN "$rawfile" not found."
160 else
161 printprocesslog "INFO "$rawfile" not found."
162 fi
163 continue
164 fi
165 runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
166 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
167 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
168 tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '[0-9][.][0-9]+([E][\-][0-9][0-9])?' | sed -e 's/[E]+*/\\*10\\^/'`
169 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
170 tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '[0-9][.][0-9]+([E][\-][0-9][0-9])?' | sed -e 's/[E]+*/\\*10\\^/'`
171 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
172 then
173 printprocesslog "WARN "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
174 continue
175 fi
176 # assuming that at least TSTARTI and TSTOPI are consistent
177 if [ $tstarti -gt 30000 ]
178 then
179 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
180 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
181 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
182 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
183 else
184 tstart=`echo " $tstarti + $tstartf " | bc -l`
185 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
186 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
187 tstop=`echo " $tstopi + $tstopf " | bc -l`
188 fi
189
190 # build query to update runinfo in DB
191 query="UPDATE RunInfo SET "
192
193 # get information from fsc: T[31]
194 if [ -e $calcurrentsfile ] && [ $calnumerrors -eq 0 ]
195 then
196 currents=( `root -q -b -l fact/processing/currents.C\("\"$calcurrentsfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[-]?[0-9]+[.]?[0-9]*'` )
197 if [ "${currents[0]}" == "" ]
198 then
199 query=$query"fCurrentsMedMean=NULL"
200 else
201 query=$query"fCurrentsMedMean="${currents[0]}
202 fi
203 if [ "${currents[1]}" == "" ]
204 then
205 query=$query", fCurrentsMedRms=NULL"
206 else
207 query=$query", fCurrentsMedRms="${currents[1]}
208 fi
209 if [ "${currents[2]}" == "" ]
210 then
211 query=$query", fCurrentsDevMean=NULL"
212 else
213 query=$query", fCurrentsDevMean="${currents[2]}
214 fi
215 if [ "${currents[3]}" == "" ]
216 then
217 query=$query", fCurrentsDevRms=NULL"
218 else
219 query=$query", fCurrentsDevRms="${currents[3]}
220 fi
221 if [ "${currents[4]}" == "" ]
222 then
223 query=$query", fCurrentsMedMeanBeg=NULL"
224 else
225 query=$query", fCurrentsMedMeanBeg="${currents[4]}
226 fi
227 if [ "${currents[5]}" == "" ]
228 then
229 query=$query", fCurrentsMedMeanEnd=NULL"
230 else
231 query=$query", fCurrentsMedMeanEnd="${currents[5]}
232 fi
233 if [ "${currents[6]}" == "" ]
234 then
235 query=$query", fCurrentsDiffToPrediction=NULL"
236 else
237 query=$query", fCurrentsDiffToPrediction="${currents[6]}
238 fi
239 if [ "${currents[7]}" == "" ]
240 then
241 query=$query", fCurrentsRelDiffToPrediction=NULL"
242 else
243 query=$query", fCurrentsRelDiffToPrediction="${currents[7]}
244 fi
245 if [ "${currents[8]}" == "" ]
246 then
247 query=$query", fCurrentsLineRms=NULL"
248 else
249 query=$query", fCurrentsLineRms="${currents[8]}
250 fi
251 if [ "${currents[9]}" == "" ]
252 then
253 query=$query", fCurrentsRelLineRms=NULL"
254 else
255 query=$query", fCurrentsRelLineRms="${currents[9]}
256 fi
257 else
258 query=$query" fCurrentsMedMean=NULL"
259 query=$query", fCurrentsMedRms=NULL"
260 query=$query", fCurrentsDevMean=NULL"
261 query=$query", fCurrentsDevRms=NULL"
262 query=$query", fCurrentsMedMeanBeg=NULL"
263 query=$query", fCurrentsMedMeanEnd=NULL"
264 query=$query", fCurrentsDiffToPrediction=NULL"
265 query=$query", fCurrentsRelDiffToPrediction=NULL"
266 query=$query", fCurrentsLineRms=NULL"
267 query=$query", fCurrentsRelLineRms=NULL"
268 fi
269
270 # add where condition
271 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
272
273 # send query to DB
274 sendquery >/dev/null
275 done
276done
277
278finish
279
280
Note: See TracBrowser for help on using the repository browser.