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

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