1 | #!/bin/bash
|
---|
2 |
|
---|
3 |
|
---|
4 | # Specify the telescope for which to run the script. Replace '1'
|
---|
5 | # by $1 if the telesocpe number is supplied as an option to the script
|
---|
6 | TELESCOPE=1
|
---|
7 |
|
---|
8 | # The data is expected to be found in /data/raw and data/callisto
|
---|
9 | DATA="/data"
|
---|
10 | CALLISTO=callisto
|
---|
11 | # output is written to data/star
|
---|
12 | STAR=star
|
---|
13 | # Directory to Mars environment (usually Mars/build)
|
---|
14 | MARS=~/Mars/build
|
---|
15 | # Relative path to macros
|
---|
16 | MACROS=../hawc
|
---|
17 |
|
---|
18 | # Get all runs that can (and should) be calibrated
|
---|
19 | # Pipe the output to mysql and read the
|
---|
20 | # mysql output line-by-libe
|
---|
21 | echo \
|
---|
22 | "\
|
---|
23 | SELECT
|
---|
24 | NIGHT, RUNID
|
---|
25 | FROM
|
---|
26 | Calibration
|
---|
27 | WHERE
|
---|
28 | Telescope=${TELESCOPE}
|
---|
29 | ORDER BY
|
---|
30 | NIGHT, RUNID\
|
---|
31 | "\
|
---|
32 | | mysql \
|
---|
33 | --defaults-file=/home/tbretz/data/.password.cnf \
|
---|
34 | --user=iceactwrite \
|
---|
35 | --host=ihp-pc45.ethz.ch \
|
---|
36 | --database=iceactdata \
|
---|
37 | --skip-column-names \
|
---|
38 | --batch --raw \
|
---|
39 | --compress \
|
---|
40 | | \
|
---|
41 | while IFS= read -r LINE
|
---|
42 | do
|
---|
43 | # Get NIGHT and RUNID of all files
|
---|
44 | NIGHT=`echo "$LINE" | awk -F"\t" '{print $1}'`
|
---|
45 | RUNID=`echo "$LINE" | awk -F"\t" '{print $2}'`
|
---|
46 |
|
---|
47 | # Split into year, month, day
|
---|
48 | YEAR=`echo ${NIGHT} | cut -c1-4`
|
---|
49 | MONTH=`echo ${NIGHT} | cut -c5-6`
|
---|
50 | DAY=`echo ${NIGHT} | cut -c7-8`
|
---|
51 |
|
---|
52 | # Formatting of the file paths and names
|
---|
53 | DATPATH="${YEAR}/${MONTH}/${DAY}"
|
---|
54 |
|
---|
55 | PREFIX=`printf ${NIGHT}_%03d ${RUNID}`
|
---|
56 |
|
---|
57 | DATNAME=`printf ${PREFIX}_Y.root ${RUNID}`
|
---|
58 |
|
---|
59 | OUT=${DATA}/${STAR}/${DATPATH}
|
---|
60 | IN=${DATA}/${CALLISTO}/${DATPATH}
|
---|
61 |
|
---|
62 | echo ""
|
---|
63 | echo ${DATNAME}
|
---|
64 | echo ${IN} " => " ${OUT}
|
---|
65 |
|
---|
66 | # Check if not yet successfully processed but sucessfully calibrated
|
---|
67 | if [[ -f "${IN}/.${PREFIX}.success" && ! -f "${IN}/.${PREFIX}.running" && ! -f "${OUT}/.${PREFIX}.success" ]]
|
---|
68 | then
|
---|
69 |
|
---|
70 | cd ${MARS}
|
---|
71 |
|
---|
72 | mkdir -p ${OUT}
|
---|
73 |
|
---|
74 | # Flag that a process is running
|
---|
75 | rm -f ${OUT}/.${PREFIX}.done
|
---|
76 | rm -f ${OUT}/.${PREFIX}.success
|
---|
77 |
|
---|
78 | touch ${OUT}/.${PREFIX}.running
|
---|
79 |
|
---|
80 | # Execute image parameter calculation and write log-file
|
---|
81 | root -b -q -l ${MACROS}/star.C'("'${IN}/${DATNAME}'","'${OUT}'")' \
|
---|
82 | 2>&1 | tee ${OUT}/${PREFIX}.log
|
---|
83 |
|
---|
84 | # Remember exit status of callisto
|
---|
85 | RC=${PIPESTATUS[0]}
|
---|
86 |
|
---|
87 | echo RC=${RC} | tee -a ${OUT}/${PREFIX}.log
|
---|
88 | echo ${RC} > ${OUT}/.${PREFIX}.done
|
---|
89 |
|
---|
90 | # Flag that processing is finished
|
---|
91 | rm -f ${OUT}/.${PREFIX}.running
|
---|
92 |
|
---|
93 | # If processing was successfull write coresponding flag
|
---|
94 | if [ "${RC}" == "0" ]
|
---|
95 | then
|
---|
96 | touch ${OUT}/.${PREFIX}.success
|
---|
97 | fi
|
---|
98 |
|
---|
99 | cd -
|
---|
100 |
|
---|
101 | else
|
---|
102 | echo Skipped.
|
---|
103 | fi
|
---|
104 |
|
---|
105 | done
|
---|