source: branches/trigger_burst_research/Processing/FillEffectiveOn.sh@ 18407

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