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