source: trunk/DataCheck/Processing/FillDrsTemp.sh@ 18341

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