source: branches/trigger_burst_research/Processing/FillAuxCtrDev.sh@ 19187

Last change on this file since 19187 was 18253, checked in by Daniela Dorner, 9 years ago
removed not needed logging
  • Property svn:executable set to *
File size: 5.8 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 checkstring=`echo $certaindate | grep -E -o '^20[0-9][0-9]\/[01][0-9]\/[0-3][0-9]$'`
31 if [ "$checkstring" = "" ]
32 then
33 echo "Please give the variable certaindate in the correct format (YYYY/MM/DD)"
34 finish
35 fi
36 getdates $certaindate
37else
38 # get all night
39 #getdates "all"
40 # get last 6 nights
41 getdates 6
42fi
43
44printprocesslog "INFO processing the following night(s): "${dates[@]}
45echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
46
47cd $mars
48
49# do filling of aux data
50for date in ${dates[@]}
51do
52 auxdir=$auxdata/$date
53 runnumber=`echo $date | sed -e 's/\///g'`
54 if [ $runnumber -lt 20111115 ]
55 then
56 continue
57 fi
58
59 # check if aux files are available from that night
60 if ! [ -d $auxdir ]
61 then
62 printprocesslog "INFO no data available in "$auxdir
63 continue
64 else
65 printprocesslog "INFO processing files in "$auxdir
66 fi
67
68 # get file numbers from DB
69 # but only for not-corrupted files
70 query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
71 if [ "$doupdate" = "no" ]
72 then
73 query=$query" AND ISNULL(fCtrlDevMean) "
74 fi
75 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
76 filenumbers=( `sendquery $query` )
77 # proceed only if there are files available
78 if [ ${#filenumbers} -eq 0 ]
79 then
80 printprocesslog "INFO No files found in the DB for night "$date
81 continue
82 fi
83
84 # get daily fits files
85 trackingfile=$auxdir/$runnumber.DRIVE_CONTROL_TRACKING_POSITION.fits
86 if ! [ -e $trackingfile ]
87 then
88 printprocesslog "WARN "$trackingfile" not found."
89 #echo "WARN "$trackingfile" not found."
90 continue
91 else
92 tracknumerrors=`fverify $trackingfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
93 if [ $tracknumerrors -gt 0 ]
94 then
95 printprocesslog "WARN for $trackingfile fverify returned "$tracknumerrors" error(s)."
96 fi
97 fi
98
99 # fill auxiliary information for files
100 for filenum in ${filenumbers[@]}
101 do
102 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
103 echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
104 # get information from rawfile
105 rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.fz
106 if ! [ -e $rawfile ]
107 then
108 printprocesslog "ERROR: "$rawfile" not found."
109 continue
110 fi
111 runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
112 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
113 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
114 tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
115 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
116 tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '0[.][0-9]+'`
117 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
118 then
119 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
120 continue
121 fi
122 # assuming that at least TSTARTI and TSTOPI are consistent
123 #echo $rawfile
124 #echo $tstarti
125 #echo $tstopi
126 #echo $tstartf
127 #echo $tstopf
128 if [ $tstarti -gt 30000 ]
129 then
130 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
131 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
132 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
133 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
134 else
135 tstart=`echo " $tstarti + $tstartf " | bc -l`
136 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
137 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
138 tstop=`echo " $tstopi + $tstopf " | bc -l`
139 fi
140
141 # build query to update runinfo in DB
142 query="UPDATE RunInfo SET "
143
144 # get ctrl dev
145 if [ -e $trackingfile ] && [ $tracknumerrors -eq 0 ]
146 then
147 ctrldevs=( `root -q -b -l fact/processing/ctrldev.C\("\"$trackingfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
148 if [ "${ctrldevs[0]}" == "" ]
149 then
150 query=$query"fCtrlDevMean=NULL"
151 else
152 query=$query"fCtrlDevMean="${ctrldevs[0]}
153 fi
154 if [ "${ctrldevs[1]}" == "" ]
155 then
156 query=$query", fCtrlDevRms=NULL"
157 else
158 query=$query", fCtrlDevRms="${ctrldevs[1]}
159 fi
160 else
161 query=$query" fCtrlDevMean=NULL"
162 query=$query", fCtrlDevRms=NULL"
163 fi
164
165 # add where condition
166 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
167
168 # send query to DB
169 sendquery >/dev/null
170 done
171done
172
173finish
174
175
Note: See TracBrowser for help on using the repository browser.