Ignore:
Timestamp:
09/01/21 07:56:42 (3 years ago)
Author:
maslowski
Message:
Added better error handeling and tracking in the databas.
Location:
trunk/Mars/hawc/processing/DiskToDB
Files:
8 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}
  • trunk/Mars/hawc/processing/DiskToDB/extract-raw-header2.sh

    r20093 r20103  
    4545usage()
    4646{
    47         echo "usage: $PROGRAM [-hir] [-o outfile] [Telescope Directory Night]"
     47        echo "usage: $PROGRAM [-hird] [-o outfile] [Telescope Directory Night]"
    4848        echo "  -h              display help"
    4949        echo "  -i              query ignores already existing rows"
    50         echo "  -r              query replaces already existing rows(overwrites -i)"
     50        echo "  -r              query replaces already existing rows (overwrites -i)"
    5151        echo "  -d              delete all entries for a given Night and Telescope"
    5252        echo "  -o outfile      name of the SQL query file"
     
    9292readonly CNTLONG=35
    9393
     94function InsertRaw()
     95{
     96        local res="${1}"
     97
     98        echo "${INSERT} RawData SET"            >> ${OUTPUT}
     99        echo Telescope=${TEL},                  >> ${OUTPUT}
     100        echo "${res}"                           >> ${OUTPUT}
     101        echo ";"                                >> ${OUTPUT}
     102}
     103
     104function SetRawStatus()
     105{
     106        local root="${1}"
     107        local runid="${2}"
     108        local stat="${3}"
     109
     110        echo "${root} header not valid!"
     111        echo "UPDATE DataOnDisk SET"            >> ${OUTPUT}
     112        echo "header=${stat} "                  >> ${OUTPUT}
     113        echo "WHERE NIGHT = ${NIGHT}"           >> ${OUTPUT}
     114        echo "AND Telescope = ${TEL}"           >> ${OUTPUT}
     115        echo "AND RUNID = ${runid}"             >> ${OUTPUT}
     116        echo ";"                                >> ${OUTPUT}
     117}
    94118
    95119echo \
     
    156180        then
    157181                echo "${ROOT}"
     182                RUNID=`basename "${ROOT}" .fits.fz | cut -f2 -d "_"`
    158183        else
    159184                echo "${ROOT} has wrong file extension and will not be processed."
    160185                continue
    161186        fi
     187        EXT=0
    162188
    163189        # Extract the header from the fits file with fitsdump,
     
    183209                | sed 's/^DATE[^-]/\`DATE\`/' \
    184210                | sed "s/^\(.*\)'\(0x[0-9a-f]*\)'\(.*\)$/\1\2\3/g" \
    185                 | sed '$!s/$/,/'`
     211                | sed '$!s/$/,/'` || EXT=1
     212
     213        if [ $EXT -ne 0 ]
     214        then
     215                SetRawStatus "${ROOT}" ${RUNID} "1"
     216                continue
     217        fi
    186218
    187219        # compare to refference header and count commas
     
    194226                [ "${CNTCHECK}" == "${CNTLONG}" ]
    195227        then
    196                 echo "${INSERT} RawData SET"            >> ${OUTPUT}
    197                 echo Telescope=${TEL},                  >> ${OUTPUT}
    198                 echo ${RESULT}                          >> ${OUTPUT}
    199                 echo ";"                                >> ${OUTPUT}
     228                InsertRaw "${RESULT}"
     229                SetRawStatus "${ROOT}" ${RUNID} "0"
    200230        elif [ "${CHECKSHORT}" == "${REFSHORT}" ] &&
    201231                [ "${CNTCHECK}" == "${CNTSHORT}" ]
    202232        then
    203                 echo "${INSERT} RawData SET"            >> ${OUTPUT}
    204                 echo Telescope=${TEL},                  >> ${OUTPUT}
    205                 echo ${RESULT}                          >> ${OUTPUT}
    206                 echo ";"                                >> ${OUTPUT}
     233                InsertRaw "${RESULT}"
     234                SetRawStatus "${ROOT}" ${RUNID} "0"
    207235        else
    208                 echo "${ROOT} header not valid!"
     236                SetRawStatus "${ROOT}" ${RUNID} "2"
    209237        fi
    210238
  • trunk/Mars/hawc/processing/DiskToDB/run-callisto2.sh

    r20093 r20103  
    3232readonly STAR=star
    3333# Directory to Mars environment (usually Mars/build)
    34 readonly MARS="/home/frankm/Dateien/Mars/build/"
     34readonly MARS="/home/frankm/Dateien/Mars-6.24.00/build4/"
    3535# Absolut path to macros
    36 readonly MACROS="/home/frankm/Dateien/Mars/hawc"
     36readonly MACROS="/home/frankm/Dateien/Mars-6.24.00/hawc"
    3737readonly PROGRAM=$0
    3838REPLACE=false
     
    6060if [ ! -d "${MARS}" ]
    6161then
    62         echo "Mars does not exists at ${MARS}. Please change in \
     62        echo "Mars does not exists at ${MARS}. Please change in \\
    6363                script ${PROGRAM}."
    6464        exit 1
     
    6868if [ ! -d "${MACROS}" ]
    6969then
    70         echo "Macros directorey does not exists at ${MACROS}. Please change in \
     70        echo "Macros directorey does not exists at ${MACROS}. Please change in \\
    7171                script ${PROGRAM}."
    7272        exit 1
     
    8888NIGHT="${4}"
    8989
     90function UpdateStatus()
     91{
     92        local tel="${1}"
     93        local night="${2}"
     94        local runid="${3}"
     95        local stat="${4}"
     96
     97        mysql --defaults-file=${CRED} \
     98                --compress \
     99                -e "UPDATE DataOnDisk \
     100                SET DataOnDisk.callisto = ${stat} \
     101                WHERE DataOnDisk.Telescope = ${tel} \
     102                AND DataOnDisk.NIGHT = ${night} \
     103                AND DataOnDisk.RUNID = ${runid};"
     104}
     105
    90106# Get all runs that can (and should) be calibrated
    91107# Pipe the output to mysql and read the
     
    94110"\
    95111SELECT
    96         NIGHT, RUNID, DrsNight, DrsRunID
     112        Calibration.NIGHT,
     113        Calibration.RUNID,
     114        Calibration.DrsNight,
     115        Calibration.DrsRunID
    97116FROM
    98117        Calibration
     118INNER JOIN
     119        DataOnDisk
     120ON
     121        DataOnDisk.Telescope = Calibration.Telescope
     122AND
     123        DataOnDisk.NIGHT = Calibration.NIGHT
     124AND
     125        DataOnDisk.RUNID = Calibration.RUNID
    99126WHERE
    100         Telescope=${TEL}
     127        Calibration.Telescope = ${TEL}
    101128AND     
    102         NIGHT=${NIGHT}
     129        Calibration.NIGHT = ${NIGHT}
     130AND
     131        DataOnDisk.calibration = 0
    103132ORDER BY
    104         NIGHT, RUNID\
     133        Calibration.NIGHT, Calibration.RUNID\
    105134"\
    106135|  mysql \
     
    161190
    162191                       # Execute the calibration and write output to log-file
    163                        root -b -q -l ${MACROS}/callisto.C'("'"${DATA}"/${DATPATH}/${DATNAME}'","'"${DATA}"/${DRSPATH}/${DRSNAME}'","'"${OUT}"'")' \
     192                       root -b -q -l ${MACROS}/callisto.C'("'"${DATA}"/${DATPATH}/${DATNAME}'","'"${DATA}"/${DRSPATH}/${DRSNAME}'", 0 ,"'"${OUT}"'")' \
    164193                               2>&1 | tee "${OUT}"/${PREFIX}.log
    165194
     
    176205                       if [ "${RC}" == "0" ]
    177206                       then
    178                                touch "${OUT}"/.${PREFIX}.success
     207                                touch "${OUT}"/.${PREFIX}.success
     208                       else
     209                                UpdateStatus ${TEL} ${NIGHT} ${DATRUNID} 1
    179210                       fi
    180211
  • trunk/Mars/hawc/processing/DiskToDB/run-root2sql2.sh

    r20093 r20103  
    8989fi
    9090
     91function UpdateStatus()
     92{
     93        local tel="${1}"
     94        local night="${2}"
     95        local runid="${3}"
     96        local suf="${4}"
     97        local stat="${5}"
     98
     99        if [ $suf = I ]
     100        then
     101                local col=star
     102        elif [ $suf = Y ]
     103        then
     104                local col=callisto
     105        fi
     106
     107        mysql --defaults-file=${CRED} \
     108                --compress \
     109                -e "UPDATE DataOnDisk \
     110                SET DataOnDisk.${col} = ${stat} \
     111                WHERE DataOnDisk.Telescope = ${tel} \
     112                AND DataOnDisk.NIGHT = ${night} \
     113                AND DataOnDisk.RUNID = ${runid};"
     114}
     115
     116function PropagateStatus()
     117{
     118        local tel="${1}"
     119        local night="${2}"
     120        local suf="${3}"
     121
     122        if [ $suf = I ]
     123        then
     124                local col=star
     125        elif [ $suf = Y ]
     126        then
     127                local col=callisto
     128        fi
     129
     130        mysql --defaults-file=${CRED} \
     131                --compress \
     132                -e "UPDATE DataOnDisk \
     133                SET DataOnDisk.${col} = 6 \
     134                WHERE DataOnDisk.Telescope = ${tel} \
     135                AND DataOnDisk.NIGHT = ${night} \
     136                AND DataOnDisk.calibration != 0;"
     137
     138        mysql --defaults-file=${CRED} \
     139                --compress \
     140                -e "UPDATE DataOnDisk \
     141                SET DataOnDisk.${col} = 3 \
     142                WHERE DataOnDisk.Telescope = ${tel} \
     143                AND DataOnDisk.NIGHT = ${night} \
     144                AND DataOnDisk.calibration = 0 \
     145                AND DataOnDisk.${col} IS NULL;"
     146}
     147
    91148# Get all runs that can (and should) be calibrated
    92149# Pipe the output to mysql and read the
     
    95152"\
    96153SELECT
    97         NIGHT, RUNID
     154        Calibration.NIGHT,
     155        Calibration.RUNID
    98156FROM
    99157        Calibration
     158INNER JOIN
     159        DataOnDisk
     160ON
     161        DataOnDisk.Telescope = Calibration.Telescope
     162AND
     163        DataOnDisk.NIGHT = Calibration.NIGHT
     164AND
     165        DataOnDisk.RUNID = Calibration.RUNID
    100166WHERE
    101         Telescope = ${TEL}
     167        Calibration.Telescope = ${TEL}
     168AND     
     169        Calibration.NIGHT = ${NIGHT}
    102170AND
    103         NIGHT = ${NIGHT}
     171        DataOnDisk.calibration = 0
    104172ORDER BY
    105         NIGHT, RUNID\
    106 
     173        Calibration.NIGHT, Calibration.RUNID;\
    107174"\
    108175 |  mysql \
     
    139206
    140207                echo RC=${PIPESTATUS[0]} >> "${DIR}"/${PREFIX}-root2sql.log
     208
     209                UpdateStatus ${TEL} ${NIGHT} ${RUNID} ${SUFFIX} 0
     210
    141211        else
    142212                echo Skipped.
     213                UpdateStatus ${TEL} ${NIGHT} ${RUNID} ${SUFFIX} 2
    143214        fi
    144215
    145216done
     217
     218PropagateStatus ${TEL} ${NIGHT} ${SUFFIX}
  • trunk/Mars/hawc/processing/DiskToDB/run-scripts.sh

    r20093 r20103  
    7777readonly DATE=`date +%Y%m%d_%H%M`
    7878readonly LOG="./log/${SCRPTN}_${DATE}.log"
    79 exec 3>&1 1>>${LOG}
    80 exec 4>>${LOG}
    81 # exec 3>&1
    82 # exec 4>&1
     79# exec 3>&1 1>>${LOG}
     80# exec 4>>${LOG}
     81exec 3>&1
     82exec 4>&1
    8383
    8484echo "Start processing data"
     
    8888        # Delete entries form table ${3} for a given Telescope and Night
    8989        # Arguments: Credentials Telescope Table Night
    90         mysql --defaults-file="${1}" \
     90        local cred="${1}"
     91        local tel="${2}"
     92        local table="${3}"
     93        local night="${4}"
     94
     95        mysql --defaults-file="${cred}" \
    9196                --skip-column-names \
    9297                --batch \
    9398                --raw \
    9499                --compress \
    95                 -e "DELETE FROM ${3} WHERE Telescope = ${2} AND NIGHT = ${4};"
     100                -e "DELETE FROM ${table} WHERE Telescope = ${tel} \
     101                AND NIGHT = ${night};"
    96102}
    97103
    98104function SetStatus()
    99105{
    100         # Query with process update
    101         # Arguments: Credentials Telescope Status Night
    102         mysql --defaults-file="${1}" \
     106        # Status update for one Column, Night and Telescope
     107        # Arguments: Credentials Telescope Column Value Night
     108        local cred="${1}"
     109        local tel="${2}"
     110        local col="${3}"
     111        local val="${4}"
     112        local night="${5}"
     113
     114        # Check if a valid Column was selected
     115        if [ ${col} != "header" ] \
     116                && [ ${col} != "calibration" ] \
     117                && [ ${col} != "auxiliary" ] \
     118                && [ ${col} != "callisto" ] \
     119                && [ ${col} != "star" ]
     120        then
     121                echo "ERROR: ${col} is not a valid column."
     122                exit 1
     123        fi
     124
     125        mysql --defaults-file="${cred}" \
    103126                --skip-column-names \
    104127                --batch \
    105128                --raw \
    106129                --compress \
    107                 -e "UPDATE DataOnDisk SET STATUS = ${3} WHERE NIGHT = ${4} \
    108                 AND Telescope = ${2};"
     130                -e "UPDATE DataOnDisk SET ${col} = ${val}\
     131                WHERE NIGHT = ${night} AND Telescope = ${tel};"
    109132}
    110133
    111134function GetStatus()
    112135{
    113         # Return status of Night from database
    114         # Arguments: Credentials Telescope Night
    115         local STATUS=`mysql --defaults-file="${1}" \
     136        # Return status of Night for a given Column and Telescope
     137        # Arguments: Credentials Telescope Column Night
     138        local cred="${1}"
     139        local tel="${2}"
     140        local col="${3}"
     141        local night="${4}"
     142
     143        # Check if a valid Column was selected
     144        if [ ${col} != "header" ] \
     145                && [ ${col} != "calibration" ] \
     146                && [ ${col} != "auxiliary" ] \
     147                && [ ${col} != "callisto" ] \
     148                && [ ${col} != "star" ]
     149        then
     150                echo "ERROR: ${col} is not a valid column."
     151                exit 1
     152        fi
     153
     154        local STATUS=`mysql --defaults-file="${cred}" \
    116155                --skip-column-names \
    117156                --batch \
    118157                --raw \
    119158                --compress \
    120                 -e "SELECT DISTINCT STATUS FROM DataOnDisk WHERE NIGHT = ${3} \
    121                 AND Telescope = ${2};"`
    122 
    123         if [ -z ${STATUS} ]
    124         then
    125                 echo "ERROR: Status does not exist for telescope: ${2} and night: ${3}" >&2
     159                -e "SELECT DISTINCT ${col} FROM DataOnDisk \
     160                WHERE NIGHT = ${night} \
     161                AND Telescope = ${tel} \
     162                AND ${col} IS NULL;"`
     163
     164        echo "${STATUS}"
     165}
     166
     167
     168function DoesDirExists()
     169{
     170        local thing="${1}"
     171        # Check if thing exists
     172        if [ ! -d "${thing}" ]
     173        then
     174                echo "${thing} is not a valid Path. Please change variable in script ${SCRPTN}."
    126175                exit 1
    127176        fi
    128 
    129         if [ `echo "${STATUS}" | wc -l` -ne "1" ]
    130         then
    131                 echo "ERROR: Not all status values are the same for the night: ${3}!" >&2
     177}
     178
     179function DoesFileExists()
     180{
     181        local thing="${1}"
     182        # Check if thing exists
     183        if [ ! -f "${thing}" ]
     184        then
     185                echo "${thing} is not a valid File. Please change variable in script ${SCRPTN}."
    132186                exit 1
    133187        fi
    134 
    135         echo "${STATUS}"
    136 }
     188}
     189
    137190
    138191# Define variables
     
    147200# Credentials for root2sql for star
    148201readonly STARRC='../root2sql-star.rc'
     202
     203# Check if variable paths point to something sensible
     204DoesDirExists "${DIR}"
     205DoesFileExists "${CRED}"
     206DoesFileExists "${CALLISTORC}"
     207DoesFileExists "${STARRC}"
     208
    149209# SQL outputs
    150210mkdir -p ./queries
     
    156216# Create Database of existing files
    157217# Create SQL query with:
    158 # (Telescope, Night, RUNID, ISDRSFILE, ISPROCESSED).
     218# (Telescope, Night, RUNID, ISDRSFILE).
    159219echo "Updating file table"
    160220bash ./update-file-table2.sh -i -o "${ONDISK}" "${TEL}" "${DIR}/raw"
     
    170230        --raw \
    171231        --compress \
    172         -e "SELECT DISTINCT NIGHT FROM DataOnDisk WHERE STATUS != 5 \
     232        -e "SELECT DISTINCT NIGHT FROM DataOnDisk \
     233        WHERE header IS NULL \
     234        OR calibration IS NULL \
     235        OR auxiliary IS NULL \
     236        OR callisto IS NULL \
     237        OR star IS NULL \
    173238        AND Telescope = ${TEL};"`
    174239
     
    182247echo "Updating database"
    183248
     249NIGHTS=20201111
     250
    184251echo "Nights to process:"
    185252echo "${NIGHTS}"
     
    191258for NIGHT in ${NIGHTS}
    192259do
    193         STATUS=`GetStatus ${CRED} ${TEL} ${NIGHT}`
    194         echo "Status = ${STATUS} for night = ${NIGHT}"
    195         echo " "
    196 
    197         if [ ${STATUS} -lt "1" ]
     260        HEAD_S=`GetStatus ${CRED} ${TEL} "header" ${NIGHT}`
     261        CALI_S=`GetStatus ${CRED} ${TEL} "calibration" ${NIGHT}`
     262        AUXI_S=`GetStatus ${CRED} ${TEL} "auxiliary" ${NIGHT}`
     263        CALL_S=`GetStatus ${CRED} ${TEL} "callisto" ${NIGHT}`
     264        STAR_S=`GetStatus ${CRED} ${TEL} "star" ${NIGHT}`
     265
     266        echo "header = ${HEAD_S} for night = ${NIGHT}"
     267        echo " "
     268
     269        # If header is null
     270        if [ ! -z ${HEAD_S} ] && [ ${HEAD_S} = "NULL" ]
    198271        then
    199272                # Get raw data headers
     
    205278                echo "Uploading raw headers for night: ${NIGHT}"
    206279                mysql --defaults-file="${CRED}" < "${RAW}"
    207                 SetStatus ${CRED} ${TEL} "1" ${NIGHT}
    208280                echo "Finished uploading raw headers for night: ${NIGHT}"
    209281                echo " "
    210282        fi
    211283
    212         if [ ${STATUS} -lt "2" ]
     284        echo "calibration = ${CALI_S} for night = ${NIGHT}"
     285        echo " "
     286
     287        # If header is null and or calibration is null
     288        if ([ ! -z ${HEAD_S} ] && [ ${HEAD_S} = "NULL" ]) \
     289                || ([ ! -z ${CALI_S} ] && [ ${CALI_S} = "NULL" ])
    213290        then
    214291                # Get calibration files
     
    219296                echo "Uploading calibration for night: ${NIGHT}"
    220297                mysql --defaults-file="${CRED}" < "${CALIB}"
    221                 SetStatus ${CRED} ${TEL} "2" ${NIGHT}
    222298                echo "Finished uploading calibration for night: ${NIGHT}"
    223299                echo " "
    224300        fi
    225301
    226         if [ ${STATUS} -lt "3" ]
     302        echo "auxiliary = ${AUXI_S} for night = ${NIGHT}"
     303        echo " "
     304
     305        # If header is null and or calibration is null and or auxiliary is null
     306        if ([ ! -z ${HEAD_S} ] && [ ${HEAD_S} = "NULL" ]) \
     307                || ([ ! -z ${CALI_S} ] && [ ${CALI_S} = "NULL" ]) \
     308                || ([ ! -z ${AUXI_S} ] && [ ${AUXI_S} = "NULL" ])
    227309        then
    228310                # Get aux data
     
    235317                echo "Uploading aux data for night: ${NIGHT}"
    236318                mysql --defaults-file="${CRED}" < "${AUX}"
    237                 SetStatus ${CRED} ${TEL} "3" ${NIGHT}
    238319                echo "Finished uploading aux data for night: ${NIGHT}"
    239320                echo " "
    240321        fi
    241322
    242         if [ ${STATUS} -lt "4" ]
     323        echo "callisto = ${CALL_S} for night = ${NIGHT}"
     324        echo " "
     325
     326        # If header is null and or calibration is null and or callisto is null
     327        if ([ ! -z ${HEAD_S} ] && [ ${HEAD_S} = "NULL" ]) \
     328                || ([ ! -z ${CALI_S} ] && [ ${CALI_S} = "NULL" ]) \
     329                || ([ ! -z ${CALL_S} ] && [ ${CALL_S} = "NULL" ])
    243330        then
    244331                # Get callisto data
     
    260347                        "${DIR}"/callisto \
    261348                        ${NIGHT}
    262                 SetStatus ${CRED} ${TEL} "4" ${NIGHT}
    263349                echo "Finished uploading callisto entries for night: ${NIGHT}"
    264350                echo " "
    265351        fi
    266352
    267         if [ ${STATUS} -lt "5" ]
     353        echo "star = ${STAR_S} for night = ${NIGHT}"
     354        echo " "
     355
     356        # If header is null and or calibration is null and or callisto is null
     357        # and or star is null
     358        if ([ ! -z ${HEAD_S} ] && [ ${HEAD_S} = "NULL" ]) \
     359                || ([ ! -z ${CALI_S} ] && [ ${CALI_S} = "NULL" ]) \
     360                || ([ ! -z ${CALL_S} ] && [ ${CALL_S} = "NULL" ]) \
     361                || ([ ! -z ${STAR_S} ] && [ ${STAR_S} = "NULL" ])
    268362        then
    269363                # Get star data
     
    281375                        "${DIR}"/star \
    282376                        ${NIGHT}
    283                 SetStatus ${CRED} ${TEL} "5" ${NIGHT}
    284377                echo "Finished uploading star entries for night: ${NIGHT}"
    285378                echo " "
  • trunk/Mars/hawc/processing/DiskToDB/run-star2.sh

    r20093 r20103  
    3232readonly STAR=star
    3333# Directory to Mars environment (usually Mars/build)
    34 readonly MARS="/home/frankm/Dateien/Mars/build/"
     34readonly MARS="/home/frankm/Dateien/Mars-6.24.00/build4/"
    3535# Absolut path to macros
    36 readonly MACROS="/home/frankm/Dateien/Mars/hawc"
     36readonly MACROS="/home/frankm/Dateien/Mars-6.24.00/hawc"
    3737readonly PROGRAM=$0
    3838REPLACE=false
     
    8787DATA="${3}"
    8888NIGHT="${4}"
     89
     90function UpdateStatus()
     91{
     92        local tel="${1}"
     93        local night="${2}"
     94        local runid="${3}"
     95        local stat="${4}"
     96
     97        mysql --defaults-file=${CRED} \
     98                --compress \
     99                -e "UPDATE DataOnDisk \
     100                SET DataOnDisk.star = ${stat} \
     101                WHERE DataOnDisk.Telescope = ${tel} \
     102                AND DataOnDisk.NIGHT = ${night} \
     103                AND DataOnDisk.RUNID = ${runid};"
     104}
    89105
    90106# Get all runs that can (and should) be calibrated
     
    166182                        then
    167183                                touch "${OUT}"/.${PREFIX}.success
     184                        else
     185                                UpdateStatus ${TEL} ${NIGHT} ${DATRUNID} 1
    168186                        fi
    169187
  • trunk/Mars/hawc/processing/DiskToDB/update-file-table2.sh

    r20091 r20103  
    33# Recursively finds all .fits.fz and .drs.fits files in DIR and extract
    44# NIGHT, RUNID and if the file is a DRS file and writes an SQL query with the
    5 # columns: (Telescope, NIGHT, RUNID, ISDRSFILE, ISPRECESSED) to OUTPUT.
     5# columns: (Telescope, NIGHT, RUNID, ISDRSFILE,
     6# header, calibration, auxiliary, callisto, star) to OUTPUT.
    67#
    78# Example:
     
    7778        RUNID mediumint UNSIGNED NOT NULL,
    7879        ISDRSFILE tinyint(1) NOT NULL,
    79         STATUS tinyint UNSIGNED NOT NULL,
     80        header tinyint UNSIGNED,
     81        calibration tinyint UNSIGNED,
     82        auxiliary smallint UNSIGNED,
     83        callisto tinyint UNSIGNED,
     84        star tinyint UNSIGNED,
    8085        Updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    8186                ON UPDATE CURRENT_TIMESTAMP,
     
    8994        RUNID mediumint UNSIGNED NOT NULL,
    9095        ISDRSFILE tinyint(1) NOT NULL,
    91         STATUS tinyint UNSIGNED NOT NULL,
     96        header tinyint UNSIGNED,
     97        calibration tinyint UNSIGNED,
     98        auxiliary smallint UNSIGNED,
     99        callisto tinyint UNSIGNED,
     100        star tinyint UNSIGNED,
    92101        Updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    93102                ON UPDATE CURRENT_TIMESTAMP,
     
    95104);
    96105
    97 INSERT INTO DataOnDisk_tmp (Telescope, NIGHT, RUNID, ISDRSFILE, STATUS)
     106INSERT INTO DataOnDisk_tmp (Telescope, NIGHT, RUNID, ISDRSFILE)
    98107VALUES
    99108"\ > ${OUTPUT}
     
    106115        | cut -f1 -d "."`
    107116
    108 # Format to (Telescope, NIGHT, RUNID, ISDRSFILE, ISPROCESSED),
     117# Format to (Telescope, NIGHT, RUNID, ISDRSFILE),
    109118FZQUERY=`paste <(for i in ${NRID}; do echo ${TEL}; done) \
    110119        <(echo "${NRID}" | cut -f1 -d "_") \
    111120        <(echo "${NRID}" | cut -f2 -d "_") \
    112121        <(for i in ${NRID}; do echo "false"; done) \
    113         <(for i in ${NRID}; do echo "0"; done) \
    114122        --delimiters "," \
    115123        | sed 's/^/(/' \
     
    123131        | cut -f1 -d "."`
    124132
    125 # Format to (Telescope, NIGHT, RUNID, ISDRSFILE, ISPROCESSED),
     133# Format to (Telescope, NIGHT, RUNID, ISDRSFILE),
    126134DRSQUERY=`paste <(for i in ${DNRID}; do echo ${TEL}; done) \
    127135        <(echo "${DNRID}" | cut -f1 -d "_") \
    128136        <(echo "${DNRID}" | cut -f2 -d "_") \
    129137        <(for i in ${DNRID}; do echo "true"; done) \
    130         <(for i in ${DNRID}; do echo "0"; done) \
    131138        --delimiters "," \
    132139        | sed 's/^/(/' \
     
    140147sed -i '$s/,$/;/' "${OUTPUT}"
    141148
    142 # 1) If there is data in the database that is not on disk then set status = 0
     149# 1) If there is data in the database that is not on disk then set star = 0
    143150#    for that night
    144151# 2) Delete all entries from the database that are not on disk
     
    152159        RUNID mediumint UNSIGNED NOT NULL,
    153160        ISDRSFILE tinyint(1) NOT NULL,
    154         STATUS tinyint UNSIGNED NOT NULL,
     161        header tinyint UNSIGNED,
     162        calibration tinyint UNSIGNED,
     163        auxiliary smallint UNSIGNED,
     164        callisto tinyint UNSIGNED,
     165        star tinyint UNSIGNED,
    155166        Updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    156167                ON UPDATE CURRENT_TIMESTAMP,
     
    160171        (SELECT Telescope, NIGHT, RUNID, ISDRSFILE FROM DataOnDisk_tmp);
    161172
    162 UPDATE DataOnDisk SET STATUS = 0 WHERE NIGHT IN
     173UPDATE DataOnDisk SET star = NULL WHERE NIGHT IN
    163174        (SELECT NIGHT FROM TableNotDisk);
    164175
  • trunk/Mars/hawc/processing/DiskToDB/write-calibration-query.sh

    r20091 r20103  
    1414function ErrExit()
    1515{
    16         echo "ERROR: Line `caller`: ${BASH_COMMAND}" >&2
     16        echo "ERROR: Line \`caller\`: ${BASH_COMMAND}" >&2
    1717        exit 1
    1818}
     
    9494echo \
    9595"\
     96-- Set Status to 6 if there was an error is the extraction of RawData
     97UPDATE DataOnDisk
     98SET DataOnDisk.calibration = 6
     99WHERE DataOnDisk.header != 0;
     100
    96101CREATE TEMPORARY TABLE Calibration_tmp
    97102(
    98    WITH Table1 AS
    99    (
    100       SELECT
    101          -- NIGHT and RUNID of the data file
    102          R1.Telescope AS Telescope,
    103          R1.NIGHT     AS NIGHT,
    104          R1.RUNID     AS RUNID,
    105          -- NIGHT and RUNID of the DRS file
    106          R2.NIGHT     AS DrsNight,
    107          R2.RUNID     AS DrsRunID,
    108          -- Time difference between the two
    109          LEAST(
    110              ABS(UNIX_TIMESTAMP(R2.\`DATE-OBS\`)-UNIX_TIMESTAMP(R1.\`DATE-OBS\`)),
    111              ABS(UNIX_TIMESTAMP(R2.\`DATE-OBS\`)-UNIX_TIMESTAMP(R1.\`DATE-END\`)),
    112              ABS(UNIX_TIMESTAMP(R2.\`DATE-END\`)-UNIX_TIMESTAMP(R1.\`DATE-OBS\`)),
    113              ABS(UNIX_TIMESTAMP(R2.\`DATE-END\`)-UNIX_TIMESTAMP(R1.\`DATE-END\`))
    114          ) AS DeltaT,
    115          -- Assign a row number to each combination of data-file and drs-file
    116          -- after sorting them by time difference
    117          ROW_NUMBER() OVER(PARTITION BY R1.NIGHT, R1.RUNID, R1.Telescope ORDER BY
    118             LEAST(
    119             ABS(UNIX_TIMESTAMP(R2.\`DATE-OBS\`)-UNIX_TIMESTAMP(R1.\`DATE-OBS\`)),
    120             ABS(UNIX_TIMESTAMP(R2.\`DATE-OBS\`)-UNIX_TIMESTAMP(R1.\`DATE-END\`)),
    121             ABS(UNIX_TIMESTAMP(R2.\`DATE-END\`)-UNIX_TIMESTAMP(R1.\`DATE-OBS\`)),
    122             ABS(UNIX_TIMESTAMP(R2.\`DATE-END\`)-UNIX_TIMESTAMP(R1.\`DATE-END\`))
    123             )
    124          ) AS RowNumber
    125       FROM
    126          RawData R1
    127       -- Join the table with itself to get all possible combinations of runs
    128       CROSS JOIN
    129          RawData R2
    130       -- Join the DRS files with the table that tells you whether they can be used
    131       -- if the table does not (yet) exists, this can be omitted
    132       -- LEFT JOIN
    133       --    DoNotUse ON (R2.NIGHT=DoNotUse.NIGHT AND R2.RUNID=DoNotUse.RUNID)
    134       WHERE
    135          -- Of course claibration must be from the same telescope
    136          R1.Telescope=R2.Telescope
    137       AND
    138          -- Select all combinations that have a data file in R1 and a drs file (at step 1) in R2
    139          ISNULL(R1.DRSSTEP) AND R2.DRSSTEP=1
    140       AND
    141          -- Only DRS files with 100 events and the correct ROI are considered
    142          R2.ZNAXIS2=1000 AND R1.NROI=R2.NROI
    143          AND R1.NIGHT = ${NIGHT}
    144          AND R1.NIGHT = ${NIGHT}
    145          AND R1.Telescope = ${TEL}
    146       -- AND
    147          -- Check if they are valid
    148          -- IFNULL(DoNotUse.WrongVoltage,false)!=true
    149       -- This can be used to restrict the number of combinations     
    150       -- AND ABS(UNIX_TIMESTAMP(R2.\`DATE-OBS\`)-UNIX_TIMESTAMP(R1.\`DATE-OBS\`))<78*3600
    151       ORDER BY
    152          R1.Telescope,
    153          R1.NIGHT,
    154          R1.RUNID,
    155          DeltaT
    156     )
    157     SELECT
    158        Telescope,
    159        NIGHT,
    160        RUNID,
    161        DrsNight,
    162        DrsRunId,
    163        DeltaT/3600e0 AS DeltaT
    164     FROM
    165        Table1
    166     WHERE
    167        -- Select only the rows with the smallest DeltaT
    168        RowNumber = 1
     103        WITH Table1 AS
     104        (
     105                SELECT
     106                -- NIGHT and RUNID of the data file
     107                R1.Telescope AS Telescope,
     108                R1.NIGHT     AS NIGHT,
     109                R1.RUNID     AS RUNID,
     110                -- NIGHT and RUNID of the DRS file
     111                R2.NIGHT     AS DrsNight,
     112                R2.RUNID     AS DrsRunID,
     113                -- Time difference between the two
     114                LEAST(
     115                        ABS(UNIX_TIMESTAMP(R2.\`DATE-OBS\`)
     116                                - UNIX_TIMESTAMP(R1.\`DATE-OBS\`)),
     117                        ABS(UNIX_TIMESTAMP(R2.\`DATE-OBS\`)
     118                                - UNIX_TIMESTAMP(R1.\`DATE-END\`)),
     119                        ABS(UNIX_TIMESTAMP(R2.\`DATE-END\`)
     120                                - UNIX_TIMESTAMP(R1.\`DATE-OBS\`)),
     121                        ABS(UNIX_TIMESTAMP(R2.\`DATE-END\`)
     122                                - UNIX_TIMESTAMP(R1.\`DATE-END\`))
     123                ) AS DeltaT,
     124                -- Assign a row number to each combination of data-file and
     125                -- drs-file after sorting them by time difference
     126                ROW_NUMBER() OVER(PARTITION BY R1.NIGHT, R1.RUNID, R1.Telescope
     127                        ORDER BY
     128                        LEAST(
     129                                ABS(UNIX_TIMESTAMP(R2.\`DATE-OBS\`)
     130                                        - UNIX_TIMESTAMP(R1.\`DATE-OBS\`)),
     131                                ABS(UNIX_TIMESTAMP(R2.\`DATE-OBS\`)
     132                                        - UNIX_TIMESTAMP(R1.\`DATE-END\`)),
     133                                ABS(UNIX_TIMESTAMP(R2.\`DATE-END\`)
     134                                        - UNIX_TIMESTAMP(R1.\`DATE-OBS\`)),
     135                                ABS(UNIX_TIMESTAMP(R2.\`DATE-END\`)
     136                                        - UNIX_TIMESTAMP(R1.\`DATE-END\`))
     137                        )
     138                ) AS RowNumber
     139                FROM (
     140                        SELECT RawData.* FROM RawData
     141                        INNER JOIN DataOnDisk
     142                        ON DataOnDisk.Telescope = RawData.Telescope
     143                        AND DataOnDisk.NIGHT = RawData.NIGHT
     144                        AND DataOnDisk.RUNID = RawData.RUNID
     145                        AND DataOnDisk.ISDRSFILE = 0
     146                        WHERE DataOnDisk.header = 0
     147                ) AS R1
     148                -- Join the table with itself to get all possible combinations
     149                -- of runs
     150                CROSS JOIN (
     151                        SELECT RawData.* FROM RawData
     152                        INNER JOIN DataOnDisk
     153                        ON DataOnDisk.Telescope = RawData.Telescope
     154                        AND DataOnDisk.NIGHT = RawData.NIGHT
     155                        AND DataOnDisk.RUNID = RawData.RUNID
     156                        AND DataOnDisk.ISDRSFILE = 0
     157                        WHERE DataOnDisk.header = 0
     158                ) AS R2
     159                -- Join the DRS files with the table that tells you whether
     160                -- they can be used if the table does not (yet) exists, this
     161                -- can be omitted
     162                WHERE
     163                -- Of course claibration must be from the same telescope
     164                R1.Telescope=R2.Telescope
     165                AND
     166                -- Select all combinations that have a data file in R1 and a
     167                -- drs file (at step 1) in R2
     168                ISNULL(R1.DRSSTEP) AND R2.DRSSTEP=1
     169                AND
     170                -- Only DRS files with 100 events and the correct ROI are
     171                -- considered
     172                R2.ZNAXIS2=1000 AND R1.NROI=R2.NROI
     173                AND R1.NIGHT = ${NIGHT}
     174                AND R2.NIGHT = ${NIGHT}
     175                AND R1.Telescope = ${TEL}
     176                -- AND
     177                -- Check if they are valid
     178                -- IFNULL(DoNotUse.WrongVoltage,false)!=true
     179                -- This can be used to restrict the number of combinations     
     180                -- AND ABS(UNIX_TIMESTAMP(R2.\`DATE-OBS\`)-UNIX_TIMESTAMP(R1.\`DATE-OBS\`))<78*3600
     181                ORDER BY
     182                R1.Telescope,
     183                R1.NIGHT,
     184                R1.RUNID,
     185                DeltaT
     186        )
     187        SELECT
     188        Telescope,
     189        NIGHT,
     190        RUNID,
     191        DrsNight,
     192        DrsRunId,
     193        DeltaT/3600e0 AS DeltaT
     194        FROM
     195        Table1
     196        WHERE
     197        -- Select only the rows with the smallest DeltaT
     198        RowNumber = 1
    169199);
    170200
    171 ${INSERT} Calibration SELECT * FROM Calibration_tmp;
     201-- Insert Calibration data into Database
     202INSERT INTO Calibration SELECT * FROM Calibration_tmp;
     203
     204-- Set Status to 0 for all valid headers
     205UPDATE DataOnDisk
     206SET DataOnDisk.calibration = 0
     207WHERE DataOnDisk.header = 0;
     208
     209-- Set Status to 2 if there was no drs file with step = 1 in the NIGHT
     210UPDATE DataOnDisk
     211SET DataOnDisk.calibration = 2
     212WHERE EXISTS(SELECT * FROM Calibration WHERE NIGHT=${NIGHT}) = 0;
    172213"\ >> ${OUTPUT}
Note: See TracChangeset for help on using the changeset viewer.