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

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