source: trunk/DataCheck/Processing/FillEffectiveOn.sh@ 17050

Last change on this file since 17050 was 15604, checked in by mknoetig, 12 years ago
add fTriggerRateTimeOverx and TriggerRateRms to FillEffectiveOn.sh
  • Property svn:executable set to *
File size: 7.4 KB
Line 
1#!/bin/bash
2
3# option
4doupdate="yes" # update all entries (needed when new fields have been added)
5#doupdate="no" # fill only entries which are not yet existing (default)
6
7
8source `dirname $0`/../Sourcefile.sh
9printprocesslog "INFO starting $0 with option doupdate="$doupdate
10
11logfile=$runlogpath"/EffectiveOn-"$datetime".log"
12date >> $logfile
13
14echo $logfile
15
16# setup to use ftools
17source $HEADAS/headas-init.sh
18
19# check if software is available
20if ! ls $factpath/fitsdump >/dev/null 2>&1
21then
22 printprocesslog "ERROR "$factpath"/fitsdump is not available."
23 finish
24fi
25
26
27# get last 3, 6 or 9 nights
28dates=( `date +%Y/%m/%d --date="-12hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-60hour"` \
29 `date +%Y/%m/%d --date="-84hour"` `date +%Y/%m/%d --date="-108hour"` `date +%Y/%m/%d --date="-132hour"` \
30# `date +%Y/%m/%d --date="-156hour"` `date +%Y/%m/%d --date="-180hour"` `date +%Y/%m/%d --date="-204hour"` \
31 )
32dates=( `find -L $ziprawdata -mindepth 3 -type d | sort -r | sed "s/\${ziprawdata_for_sed}//g" | sed -e 's/^\///'` ) #all available dates in /loc_data/zipraw
33
34#dates=( "2012/11/19" )
35
36printprocesslog "INFO processing the following night(s): "${dates[@]}
37echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
38
39echo ${dates[@]}
40
41cd $mars
42
43# do filling of aux data
44for date in ${dates[@]}
45do
46 auxdir=$auxdata/$date
47 runnumber=`echo $date | sed -e 's/\///g'`
48
49# if [ $runnumber -lt 20130301 ]
50# then
51# continue
52# fi
53
54 # check if aux files are available from that night
55 if ! [ -d $auxdir ]
56 then
57 printprocesslog "INFO no data available in "$auxdir
58 continue
59 else
60 printprocesslog "INFO processing files in "$auxdir
61 fi
62
63 ftmcontrolfile=$auxdir/$runnumber.FTM_CONTROL_TRIGGER_RATES.fits
64 if ! [ -e $ftmcontrolfile ]
65 then
66 printprocesslog "WARN "$ftmcontrolfile" not found."
67 continue
68 else
69 ftmnumerrors=`fverify $ftmcontrolfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
70 if [ $ftmnumerrors -gt 0 ]
71 then
72 printprocesslog "WARN for $ftmcontrolfile fverify returned "$ftmnumerrors" error(s)."
73 fi
74 fi
75
76 echo "run ontime.C for night "$runnumber
77 # get file numbers from DB
78 # but only for not-corrupted files
79 query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
80 if [ "$doupdate" = "no" ]
81 then
82 query=$query" AND ISNULL(fEffectiveOn) "
83 fi
84
85 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
86 filenumbers=( `sendquery $query` )
87 if [ ${#filenumbers} -eq 0 ]
88 then
89 printprocesslog "INFO No files found in the DB for night "$date
90 continue
91 fi
92
93 #echo ${filenumbers[@]}
94 # fill auxiliary information for files
95 for filenum in ${filenumbers[@]}
96 do
97 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
98 echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
99 # get information from rawfile
100 rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.gz
101 if ! [ -e $rawfile ]
102 then
103 printprocesslog "ERROR: "$rawfile" not found."
104 continue
105 fi
106 runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
107 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
108 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
109 tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
110 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
111 tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '0[.][0-9]+'`
112 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
113 then
114 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
115 continue
116 fi
117 # assuming that at least TSTARTI and TSTOPI are consistent
118 #echo $rawfile
119 #echo $tstarti
120 #echo $tstopi
121 #echo $tstartf
122 #echo $tstopf
123 if [ $tstarti -gt 30000 ]
124 then
125 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
126 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
127 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
128 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
129 else
130 tstart=`echo " $tstarti + $tstartf " | bc -l`
131 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
132 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
133 tstop=`echo " $tstopi + $tstopf " | bc -l`
134 fi
135
136 # build query to update runinfo in DB
137 query="UPDATE RunInfo SET "
138
139 # get information from fsc: T[31]
140 if [ -e $ftmcontrolfile ] && [ $ftmnumerrors -eq 0 ]
141 then
142 effectiveon=( `root -q -b -l fact/processing/ontime.C\("\"$ftmcontrolfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
143 if [ "${effectiveon[0]}" == "" ]
144 then
145 query=$query"fEffectiveOn=NULL"
146 else
147 query=$query"fEffectiveOn="${effectiveon[0]}
148 fi
149 if [ "${effectiveon[1]}" == "" ]
150 then
151 query=$query", fEffectiveOnRms=NULL"
152 else
153 query=$query", fEffectiveOnRms="${effectiveon[1]}
154 fi
155 if [ "${effectiveon[2]}" == "" ]
156 then
157 query=$query", fOnTime=NULL"
158 else
159 query=$query", fOnTime="${effectiveon[2]}
160 fi
161 if [ "${effectiveon[3]}" == "" ]
162 then
163 query=$query", fTriggerRateTimeOver100=NULL"
164 else
165 query=$query", fTriggerRateTimeOver100="${effectiveon[3]}
166 fi
167 if [ "${effectiveon[4]}" == "" ]
168 then
169 query=$query", fTriggerRateTimeOver125=NULL"
170 else
171 query=$query", fTriggerRateTimeOver125="${effectiveon[4]}
172 fi
173 if [ "${effectiveon[5]}" == "" ]
174 then
175 query=$query", fTriggerRateTimeOver150=NULL"
176 else
177 query=$query", fTriggerRateTimeOver150="${effectiveon[5]}
178 fi
179 if [ "${effectiveon[6]}" == "" ]
180 then
181 query=$query", fTriggerRateTimeOver175=NULL"
182 else
183 query=$query", fTriggerRateTimeOver175="${effectiveon[6]}
184 fi
185 if [ "${effectiveon[7]}" == "" ]
186 then
187 query=$query", fTriggerRateRms=NULL"
188 else
189 query=$query", fTriggerRateRms="${effectiveon[7]}
190 fi
191 else
192 query=$query" fEffectiveOn=NULL"
193 query=$query", fEffectiveOnRms=NULL"
194 query=$query", fOnTime=NULL"
195 query=$query", fTriggerRateTimeOver100=NULL"
196 query=$query", fTriggerRateTimeOver125=NULL"
197 query=$query", fTriggerRateTimeOver150=NULL"
198 query=$query", fTriggerRateTimeOver175=NULL"
199 query=$query", fTriggerRateRms=NULL"
200
201 fi
202
203 # add where condition
204 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
205
206 echo $query
207 #echo "EffectiveOn:${effectiveon[0]} # RMSEffectiveOn:${effectiveon[1]} # SumOnTime:${effectiveon[2]} # TriggerTimeOver125:${effectiveon[3]}"
208 #send query to DB
209 sendquery >/dev/null
210
211 done
212done
213
214finish
215
216
Note: See TracBrowser for help on using the repository browser.