source: trunk/DataCheck/Processing/FillAuxCam.sh@ 20115

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