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