source: trunk/Mars/hawc/processing/run-star.sh@ 20033

Last change on this file since 20033 was 20033, checked in by tbretz, 4 years ago
Made the file with the credentials a variable; moved all credentials to that file; directly read the mysql output into an array.
File size: 2.4 KB
Line 
1#!/bin/bash
2
3# File containing the access credentials for the database
4CREDENTIALS=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
8TELESCOPE=1
9
10# The data is expected to be found in /data/raw and data/callisto
11DATA="/data"
12CALLISTO=callisto
13# output is written to data/star
14STAR=star
15# Directory to Mars environment (usually Mars/build)
16MARS=~/Mars/build
17# Relative path to macros
18MACROS=../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
23echo \
24"\
25SELECT
26 NIGHT, RUNID
27FROM
28 Calibration
29WHERE
30 Telescope=${TELESCOPE}
31ORDER BY
32 NIGHT, RUNID\
33"\
34 | mysql \
35 --defaults-file=${CREDENTIALS} \
36 --skip-column-names \
37 --batch --raw \
38 --compress \
39 | \
40while read -r -a LINE
41do
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
104done
Note: See TracBrowser for help on using the repository browser.