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

Last change on this file since 17850 was 17597, checked in by Daniela Dorner, 11 years ago
give warning about missing files only when runinfo in DB available
  • 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
39printprocesslog "INFO processing the following night(s): "${dates[@]}
40echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
41
42#echo ${dates[@]}
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 #ls $thresholdfile2
94 if ! [ -e $thresholdfile2 ]
95 then
96 printprocesslog "WARN "$thresholdfile2" not found."
97 continue
98 else
99 threshnumerrors2=`fverify $thresholdfile2 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
100 if [ $threshnumerrors2 -gt 0 ]
101 then
102 printprocesslog "WARN for $thresholdfile2 fverify returned "$threshnumerrors2" 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 then
115 printprocesslog "ERROR: "$rawfile" not found."
116 continue
117 fi
118 runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
119 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
120 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
121 tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
122 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
123 tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '0[.][0-9]+'`
124 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
125 then
126 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
127 continue
128 fi
129 # assuming that at least TSTARTI and TSTOPI are consistent
130 #echo $rawfile
131 #echo $tstarti
132 #echo $tstopi
133 #echo $tstartf
134 #echo $tstopf
135 if [ $tstarti -gt 30000 ]
136 then
137 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
138 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
139 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
140 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
141 else
142 tstart=`echo " $tstarti + $tstartf " | bc -l`
143 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
144 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
145 tstop=`echo " $tstopi + $tstopf " | bc -l`
146 fi
147
148 # build query to update runinfo in DB
149 query="UPDATE RunInfo SET "
150
151 # get information
152 if [ -e $threshcurrentsfile ] && [ $threshnumerrors -eq 0 ]
153 then
154 thresholds1=( `root -q -b -l fact/processing/threshold.C\("\"$thresholdfile2\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
155 #root -q -b -l fact/threshold.C\("\"$thresholdfile2\""\,$tstart\,$tstop\) | grep "result"
156 #echo ${thresholds1[@]}
157 if [ "${thresholds1[0]}" == "" ]
158 then
159 query=$query"fThresholdMedMean=NULL"
160 else
161 query=$query"fThresholdMedMean="${thresholds1[0]}
162 fi
163 if [ "${thresholds1[1]}" == "" ]
164 then
165 query=$query", fThresholdMedRms=NULL"
166 else
167 query=$query", fThresholdMedRms="${thresholds1[1]}
168 fi
169 if [ "${thresholds1[2]}" == "" ]
170 then
171 query=$query", fThresholdMax=NULL"
172 else
173 query=$query", fThresholdMax="${thresholds1[2]}
174 fi
175 if [ "${thresholds1[3]}" == "" ]
176 then
177 query=$query", fThresholdAvgMean=NULL"
178 else
179 query=$query", fThresholdAvgMean="${thresholds1[3]}
180 fi
181 else
182 query=$query" fThresholdMedMean=NULL"
183 query=$query", fThresholdMedRms=NULL"
184 query=$query", fThresholdMax=NULL"
185 query=$query", fThresholdAvgMean=NULL"
186 fi
187
188 # get information
189 if [ -e $threshcurrentsfile2 ] && [ $threshnumerrors2 -eq 0 ]
190 then
191 thresholds2=( `root -q -b -l fact/processing/lastth.C\("\"$thresholdfile\""\,$tstart\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
192 #root -q -b -l fact/lastth.C\("\"$thresholdfile\""\,$tstart\) | grep "result"
193 #echo ${thresholds2[@]}
194 if [ "${thresholds2[0]}" == "" ]
195 then
196 query=$query", fThresholdMinSet=NULL"
197 else
198 query=$query", fThresholdMinSet="${thresholds2[0]}
199 fi
200 if [ "${thresholds2[1]}" == "" ]
201 then
202 query=$query", fThresholdMinTimeDiff=NULL"
203 else
204 query=$query", fThresholdMinTimeDiff="${thresholds2[1]}
205 fi
206 else
207 query=$query", fThresholdMinSet=NULL"
208 query=$query", fThresholdMinTimeDiff=NULL"
209 fi
210
211 # add where condition
212 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
213
214 #echo $query
215 # send query to DB
216 sendquery >/dev/null
217 done
218done
219
220finish
221
222
Note: See TracBrowser for help on using the repository browser.