source: trunk/DataCheck/Processing/FillAuxTemp.sh@ 17892

Last change on this file since 17892 was 17597, checked in by Daniela Dorner, 11 years ago
give warning about missing files only when runinfo in DB available
  • Property svn:executable set to *
File size: 7.3 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"/FillAuxTemp-"$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
38printprocesslog "INFO processing the following night(s): "${dates[@]}
39echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
40
41cd $mars
42
43# do filling of aux data
44for date in ${dates[@]}
45do
46 auxdir=$auxdata/$date
47 runnumber=`echo $date | sed -e 's/\///g'`
48 if [ $runnumber -lt 20120328 ]
49 then
50 continue
51 fi
52
53 # check if aux files are available from that night
54 if ! [ -d $auxdir ]
55 then
56 printprocesslog "INFO no data available in "$auxdir
57 continue
58 else
59 printprocesslog "INFO processing files in "$auxdir
60 fi
61
62 # get file numbers from DB
63 # but only for not-corrupted files
64 query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
65 if [ "$doupdate" = "no" ]
66 then
67 query=$query" AND ISNULL(fCameraTempMean) "
68 fi
69 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
70 filenumbers=( `sendquery $query` )
71 # proceed only if there are files available
72 if [ ${#filenumbers} -eq 0 ]
73 then
74 printprocesslog "INFO No files found in the DB for night "$date
75 continue
76 fi
77
78 magicweatherfile=$auxdir/$runnumber.MAGIC_WEATHER_DATA.fits
79 if ! [ -e $magicweatherfile ]
80 then
81 printprocesslog "WARN "$magicweatherfile" not found."
82 echo "WARN "$magicweatherfile" not found."
83 else
84 weathernumerrors=`fverify $magicweatherfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
85 if [ $weathernumerrors -gt 0 ]
86 then
87 printprocesslog "WARN for $magicweatherfile fverify returned "$weathernumerrors" error(s)."
88 fi
89 fi
90
91 fsctempfile=$auxdir/$runnumber.FSC_CONTROL_TEMPERATURE.fits
92 if ! [ -e $fsctempfile ]
93 then
94 printprocesslog "WARN "$fsctempfile" not found."
95 echo "WARN "$fsctempfile" not found."
96 else
97 tempnumerrors=`fverify $fsctempfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
98 if [ $tempnumerrors -gt 0 ]
99 then
100 printprocesslog "WARN for $fsctempfile fverify returned "$tempnumerrors" error(s)."
101 fi
102 fi
103
104 # fill auxiliary information for files
105 for filenum in ${filenumbers[@]}
106 do
107 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
108 echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
109 # get information from rawfile
110 rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.fz
111 if ! [ -e $rawfile ]
112 then
113 printprocesslog "ERROR: "$rawfile" not found."
114 continue
115 fi
116 #checkfitsfile=`fverify $rawfile 2>/dev/null | grep '0 error(s)'`
117 #if [ "$checkfitsfile" == "" ]
118 #then
119 # numfitserrors=1
120 # printprocesslog "WARN: "$rawfile" probably corrupted."
121 # continue
122 #fi
123 runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
124 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
125 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
126 tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
127 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
128 tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '0[.][0-9]+'`
129 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
130 then
131 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
132 continue
133 fi
134 # assuming that at least TSTARTI and TSTOPI are consistent
135 #echo $rawfile
136 #echo $tstarti
137 #echo $tstopi
138 #echo $tstartf
139 #echo $tstopf
140 if [ $tstarti -gt 30000 ]
141 then
142 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
143 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
144 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
145 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
146 else
147 tstart=`echo " $tstarti + $tstartf " | bc -l`
148 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
149 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
150 tstop=`echo " $tstopi + $tstopf " | bc -l`
151 fi
152 #echo $rawfile" "$tstart" "$tstop
153
154 # build query to update runinfo in DB
155 query="UPDATE RunInfo SET "
156
157 # get information from fsc: T[31]
158 if [ -e $fsctempfile ] && [ $tempnumerrors -eq 0 ]
159 then
160 fsctemps=( `root -q -b -l fact/processing/camtemp.C\("\"$fsctempfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
161 if [ "${fsctemps[0]}" == "" ]
162 then
163 query=$query"fCameraTempMean=NULL"
164 else
165 query=$query"fCameraTempMean="${fsctemps[0]}
166 fi
167 if [ "${fsctemps[1]}" == "" ]
168 then
169 query=$query", fCameraTempRms=NULL"
170 else
171 query=$query", fCameraTempRms="${fsctemps[1]}
172 fi
173 if [ "${fsctemps[2]}" == "" ]
174 then
175 query=$query", fCameraTempRmsMean=NULL"
176 else
177 query=$query", fCameraTempRmsMean="${fsctemps[2]}
178 fi
179 else
180 query=$query" fCameraTempMean=NULL"
181 query=$query", fCameraTempRms=NULL"
182 query=$query", fCameraTempRmsMean=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/processing/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 # send query to DB
211 sendquery >/dev/null
212 done
213done
214
215finish
216
217
Note: See TracBrowser for help on using the repository browser.