1 |
/** |
2 |
* \file GLTables.cpp |
3 |
* \author Elena Vannuccini |
4 |
* |
5 |
* The file contains implementation of the methods to query the DB. |
6 |
*/ |
7 |
// |
8 |
#include <GLTables.h> |
9 |
#include <sstream> |
10 |
// |
11 |
// |
12 |
// |
13 |
using namespace std; |
14 |
//extern Bool_t debug; |
15 |
|
16 |
GL_RUN::GL_RUN() { |
17 |
ID = 0ULL; |
18 |
ID_REG_RUN = 0ULL; |
19 |
ID_REG_RUN_L2 = 0ULL; |
20 |
RUNHEADER_TIME = 0ULL; |
21 |
RUNTRAILER_TIME = 0ULL; |
22 |
EV_REG_PHYS_FROM = 0; |
23 |
EV_REG_PHYS_TO = 0; |
24 |
EV_REG_RUNHEADER = 0; |
25 |
EV_REG_RUNTRAILER = 0; |
26 |
TRK_CALIB_USED = 0; |
27 |
EFF_WRK_SCHEDULE = 0; |
28 |
PRH_VAR_TRG_MODE_A = 0; |
29 |
PRH_VAR_TRG_MODE_B = 0; |
30 |
ACQ_BUILD_INFO = 0; |
31 |
ACQ_VAR_INFO = 0; |
32 |
} |
33 |
|
34 |
GL_ROOT::GL_ROOT(){ |
35 |
ID = 0ULL; |
36 |
ID_RAW = 0ULL; |
37 |
PATH = ""; |
38 |
NAME = ""; |
39 |
} |
40 |
|
41 |
GL_PARAM::GL_PARAM(){ |
42 |
ID = 0ULL; |
43 |
PATH = ""; |
44 |
NAME = ""; |
45 |
DESCR = ""; |
46 |
FROM_TIME = 0ULL; |
47 |
TO_TIME = 0ULL; |
48 |
} |
49 |
|
50 |
GL_TRK_CALIB::GL_TRK_CALIB(){ |
51 |
ID = 0ULL; |
52 |
ID_REG_CALIBTRK = 0ULL; |
53 |
EV_REG_CALIBTRK1 = 0; |
54 |
EV_REG_CALIBTRK2 = 0; |
55 |
FROM_TIME = 0ULL; |
56 |
TO_TIME = 0ULL; |
57 |
} |
58 |
|
59 |
GL_CALO_CALIB::GL_CALO_CALIB(){ |
60 |
ID = 0ULL; |
61 |
ID_REG_CALIBCALPED = 0ULL; |
62 |
EV_REG_CALIBCALPED = 0; |
63 |
FROM_TIME = 0ULL; |
64 |
TO_TIME = 0ULL; |
65 |
SECTION = 0; |
66 |
} |
67 |
|
68 |
GL_S4_CALIB::GL_S4_CALIB(){ |
69 |
ID = 0ULL; |
70 |
ID_REG_CALIBS4 = 0ULL; |
71 |
EV_REG_CALIBS4 = 0; |
72 |
FROM_TIME = 0ULL; |
73 |
TO_TIME = 0ULL; |
74 |
PARAM_FIT0 = 0; |
75 |
PARAM_FIT1 = 0; |
76 |
}// **************************************************** |
77 |
/** |
78 |
* Function to query the GL_RUN table of the DB. |
79 |
* |
80 |
* \param RUN id |
81 |
* \return struct of type GL_RUN _data, which stores the query result |
82 |
* |
83 |
*/ |
84 |
Int_t GL_RUN::Query_GL_RUN(ULong64_t run, TSQLServer *dbc){ |
85 |
// Bool_t debug = 1; |
86 |
// MySQL variables |
87 |
TSQLResult *pResult; |
88 |
TSQLRow *Row; |
89 |
int t; |
90 |
int r; |
91 |
char *pEnd; |
92 |
stringstream myquery; |
93 |
// ---------------- |
94 |
// NB! unsigned long long integers: when set to a number use ULL to store the correct number |
95 |
myquery.str(""); |
96 |
myquery << " select "; |
97 |
// myquery << " * "; |
98 |
myquery << " ID"; |
99 |
myquery << ",ID_REG_RUN"; |
100 |
myquery << ",ID_REG_RUN_L2"; |
101 |
myquery << ",RUNHEADER_TIME"; |
102 |
myquery << ",RUNTRAILER_TIME"; |
103 |
myquery << ",EV_REG_PHYS_FROM"; |
104 |
myquery << ",EV_REG_PHYS_TO"; |
105 |
myquery << ",EV_REG_RUNHEADER"; |
106 |
myquery << ",EV_REG_RUNTRAILER"; |
107 |
myquery << ",TRK_CALIB_USED"; |
108 |
myquery << ",EFF_WRK_SCHEDULE"; |
109 |
myquery << ",PRH_VAR_TRG_MODE_A"; |
110 |
myquery << ",PRH_VAR_TRG_MODE_B"; |
111 |
myquery << ",ACQ_BUILD_INFO"; |
112 |
myquery << ",ACQ_VAR_INFO"; |
113 |
myquery << " from GL_RUN where ID=" << run << ";"; |
114 |
pResult = dbc->Query(myquery.str().c_str()); |
115 |
if(!pResult->GetRowCount())return(-50);//throw -50; |
116 |
for( r=0; r < 1000; r++){ |
117 |
Row = pResult->Next(); |
118 |
if( Row == NULL ) break; |
119 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
120 |
if (t== 0) ID = strtoull(Row->GetField(t),&pEnd,0); |
121 |
if (t== 1) ID_REG_RUN = strtoull(Row->GetField(t),&pEnd,0); |
122 |
if (t== 2) ID_REG_RUN_L2 = strtoull(Row->GetField(t),&pEnd,0); |
123 |
if (t== 3) RUNHEADER_TIME = strtoull(Row->GetField(t),&pEnd,0); |
124 |
if (t== 4) RUNTRAILER_TIME = strtoull(Row->GetField(t),&pEnd,0); |
125 |
if (t== 5) EV_REG_PHYS_FROM = atoi(Row->GetField(t)); |
126 |
if (t== 6) EV_REG_PHYS_TO = atoi(Row->GetField(t)); |
127 |
if (t== 7) EV_REG_RUNHEADER = atoi(Row->GetField(t)); |
128 |
if (t== 8) EV_REG_RUNTRAILER= atoi(Row->GetField(t)); |
129 |
if (t== 9) TRK_CALIB_USED = atoi(Row->GetField(t)); |
130 |
if (t==10) EFF_WRK_SCHEDULE = atoi(Row->GetField(t)); |
131 |
if (t==11) PRH_VAR_TRG_MODE_A = atoi(Row->GetField(t)); |
132 |
if (t==12) PRH_VAR_TRG_MODE_B = atoi(Row->GetField(t)); |
133 |
if (t==13) ACQ_BUILD_INFO = atoi(Row->GetField(t)); |
134 |
if (t==14) ACQ_VAR_INFO = atoi(Row->GetField(t)); |
135 |
}; |
136 |
}; |
137 |
delete pResult; |
138 |
|
139 |
return 0; |
140 |
|
141 |
}; |
142 |
// **************************************************** |
143 |
/** |
144 |
* Function to query the GL_ROOT table of the DB. |
145 |
* |
146 |
* \param entry ID |
147 |
* \return struct of type GL_ROOT_data, which stores the query result |
148 |
*/ |
149 |
Int_t GL_ROOT::Query_GL_ROOT(ULong64_t id, TSQLServer *dbc){ |
150 |
|
151 |
// MySQL variables |
152 |
TSQLResult *pResult; |
153 |
TSQLRow *Row; |
154 |
int t; |
155 |
int r; |
156 |
stringstream myquery; |
157 |
// ---------------- |
158 |
|
159 |
myquery.str(""); |
160 |
myquery << "select "; |
161 |
myquery << " ID"; |
162 |
myquery << ",ID_RAW"; |
163 |
myquery << ",PATH"; |
164 |
myquery << ",NAME"; |
165 |
myquery << " from GL_ROOT where ID=" << id << ";"; |
166 |
// if ( debug ) printf("Query:\n \"%s\" \n",myquery.str().c_str()); |
167 |
pResult = dbc->Query(myquery.str().c_str()); |
168 |
if(!pResult->GetRowCount())return (-51); //throw -51; |
169 |
for( r=0; r < 1000; r++){ |
170 |
Row = pResult->Next(); |
171 |
if( Row == NULL ) break; |
172 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
173 |
if(t==0) ID = atoi(Row->GetField(t)); |
174 |
if(t==1) ID_RAW = atoi(Row->GetField(t)); |
175 |
if(t==2) PATH = Row->GetField(t); |
176 |
if(t==3) NAME = Row->GetField(t); |
177 |
}; |
178 |
}; |
179 |
delete pResult; |
180 |
return 0; |
181 |
}; |
182 |
// **************************************************** |
183 |
/** |
184 |
* Function to query the GL_TRK_CALIB table of the DB. |
185 |
* |
186 |
* \param run starting time |
187 |
* \return struct of type GL_TRK_CALIB_data, which stores the query result |
188 |
*/ |
189 |
Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(ULong64_t time, TSQLServer *dbc){ |
190 |
// MySQL variables |
191 |
TSQLResult *pResult; |
192 |
TSQLRow *Row; |
193 |
int t; |
194 |
int r; |
195 |
char *pEnd; |
196 |
stringstream myquery; |
197 |
// ---------------- |
198 |
myquery.str(""); |
199 |
myquery << "select * from GL_TRK_CALIB where FROM_TIME <= "<< time; |
200 |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
201 |
pResult = dbc->Query(myquery.str().c_str()); |
202 |
if(!pResult->GetRowCount())return (-53);//throw -53; |
203 |
for( r=0; r < 1000; r++){ |
204 |
Row = pResult->Next(); |
205 |
if( Row == NULL ) break; |
206 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
207 |
if (t==0) ID = strtoull(Row->GetField(t),&pEnd,0); |
208 |
if (t==1) ID_REG_CALIBTRK = strtoull(Row->GetField(t),&pEnd,0); |
209 |
if (t==2) EV_REG_CALIBTRK1 = atoi(Row->GetField(t)); |
210 |
if (t==3) EV_REG_CALIBTRK2 = atoi(Row->GetField(t)); |
211 |
if (t==4) FROM_TIME = strtoull(Row->GetField(t),&pEnd,0); |
212 |
if (t==5) TO_TIME = strtoull(Row->GetField(t),&pEnd,0); |
213 |
// if ( debug ) printf(" Row %i value = %s \n",t,Row->GetField(t)); |
214 |
}; |
215 |
}; |
216 |
delete pResult; |
217 |
// |
218 |
if(TO_TIME < time)return(51); |
219 |
// |
220 |
return 0; |
221 |
}; |
222 |
|
223 |
// **************************************************** |
224 |
/** |
225 |
* Function to query the GL_CALO_CALIB table of the DB. |
226 |
* |
227 |
* \param run starting time |
228 |
* \return struct of type GL_CALO_CALIB_data, which stores the query result |
229 |
*/ |
230 |
Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(ULong64_t time, Int_t section, TSQLServer *dbc){ |
231 |
// Bool_t debug = 1; |
232 |
// MySQL variables |
233 |
TSQLResult *pResult; |
234 |
TSQLRow *Row; |
235 |
int t; |
236 |
int r; |
237 |
char *pEnd; |
238 |
stringstream myquery; |
239 |
// ---------------- |
240 |
myquery.str(""); |
241 |
myquery << "select ID_REG_CALIBCALPED, FROM_TIME, TO_TIME, EV_REG_CALIBCALPED from GL_CALO_CALIB where SECTION=" << section; |
242 |
myquery << " and FROM_TIME <= " << time; |
243 |
myquery << " and TO_TIME >= " << time; |
244 |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
245 |
// |
246 |
// if ( debug ) printf("\n Querying DB for data files informations...\n"); |
247 |
// if ( debug ) printf("The query is:\n \"%s\" \n",myquery.str().c_str()); |
248 |
// |
249 |
pResult = dbc->Query(myquery.str().c_str()); |
250 |
if(!pResult->GetRowCount())return (-54);//throw -54; |
251 |
for ( r = 0 ; r < 10 ; r++ ) { |
252 |
Row = pResult->Next(); |
253 |
if( Row == NULL ) break; |
254 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
255 |
// if ( debug ) printf(" Row %i value = %s \n",t,Row->GetField(t)); |
256 |
// if (t==0) ID = strtoull(Row->GetField(t),&pEnd,0); |
257 |
if (t==0) ID_REG_CALIBCALPED = strtoull(Row->GetField(t),&pEnd,0); |
258 |
if (t==1) FROM_TIME = strtoull(Row->GetField(t),&pEnd,0); |
259 |
if (t==2) TO_TIME = strtoull(Row->GetField(t),&pEnd,0); |
260 |
if (t==3) EV_REG_CALIBCALPED = atoi(Row->GetField(t)); |
261 |
// if (t==5) SECTION = atoi(Row->GetField(t)); |
262 |
}; |
263 |
}; |
264 |
pResult->Delete(); |
265 |
return 0; |
266 |
}; |
267 |
// **************************************************** |
268 |
/** |
269 |
* Function to query the GL_S4_CALIB table of the DB. |
270 |
* |
271 |
* \param run starting time |
272 |
* \return struct of type GL_S4_CALIB_data, which stores the query result |
273 |
*/ |
274 |
Int_t GL_S4_CALIB::Query_GL_S4_CALIB(ULong64_t time, TSQLServer *dbc){ |
275 |
// MySQL variables |
276 |
TSQLResult *pResult; |
277 |
TSQLRow *Row; |
278 |
int t; |
279 |
int r; |
280 |
char *pEnd; |
281 |
stringstream myquery; |
282 |
// ---------------- |
283 |
myquery.str(""); |
284 |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
285 |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
286 |
// if ( debug ) printf("Query:\n \"%s\" \n",myquery.str().c_str()); |
287 |
pResult = dbc->Query(myquery.str().c_str()); |
288 |
if(!pResult->GetRowCount())return (-55);//throw -55; |
289 |
for( r=0; r < 1000; r++){ |
290 |
Row = pResult->Next(); |
291 |
if( Row == NULL ) break; |
292 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
293 |
if (t==0) ID = strtoull(Row->GetField(t),&pEnd,0); |
294 |
if (t==1) ID_REG_CALIBS4 = strtoull(Row->GetField(t),&pEnd,0); |
295 |
if (t==2) EV_REG_CALIBS4 = atoi(Row->GetField(t)); |
296 |
if (t==3) FROM_TIME = strtoull(Row->GetField(t),&pEnd,0); |
297 |
if (t==4) TO_TIME = strtoull(Row->GetField(t),&pEnd,0); |
298 |
if (t==5) PARAM_FIT0 = atof(Row->GetField(t)); |
299 |
if (t==6) PARAM_FIT1 = atof(Row->GetField(t)); |
300 |
// if ( debug ) printf(" Row %i value = %s \n",t,Row->GetField(t)); |
301 |
}; |
302 |
}; |
303 |
delete pResult; |
304 |
// |
305 |
if(TO_TIME < time)return(51); |
306 |
// |
307 |
return 0; |
308 |
}; |
309 |
// **************************************************** |
310 |
/** |
311 |
* Function to query the GL_PARAM table of the DB. |
312 |
* |
313 |
* \param run starting time |
314 |
* \param parameter description (DESCR) |
315 |
* \return struct of type GL_ROOT_data, which stores the query result |
316 |
*/ |
317 |
Int_t GL_PARAM::Query_GL_PARAM(ULong64_t time, TString descr, TSQLServer *dbc){ |
318 |
// Bool_t debug = 1; |
319 |
// MySQL variables |
320 |
TSQLResult *pResult; |
321 |
TSQLRow *Row; |
322 |
int t; |
323 |
int r; |
324 |
char *pEnd; |
325 |
stringstream myquery; |
326 |
// ---------------- |
327 |
myquery.str(""); |
328 |
myquery << " select "; |
329 |
myquery << " ID, PATH, NAME, DESCR, FROM_TIME,TO_TIME "; |
330 |
myquery << " from GL_PARAM "; |
331 |
myquery << " where DESCR = '"<<descr<<"' "; |
332 |
myquery << " and FROM_TIME <= " << time; |
333 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
334 |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
335 |
// if ( debug ) printf("Query:\n \"%s\" \n",myquery.str().c_str()); |
336 |
pResult = dbc->Query(myquery.str().c_str()); |
337 |
if(!pResult->GetRowCount())return (-52);//throw -52; |
338 |
for( r=0; r < 1000; r++){ |
339 |
Row = pResult->Next(); |
340 |
if( Row == NULL ) break; |
341 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
342 |
if (t==0) ID = strtoull(Row->GetField(t),&pEnd,0); |
343 |
if (t==1) PATH = Row->GetField(t);// put in fpath the path to that file |
344 |
if (t==2) NAME = Row->GetField(t); |
345 |
if (t==3) DESCR = Row->GetField(t); |
346 |
if (t==4) FROM_TIME = strtoull(Row->GetField(t),&pEnd,0); |
347 |
if (t==5) TO_TIME = strtoull(Row->GetField(t),&pEnd,0); |
348 |
// if ( debug ) printf(" Row %i value = %s \n",t,Row->GetField(t)); |
349 |
}; |
350 |
}; |
351 |
delete pResult; |
352 |
// |
353 |
// if (TO_TIME==0) TO_TIME=(ULong64_t)(1e15); // temporaneo!!!! |
354 |
if(TO_TIME==0) TO_TIME = numeric_limits<ULong64_t>::max(); |
355 |
// |
356 |
if(TO_TIME < time) return(51); |
357 |
// |
358 |
return 0; |
359 |
}; |
360 |
// |
361 |
ClassImp(GL_TRK_CALIB); |
362 |
ClassImp(GL_RUN); |
363 |
ClassImp(GL_ROOT); |
364 |
ClassImp(GL_PARAM); |
365 |
ClassImp(GL_S4_CALIB); |
366 |
ClassImp(GL_CALO_CALIB); |