source: trunk/DataCheck/Processing/FillDrsTemp.sh

Last change on this file was 19524, checked in by Daniela Dorner, 5 years ago
removed not needed line
  • Property svn:executable set to *
File size: 6.4 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 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 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 if ! check_file_avail $drstempfile
83 then
84 #printprocesslog "WARN "$drstempfile" not found."
85 continue
86 else
87 tempnumerrors=`fverify $drstempfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
88 if [ $tempnumerrors -gt 0 ]
89 then
90 printprocesslog "WARN for "$drstempfile" fverify returned "$tempnumerrors" error(s)."
91 fi
92 fi
93
94 # fill auxiliary information for files
95 for filenum in ${filenumbers[@]}
96 do
97 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
98 echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
99 # get information from rawfile
100 rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.fz
101 #if ! [ -e $rawfile ]
102 if ! check_file_avail $rawfile
103 then
104 #if [ $runnumber -lt $checknight ]
105 #then
106 # printprocesslog "WARN "$rawfile" not found. "$night" "$checknight
107 #else
108 # printprocesslog "INFO "$rawfile" not found."
109 #fi
110 continue
111 fi
112 #checkfitsfile=`fverify $rawfile 2>/dev/null | grep '0 error(s)'`
113 #if [ "$checkfitsfile" == "" ]
114 #then
115 # numfitserrors=1
116 # printprocesslog "WARN: "$rawfile" probably corrupted."
117 # continue
118 #fi
119 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
120 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
121 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\\^/'`
122 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
123 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\\^/'`
124 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
125 then
126 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
127 continue
128 fi
129 # assuming that at least TSTARTI and TSTOPI are consistent
130 if [ $tstarti -gt 30000 ]
131 then
132 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
133 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
134 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
135 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
136 else
137 tstart=`echo " $tstarti + $tstartf " | bc -l`
138 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
139 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
140 tstop=`echo " $tstopi + $tstopf " | bc -l`
141 fi
142
143 # build query to update runinfo in DB
144 query="UPDATE RunInfo SET "
145
146 # get information from fsc: T[31]
147 if [ -e $drstempfile ] && [ $tempnumerrors -eq 0 ]
148 then
149 drstemps=( `root -q -b -l fact/processing/drstemp.C\("\"$drstempfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
150 if [ "${drstemps[0]}" == "" ]
151 then
152 query=$query"fDrsTempMinMean=NULL"
153 else
154 query=$query"fDrsTempMinMean="${drstemps[0]}
155 fi
156 if [ "${drstemps[1]}" == "" ]
157 then
158 query=$query", fDrsTempMaxMean=NULL"
159 else
160 query=$query", fDrsTempMaxMean="${drstemps[1]}
161 fi
162 if [ "${drstemps[2]}" == "" ]
163 then
164 query=$query", fDrsTempMinRmsMean=NULL"
165 else
166 query=$query", fDrsTempMinRmsMean="${drstemps[2]}
167 fi
168 if [ "${drstemps[3]}" == "" ]
169 then
170 query=$query", fDrsTempMaxRmsMean=NULL"
171 else
172 query=$query", fDrsTempMaxRmsMean="${drstemps[3]}
173 fi
174 else
175 query=$query" fDrsTempMinMean=NULL"
176 query=$query", fDrsTempMaxMean=NULL"
177 query=$query", fDrsTempMinRmsMean=NULL"
178 query=$query", fDrsTempMaxRmsMean=NULL"
179 fi
180 #fCameraTempMeanRms: mean of rms of single sensors
181
182 # add where condition
183 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
184
185 # send query to DB
186 sendquery >/dev/null
187 done
188done
189
190finish
191
192
Note: See TracBrowser for help on using the repository browser.