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