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 | # output is written to data/star
|
---|
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
|
---|
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 | # Get NIGHT and RUNID of all files
|
---|
43 | NIGHT=${LINE[0]}
|
---|
44 | RUNID=${LINE[1]}
|
---|
45 |
|
---|
46 | # Split into year, month, day
|
---|
47 | YEAR=`echo ${NIGHT} | cut -c1-4`
|
---|
48 | MONTH=`echo ${NIGHT} | cut -c5-6`
|
---|
49 | DAY=`echo ${NIGHT} | cut -c7-8`
|
---|
50 |
|
---|
51 | # Formatting of the file paths and names
|
---|
52 | DATPATH="${YEAR}/${MONTH}/${DAY}"
|
---|
53 |
|
---|
54 | PREFIX=`printf ${NIGHT}_%03d ${RUNID}`
|
---|
55 |
|
---|
56 | DATNAME=`printf ${PREFIX}_Y.root ${RUNID}`
|
---|
57 |
|
---|
58 | OUT=${DATA}/${STAR}/${DATPATH}
|
---|
59 | IN=${DATA}/${CALLISTO}/${DATPATH}
|
---|
60 |
|
---|
61 | echo ""
|
---|
62 | echo ${DATNAME}
|
---|
63 | echo ${IN} " => " ${OUT}
|
---|
64 |
|
---|
65 | # Check if not yet successfully processed but sucessfully calibrated
|
---|
66 | if [[ -f "${IN}/.${PREFIX}.success" && ! -f "${IN}/.${PREFIX}.running" && ! -f "${OUT}/.${PREFIX}.success" ]]
|
---|
67 | then
|
---|
68 |
|
---|
69 | cd ${MARS}
|
---|
70 |
|
---|
71 | mkdir -p ${OUT}
|
---|
72 |
|
---|
73 | # Flag that a process is running
|
---|
74 | rm -f ${OUT}/.${PREFIX}.done
|
---|
75 | rm -f ${OUT}/.${PREFIX}.success
|
---|
76 |
|
---|
77 | touch ${OUT}/.${PREFIX}.running
|
---|
78 |
|
---|
79 | # Execute image parameter calculation and write log-file
|
---|
80 | root -b -q -l ${MACROS}/star.C'("'${IN}/${DATNAME}'","'${OUT}'")' \
|
---|
81 | 2>&1 | tee ${OUT}/${PREFIX}.log
|
---|
82 |
|
---|
83 | # Remember exit status of callisto
|
---|
84 | RC=${PIPESTATUS[0]}
|
---|
85 |
|
---|
86 | echo RC=${RC} | tee -a ${OUT}/${PREFIX}.log
|
---|
87 | echo ${RC} > ${OUT}/.${PREFIX}.done
|
---|
88 |
|
---|
89 | # Flag that processing is finished
|
---|
90 | rm -f ${OUT}/.${PREFIX}.running
|
---|
91 |
|
---|
92 | # If processing was successfull write coresponding flag
|
---|
93 | if [ "${RC}" == "0" ]
|
---|
94 | then
|
---|
95 | touch ${OUT}/.${PREFIX}.success
|
---|
96 | fi
|
---|
97 |
|
---|
98 | cd -
|
---|
99 |
|
---|
100 | else
|
---|
101 | echo Skipped.
|
---|
102 | fi
|
---|
103 |
|
---|
104 | done
|
---|