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

Last change on this file since 17120 was 17090, checked in by Daniela Dorner, 11 years ago
new macro paths, usage of getdates function, prepared script to be used in RunMoreNights.sh, minor logging changes
  • Property svn:executable set to *
File size: 7.5 KB
Line 
1#!/bin/bash
2
3# option whether to fill all row or only those where information is missing
4# $doupdate might be given as environment variable
5if [ "$doupdate" = "" ]
6then
7 doupdate="yes" # update all entries (needed when new fields have been added)
8 doupdate="no" # fill only entries which are not yet existing (default)
9fi
10
11source `dirname $0`/../Sourcefile.sh
12printprocesslog "INFO starting $0 with option doupdate="$doupdate
13
14logfile=$runlogpath"/FillDrsTemp-"$datetime".log"
15date >> $logfile
16
17# setup to use ftools
18source $HEADAS/headas-init.sh
19
20# check if software is available
21if ! ls $factpath/fitsdump >/dev/null 2>&1
22then
23 printprocesslog "ERROR "$factpath"/fitsdump is not available."
24 finish
25fi
26
27# get dates
28if [ "$certaindate" != "" ]
29then
30 getdates $certaindate
31else
32 # get all night
33 #getdates "all"
34 # get last 6 nights
35 getdates 6
36fi
37
38
39printprocesslog "INFO processing the following night(s): "${dates[@]}
40echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
41
42#echo ${dates[@]}
43
44cd $mars
45
46# do filling of aux data
47for date in ${dates[@]}
48do
49 auxdir=$auxdata/$date
50 runnumber=`echo $date | sed -e 's/\///g'`
51 if [ $runnumber -lt 20120328 ]
52 then
53 continue
54 fi
55 #echo $auxdir" @ "`date`
56
57 # check if aux files are available from that night
58 if ! [ -d $auxdir ]
59 then
60 printprocesslog "INFO no data available in "$auxdir
61 continue
62 else
63 printprocesslog "INFO processing files in "$auxdir
64 fi
65
66 # get file numbers from DB
67 # but only for not-corrupted files
68 query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
69 if [ "$doupdate" = "no" ]
70 then
71 query=$query" AND ISNULL(fCameraTempMean) "
72 fi
73
74 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
75 filenumbers=( `sendquery $query` )
76 if [ ${#filenumbers} -eq 0 ]
77 then
78 printprocesslog "INFO No files found in the DB for night "$date
79 continue
80 fi
81
82 magicweatherfile=$auxdir/$runnumber.MAGIC_WEATHER_DATA.fits
83 if ! [ -e $magicweatherfile ]
84 then
85 printprocesslog "WARN "$magicweatherfile" not found."
86 echo "WARN "$magicweatherfile" not found."
87 else
88 weathernumerrors=`fverify $magicweatherfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
89 if [ $weathernumerrors -gt 0 ]
90 then
91 printprocesslog "WARN for $magicweatherfile fverify returned "$weathernumerrors" error(s)."
92 fi
93 fi
94
95 drstempfile=$auxdir/$runnumber.FAD_CONTROL_TEMPERATURE.fits
96 if ! [ -e $drstempfile ]
97 then
98 printprocesslog "WARN "$drstempfile" not found."
99 echo "WARN "$drstempfile" not found."
100 else
101 tempnumerrors=`fverify $drstempfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
102 if [ $tempnumerrors -gt 0 ]
103 then
104 printprocesslog "WARN for "$drstempfile" fverify returned "$tempnumerrors" error(s)."
105 fi
106 fi
107
108 # fill auxiliary information for files
109 for filenum in ${filenumbers[@]}
110 do
111 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
112 echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
113 # get information from rawfile
114 rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.gz
115 if ! [ -e $rawfile ]
116 then
117 printprocesslog "ERROR: "$rawfile" not found."
118 continue
119 fi
120 #checkfitsfile=`fverify $rawfile 2>/dev/null | grep '0 error(s)'`
121 #if [ "$checkfitsfile" == "" ]
122 #then
123 # numfitserrors=1
124 # printprocesslog "WARN: "$rawfile" probably corrupted."
125 # continue
126 #fi
127 runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
128 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
129 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
130 tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
131 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
132 tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '0[.][0-9]+'`
133 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
134 then
135 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
136 continue
137 fi
138 # assuming that at least TSTARTI and TSTOPI are consistent
139 #echo $rawfile
140 #echo $tstarti
141 #echo $tstopi
142 #echo $tstartf
143 #echo $tstopf
144 if [ $tstarti -gt 30000 ]
145 then
146 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
147 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
148 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
149 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
150 else
151 tstart=`echo " $tstarti + $tstartf " | bc -l`
152 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
153 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
154 tstop=`echo " $tstopi + $tstopf " | bc -l`
155 fi
156
157 # build query to update runinfo in DB
158 query="UPDATE RunInfo SET "
159
160 # get information from fsc: T[31]
161 if [ -e $drstempfile ] && [ $tempnumerrors -eq 0 ]
162 then
163 drstemps=( `root -q -b -l fact/processing/drstemp.C\("\"$drstempfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
164 if [ "${drstemps[0]}" == "" ]
165 then
166 query=$query"fDrsTempMinMean=NULL"
167 else
168 query=$query"fDrsTempMinMean="${drstemps[0]}
169 fi
170 if [ "${drstemps[1]}" == "" ]
171 then
172 query=$query", fDrsTempMaxMean=NULL"
173 else
174 query=$query", fDrsTempMaxMean="${drstemps[1]}
175 fi
176 if [ "${drstemps[2]}" == "" ]
177 then
178 query=$query", fDrsTempMinRmsMean=NULL"
179 else
180 query=$query", fDrsTempMinRmsMean="${drstemps[2]}
181 fi
182 if [ "${drstemps[3]}" == "" ]
183 then
184 query=$query", fDrsTempMaxRmsMean=NULL"
185 else
186 query=$query", fDrsTempMaxRmsMean="${drstemps[3]}
187 fi
188 else
189 query=$query" fDrsTempMinMean=NULL"
190 query=$query", fDrsTempMaxMean=NULL"
191 query=$query", fDrsTempMinRmsMean=NULL"
192 query=$query", fDrsTempMaxRmsMean=NULL"
193 fi
194 #fCameraTempMeanRms: mean of rms of single sensors
195
196 # get information from weather: T
197 if [ -e $magicweatherfile ] && [ $weathernumerrors -eq 0 ]
198 then
199 mtemps=( `root -q -b -l fact/processing/magictemp.C\("\"$magicweatherfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
200 if [ "${mtemps[0]}" == "" ]
201 then
202 query=$query", fOutsideTempMean=NULL"
203 else
204 query=$query", fOutsideTempMean="${mtemps[0]}
205 fi
206 if [ "${mtemps[1]}" == "" ]
207 then
208 query=$query", fOutsideTempRms=NULL"
209 else
210 query=$query", fOutsideTempRms="${mtemps[1]}
211 fi
212 else
213 query=$query", fOutsideTempMean=NULL"
214 query=$query", fOutsideTempRms=NULL"
215 fi
216
217 # add where condition
218 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
219
220 #echo $query
221 # send query to DB
222 sendquery >/dev/null
223 done
224done
225
226finish
227
228
Note: See TracBrowser for help on using the repository browser.