source: branches/trigger_burst_research/Processing/FillAuxContTemp.sh@ 18803

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