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

Last change on this file since 17689 was 17597, checked in by Daniela Dorner, 11 years ago
give warning about missing files only when runinfo in DB available
  • Property svn:executable set to *
File size: 5.5 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 #echo $rawfile
119 #echo $tstarti
120 #echo $tstopi
121 #echo $tstartf
122 #echo $tstopf
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 #echo "run "$filenum" "$tstart" "$tstop
136
137 # build query to update runinfo in DB
138 query="UPDATE RunInfo SET "
139
140 # get ctrl dev
141 if [ -e $conttempfile ] && [ $conttempnumerrors -eq 0 ]
142 then
143 conttemps=( `root -q -b -l fact/processing/contemp.C\("\"$conttempfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
144 #echo " "${conttemps[@]}
145 if [ "${conttemps[0]}" == "" ]
146 then
147 query=$query" fContainerTempMean=NULL "
148 else
149 query=$query" fContainerTempMean="${conttemps[0]}
150 fi
151 else
152 query=$query" fContainerTempMean=NULL"
153 fi
154
155 # add where condition
156 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
157
158 # send query to DB
159 sendquery >/dev/null
160 done
161done
162
163finish
164
165
Note: See TracBrowser for help on using the repository browser.