source: trunk/DataCheck/Processing/FillAuxContTemp.sh@ 18477

Last change on this file since 18477 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: 5.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"/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 getdates $certaindate
31else
32 # get all night
33 #getdates "all"
34 # get last 6 nights
35 getdates 6
36fi
37
38printprocesslog "INFO processing the following night(s): "${dates[@]}
39echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
40
41cd $mars
42
43# do filling of aux data
44for date in ${dates[@]}
45do
46 auxdir=$auxdata/$date
47 runnumber=`echo $date | sed -e 's/\///g'`
48 # the container temperature was not available before this date
49 if [ $runnumber -lt 20130413 ]
50 then
51 printprocesslog "INFO container temperature was not available before 20130413 "
52 continue
53 fi
54
55 # get file numbers from DB
56 # but only for not-corrupted files
57 query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
58 if [ "$doupdate" = "no" ]
59 then
60 query=$query" AND ISNULL(fContainerTempMean) "
61 fi
62 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
63 filenumbers=( `sendquery $query` )
64 # proceed only if there are files available
65 if [ ${#filenumbers} -eq 0 ]
66 then
67 printprocesslog "INFO No files found in the DB for night "$date
68 continue
69 fi
70
71 # check if aux files are available from that night
72 if ! [ -d $auxdir ]
73 then
74 printprocesslog "INFO no data available in "$auxdir
75 continue
76 else
77 printprocesslog "INFO processing files in "$auxdir
78 fi
79
80 # get daily fits files
81 conttempfile=$auxdir/$runnumber.TEMPERATURE_DATA.fits
82 if ! [ -e $conttempfile ]
83 then
84 printprocesslog "WARN "$conttempfile" not found."
85 continue
86 else
87 conttempnumerrors=`fverify $conttempfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
88 if [ $conttempnumerrors -gt 0 ]
89 then
90 printprocesslog "WARN for $conttempfile fverify returned "$conttempnumerrors" 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 then
103 printprocesslog "ERROR: "$rawfile" not found."
104 continue
105 fi
106 runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
107 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
108 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
109 tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
110 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
111 tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '0[.][0-9]+'`
112 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
113 then
114 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
115 continue
116 fi
117 # assuming that at least TSTARTI and TSTOPI are consistent
118 if [ $tstarti -gt 30000 ]
119 then
120 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
121 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
122 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
123 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
124 else
125 tstart=`echo " $tstarti + $tstartf " | bc -l`
126 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
127 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
128 tstop=`echo " $tstopi + $tstopf " | bc -l`
129 fi
130 #echo "run "$filenum" "$tstart" "$tstop
131
132 # build query to update runinfo in DB
133 query="UPDATE RunInfo SET "
134
135 # get ctrl dev
136 if [ -e $conttempfile ] && [ $conttempnumerrors -eq 0 ]
137 then
138 conttemps=( `root -q -b -l fact/processing/contemp.C\("\"$conttempfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
139 if [ "${conttemps[0]}" == "" ]
140 then
141 query=$query" fContainerTempMean=NULL "
142 else
143 query=$query" fContainerTempMean="${conttemps[0]}
144 fi
145 else
146 query=$query" fContainerTempMean=NULL"
147 fi
148
149 # add where condition
150 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
151
152 # send query to DB
153 sendquery >/dev/null
154 done
155done
156
157finish
158
159
Note: See TracBrowser for help on using the repository browser.