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

Last change on this file since 14835 was 14833, checked in by Daniela Dorner, 12 years ago
added (script to check some auxiliary files, to calibrate currents and to fill currents to DB
  • Property svn:executable set to *
File size: 7.3 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"/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 )
29dates=( `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
30printprocesslog "INFO processing the following night(s): "${dates[@]}
31echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
32
33echo ${dates[@]}
34
35cd $mars
36
37# do filling of aux data
38for date in ${dates[@]}
39do
40 auxdir=$auxdata/$date
41 runnumber=`echo $date | sed -e 's/\///g'`
42 #if [ $runnumber -lt 20120301 ]
43 #then
44 # continue
45 #fi
46 #if [ $runnumber -gt 20120714 ]
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 echo "run calibrate.C for night "$runnumber
100 root -q -b -l fact/calibrate.C\($runnumber\)
101
102 calcurrentsfile=$auxdir/$runnumber.CALIBRATED_CURRENTS.fits
103 calcurrentsfile=/scratch_nfs/calibrated_currents/$runnumber.CALIBRATED_CURRENTS.fits
104 if ! [ -e $calcurrentsfile ]
105 then
106 printprocesslog "WARN "$calcurrentsfile" not found."
107 continue
108 else
109 calnumerrors=`fverify $calcurrentsfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
110 if [ $calnumerrors -gt 0 ]
111 then
112 printprocesslog "WARN for $calcurrentsfile fverify returned "$calnumerrors" error(s)."
113 fi
114 fi
115
116
117 # get file numbers from DB
118 # but only for not-corrupted files
119 query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
120 if [ "$doupdate" = "no" ]
121 then
122 query=$query" AND ISNULL(fCurrentsMean) "
123 fi
124
125 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
126 filenumbers=( `sendquery $query` )
127 if [ ${#filenumbers} -eq 0 ]
128 then
129 printprocesslog "INFO No files found in the DB for night "$date
130 continue
131 fi
132
133 # fill auxiliary information for files
134 for filenum in ${filenumbers[@]}
135 do
136 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
137 echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
138 # get information from rawfile
139 rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.gz
140 if ! [ -e $rawfile ]
141 then
142 printprocesslog "ERROR: "$rawfile" not found."
143 continue
144 fi
145 runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
146 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
147 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
148 tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
149 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
150 tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '0[.][0-9]+'`
151 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
152 then
153 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
154 continue
155 fi
156 # assuming that at least TSTARTI and TSTOPI are consistent
157 #echo $rawfile
158 #echo $tstarti
159 #echo $tstopi
160 #echo $tstartf
161 #echo $tstopf
162 if [ $tstarti -gt 30000 ]
163 then
164 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
165 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
166 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
167 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
168 else
169 tstart=`echo " $tstarti + $tstartf " | bc -l`
170 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
171 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
172 tstop=`echo " $tstopi + $tstopf " | bc -l`
173 fi
174
175 # build query to update runinfo in DB
176 query="UPDATE RunInfo SET "
177
178 # get information from fsc: T[31]
179 if [ -e $calcurrentsfile ] && [ $calnumerrors -eq 0 ]
180 then
181 currents=( `root -q -b -l fact/curavg.C\("\"$calcurrentsfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
182 if [ "${currents[0]}" == "" ]
183 then
184 query=$query"fCurrentsMean=NULL"
185 else
186 query=$query"fCurrentsMean="${currents[0]}
187 fi
188 if [ "${currents[1]}" == "" ]
189 then
190 query=$query", fCurrentsRms=NULL"
191 else
192 query=$query", fCurrentsRms="${currents[1]}
193 fi
194 else
195 query=$query" fCurrentsMean=NULL"
196 query=$query", fCurrentsRms=NULL"
197 fi
198
199 # add where condition
200 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
201
202 echo $query
203 # send query to DB
204 sendquery >/dev/null
205 done
206done
207
208finish
209
210
Note: See TracBrowser for help on using the repository browser.