source: trunk/DataCheck/Processing/FillAuxThresholds.sh@ 17054

Last change on this file since 17054 was 15330, checked in by Daniela Dorner, 12 years ago
adapted name of logfile
  • Property svn:executable set to *
File size: 7.8 KB
Line 
1#!/bin/bash
2
3# option
4doupdate="yes" # update all entries (needed when new fields have been added)
5doupdate="no" # fill only entries which are not yet existing (default)
6
7source `dirname $0`/../Sourcefile.sh
8printprocesslog "INFO starting $0 with option doupdate="$doupdate
9
10logfile=$runlogpath"/FillThresholds-"$datetime".log"
11date >> $logfile
12
13# setup to use ftools
14source $HEADAS/headas-init.sh
15
16# check if software is available
17if ! ls $factpath/fitsdump >/dev/null 2>&1
18then
19 printprocesslog "ERROR "$factpath"/fitsdump is not available."
20 finish
21fi
22
23
24# get last 3, 6 or 9 nights
25dates=( `date +%Y/%m/%d --date="-12hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-60hour"` \
26# `date +%Y/%m/%d --date="-84hour"` `date +%Y/%m/%d --date="-108hour"` `date +%Y/%m/%d --date="-132hour"` \
27# `date +%Y/%m/%d --date="-156hour"` `date +%Y/%m/%d --date="-180hour"` `date +%Y/%m/%d --date="-204hour"` \
28 )
29#dates=( `find -L $ziprawdata -mindepth 3 -type d | sort -r | sed "s/\${ziprawdata_for_sed}//g" | sed -e 's/^\///'` ) #all available dates in /loc_data/zipraw
30#dates=( `find -L $rawdata -mindepth 3 -type d | sort -r | sed "s/\${rawdata_for_sed}//g" | sed -e 's/^\///'` ) #all available dates in /fact/raw
31
32#dates=( "2013/01/31" )
33
34printprocesslog "INFO processing the following night(s): "${dates[@]}
35echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
36
37echo ${dates[@]}
38
39cd $mars
40
41# do filling of aux data
42for date in ${dates[@]}
43do
44 auxdir=$auxdata/$date
45 runnumber=`echo $date | sed -e 's/\///g'`
46
47 echo $auxdir
48
49 # check if aux files are available from that night
50 if ! [ -d $auxdir ]
51 then
52 printprocesslog "INFO no data available in "$auxdir
53 continue
54 else
55 printprocesslog "INFO processing files in "$auxdir
56 fi
57
58 thresholdfile=$auxdir/$runnumber.RATE_CONTROL_THRESHOLD.fits
59 ls $thresholdfile
60 if ! [ -e $thresholdfile ]
61 then
62 printprocesslog "WARN "$thresholdfile" not found."
63 continue
64 else
65 threshnumerrors=`fverify $thresholdfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
66 if [ $threshnumerrors -gt 0 ]
67 then
68 printprocesslog "WARN for $thresholdfile fverify returned "$threshnumerrors" error(s)."
69 fi
70 fi
71
72 thresholdfile2=$auxdir/$runnumber.FTM_CONTROL_STATIC_DATA.fits
73 ls $thresholdfile2
74 if ! [ -e $thresholdfile2 ]
75 then
76 printprocesslog "WARN "$thresholdfile2" not found."
77 continue
78 else
79 threshnumerrors2=`fverify $thresholdfile2 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
80 if [ $threshnumerrors2 -gt 0 ]
81 then
82 printprocesslog "WARN for $thresholdfile2 fverify returned "$threshnumerrors2" error(s)."
83 fi
84 fi
85
86
87
88 # get file numbers from DB
89 # but only for not-corrupted files
90 query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
91 if [ "$doupdate" = "no" ]
92 then
93 query=$query" AND ISNULL(fThresholdMedMean) AND ISNULL(fThresholdMinSet) "
94 fi
95
96 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
97 filenumbers=( `sendquery $query` )
98 if [ ${#filenumbers} -eq 0 ]
99 then
100 printprocesslog "INFO No files found in the DB for night "$date
101 continue
102 fi
103
104 # fill auxiliary information for files
105 for filenum in ${filenumbers[@]}
106 do
107 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
108 echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
109 # get information from rawfile
110 rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.gz
111 if ! [ -e $rawfile ]
112 then
113 printprocesslog "ERROR: "$rawfile" not found."
114 continue
115 fi
116 runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
117 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
118 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
119 tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
120 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
121 tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '0[.][0-9]+'`
122 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
123 then
124 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
125 continue
126 fi
127 # assuming that at least TSTARTI and TSTOPI are consistent
128 #echo $rawfile
129 #echo $tstarti
130 #echo $tstopi
131 #echo $tstartf
132 #echo $tstopf
133 if [ $tstarti -gt 30000 ]
134 then
135 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
136 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
137 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
138 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
139 else
140 tstart=`echo " $tstarti + $tstartf " | bc -l`
141 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
142 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
143 tstop=`echo " $tstopi + $tstopf " | bc -l`
144 fi
145
146 # build query to update runinfo in DB
147 query="UPDATE RunInfo SET "
148
149 # get information
150 if [ -e $threshcurrentsfile ] && [ $threshnumerrors -eq 0 ]
151 then
152 thresholds1=( `root -q -b -l fact/threshold.C\("\"$thresholdfile2\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
153 #root -q -b -l fact/threshold.C\("\"$thresholdfile2\""\,$tstart\,$tstop\) | grep "result"
154 echo ${thresholds1[@]}
155 if [ "${thresholds1[0]}" == "" ]
156 then
157 query=$query"fThresholdMedMean=NULL"
158 else
159 query=$query"fThresholdMedMean="${thresholds1[0]}
160 fi
161 if [ "${thresholds1[1]}" == "" ]
162 then
163 query=$query", fThresholdMedRms=NULL"
164 else
165 query=$query", fThresholdMedRms="${thresholds1[1]}
166 fi
167 if [ "${thresholds1[2]}" == "" ]
168 then
169 query=$query", fThresholdMax=NULL"
170 else
171 query=$query", fThresholdMax="${thresholds1[2]}
172 fi
173 if [ "${thresholds1[3]}" == "" ]
174 then
175 query=$query", fThresholdAvgMean=NULL"
176 else
177 query=$query", fThresholdAvgMean="${thresholds1[3]}
178 fi
179 else
180 query=$query" fThresholdMedMean=NULL"
181 query=$query", fThresholdMedRms=NULL"
182 query=$query", fThresholdMax=NULL"
183 query=$query", fThresholdAvgMean=NULL"
184 fi
185
186 # get information
187 if [ -e $threshcurrentsfile2 ] && [ $threshnumerrors2 -eq 0 ]
188 then
189 thresholds2=( `root -q -b -l fact/lastth.C\("\"$thresholdfile\""\,$tstart\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
190 #root -q -b -l fact/lastth.C\("\"$thresholdfile\""\,$tstart\) | grep "result"
191 echo ${thresholds2[@]}
192 if [ "${thresholds2[0]}" == "" ]
193 then
194 query=$query", fThresholdMinSet=NULL"
195 else
196 query=$query", fThresholdMinSet="${thresholds2[0]}
197 fi
198 if [ "${thresholds2[1]}" == "" ]
199 then
200 query=$query", fThresholdMinTimeDiff=NULL"
201 else
202 query=$query", fThresholdMinTimeDiff="${thresholds2[1]}
203 fi
204 else
205 query=$query", fThresholdMinSet=NULL"
206 query=$query", fThresholdMinTimeDiff=NULL"
207 fi
208
209 # add where condition
210 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
211
212 echo $query
213 # send query to DB
214 sendquery >/dev/null
215 done
216done
217
218finish
219
220
Note: See TracBrowser for help on using the repository browser.