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

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