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

Last change on this file since 17054 was 15154, checked in by Daniela Dorner, 12 years ago
fixed logfile name
  • Property svn:executable set to *
File size: 5.7 KB
Line 
1#!/bin/bash
2
3# option
4doupdate="yes" # update all entries (needed when new fields have been added)
5doupdate="no" # fill only entries which are not yet existing (default)
6
7source `dirname $0`/../Sourcefile.sh
8printprocesslog "INFO starting $0 with option doupdate="$doupdate
9
10logfile=$runlogpath"/FillCtrlDev-"$datetime".log"
11date >> $logfile
12
13# setup to use ftools
14source $HEADAS/headas-init.sh
15
16# check if software is available
17if ! ls $factpath/fitsdump >/dev/null 2>&1
18then
19 printprocesslog "ERROR "$factpath"/fitsdump is not available."
20 finish
21fi
22
23
24# get last 3, 6 or 9 nights
25dates=( `date +%Y/%m/%d --date="-12hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-60hour"` \
26# `date +%Y/%m/%d --date="-84hour"` `date +%Y/%m/%d --date="-108hour"` `date +%Y/%m/%d --date="-132hour"` \
27# `date +%Y/%m/%d --date="-156hour"` `date +%Y/%m/%d --date="-180hour"` `date +%Y/%m/%d --date="-204hour"` \
28 )
29dates=( `find -L $ziprawdata -mindepth 3 -type d | sort | sed "s/\${ziprawdata_for_sed}//g" | sed -e 's/^\///'` ) #all available dates in /loc_data/zipraw
30printprocesslog "INFO processing the following night(s): "${dates[@]}
31echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
32
33echo ${dates[@]}
34
35cd $mars
36
37# do filling of aux data
38for date in ${dates[@]}
39do
40 auxdir=$auxdata/$date
41 runnumber=`echo $date | sed -e 's/\///g'`
42 if [ $runnumber -lt 20111115 ]
43 then
44 continue
45 fi
46
47 # check if aux files are available from that night
48 if ! [ -d $auxdir ]
49 then
50 printprocesslog "INFO no data available in "$auxdir
51 continue
52 else
53 printprocesslog "INFO processing files in "$auxdir
54 fi
55
56 # get file numbers from DB
57 # but only for not-corrupted files
58 query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 "
59 if [ "$doupdate" = "no" ]
60 then
61 query=$query" AND ISNULL(fCtrlDevMean) "
62 fi
63
64 printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
65 filenumbers=( `sendquery $query` )
66 if [ ${#filenumbers} -eq 0 ]
67 then
68 printprocesslog "INFO No files found in the DB for night "$date
69 continue
70 fi
71
72 # get daily fits files
73 trackingfile=$auxdir/$runnumber.DRIVE_CONTROL_TRACKING_POSITION.fits
74 if ! [ -e $trackingfile ]
75 then
76 printprocesslog "WARN "$trackingfile" not found."
77 echo "WARN "$trackingfile" not found."
78 continue
79 else
80 tracknumerrors=`fverify $trackingfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
81 if [ $tracknumerrors -gt 0 ]
82 then
83 printprocesslog "WARN for $trackingfile fverify returned "$tracknumerrors" error(s)."
84 fi
85 fi
86
87 # fill auxiliary information for files
88 for filenum in ${filenumbers[@]}
89 do
90 printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
91 echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
92 # get information from rawfile
93 rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.gz
94 if ! [ -e $rawfile ]
95 then
96 printprocesslog "ERROR: "$rawfile" not found."
97 continue
98 fi
99 runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
100 mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
101 tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
102 tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
103 tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
104 tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '0[.][0-9]+'`
105 if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
106 then
107 printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
108 continue
109 fi
110 # assuming that at least TSTARTI and TSTOPI are consistent
111 #echo $rawfile
112 #echo $tstarti
113 #echo $tstopi
114 #echo $tstartf
115 #echo $tstopf
116 if [ $tstarti -gt 30000 ]
117 then
118 tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
119 tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
120 #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
121 tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
122 else
123 tstart=`echo " $tstarti + $tstartf " | bc -l`
124 tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
125 #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
126 tstop=`echo " $tstopi + $tstopf " | bc -l`
127 fi
128
129 # build query to update runinfo in DB
130 query="UPDATE RunInfo SET "
131
132 # get ctrl dev
133 if [ -e $trackingfile ] && [ $tracknumerrors -eq 0 ]
134 then
135 ctrldevs=( `root -q -b -l fact/ctrldev.C\("\"$trackingfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
136 if [ "${ctrldevs[0]}" == "" ]
137 then
138 query=$query"fCtrlDevMean=NULL"
139 else
140 query=$query"fCtrlDevMean="${ctrldevs[0]}
141 fi
142 if [ "${ctrldevs[1]}" == "" ]
143 then
144 query=$query", fCtrlDevRms=NULL"
145 else
146 query=$query", fCtrlDevRms="${ctrldevs[1]}
147 fi
148 else
149 query=$query" fCtrlDevMean=NULL"
150 query=$query", fCtrlDevRms=NULL"
151 fi
152
153 # add where condition
154 query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
155
156 echo $query
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.