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

Last change on this file since 18752 was 18708, checked in by Daniela Dorner, 8 years ago
avoid warnings for missing files for the first few days; fixed bug in finding start and stop time; improved logging
  • Property svn:executable set to *
File size: 7.1 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
39
40printprocesslog "INFO processing the following night(s): "${dates[@]}
41echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
42
43cd $mars
44
45# do filling of aux data
46for date in ${dates[@]}
47do
48 auxdir=$auxdata/$date
49 runnumber=`echo $date | sed -e 's/\///g'`
50
51 # get file numbers from DB
52 # but only for not-corrupted files
53 query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
54 if [ "$doupdate" = "no" ]
55 then
56 query=$query" AND ISNULL(fEffectiveOn) "
57 fi
58 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
59 filenumbers=( `sendquery $query` )
60 # proceed only if there are files available
61 if [ ${#filenumbers} -eq 0 ]
62 then
63 printprocesslog "INFO No files found in the DB for night "$date
64 continue
65 fi
66
67 # check if aux files are available from that night
68 if ! [ -d $auxdir ]
69 then
70 printprocesslog "INFO no data available in "$auxdir
71 continue
72 else
73 printprocesslog "INFO processing files in "$auxdir
74 fi
75
76 ftmcontrolfile=$auxdir/$runnumber.FTM_CONTROL_TRIGGER_RATES.fits
77 if ! [ -e $ftmcontrolfile ]
78 then
79 printprocesslog "WARN "$ftmcontrolfile" not found."
80 continue
81 else
82 ftmnumerrors=`fverify $ftmcontrolfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
83 if [ $ftmnumerrors -gt 0 ]
84 then
85 printprocesslog "WARN for $ftmcontrolfile fverify returned "$ftmnumerrors" error(s)."
86 fi
87 fi
88
89 # fill auxiliary information for files
90 for filenum in ${filenumbers[@]}
91 do
92 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
93 echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
94 # get information from rawfile
95 rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.fz
96 if ! [ -e $rawfile ]
97 then
98 if [ $runnumber -lt $checknight ]
99 then
100 printprocesslog "WARN "$rawfile" not found."
101 else
102 printprocesslog "INFO "$rawfile" not found."
103 fi
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-9][.][0-9]+([E][\-][0-9][0-9])?' | sed -e 's/[E]+*/\\*10\\^/'`
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-9][.][0-9]+([E][\-][0-9][0-9])?' | sed -e 's/[E]+*/\\*10\\^/'`
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 if [ $tstarti -gt 30000 ]
119 then
120 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
121 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
122 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
123 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
124 else
125 tstart=`echo " $tstarti + $tstartf " | bc -l`
126 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
127 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
128 tstop=`echo " $tstopi + $tstopf " | bc -l`
129 fi
130
131 # build query to update runinfo in DB
132 query="UPDATE RunInfo SET "
133
134 # get information from fsc: T[31]
135 if [ -e $ftmcontrolfile ] && [ $ftmnumerrors -eq 0 ]
136 then
137 effectiveon=( `root -q -b -l fact/processing/ontime.C\("\"$ftmcontrolfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
138 if [ "${effectiveon[0]}" == "" ]
139 then
140 query=$query"fEffectiveOn=NULL"
141 else
142 query=$query"fEffectiveOn="${effectiveon[0]}
143 fi
144 if [ "${effectiveon[1]}" == "" ]
145 then
146 query=$query", fEffectiveOnRms=NULL"
147 else
148 query=$query", fEffectiveOnRms="${effectiveon[1]}
149 fi
150 if [ "${effectiveon[2]}" == "" ]
151 then
152 query=$query", fOnTime=NULL"
153 else
154 query=$query", fOnTime="${effectiveon[2]}
155 fi
156 if [ "${effectiveon[3]}" == "" ]
157 then
158 query=$query", fTriggerRateTimeOver100=NULL"
159 else
160 query=$query", fTriggerRateTimeOver100="${effectiveon[3]}
161 fi
162 if [ "${effectiveon[4]}" == "" ]
163 then
164 query=$query", fTriggerRateTimeOver125=NULL"
165 else
166 query=$query", fTriggerRateTimeOver125="${effectiveon[4]}
167 fi
168 if [ "${effectiveon[5]}" == "" ]
169 then
170 query=$query", fTriggerRateTimeOver150=NULL"
171 else
172 query=$query", fTriggerRateTimeOver150="${effectiveon[5]}
173 fi
174 if [ "${effectiveon[6]}" == "" ]
175 then
176 query=$query", fTriggerRateTimeOver175=NULL"
177 else
178 query=$query", fTriggerRateTimeOver175="${effectiveon[6]}
179 fi
180 if [ "${effectiveon[7]}" == "" ]
181 then
182 query=$query", fTriggerRateRms=NULL"
183 else
184 query=$query", fTriggerRateRms="${effectiveon[7]}
185 fi
186 else
187 query=$query" fEffectiveOn=NULL"
188 query=$query", fEffectiveOnRms=NULL"
189 query=$query", fOnTime=NULL"
190 query=$query", fTriggerRateTimeOver100=NULL"
191 query=$query", fTriggerRateTimeOver125=NULL"
192 query=$query", fTriggerRateTimeOver150=NULL"
193 query=$query", fTriggerRateTimeOver175=NULL"
194 query=$query", fTriggerRateRms=NULL"
195
196 fi
197
198 # add where condition
199 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
200
201 #send query to DB
202 sendquery >/dev/null
203
204 done
205done
206
207finish
208
209
Note: See TracBrowser for help on using the repository browser.