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