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

Last change on this file since 17120 was 17097, checked in by Daniela Dorner, 11 years ago
usage of getdates function, prepared script to be used in RunMoreNights.sh, added 4 new variables, cleanup
  • Property svn:executable set to *
File size: 7.0 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 getdates $certaindate
31else
32 # get all night
33 #getdates "all"
34 # get last 6 nights
35 getdates 6
36fi
37
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# if [ $runnumber -lt 20130301 ]
51# then
52# continue
53# fi
54# echo $auxdir" @ "`date`
55
56 # check if aux files are available from that night
57 if ! [ -d $auxdir ]
58 then
59 printprocesslog "INFO no data available in "$auxdir
60 continue
61 else
62 printprocesslog "INFO processing files in "$auxdir
63 fi
64
65 ftmcontrolfile=$auxdir/$runnumber.FTM_CONTROL_TRIGGER_RATES.fits
66 if ! [ -e $ftmcontrolfile ]
67 then
68 printprocesslog "WARN "$ftmcontrolfile" not found."
69 continue
70 else
71 ftmnumerrors=`fverify $ftmcontrolfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
72 if [ $ftmnumerrors -gt 0 ]
73 then
74 printprocesslog "WARN for $ftmcontrolfile fverify returned "$ftmnumerrors" error(s)."
75 fi
76 fi
77
78 # get file numbers from DB
79 # but only for not-corrupted files
80 query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
81 if [ "$doupdate" = "no" ]
82 then
83 query=$query" AND ISNULL(fEffectiveOn) "
84 fi
85
86 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
87 filenumbers=( `sendquery $query` )
88 if [ ${#filenumbers} -eq 0 ]
89 then
90 printprocesslog "INFO No files found in the DB for night "$date
91 continue
92 fi
93
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 #send query to DB
207 sendquery >/dev/null
208
209 done
210done
211
212finish
213
214
Note: See TracBrowser for help on using the repository browser.