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

Last change on this file since 19440 was 19201, checked in by Daniela Dorner, 6 years ago
usage of check_file_avail function
  • Property svn:executable set to *
File size: 7.6 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 echo "INFO no data available in "$auxdir
73 continue
74 else
75 printprocesslog "INFO processing files in "$auxdir
76 fi
77
78 thresholdfile=$auxdir/$runnumber.RATE_CONTROL_THRESHOLD.fits
79 printprocesslog "INFO processing "$thresholdfile
80 echo "INFO processing "$thresholdfile >> $logfile 2>&1
81 #if ! [ -e $thresholdfile ]
82 if ! check_file_avail $thresholdfile
83 then
84 #printprocesslog "WARN "$thresholdfile" not found."
85 continue
86 else
87 threshnumerrors=`fverify $thresholdfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
88 if [ $threshnumerrors -gt 0 ]
89 then
90 printprocesslog "WARN for $thresholdfile fverify returned "$threshnumerrors" error(s)."
91 fi
92 fi
93
94 thresholdfile2=$auxdir/$runnumber.FTM_CONTROL_STATIC_DATA.fits
95 #if ! [ -e $thresholdfile2 ]
96 if ! check_file_avail $thresholdfile2
97 then
98 #printprocesslog "WARN "$thresholdfile2" not found."
99 continue
100 else
101 threshnumerrors2=`fverify $thresholdfile2 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
102 if [ $threshnumerrors2 -gt 0 ]
103 then
104 printprocesslog "WARN for $thresholdfile2 fverify returned "$threshnumerrors2" error(s)."
105 fi
106 fi
107
108 # fill auxiliary information for files
109 for filenum in ${filenumbers[@]}
110 do
111 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
112 echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
113 # get information from rawfile
114 rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.fz
115 #if ! [ -e $rawfile ]
116 if ! check_file_avail $rawfile
117 then
118 #if [ $runnumber -lt $checknight ]
119 #then
120 # printprocesslog "WARN "$rawfile" not found."
121 #else
122 # printprocesslog "INFO "$rawfile" not found."
123 #fi
124 continue
125 fi
126 runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
127 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
128 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
129 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\\^/'`
130 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
131 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\\^/'`
132 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
133 then
134 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
135 continue
136 fi
137 # assuming that at least TSTARTI and TSTOPI are consistent
138 if [ $tstarti -gt 30000 ]
139 then
140 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
141 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
142 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
143 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
144 else
145 tstart=`echo " $tstarti + $tstartf " | bc -l`
146 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
147 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
148 tstop=`echo " $tstopi + $tstopf " | bc -l`
149 fi
150
151 # build query to update runinfo in DB
152 query="UPDATE RunInfo SET "
153
154 # get information
155 if [ -e $threshcurrentsfile ] && [ $threshnumerrors -eq 0 ]
156 then
157 thresholds1=( `root -q -b -l fact/processing/threshold.C\("\"$thresholdfile2\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
158 if [ "${thresholds1[0]}" == "" ]
159 then
160 query=$query"fThresholdMedMean=NULL"
161 else
162 query=$query"fThresholdMedMean="${thresholds1[0]}
163 fi
164 if [ "${thresholds1[1]}" == "" ]
165 then
166 query=$query", fThresholdMedRms=NULL"
167 else
168 query=$query", fThresholdMedRms="${thresholds1[1]}
169 fi
170 if [ "${thresholds1[2]}" == "" ]
171 then
172 query=$query", fThresholdMax=NULL"
173 else
174 query=$query", fThresholdMax="${thresholds1[2]}
175 fi
176 if [ "${thresholds1[3]}" == "" ]
177 then
178 query=$query", fThresholdAvgMean=NULL"
179 else
180 query=$query", fThresholdAvgMean="${thresholds1[3]}
181 fi
182 else
183 query=$query" fThresholdMedMean=NULL"
184 query=$query", fThresholdMedRms=NULL"
185 query=$query", fThresholdMax=NULL"
186 query=$query", fThresholdAvgMean=NULL"
187 fi
188
189 # get information
190 if [ -e $threshcurrentsfile2 ] && [ $threshnumerrors2 -eq 0 ]
191 then
192 thresholds2=( `root -q -b -l fact/processing/lastth.C\("\"$thresholdfile\""\,$tstart\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
193 if [ "${thresholds2[0]}" == "" ]
194 then
195 query=$query", fThresholdMinSet=NULL"
196 else
197 query=$query", fThresholdMinSet="${thresholds2[0]}
198 fi
199 if [ "${thresholds2[1]}" == "" ]
200 then
201 query=$query", fThresholdMinTimeDiff=NULL"
202 else
203 query=$query", fThresholdMinTimeDiff="${thresholds2[1]}
204 fi
205 else
206 query=$query", fThresholdMinSet=NULL"
207 query=$query", fThresholdMinTimeDiff=NULL"
208 fi
209
210 # add where condition
211 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
212
213 # send query to DB
214 sendquery >/dev/null
215 done
216done
217
218finish
219
220
Note: See TracBrowser for help on using the repository browser.