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

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