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"/FillContTemp-"$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 | # the container temperature was not available before this date
|
---|
51 | if [ $runnumber -lt 20130413 ]
|
---|
52 | then
|
---|
53 | printprocesslog "INFO container temperature was not available before 20130413 "
|
---|
54 | continue
|
---|
55 | fi
|
---|
56 |
|
---|
57 | # get file numbers from DB
|
---|
58 | # but only for not-corrupted files
|
---|
59 | query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
|
---|
60 | if [ "$doupdate" = "no" ]
|
---|
61 | then
|
---|
62 | query=$query" AND ISNULL(fContainerTempMean) "
|
---|
63 | fi
|
---|
64 | printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
|
---|
65 | filenumbers=( `sendquery $query` )
|
---|
66 | # proceed only if there are files available
|
---|
67 | if [ ${#filenumbers} -eq 0 ]
|
---|
68 | then
|
---|
69 | printprocesslog "INFO No files found in the DB for night "$date
|
---|
70 | continue
|
---|
71 | fi
|
---|
72 |
|
---|
73 | # check if aux files are available from that night
|
---|
74 | if ! [ -d $auxdir ]
|
---|
75 | then
|
---|
76 | printprocesslog "INFO no data available in "$auxdir
|
---|
77 | continue
|
---|
78 | else
|
---|
79 | printprocesslog "INFO processing files in "$auxdir
|
---|
80 | fi
|
---|
81 |
|
---|
82 | # get daily fits files
|
---|
83 | conttempfile=$auxdir/$runnumber.TEMPERATURE_DATA.fits
|
---|
84 | #if ! [ -e $conttempfile ]
|
---|
85 | if ! check_file_avail $conttempfile
|
---|
86 | then
|
---|
87 | #printprocesslog "WARN "$conttempfile" not found."
|
---|
88 | continue
|
---|
89 | else
|
---|
90 | conttempnumerrors=`fverify $conttempfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
---|
91 | if [ $conttempnumerrors -gt 0 ]
|
---|
92 | then
|
---|
93 | printprocesslog "WARN for $conttempfile fverify returned "$conttempnumerrors" error(s)."
|
---|
94 | fi
|
---|
95 | fi
|
---|
96 |
|
---|
97 | # fill auxiliary information for files
|
---|
98 | for filenum in ${filenumbers[@]}
|
---|
99 | do
|
---|
100 | printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
|
---|
101 | echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
|
---|
102 | # get information from rawfile
|
---|
103 | rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.fz
|
---|
104 | #if ! [ -e $rawfile ]
|
---|
105 | if ! check_file_avail $rawfile
|
---|
106 | then
|
---|
107 | #if [ $runnumber -lt $checknight ]
|
---|
108 | #then
|
---|
109 | # printprocesslog "WARN "$rawfile" not found."
|
---|
110 | #else
|
---|
111 | # printprocesslog "INFO "$rawfile" not found."
|
---|
112 | #fi
|
---|
113 | continue
|
---|
114 | fi
|
---|
115 | runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
|
---|
116 | mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
|
---|
117 | tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
|
---|
118 | 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\\^/'`
|
---|
119 | tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
|
---|
120 | 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\\^/'`
|
---|
121 | if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
|
---|
122 | then
|
---|
123 | printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
|
---|
124 | continue
|
---|
125 | fi
|
---|
126 | # assuming that at least TSTARTI and TSTOPI are consistent
|
---|
127 | if [ $tstarti -gt 30000 ]
|
---|
128 | then
|
---|
129 | tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
|
---|
130 | tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
|
---|
131 | #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
|
---|
132 | tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
|
---|
133 | else
|
---|
134 | tstart=`echo " $tstarti + $tstartf " | bc -l`
|
---|
135 | tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
|
---|
136 | #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
|
---|
137 | tstop=`echo " $tstopi + $tstopf " | bc -l`
|
---|
138 | fi
|
---|
139 | #echo "run "$filenum" "$tstart" "$tstop
|
---|
140 |
|
---|
141 | # build query to update runinfo in DB
|
---|
142 | query="UPDATE RunInfo SET "
|
---|
143 |
|
---|
144 | # get ctrl dev
|
---|
145 | if [ -e $conttempfile ] && [ $conttempnumerrors -eq 0 ]
|
---|
146 | then
|
---|
147 | conttemps=( `root -q -b -l fact/processing/contemp.C\("\"$conttempfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
|
---|
148 | if [ "${conttemps[0]}" == "" ]
|
---|
149 | then
|
---|
150 | query=$query" fContainerTempMean=NULL "
|
---|
151 | else
|
---|
152 | query=$query" fContainerTempMean="${conttemps[0]}
|
---|
153 | fi
|
---|
154 | else
|
---|
155 | query=$query" fContainerTempMean=NULL"
|
---|
156 | fi
|
---|
157 |
|
---|
158 | # add where condition
|
---|
159 | query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
|
---|
160 |
|
---|
161 | # send query to DB
|
---|
162 | sendquery >/dev/null
|
---|
163 | done
|
---|
164 | done
|
---|
165 |
|
---|
166 | finish
|
---|
167 |
|
---|
168 |
|
---|