source: trunk/DataCheck/Processing/FillDrsTemp.sh@ 17050

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