source: trunk/DataCheck/Processing/FillAuxCtrDev.sh@ 18340

Last change on this file since 18340 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"/FillCtrlDev-"$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 20111115 ]
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(fCtrlDevMean) "
68 fi
69 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
70 filenumbers=( `sendquery $query` )
71 # proceed only if there are files available
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 trackingfile=$auxdir/$runnumber.DRIVE_CONTROL_TRACKING_POSITION.fits
80 if ! [ -e $trackingfile ]
81 then
82 printprocesslog "WARN "$trackingfile" not found."
83 #echo "WARN "$trackingfile" not found."
84 continue
85 else
86 tracknumerrors=`fverify $trackingfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
87 if [ $tracknumerrors -gt 0 ]
88 then
89 printprocesslog "WARN for $trackingfile fverify returned "$tracknumerrors" 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 if [ $tstarti -gt 30000 ]
118 then
119 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
120 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
121 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
122 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
123 else
124 tstart=`echo " $tstarti + $tstartf " | bc -l`
125 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
126 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
127 tstop=`echo " $tstopi + $tstopf " | bc -l`
128 fi
129
130 # build query to update runinfo in DB
131 query="UPDATE RunInfo SET "
132
133 # get ctrl dev
134 if [ -e $trackingfile ] && [ $tracknumerrors -eq 0 ]
135 then
136 ctrldevs=( `root -q -b -l fact/processing/ctrldev.C\("\"$trackingfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
137 if [ "${ctrldevs[0]}" == "" ]
138 then
139 query=$query"fCtrlDevMean=NULL"
140 else
141 query=$query"fCtrlDevMean="${ctrldevs[0]}
142 fi
143 if [ "${ctrldevs[1]}" == "" ]
144 then
145 query=$query", fCtrlDevRms=NULL"
146 else
147 query=$query", fCtrlDevRms="${ctrldevs[1]}
148 fi
149 else
150 query=$query" fCtrlDevMean=NULL"
151 query=$query", fCtrlDevRms=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.