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

Last change on this file since 19570 was 19524, checked in by Daniela Dorner, 5 years ago
removed not needed line
  • 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
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 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
127 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
128 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\\^/'`
129 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
130 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\\^/'`
131 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
132 then
133 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
134 continue
135 fi
136 # assuming that at least TSTARTI and TSTOPI are consistent
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 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 if [ "${thresholds2[0]}" == "" ]
193 then
194 query=$query", fThresholdMinSet=NULL"
195 else
196 query=$query", fThresholdMinSet="${thresholds2[0]}
197 fi
198 if [ "${thresholds2[1]}" == "" ]
199 then
200 query=$query", fThresholdMinTimeDiff=NULL"
201 else
202 query=$query", fThresholdMinTimeDiff="${thresholds2[1]}
203 fi
204 else
205 query=$query", fThresholdMinSet=NULL"
206 query=$query", fThresholdMinTimeDiff=NULL"
207 fi
208
209 # add where condition
210 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
211
212 # send query to DB
213 sendquery >/dev/null
214 done
215done
216
217finish
218
219
Note: See TracBrowser for help on using the repository browser.