| 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"/FillAuxTemp-"$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 | printprocesslog "INFO processing the following night(s): "${dates[@]}
|
|---|
| 39 | echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
|
|---|
| 40 |
|
|---|
| 41 | cd $mars
|
|---|
| 42 |
|
|---|
| 43 | # do filling of aux data
|
|---|
| 44 | for date in ${dates[@]}
|
|---|
| 45 | do
|
|---|
| 46 | auxdir=$auxdata/$date
|
|---|
| 47 | runnumber=`echo $date | sed -e 's/\///g'`
|
|---|
| 48 | if [ $runnumber -lt 20120328 ]
|
|---|
| 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(fCameraTempMean) "
|
|---|
| 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 | magicweatherfile=$auxdir/$runnumber.MAGIC_WEATHER_DATA.fits
|
|---|
| 79 | if ! [ -e $magicweatherfile ]
|
|---|
| 80 | then
|
|---|
| 81 | printprocesslog "WARN "$magicweatherfile" not found."
|
|---|
| 82 | else
|
|---|
| 83 | weathernumerrors=`fverify $magicweatherfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
|---|
| 84 | if [ $weathernumerrors -gt 0 ]
|
|---|
| 85 | then
|
|---|
| 86 | printprocesslog "WARN for $magicweatherfile fverify returned "$weathernumerrors" error(s)."
|
|---|
| 87 | fi
|
|---|
| 88 | fi
|
|---|
| 89 |
|
|---|
| 90 | fsctempfile=$auxdir/$runnumber.FSC_CONTROL_TEMPERATURE.fits
|
|---|
| 91 | if ! [ -e $fsctempfile ]
|
|---|
| 92 | then
|
|---|
| 93 | printprocesslog "WARN "$fsctempfile" not found."
|
|---|
| 94 | else
|
|---|
| 95 | tempnumerrors=`fverify $fsctempfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
|
|---|
| 96 | if [ $tempnumerrors -gt 0 ]
|
|---|
| 97 | then
|
|---|
| 98 | printprocesslog "WARN for $fsctempfile fverify returned "$tempnumerrors" error(s)."
|
|---|
| 99 | fi
|
|---|
| 100 | fi
|
|---|
| 101 |
|
|---|
| 102 | # fill auxiliary information for files
|
|---|
| 103 | for filenum in ${filenumbers[@]}
|
|---|
| 104 | do
|
|---|
| 105 | printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
|
|---|
| 106 | echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
|
|---|
| 107 | # get information from rawfile
|
|---|
| 108 | rawfile=$ziprawdata/$date/$runnumber"_"`printf %03d $filenum`.fits.fz
|
|---|
| 109 | if ! [ -e $rawfile ]
|
|---|
| 110 | then
|
|---|
| 111 | printprocesslog "ERROR: "$rawfile" not found."
|
|---|
| 112 | continue
|
|---|
| 113 | fi
|
|---|
| 114 | #checkfitsfile=`fverify $rawfile 2>/dev/null | grep '0 error(s)'`
|
|---|
| 115 | #if [ "$checkfitsfile" == "" ]
|
|---|
| 116 | #then
|
|---|
| 117 | # numfitserrors=1
|
|---|
| 118 | # printprocesslog "WARN: "$rawfile" probably corrupted."
|
|---|
| 119 | # continue
|
|---|
| 120 | #fi
|
|---|
| 121 | runtype=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
|
|---|
| 122 | mjdrefraw=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'MJDREF' | grep -E -o '[0-9]{5}'`
|
|---|
| 123 | tstarti=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTI' | grep -E -o '[0-9]{5}'`
|
|---|
| 124 | tstartf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTARTF' | grep -E -o '0[.][0-9]+'`
|
|---|
| 125 | tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPI' | grep -E -o '[0-9]{5}'`
|
|---|
| 126 | tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep 'TSTOPF' | grep -E -o '0[.][0-9]+'`
|
|---|
| 127 | if [ "$tstarti" == "" ] || [ "$tstopi" == "" ] || [ "$tstartf" == "" ] || [ "$tstopf" == "" ]
|
|---|
| 128 | then
|
|---|
| 129 | printprocesslog "WARN: "$rawfile": one of the following keywords is empty or 0: TSTARTI TSTARTF TSTOPI TSTOPF "
|
|---|
| 130 | continue
|
|---|
| 131 | fi
|
|---|
| 132 | # assuming that at least TSTARTI and TSTOPI are consistent
|
|---|
| 133 | if [ $tstarti -gt 30000 ]
|
|---|
| 134 | then
|
|---|
| 135 | tstart=`echo " $tstarti + $tstartf - 40587 " | bc -l`
|
|---|
| 136 | tstart2=`echo " $tstarti + $tstartf - 40587 - 0.00011574 " | bc -l` # 10 sec
|
|---|
| 137 | #tstart2=`echo " $tstarti + $tstartf - 40587 - 0.000023148 " | bc -l` # 2 sec
|
|---|
| 138 | tstop=`echo " $tstopi + $tstopf - 40587 " | bc -l`
|
|---|
| 139 | else
|
|---|
| 140 | tstart=`echo " $tstarti + $tstartf " | bc -l`
|
|---|
| 141 | tstart2=`echo " $tstarti + $tstartf - 0.00011574 " | bc -l` # 10 sec
|
|---|
| 142 | #tstart2=`echo " $tstarti + $tstartf - 0.000023148 " | bc -l` # 2 sec
|
|---|
| 143 | tstop=`echo " $tstopi + $tstopf " | bc -l`
|
|---|
| 144 | fi
|
|---|
| 145 |
|
|---|
| 146 | # build query to update runinfo in DB
|
|---|
| 147 | query="UPDATE RunInfo SET "
|
|---|
| 148 |
|
|---|
| 149 | # get information from fsc: T[31]
|
|---|
| 150 | if [ -e $fsctempfile ] && [ $tempnumerrors -eq 0 ]
|
|---|
| 151 | then
|
|---|
| 152 | fsctemps=( `root -q -b -l fact/processing/camtemp.C\("\"$fsctempfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
|
|---|
| 153 | if [ "${fsctemps[0]}" == "" ]
|
|---|
| 154 | then
|
|---|
| 155 | query=$query"fCameraTempMean=NULL"
|
|---|
| 156 | else
|
|---|
| 157 | query=$query"fCameraTempMean="${fsctemps[0]}
|
|---|
| 158 | fi
|
|---|
| 159 | if [ "${fsctemps[1]}" == "" ]
|
|---|
| 160 | then
|
|---|
| 161 | query=$query", fCameraTempRms=NULL"
|
|---|
| 162 | else
|
|---|
| 163 | query=$query", fCameraTempRms="${fsctemps[1]}
|
|---|
| 164 | fi
|
|---|
| 165 | if [ "${fsctemps[2]}" == "" ]
|
|---|
| 166 | then
|
|---|
| 167 | query=$query", fCameraTempRmsMean=NULL"
|
|---|
| 168 | else
|
|---|
| 169 | query=$query", fCameraTempRmsMean="${fsctemps[2]}
|
|---|
| 170 | fi
|
|---|
| 171 | else
|
|---|
| 172 | query=$query" fCameraTempMean=NULL"
|
|---|
| 173 | query=$query", fCameraTempRms=NULL"
|
|---|
| 174 | query=$query", fCameraTempRmsMean=NULL"
|
|---|
| 175 | fi
|
|---|
| 176 | #fCameraTempMeanRms: mean of rms of single sensors
|
|---|
| 177 |
|
|---|
| 178 | # get information from weather: T
|
|---|
| 179 | if [ -e $magicweatherfile ] && [ $weathernumerrors -eq 0 ]
|
|---|
| 180 | then
|
|---|
| 181 | mtemps=( `root -q -b -l fact/processing/magictemp.C\("\"$magicweatherfile\""\,$tstart\,$tstop\) | grep "result" | grep -E -o '[0-9]+[.]?[0-9]*'` )
|
|---|
| 182 | if [ "${mtemps[0]}" == "" ]
|
|---|
| 183 | then
|
|---|
| 184 | query=$query", fOutsideTempMean=NULL"
|
|---|
| 185 | else
|
|---|
| 186 | query=$query", fOutsideTempMean="${mtemps[0]}
|
|---|
| 187 | fi
|
|---|
| 188 | if [ "${mtemps[1]}" == "" ]
|
|---|
| 189 | then
|
|---|
| 190 | query=$query", fOutsideTempRms=NULL"
|
|---|
| 191 | else
|
|---|
| 192 | query=$query", fOutsideTempRms="${mtemps[1]}
|
|---|
| 193 | fi
|
|---|
| 194 | else
|
|---|
| 195 | query=$query", fOutsideTempMean=NULL"
|
|---|
| 196 | query=$query", fOutsideTempRms=NULL"
|
|---|
| 197 | fi
|
|---|
| 198 |
|
|---|
| 199 | # add where condition
|
|---|
| 200 | query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
|
|---|
| 201 |
|
|---|
| 202 | # send query to DB
|
|---|
| 203 | sendquery >/dev/null
|
|---|
| 204 | done
|
|---|
| 205 | done
|
|---|
| 206 |
|
|---|
| 207 | finish
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|