1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # File containing the access credentials for the database
|
---|
4 | CREDENTIALS=credentials-read-only.cnf
|
---|
5 |
|
---|
6 | # Specify the telescope for which to run the script. Replace '1'
|
---|
7 | # by $1 if the telesocpe number is supplied as an option to the script
|
---|
8 | TELESCOPE=1
|
---|
9 |
|
---|
10 | # The data is expected to be found in /data/raw and data/callisto
|
---|
11 | DATA="/data"
|
---|
12 | CALLISTO=callisto
|
---|
13 | # The .success file in /data/star will be resetted
|
---|
14 | STAR=star
|
---|
15 | # Directory to Mars environment (usually Mars/build)
|
---|
16 | MARS=~/Mars/build
|
---|
17 | # Relative path to macros
|
---|
18 | MACROS=../hawc
|
---|
19 |
|
---|
20 | # Get all runs that can (and should) be calibrated
|
---|
21 | # Pipe the output to mysql and read the
|
---|
22 | # mysql output line-by-libe
|
---|
23 | echo \
|
---|
24 | "\
|
---|
25 | SELECT
|
---|
26 | NIGHT, RUNID, DrsNight, DrsRunID
|
---|
27 | FROM
|
---|
28 | Calibration
|
---|
29 | WHERE
|
---|
30 | Telescope=${TELESCOPE}
|
---|
31 | ORDER BY
|
---|
32 | NIGHT, RUNID\
|
---|
33 | "\
|
---|
34 | | mysql \
|
---|
35 | --defaults-file=${CREDENTIALS} \
|
---|
36 | --skip-column-names \
|
---|
37 | --batch --raw \
|
---|
38 | --compress \
|
---|
39 | | \
|
---|
40 | while read -r -a LINE
|
---|
41 | do
|
---|
42 | # Extract night/runid for data file and calibration file
|
---|
43 | DATNIGHT=${LINE[0]}
|
---|
44 | DATRUNID=${LINE[1]}
|
---|
45 | DRSNIGHT=${LINE[2]}
|
---|
46 | DRSRUNID=${LINE[3]}
|
---|
47 |
|
---|
48 | # Formatting of the file paths and names
|
---|
49 | DATPATH=${DATNIGHT:0:4}/${DATNIGHT:4:2}/${DATNIGHT:6:2}
|
---|
50 | DRSPATH=${DRSNIGHT:0:4}/${DRSNIGHT:4:2}/${DRSNIGHT:6:2}
|
---|
51 |
|
---|
52 | PREFIX=`printf ${DATNIGHT}_%03d ${DATRUNID}`
|
---|
53 |
|
---|
54 | DATNAME=`printf ${DATNIGHT}_%03d.fits.fz ${DATRUNID}`
|
---|
55 | DRSNAME=`printf ${DRSNIGHT}_%03d.drs.fits ${DRSRUNID}`
|
---|
56 |
|
---|
57 | OUT=${DATA}/${CALLISTO}/${DATPATH}
|
---|
58 |
|
---|
59 | echo ""
|
---|
60 | echo DAT=${DATNAME} [${DATPATH}]
|
---|
61 | echo DRS=${DRSNAME} [${DRSPATH}]
|
---|
62 |
|
---|
63 | # Check if not yet successfully processed
|
---|
64 | # Removing this file can be used to trigger a re-processing
|
---|
65 | # the next time this script is executed
|
---|
66 | if [ ! -f "${OUT}/.${PREFIX}.success" ]
|
---|
67 | then
|
---|
68 |
|
---|
69 | cd ${MARS}
|
---|
70 |
|
---|
71 | mkdir -p ${OUT}
|
---|
72 |
|
---|
73 | # Trigger reprocessing of the process-fils in the star directory
|
---|
74 | rm -f "${DATA}/${STAR}/${DATPATH}/.${PREFIX}.*"
|
---|
75 |
|
---|
76 | # Flag that a process is running
|
---|
77 | rm ${OUT}/.${PREFIX}.done
|
---|
78 | rm ${OUT}/.${PREFIX}.success
|
---|
79 |
|
---|
80 | touch ${OUT}/.${PREFIX}.running
|
---|
81 |
|
---|
82 | # Execute the calibration and write output to log-file
|
---|
83 | root -b -q -l ${MACROS}/callisto.C'("'${DATA}/raw/${DATPATH}/${DATNAME}'","'${DATA}/raw/${DRSPATH}/${DRSNAME}'","'${OUT}'")' \
|
---|
84 | 2>&1 | tee ${OUT}/${PREFIX}.log
|
---|
85 |
|
---|
86 | RC=${PIPESTATUS[0]}
|
---|
87 |
|
---|
88 | # Remember exit status of callisto
|
---|
89 | echo RC=${RC} | tee -a ${OUT}/${PREFIX}.log
|
---|
90 | echo ${RC} > ${OUT}/.${PREFIX}.done
|
---|
91 |
|
---|
92 | # Processing is finished
|
---|
93 | rm -f ${OUT}/.${PREFIX}.running
|
---|
94 |
|
---|
95 | # If processing was successfull write corresponding flag
|
---|
96 | if [ "${RC}" == "0" ]
|
---|
97 | then
|
---|
98 | touch ${OUT}/.${PREFIX}.success
|
---|
99 | fi
|
---|
100 |
|
---|
101 | cd -
|
---|
102 |
|
---|
103 | else
|
---|
104 | echo Skipped.
|
---|
105 | fi
|
---|
106 |
|
---|
107 | done
|
---|