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