Ignore:
Timestamp:
09/01/21 07:56:42 (3 years ago)
Author:
maslowski
Message:
Added better error handeling and tracking in the databas.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/hawc/processing/DiskToDB/extract-aux-data2.sh

    r20091 r20103  
    1212{
    1313        echo "ERROR: Line `caller`: ${BASH_COMMAND}" >&2
     14        rm -f ${TMPOUT}
    1415        exit 1
    1516}
     
    1920        echo " "
    2021        echo "$0 was forcefully terminated" >&2
     22        rm -f ${TMPOUT}
    2123        exit 1
    2224}
     
    2830# File to which the queries are written
    2931OUTPUT="insert-aux.sql"
     32TMPOUT="./tmpAuxOut.sql"
    3033# The Mars build directory
    31 readonly MARS="/home/frankm/Dateien/Mars/build/"
     34readonly MARS="/home/frankm/Dateien/Mars-6.24.00/build4/"
    3235# The path to your Mars/build directory where the processing macros are stored
    3336# MACROS="/home/frankm/Dateien/Mars/hawc/processing"
    34 readonly MACROS="/home/frankm/Dateien/Mars/build/Masterarbeit/Datenbank/HE01/Mexico/Cfiles/"
     37readonly MACROS="/home/frankm/Dateien/Mars-6.24.00/build/Masterarbeit/Datenbank/HE01/Mexico/Cfiles/"
    3538readonly PROGRAM=$0
    3639INSERT="INSERT INTO"
     
    9396NIGHT="${4}"
    9497
    95 
     98ERRCODE=
    9699
    97100# Open the query-file with the create table statement
     
    140143"\ > ${OUTPUT}
    141144
     145# Set previous fail stats to also be fail here
     146echo "UPDATE DataOnDisk"                        >> ${OUTPUT}
     147echo "SET DataOnDisk.auxiliary = 6"             >> ${OUTPUT}
     148echo "WHERE (DataOnDisk.calibration != 0"       >> ${OUTPUT}
     149echo "OR DataOnDisk.header != 0)"               >> ${OUTPUT}
     150echo "AND DataOnDisk.Telescope = ${TEL}"        >> ${OUTPUT}
     151echo "AND DataOnDisk.NIGHT = ${NIGHT};"         >> ${OUTPUT}
     152
    142153if [ ${DELETE} = "true" ]
    143154then
     
    159170echo \
    160171"\
    161 SELECT
    162         NIGHT, RUNID, TSTARTI+TSTARTF, TSTOPI+TSTOPF
    163 FROM
    164         RawData
    165 WHERE
    166         Telescope=${TEL}
    167 AND
    168         NIGHT=${NIGHT}\
     172SELECT RawData.NIGHT,
     173        RawData.RUNID,
     174        RawData.TSTARTI + RawData.TSTARTF,
     175        RawData.TSTOPI + RawData.TSTOPF
     176FROM RawData
     177INNER JOIN DataOnDisk
     178ON DataOnDisk.Telescope = RawData.Telescope
     179AND DataOnDisk.NIGHT = RawData.NIGHT
     180AND DataOnDisk.RUNID = RawData.RUNID
     181WHERE RawData.Telescope=${TEL}
     182AND RawData.NIGHT=${NIGHT}
     183AND DataOnDisk.ISDRSFILE = 0
     184AND DataOnDisk.header = 0
     185AND DataOnDisk.calibration = 0\
    169186"\
    170187 |  mysql \
     
    176193while read -r -a LINE
    177194do
    178   # Extract night, runid, begin and end
    179   NIGHT=${LINE[0]}
    180   RUNID=${LINE[1]}
    181   BEG=${LINE[2]}
    182   END=${LINE[3]}
    183 
    184   # Split night into year, month, day
    185   # Base path for the night
    186   FNAME="${DIR}"/${NIGHT:0:4}/${NIGHT:4:2}/${NIGHT:6:2}/${NIGHT}
    187 
    188   echo ${FNAME}
    189 
    190   cd ${MARS}
    191 
    192   # Return corresponding data for DRS temperatures from FAD_CONTROL_TEMPEREATURE
    193   DRS_TEMP=`root -b -q -l "${MACROS}"/drstemp.C\(\""${FNAME}".FAD_CONTROL_TEMPERATURE.fits\","${BEG}","${END}"\) | grep result | cut -f2- -d" "`
    194   if [ ! -n "${DRS_TEMP}" ]
    195   then
    196         DRS_TEMP="NULL, NULL"
    197   fi
    198   echo ${DRS_TEMP}
    199 
    200   # Return corresponding data for currents from BIAS_CONTROL_DYNAMIC_DATA
    201   BIAS_DATA=`root -b -q -l "${MACROS}"/currents.C\(\""${FNAME}".BIAS_CONTROL_DYNAMIC_DATA.fits\","${BEG}","${END}"\) | grep result | cut -f2- -d" "`
    202   if [ ! -n "${BIAS_DATA}" ]
    203   then 
    204         BIAS_DATA="NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL"
    205   fi
    206   echo ${BIAS_DATA}
    207 
    208   # Return corresponding data for trigger information from FTM_CONTROL_DATA
    209   FTM_DATA=`root -b -q -l "${MACROS}"/trigger.C\(\""${FNAME}".FTM_CONTROL_DATA.fits\","${BEG}","${END}"\) | grep result | cut -f2- -d" "`
    210   if [ ! -n "${FTM_DATA}" ]
    211   then
    212         FTM_DATA="NULL, NULL, NULL, NULL"
    213   fi
    214   echo ${FTM_DATA}
    215 
    216   # Return corresponding data for threshold seeting from FTU_CONTROL_DATA
    217   FTU_DATA=`root -b -q -l "${MACROS}"/threshold.C\(\""${FNAME}".FTU_CONTROL_DATA.fits\","${BEG}","${END}"\) | grep result | cut -f2- -d" "`
    218   if [ ! -n "${FTU_DATA}" ]
    219   then
    220         FTU_DATA="NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL"
    221   fi
    222   echo ${FTU_DATA}
    223 
    224   cd -
    225 
    226   # Write the result as one row to the query file
    227   echo "/* "${FNAME}" */"               >> ${OUTPUT}
    228   echo "ROW("                           >> ${OUTPUT}
    229   echo " "${TEL}, ${NIGHT}, ${RUNID},   >> ${OUTPUT}
    230   echo " "${DRS_TEMP},                  >> ${OUTPUT}
    231   echo " "${BIAS_DATA},                 >> ${OUTPUT}
    232   echo " "${FTM_DATA},                  >> ${OUTPUT}
    233   echo " "${FTU_DATA}                   >> ${OUTPUT}
    234   echo "),"                             >> ${OUTPUT}
     195        # Extract night, runid, begin and end
     196        NIGHT=${LINE[0]}
     197        RUNID=${LINE[1]}
     198        BEG=${LINE[2]}
     199        END=${LINE[3]}
     200
     201        # Split night into year, month, day
     202        # Base path for the night
     203        FNAME="${DIR}"/${NIGHT:0:4}/${NIGHT:4:2}/${NIGHT:6:2}/${NIGHT}
     204
     205        echo ${FNAME}
     206
     207        cd ${MARS}
     208
     209        TNAME="${FNAME}".FAD_CONTROL_TEMPERATURE.fits
     210        if [ ! -f "${TNAME}" ]
     211        then
     212                DRS_TEMP="NULL, NULL"
     213                DRS_TEMP_ERR=2
     214        else
     215                # Return corresponding data for DRS temperatures from
     216                # FAD_CONTROL_TEMPEREATURE
     217                DRS_TEMP=`root -b -q -l \
     218                        "${MACROS}"/drstemp.C\(\""${TNAME}"\","${BEG}","${END}"\) \
     219                        | grep result \
     220                        | cut -f2- -d" "`
     221
     222                if [ ! -n "${DRS_TEMP}" ]
     223                then
     224                        DRS_TEMP="NULL, NULL"
     225                        DRS_TEMP_ERR=1
     226                else
     227                        DRS_TEMP_ERR=0
     228                fi
     229                echo ${DRS_TEMP}
     230        fi
     231
     232        # Return corresponding data for currents from BIAS_CONTROL_DYNAMIC_DATA
     233        BNAME="${FNAME}".BIAS_CONTROL_DYNAMIC_DATA.fits
     234        if [ ! -f "${BNAME}" ]
     235        then
     236                BIAS_DATA="NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL"
     237                BIAS_DATA_ERR=20
     238        else
     239                BIAS_DATA=`root -b -q -l \
     240                        "${MACROS}"/currents.C\(\""${BNAME}"\","${BEG}","${END}"\) \
     241                        | grep result \
     242                        | cut -f2- -d" "`
     243
     244                if [ ! -n "${BIAS_DATA}" ]
     245                then 
     246                        BIAS_DATA="NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL"
     247                        BIAS_DATA_ERR=10
     248                else
     249                        BIAS_DATA_ERR=0
     250                fi
     251                echo ${BIAS_DATA}
     252        fi
     253
     254        # Return corresponding data for trigger information from FTM_CONTROL_DATA
     255        MNAME="${FNAME}".FTM_CONTROL_DATA.fits
     256        if [ ! -f "${MNAME}" ]
     257        then
     258                        FTM_DATA="NULL, NULL, NULL, NULL"
     259                        FTM_DATA_ERR=200
     260        else
     261                FTM_DATA=`root -b -q -l \
     262                        "${MACROS}"/trigger.C\(\""${MNAME}"\","${BEG}","${END}"\) \
     263                        | grep result \
     264                        | cut -f2- -d" "`
     265
     266                if [ ! -n "${FTM_DATA}" ]
     267                then
     268                        FTM_DATA="NULL, NULL, NULL, NULL"
     269                        FTM_DATA_ERR=100
     270                else
     271                        FTM_DATA_ERR=0
     272                fi
     273                echo ${FTM_DATA}
     274        fi
     275
     276        # Return corresponding data for threshold seeting from FTU_CONTROL_DATA
     277        UNAME="${FNAME}".FTU_CONTROL_DATA.fits
     278        if [ ! -f "${UNAME}" ]
     279        then
     280                        FTU_DATA="NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL"
     281                        FTU_DATA_ERR=2000
     282        else
     283                FTU_DATA=`root -b -q -l \
     284                        "${MACROS}"/threshold.C\(\""${UNAME}"\","${BEG}","${END}"\) \
     285                        | grep result \
     286                        | cut -f2- -d" "`
     287
     288                if [ ! -n "${FTU_DATA}" ]
     289                then
     290                        FTU_DATA="NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL"
     291                        FTU_DATA_ERR=1000
     292                else
     293                        FTU_DATA_ERR=0
     294                fi
     295                echo ${FTU_DATA}
     296        fi
     297
     298        cd -
     299
     300        # Write the result as one row to the query file
     301        echo "/* "${FNAME}" */"                 >> ${OUTPUT}
     302        echo "ROW("                             >> ${OUTPUT}
     303        echo " "${TEL}, ${NIGHT}, ${RUNID},     >> ${OUTPUT}
     304        echo " "${DRS_TEMP},                    >> ${OUTPUT}
     305        echo " "${BIAS_DATA},                   >> ${OUTPUT}
     306        echo " "${FTM_DATA},                    >> ${OUTPUT}
     307        echo " "${FTU_DATA}                     >> ${OUTPUT}
     308        echo "),"                               >> ${OUTPUT}
     309
     310        ERRCODE=$((DRS_TEMP_ERR + BIAS_DATA_ERR + FTM_DATA_ERR + FTU_DATA_ERR))
     311
     312        echo "UPDATE DataOnDisk SET auxiliary=${ERRCODE}"       >> ${TMPOUT}
     313        echo "WHERE NIGHT=${NIGHT}"                             >> ${TMPOUT}
     314        echo "AND Telescope=${TEL}"                             >> ${TMPOUT}
     315        echo "AND RUNID=${RUNID};"                              >> ${TMPOUT}
    235316
    236317done
     
    255336   );
    256337"\ >> ${OUTPUT}
     338
     339cat ${TMPOUT} >> ${OUTPUT}
     340
     341rm -f ${TMPOUT}
Note: See TracChangeset for help on using the changeset viewer.