source: branches/trigger_burst_research/Processing/FillAuxTemp.sh@ 19875

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