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

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