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

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