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

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