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

Last change on this file since 19952 was 19524, checked in by Daniela Dorner, 6 years ago
removed not needed line
  • 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
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 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-9][.][0-9]+([E][\-][0-9][0-9])?' | sed -e 's/[E]+*/\\*10\\^/'`
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-9][.][0-9]+([E][\-][0-9][0-9])?' | sed -e 's/[E]+*/\\*10\\^/'`
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 if [ $tstarti -gt 30000 ]
120 then
121 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
122 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
123 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
124 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
125 else
126 tstart=`echo " $tstarti + $tstartf " | bc -l`
127 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
128 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
129 tstop=`echo " $tstopi + $tstopf " | bc -l`
130 fi
131
132 # build query to update runinfo in DB
133 query="UPDATE RunInfo SET "
134
135 # get information from fsc: T[31]
136 if [ -e $ftmcontrolfile ] && [ $ftmnumerrors -eq 0 ]
137 then
138 effectiveon=( `root -q -b -l fact/processing/ontime.C\("\"$ftmcontrolfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
139 if [ "${effectiveon[0]}" == "" ]
140 then
141 query=$query"fEffectiveOn=NULL"
142 else
143 query=$query"fEffectiveOn="${effectiveon[0]}
144 fi
145 if [ "${effectiveon[1]}" == "" ]
146 then
147 query=$query", fEffectiveOnRms=NULL"
148 else
149 query=$query", fEffectiveOnRms="${effectiveon[1]}
150 fi
151 if [ "${effectiveon[2]}" == "" ]
152 then
153 query=$query", fOnTime=NULL"
154 else
155 query=$query", fOnTime="${effectiveon[2]}
156 fi
157 if [ "${effectiveon[3]}" == "" ]
158 then
159 query=$query", fTriggerRateTimeOver100=NULL"
160 else
161 query=$query", fTriggerRateTimeOver100="${effectiveon[3]}
162 fi
163 if [ "${effectiveon[4]}" == "" ]
164 then
165 query=$query", fTriggerRateTimeOver125=NULL"
166 else
167 query=$query", fTriggerRateTimeOver125="${effectiveon[4]}
168 fi
169 if [ "${effectiveon[5]}" == "" ]
170 then
171 query=$query", fTriggerRateTimeOver150=NULL"
172 else
173 query=$query", fTriggerRateTimeOver150="${effectiveon[5]}
174 fi
175 if [ "${effectiveon[6]}" == "" ]
176 then
177 query=$query", fTriggerRateTimeOver175=NULL"
178 else
179 query=$query", fTriggerRateTimeOver175="${effectiveon[6]}
180 fi
181 if [ "${effectiveon[7]}" == "" ]
182 then
183 query=$query", fTriggerRateRms=NULL"
184 else
185 query=$query", fTriggerRateRms="${effectiveon[7]}
186 fi
187 else
188 query=$query" fEffectiveOn=NULL"
189 query=$query", fEffectiveOnRms=NULL"
190 query=$query", fOnTime=NULL"
191 query=$query", fTriggerRateTimeOver100=NULL"
192 query=$query", fTriggerRateTimeOver125=NULL"
193 query=$query", fTriggerRateTimeOver150=NULL"
194 query=$query", fTriggerRateTimeOver175=NULL"
195 query=$query", fTriggerRateRms=NULL"
196
197 fi
198
199 # add where condition
200 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
201
202 #send query to DB
203 sendquery >/dev/null
204
205 done
206done
207
208finish
209
210
Note: See TracBrowser for help on using the repository browser.