source: branches/trigger_burst_research/Processing/FillDrsTemp.sh@ 19875

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