source: trunk/DataCheck/Processing/FillAuxThresholds.sh@ 19187

Last change on this file since 19187 was 18708, checked in by Daniela Dorner, 8 years ago
avoid warnings for missing files for the first few days; fixed bug in finding start and stop time; improved logging
  • Property svn:executable set to *
File size: 7.4 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"/FillThresholds-"$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
28# get dates
29if [ "$certaindate" != "" ]
30then
31 getdates $certaindate
32else
33 # get all night
34 #getdates "all"
35 # get last 6 nights
36 getdates 6
37fi
38
39
40
41printprocesslog "INFO processing the following night(s): "${dates[@]}
42echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
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
52 # get file numbers from DB
53 # but only for not-corrupted files
54 query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
55 if [ "$doupdate" = "no" ]
56 then
57 query=$query" AND ISNULL(fThresholdMedMean) AND ISNULL(fThresholdMinSet) "
58 fi
59 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
60 filenumbers=( `sendquery $query` )
61 # proceed only if there are files available
62 if [ ${#filenumbers} -eq 0 ]
63 then
64 printprocesslog "INFO No files found in the DB for night "$date
65 continue
66 fi
67
68 # check if aux files are available from that night
69 if ! [ -d $auxdir ]
70 then
71 printprocesslog "INFO no data available in "$auxdir
72 continue
73 else
74 printprocesslog "INFO processing files in "$auxdir
75 fi
76
77 thresholdfile=$auxdir/$runnumber.RATE_CONTROL_THRESHOLD.fits
78 printprocesslog "INFO processing "$thresholdfile
79 echo "INFO processing "$thresholdfile >> $logfile 2>&1
80 if ! [ -e $thresholdfile ]
81 then
82 printprocesslog "WARN "$thresholdfile" not found."
83 continue
84 else
85 threshnumerrors=`fverify $thresholdfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
86 if [ $threshnumerrors -gt 0 ]
87 then
88 printprocesslog "WARN for $thresholdfile fverify returned "$threshnumerrors" error(s)."
89 fi
90 fi
91
92 thresholdfile2=$auxdir/$runnumber.FTM_CONTROL_STATIC_DATA.fits
93 if ! [ -e $thresholdfile2 ]
94 then
95 printprocesslog "WARN "$thresholdfile2" not found."
96 continue
97 else
98 threshnumerrors2=`fverify $thresholdfile2 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
99 if [ $threshnumerrors2 -gt 0 ]
100 then
101 printprocesslog "WARN for $thresholdfile2 fverify returned "$threshnumerrors2" error(s)."
102 fi
103 fi
104
105 # fill auxiliary information for files
106 for filenum in ${filenumbers[@]}
107 do
108 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
109 echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
110 # get information from rawfile
111 rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.fz
112 if ! [ -e $rawfile ]
113 then
114 if [ $runnumber -lt $checknight ]
115 then
116 printprocesslog "WARN "$rawfile" not found."
117 else
118 printprocesslog "INFO "$rawfile" not found."
119 fi
120 continue
121 fi
122 runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
123 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
124 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
125 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\\^/'`
126 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
127 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\\^/'`
128 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
129 then
130 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
131 continue
132 fi
133 # assuming that at least TSTARTI and TSTOPI are consistent
134 if [ $tstarti -gt 30000 ]
135 then
136 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
137 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
138 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
139 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
140 else
141 tstart=`echo " $tstarti + $tstartf " | bc -l`
142 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
143 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
144 tstop=`echo " $tstopi + $tstopf " | bc -l`
145 fi
146
147 # build query to update runinfo in DB
148 query="UPDATE RunInfo SET "
149
150 # get information
151 if [ -e $threshcurrentsfile ] && [ $threshnumerrors -eq 0 ]
152 then
153 thresholds1=( `root -q -b -l fact/processing/threshold.C\("\"$thresholdfile2\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
154 if [ "${thresholds1[0]}" == "" ]
155 then
156 query=$query"fThresholdMedMean=NULL"
157 else
158 query=$query"fThresholdMedMean="${thresholds1[0]}
159 fi
160 if [ "${thresholds1[1]}" == "" ]
161 then
162 query=$query", fThresholdMedRms=NULL"
163 else
164 query=$query", fThresholdMedRms="${thresholds1[1]}
165 fi
166 if [ "${thresholds1[2]}" == "" ]
167 then
168 query=$query", fThresholdMax=NULL"
169 else
170 query=$query", fThresholdMax="${thresholds1[2]}
171 fi
172 if [ "${thresholds1[3]}" == "" ]
173 then
174 query=$query", fThresholdAvgMean=NULL"
175 else
176 query=$query", fThresholdAvgMean="${thresholds1[3]}
177 fi
178 else
179 query=$query" fThresholdMedMean=NULL"
180 query=$query", fThresholdMedRms=NULL"
181 query=$query", fThresholdMax=NULL"
182 query=$query", fThresholdAvgMean=NULL"
183 fi
184
185 # get information
186 if [ -e $threshcurrentsfile2 ] && [ $threshnumerrors2 -eq 0 ]
187 then
188 thresholds2=( `root -q -b -l fact/processing/lastth.C\("\"$thresholdfile\""\,$tstart\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
189 if [ "${thresholds2[0]}" == "" ]
190 then
191 query=$query", fThresholdMinSet=NULL"
192 else
193 query=$query", fThresholdMinSet="${thresholds2[0]}
194 fi
195 if [ "${thresholds2[1]}" == "" ]
196 then
197 query=$query", fThresholdMinTimeDiff=NULL"
198 else
199 query=$query", fThresholdMinTimeDiff="${thresholds2[1]}
200 fi
201 else
202 query=$query", fThresholdMinSet=NULL"
203 query=$query", fThresholdMinTimeDiff=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.