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

Last change on this file since 17440 was 17081, checked in by Daniela Dorner, 11 years ago
new paths for macros, usage of fuction getdates
  • Property svn:executable set to *
File size: 7.2 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
70 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
71 filenumbers=( `sendquery $query` )
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.gz
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
153 # build query to update runinfo in DB
154 query="UPDATE RunInfo SET "
155
156 # get information from fsc: T[31]
157 if [ -e $fsctempfile ] && [ $tempnumerrors -eq 0 ]
158 then
159 fsctemps=( `root -q -b -l fact/processing/camtemp.C\("\"$fsctempfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
160 if [ "${fsctemps[0]}" == "" ]
161 then
162 query=$query"fCameraTempMean=NULL"
163 else
164 query=$query"fCameraTempMean="${fsctemps[0]}
165 fi
166 if [ "${fsctemps[1]}" == "" ]
167 then
168 query=$query", fCameraTempRms=NULL"
169 else
170 query=$query", fCameraTempRms="${fsctemps[1]}
171 fi
172 if [ "${fsctemps[2]}" == "" ]
173 then
174 query=$query", fCameraTempRmsMean=NULL"
175 else
176 query=$query", fCameraTempRmsMean="${fsctemps[2]}
177 fi
178 else
179 query=$query" fCameraTempMean=NULL"
180 query=$query", fCameraTempRms=NULL"
181 query=$query", fCameraTempRmsMean=NULL"
182 fi
183 #fCameraTempMeanRms: mean of rms of single sensors
184
185 # get information from weather: T
186 if [ -e $magicweatherfile ] && [ $weathernumerrors -eq 0 ]
187 then
188 mtemps=( `root -q -b -l fact/processing/magictemp.C\("\"$magicweatherfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
189 if [ "${mtemps[0]}" == "" ]
190 then
191 query=$query", fOutsideTempMean=NULL"
192 else
193 query=$query", fOutsideTempMean="${mtemps[0]}
194 fi
195 if [ "${mtemps[1]}" == "" ]
196 then
197 query=$query", fOutsideTempRms=NULL"
198 else
199 query=$query", fOutsideTempRms="${mtemps[1]}
200 fi
201 else
202 query=$query", fOutsideTempMean=NULL"
203 query=$query", fOutsideTempRms=NULL"
204 fi
205
206 # add where condition
207 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
208
209 # send query to DB
210 sendquery >/dev/null
211 done
212done
213
214finish
215
216
Note: See TracBrowser for help on using the repository browser.