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

Last change on this file since 19440 was 19201, checked in by Daniela Dorner, 6 years ago
usage of check_file_avail function
  • 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 if ! check_file_avail $ftmcontrolfile
79 then
80 #printprocesslog "WARN "$ftmcontrolfile" not found."
81 continue
82 else
83 ftmnumerrors=`fverify $ftmcontrolfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
84 if [ $ftmnumerrors -gt 0 ]
85 then
86 printprocesslog "WARN for $ftmcontrolfile fverify returned "$ftmnumerrors" error(s)."
87 fi
88 fi
89
90 # fill auxiliary information for files
91 for filenum in ${filenumbers[@]}
92 do
93 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
94 echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
95 # get information from rawfile
96 rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.fz
97 #if ! [ -e $rawfile ]
98 if ! check_file_avail $rawfile
99 then
100 #if [ $runnumber -lt $checknight ]
101 #then
102 # printprocesslog "WARN "$rawfile" not found."
103 #else
104 # printprocesslog "INFO "$rawfile" not found."
105 #fi
106 continue
107 fi
108 runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
109 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
110 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
111 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\\^/'`
112 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
113 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\\^/'`
114 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
115 then
116 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
117 continue
118 fi
119 # assuming that at least TSTARTI and TSTOPI are consistent
120 if [ $tstarti -gt 30000 ]
121 then
122 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
123 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
124 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
125 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
126 else
127 tstart=`echo " $tstarti + $tstartf " | bc -l`
128 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
129 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
130 tstop=`echo " $tstopi + $tstopf " | bc -l`
131 fi
132
133 # build query to update runinfo in DB
134 query="UPDATE RunInfo SET "
135
136 # get information from fsc: T[31]
137 if [ -e $ftmcontrolfile ] && [ $ftmnumerrors -eq 0 ]
138 then
139 effectiveon=( `root -q -b -l fact/processing/ontime.C\("\"$ftmcontrolfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
140 if [ "${effectiveon[0]}" == "" ]
141 then
142 query=$query"fEffectiveOn=NULL"
143 else
144 query=$query"fEffectiveOn="${effectiveon[0]}
145 fi
146 if [ "${effectiveon[1]}" == "" ]
147 then
148 query=$query", fEffectiveOnRms=NULL"
149 else
150 query=$query", fEffectiveOnRms="${effectiveon[1]}
151 fi
152 if [ "${effectiveon[2]}" == "" ]
153 then
154 query=$query", fOnTime=NULL"
155 else
156 query=$query", fOnTime="${effectiveon[2]}
157 fi
158 if [ "${effectiveon[3]}" == "" ]
159 then
160 query=$query", fTriggerRateTimeOver100=NULL"
161 else
162 query=$query", fTriggerRateTimeOver100="${effectiveon[3]}
163 fi
164 if [ "${effectiveon[4]}" == "" ]
165 then
166 query=$query", fTriggerRateTimeOver125=NULL"
167 else
168 query=$query", fTriggerRateTimeOver125="${effectiveon[4]}
169 fi
170 if [ "${effectiveon[5]}" == "" ]
171 then
172 query=$query", fTriggerRateTimeOver150=NULL"
173 else
174 query=$query", fTriggerRateTimeOver150="${effectiveon[5]}
175 fi
176 if [ "${effectiveon[6]}" == "" ]
177 then
178 query=$query", fTriggerRateTimeOver175=NULL"
179 else
180 query=$query", fTriggerRateTimeOver175="${effectiveon[6]}
181 fi
182 if [ "${effectiveon[7]}" == "" ]
183 then
184 query=$query", fTriggerRateRms=NULL"
185 else
186 query=$query", fTriggerRateRms="${effectiveon[7]}
187 fi
188 else
189 query=$query" fEffectiveOn=NULL"
190 query=$query", fEffectiveOnRms=NULL"
191 query=$query", fOnTime=NULL"
192 query=$query", fTriggerRateTimeOver100=NULL"
193 query=$query", fTriggerRateTimeOver125=NULL"
194 query=$query", fTriggerRateTimeOver150=NULL"
195 query=$query", fTriggerRateTimeOver175=NULL"
196 query=$query", fTriggerRateRms=NULL"
197
198 fi
199
200 # add where condition
201 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
202
203 #send query to DB
204 sendquery >/dev/null
205
206 done
207done
208
209finish
210
211
Note: See TracBrowser for help on using the repository browser.