source: trunk/Mars/hawc/processing/extract-aux-data.sh@ 20084

Last change on this file since 20084 was 20039, checked in by tbretz, 4 years ago
Fixed some typos.
File size: 4.7 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 base directory of the aux-files
11AUX=/home/tbretz/data/aux
12# The Mars build directory
13MARS=~/Mars/build
14# The path (relative to your Mars/build directory where the processing macros are stored
15MACROS=../hawc/processing
16# File to which the queries are written
17OUTPUT="insert-aux.sql"
18
19# Open the query-file with the create table statement
20echo \
21"\
22CREATE TABLE IF NOT EXISTS AuxData
23(
24 Telescope TINYINT UNSIGNED NOT NULL,
25 NIGHT INT UNSIGNED NOT NULL,
26 RUNID MEDIUMINT UNSIGNED NOT NULL,
27 TavgDRS FLOAT,
28 TrmsDRS FLOAT,
29 Umed FLOAT,
30 Uavg FLOAT,
31 Udev FLOAT,
32 Urms FLOAT,
33 Imed FLOAT,
34 Iavg FLOAT,
35 Idev FLOAT,
36 Irms FLOAT,
37 Tmed FLOAT,
38 Tavg FLOAT,
39 Tdev FLOAT,
40 Trms FLOAT,
41 TavgPSU FLOAT,
42 TotalOnTime FLOAT,
43 TotalDeadTime FLOAT,
44 TavgFTM FLOAT,
45 ThresholdChMin MEDIUMINT UNSIGNED,
46 ThresholdChMed FLOAT,
47 ThresholdChMax MEDIUMINT UNSIGNED,
48 ThresholdSumMin MEDIUMINT UNSIGNED,
49 ThresholdSumMax MEDIUMINT UNSIGNED,
50 RateCh0 FLOAT,
51 RateCh1 FLOAT,
52 RateCh2 FLOAT,
53 RateCh3 FLOAT,
54 RateCh4 FLOAT,
55 RateCh5 FLOAT,
56 RateCh6 FLOAT,
57 RateCh7 FLOAT,
58 RateSum0 FLOAT,
59 RateSum1 FLOAT,
60 PRIMARY KEY(Telescope, NIGHT, RUNID)
61)
62SELECT * FROM
63( VALUES
64"\ > ${OUTPUT}
65
66# Get all available runs and their start and stop time
67# note that no check is done on the stop time!
68echo \
69"\
70SELECT
71 NIGHT, RUNID, TSTARTI+TSTARTF, TSTOPI+TSTOPF
72FROM
73 RawData
74WHERE
75 Telescope=${TELESCOPE}\
76"\
77 | mysql \
78 --defaults-file=${CREDENTIALS} \
79 --skip-column-names \
80 --batch --raw \
81 --compress \
82 | \
83while read -r -a LINE
84do
85 # Extract night, runid, begin and end
86 NIGHT=${LINE[0]}
87 RUNID=${LINE[1]}
88 BEG=${LINE[2]}
89 END=${LINE[3]}
90
91 # Split night into year, month, day
92 # Base path for the night
93 FNAME="${AUX}"/${NIGHT:0:4}/${NIGHT:4:2}/${NIGHT:6:2}/${NIGHT}
94
95 echo ""
96 echo ${FNAME}
97
98 cd ${MARS}
99
100 # Return corresponding data for DRS temperatures from FAD_CONTROL_TEMPEREATURE
101 DRSTEMP=`root -b -q -l '${MACROS}/drstemp.C("'${FNAME}'.FAD_CONTROL_TEMPERATURE.fits",'${BEG}','${END}')' | grep result | cut -f2- -d" "`
102 if [ ! -n "${DRSTEMP}" ]
103 then
104 DRSTEMP="NULL, NULL"
105 fi
106 echo ${DRSTEMP}
107
108 # Return corresponding data for currents from BIAS_CONTROL_DYNAMIC_DATA
109 BIAS_DATA=`root -b -q -l '${MACROS}/currents.C("'${FNAME}'.BIAS_CONTROL_DYNAMIC_DATA.fits",'${BEG}','${END}')' | grep result | cut -f2- -d" "`
110 if [ ! -n "${BIAS_DATA}" ]
111 then
112 BIAS_DATA="NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL"
113 fi
114 echo ${BIAS_DATA}
115
116 # Return corresponding data for trigger information from FTM_CONTROL_DATA
117 FTM_DATA=`root -b -q -l '${MACROS}/trigger.C("'${FNAME}'.FTM_CONTROL_DATA.fits",'${BEG}','${END}')' | grep result | cut -f2- -d" "`
118 if [ ! -n "${RESULT}" ]
119 then
120 FTM_DATA="NULL, NULL, NULL, NULL"
121 fi
122 echo ${FTM_DATA}
123
124 # Return corresponding data for threshold seeting from FTU_CONTROL_DATA
125 FTU_DATA=`root -b -q -l '${MACROS}/threshold.C("'${FNAME}'.FTU_CONTROL_DATA.fits",'${BEG}','${END}')' | grep result | cut -f2- -d" "`
126 if [ ! -n "${FTU_DATA}" ]
127 then
128 FTU_DATA="NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL"
129 fi
130 echo ${FTU_DATA}
131
132 cd -
133
134 # Write the result as one row to the query file
135 echo "/* "${FNAME}" */" >> ${OUTPUT}
136 echo "ROW(" >> ${OUTPUT}
137 echo " "${TELESCOPE}, ${NIGHT}, ${RUNID}, >> ${OUTPUT}
138 echo " "${DRS_TEMP}, >> ${OUTPUT}
139 echo " "${BIAS_DATA}, >> ${OUTPUT}
140 echo " "${FTU_DATA}, >> ${OUTPUT}
141 echo " "${FTM_DATA} >> ${OUTPUT}
142 echo ")," >> ${OUTPUT}
143
144done
145
146# Finish the query file with defining the column names
147echo "\
148AS
149(
150 Telescope, NIGHT, RUNID,
151 TavgDRS, TrmsDRS,
152 Umed, Uavg, Udev, Urms,
153 Imed, Iavg, Idev, Irms,
154 Tmed, Tavg, Tdev, Trms,
155 TavgPSU,
156 TotalOnTime, TotalDeadTime, Efficiency, TavgFTM,
157 ThresholdChMin, ThresholdChMed, ThresholdChMax,
158 ThresholdSumMin, ThresholdSumMax,
159 RateCh0, RateCh1, RateCh2, RateCh3, RateCh4, RateCh5, RateCh6, RateCh7,
160 RateSum0, RateSum1
161)\
162" >> ${OUTPUT}
Note: See TracBrowser for help on using the repository browser.