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

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