#!/bin/bash # File containing the access credentials for the database CREDENTIALS=credentials-read-only.cnf # Specify the telescope for which to run the script. Replace '1' # by $1 if the telesocpe number is supplied as an option to the script TELESCOPE=1 # The data is expected to be found in /data/raw and data/callisto DATA="/data" CALLISTO=callisto # output is written to data/star STAR=star # Directory to Mars environment (usually Mars/build) MARS=~/Mars/build # Relative path to macros MACROS=../hawc # Get all runs that can (and should) be calibrated # Pipe the output to mysql and read the # mysql output line-by-libe echo \ "\ SELECT NIGHT, RUNID FROM Calibration WHERE Telescope=${TELESCOPE} ORDER BY NIGHT, RUNID\ "\ | mysql \ --defaults-file=${CREDENTIALS} \ --skip-column-names \ --batch --raw \ --compress \ | \ while read -r -a LINE do # Get NIGHT and RUNID of all files NIGHT=${LINE[0]} RUNID=${LINE[1]} # Formatting of the file paths and names DATPATH=${NIGHT:0:4}/${NIGHT:4:2}/${NIGHT:6:2} PREFIX=`printf ${NIGHT}_%03d ${RUNID}` DATNAME=`printf ${PREFIX}_Y.root ${RUNID}` OUT=${DATA}/${STAR}/${DATPATH} IN=${DATA}/${CALLISTO}/${DATPATH} echo "" echo ${DATNAME} echo ${IN} " => " ${OUT} # Check if not yet successfully processed but sucessfully calibrated if [[ -f "${IN}/.${PREFIX}.success" && ! -f "${IN}/.${PREFIX}.running" && ! -f "${OUT}/.${PREFIX}.success" ]] then cd ${MARS} mkdir -p ${OUT} # Flag that a process is running rm -f ${OUT}/.${PREFIX}.done rm -f ${OUT}/.${PREFIX}.success touch ${OUT}/.${PREFIX}.running # Execute image parameter calculation and write log-file root -b -q -l ${MACROS}/star.C'("'${IN}/${DATNAME}'","'${OUT}'")' \ 2>&1 | tee ${OUT}/${PREFIX}.log # Remember exit status of callisto RC=${PIPESTATUS[0]} echo RC=${RC} | tee -a ${OUT}/${PREFIX}.log echo ${RC} > ${OUT}/.${PREFIX}.done # Flag that processing is finished rm -f ${OUT}/.${PREFIX}.running # If processing was successfull write coresponding flag if [ "${RC}" == "0" ] then touch ${OUT}/.${PREFIX}.success fi cd - else echo Skipped. fi done