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 <sstream> |
9 |
#include <iostream> |
10 |
// |
11 |
#include <TFile.h> |
12 |
#include <TTree.h> |
13 |
#include <TTimeStamp.h> |
14 |
#include <EventHeader.h> |
15 |
#include <PscuHeader.h> |
16 |
// |
17 |
#include <GLTables.h> |
18 |
#include <sgp4.h> |
19 |
// |
20 |
ClassImp(GL_TABLES); |
21 |
ClassImp(GL_TRK_CALIB); |
22 |
ClassImp(GL_RUN); |
23 |
ClassImp(GL_ROOT); |
24 |
ClassImp(GL_PARAM); |
25 |
ClassImp(GL_S4_CALIB); |
26 |
ClassImp(GL_CALO_CALIB); |
27 |
ClassImp(GL_CALOPULSE_CALIB); |
28 |
ClassImp(GL_TIMESYNC); |
29 |
ClassImp(GL_TLE); |
30 |
// |
31 |
using namespace std; |
32 |
|
33 |
GL_TABLES::GL_TABLES(){ |
34 |
}; |
35 |
|
36 |
GL_TABLES::GL_TABLES(TString host, TString user, TString psw){ |
37 |
fHost = new TString(host.Data()); |
38 |
fUser = new TString(user.Data()); |
39 |
fPsw = new TString(psw.Data()); |
40 |
fSet = true; |
41 |
fNquery = 0; |
42 |
mh = host.Data(); |
43 |
mu = user.Data(); |
44 |
mp = psw.Data(); |
45 |
}; |
46 |
|
47 |
|
48 |
void GL_TABLES::Set(TString host, TString user, TString psw){ |
49 |
fHost = new TString(host.Data()); |
50 |
fUser = new TString(user.Data()); |
51 |
fPsw = new TString(psw.Data()); |
52 |
fSet = true; |
53 |
fNquery = 0; |
54 |
mh = host.Data(); |
55 |
mu = user.Data(); |
56 |
mp = psw.Data(); |
57 |
}; |
58 |
|
59 |
Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
60 |
// |
61 |
// |
62 |
// |
63 |
if ( !fSet ){ |
64 |
return true; |
65 |
}; |
66 |
// |
67 |
// printf(" host is %s \n",fHost->Data()); |
68 |
// |
69 |
stringstream myquery; |
70 |
myquery.str(""); |
71 |
myquery << "show databases;"; |
72 |
if ( dbc ){ |
73 |
if ( dbc->IsConnected() ){ |
74 |
dbc->Query(myquery.str().c_str()); |
75 |
fNquery++; |
76 |
if ( !(dbc->GetErrorCode()) ){ |
77 |
// printf("ok\n"); |
78 |
// |
79 |
// if ( (dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006) ){ |
80 |
// if ( !(dbc->GetErrorCode()) ){ |
81 |
// is connected |
82 |
return true; |
83 |
// }; |
84 |
}; |
85 |
}; |
86 |
}; |
87 |
// |
88 |
if ( true ) { |
89 |
// |
90 |
printf(" WARNING: Lost connection to DB! try to recover... \n"); |
91 |
// |
92 |
TString host = fHost->Data(); |
93 |
TString user = fUser->Data(); |
94 |
TString psw = fPsw->Data(); |
95 |
delete dbc; |
96 |
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
97 |
// |
98 |
myquery.str(""); |
99 |
myquery << "show databases;"; |
100 |
dbc->Query(myquery.str().c_str()); |
101 |
fNquery++; |
102 |
// if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ |
103 |
if ( !(dbc->GetErrorCode()) ){ |
104 |
// |
105 |
printf(" ...connection recovered, I can continue! \n"); |
106 |
// |
107 |
myquery.str(""); |
108 |
myquery << "SET time_zone='+0:00'"; |
109 |
dbc->Query(myquery.str().c_str()); |
110 |
fNquery++; |
111 |
myquery.str(""); |
112 |
myquery << "SET wait_timeout=173000;"; |
113 |
dbc->Query(myquery.str().c_str()); |
114 |
fNquery++; |
115 |
return true; |
116 |
}; |
117 |
}; |
118 |
// |
119 |
printf(" GLTABLES: connection is gone away, query will fail\n"); |
120 |
// |
121 |
return false; |
122 |
// |
123 |
}; |
124 |
|
125 |
void GL_TABLES::ResetCounters(){ |
126 |
fNquery = 0; |
127 |
}; |
128 |
|
129 |
void GL_TABLES::AddQ(){ |
130 |
if ( fSet ) fNquery++; |
131 |
}; |
132 |
|
133 |
UInt_t GL_TABLES::GetNqueries(){ |
134 |
UInt_t rn = 0; |
135 |
rn += (UInt_t&)fNquery; |
136 |
return(rn); |
137 |
}; |
138 |
|
139 |
GL_RUN::GL_RUN() { |
140 |
ID = 0; |
141 |
ID_RUN_FRAG = 0; |
142 |
ID_ROOT_L0 = 0; |
143 |
ID_ROOT_L2 = 0; |
144 |
RUNHEADER_TIME = 0; |
145 |
RUNTRAILER_TIME = 0; |
146 |
EV_FROM = 0; |
147 |
EV_TO = 0; |
148 |
TRK_CALIB_USED = 0; |
149 |
EFF_WRK_SCHEDULE = 0; |
150 |
PRH_VAR_TRG_MODE_A = 0; |
151 |
PRH_VAR_TRG_MODE_B = 0; |
152 |
ACQ_BUILD_INFO = 0; |
153 |
ACQ_VAR_INFO = 0; |
154 |
RUNHEADER_OBT = 0; |
155 |
RUNTRAILER_OBT = 0; |
156 |
RUNHEADER_PKT = 0; |
157 |
RUNTRAILER_PKT = 0; |
158 |
NEVENTS = 0; |
159 |
LAST_TIMESYNC = 0; |
160 |
OBT_TIMESYNC = 0; |
161 |
COMPILATIONTIMESTAMP = 0; |
162 |
FAV_WRK_SCHEDULE = 0; |
163 |
RM_ACQ_AFTER_CALIB = 0; |
164 |
RM_ACQ_SETTING_MODE = 0; |
165 |
PKT_COUNTER = 0; |
166 |
PKT_READY_COUNTER = 0; |
167 |
TRK_CALIB_USED = 0; |
168 |
CAL_DSP_MASK = 0; |
169 |
BOOT_NUMBER = 0; |
170 |
VALIDATION = 0; |
171 |
} |
172 |
|
173 |
|
174 |
void GL_RUN::Clear() { |
175 |
ID = 0; |
176 |
ID_RUN_FRAG = 0; |
177 |
ID_ROOT_L0 = 0; |
178 |
ID_ROOT_L2 = 0; |
179 |
RUNHEADER_TIME = 0; |
180 |
RUNTRAILER_TIME = 0; |
181 |
EV_FROM = 0; |
182 |
EV_TO = 0; |
183 |
TRK_CALIB_USED = 0; |
184 |
EFF_WRK_SCHEDULE = 0; |
185 |
PRH_VAR_TRG_MODE_A = 0; |
186 |
PRH_VAR_TRG_MODE_B = 0; |
187 |
ACQ_BUILD_INFO = 0; |
188 |
ACQ_VAR_INFO = 0; |
189 |
RUNHEADER_OBT = 0; |
190 |
RUNTRAILER_OBT = 0; |
191 |
RUNHEADER_PKT = 0; |
192 |
RUNTRAILER_PKT = 0; |
193 |
NEVENTS = 0; |
194 |
LAST_TIMESYNC = 0; |
195 |
OBT_TIMESYNC = 0; |
196 |
COMPILATIONTIMESTAMP = 0; |
197 |
FAV_WRK_SCHEDULE = 0; |
198 |
RM_ACQ_AFTER_CALIB = 0; |
199 |
RM_ACQ_SETTING_MODE = 0; |
200 |
PKT_COUNTER = 0; |
201 |
PKT_READY_COUNTER = 0; |
202 |
TRK_CALIB_USED = 0; |
203 |
CAL_DSP_MASK = 0; |
204 |
BOOT_NUMBER = 0; |
205 |
VALIDATION = 0; |
206 |
} |
207 |
|
208 |
GL_ROOT::GL_ROOT(){ |
209 |
ID = 0; |
210 |
ID_RAW = 0; |
211 |
ID_TIMESYNC = 0; |
212 |
PATH = ""; |
213 |
NAME = ""; |
214 |
} |
215 |
|
216 |
GL_PARAM::GL_PARAM(){ |
217 |
ID = 0; |
218 |
PATH = ""; |
219 |
NAME = ""; |
220 |
DESCR = ""; |
221 |
FROM_TIME = 0; |
222 |
TO_TIME = 0; |
223 |
TYPE = 0; |
224 |
} |
225 |
|
226 |
|
227 |
GL_TRK_CALIB::GL_TRK_CALIB(){ |
228 |
ID = 0; |
229 |
ID_ROOT_L0 = 0; |
230 |
EV_ROOT_CALIBTRK1 = 0; |
231 |
EV_ROOT_CALIBTRK2 = 0; |
232 |
FROM_TIME = 0; |
233 |
TO_TIME = 0; |
234 |
OBT1 = 0; |
235 |
OBT2 = 0; |
236 |
PKT1 = 0; |
237 |
PKT2 = 0; |
238 |
BOOT_NUMBER = 0; |
239 |
VALIDATION = 0; |
240 |
} |
241 |
|
242 |
GL_CALO_CALIB::GL_CALO_CALIB(){ |
243 |
ID = 0; |
244 |
ID_ROOT_L0 = 0; |
245 |
EV_ROOT = 0; |
246 |
FROM_TIME = 0; |
247 |
TO_TIME = 0; |
248 |
SECTION = 0; |
249 |
OBT = 0; |
250 |
PKT = 0; |
251 |
BOOT_NUMBER = 0; |
252 |
VALIDATION = 0; |
253 |
} |
254 |
|
255 |
GL_CALOPULSE_CALIB::GL_CALOPULSE_CALIB(){ |
256 |
ID = 0; |
257 |
ID_ROOT_L0 = 0; |
258 |
EV_ROOT = 0; |
259 |
FROM_TIME = 0; |
260 |
TO_TIME = 0; |
261 |
SECTION = 0; |
262 |
PULSED_STRIP = 0; |
263 |
PULSE_AMPLITUDE = 0; |
264 |
OBT = 0; |
265 |
PKT = 0; |
266 |
BOOT_NUMBER = 0; |
267 |
VALIDATION = 0; |
268 |
} |
269 |
|
270 |
GL_S4_CALIB::GL_S4_CALIB(){ |
271 |
ID = 0; |
272 |
ID_ROOT_L0 = 0; |
273 |
EV_ROOT = 0; |
274 |
FROM_TIME = 0; |
275 |
TO_TIME = 0; |
276 |
OBT = 0; |
277 |
PKT = 0; |
278 |
BOOT_NUMBER = 0; |
279 |
} |
280 |
|
281 |
GL_TIMESYNC::GL_TIMESYNC(){ |
282 |
obtfirst = 0; |
283 |
pktfirst = 0; |
284 |
ID_RESURS_OFFSET = 0; |
285 |
ID = 0; |
286 |
ID_RAW = 0; |
287 |
OBT0 = 0; |
288 |
TIMESYNC = 0; |
289 |
TYPE = 0; |
290 |
} |
291 |
|
292 |
// **************************************************** |
293 |
|
294 |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
295 |
EV_FROM = evfrom; |
296 |
}; |
297 |
|
298 |
void GL_RUN::SetEV_TO(UInt_t evto){ |
299 |
EV_TO = evto; |
300 |
}; |
301 |
|
302 |
void GL_RUN::SetNEVENTS(UInt_t nev){ |
303 |
NEVENTS = nev; |
304 |
}; |
305 |
|
306 |
void GL_RUN::SetBOOTNUMBER(UInt_t boot){ |
307 |
BOOT_NUMBER = boot; |
308 |
}; |
309 |
|
310 |
void GL_RUN::SetRUNHEADER_TIME(UInt_t absth){ |
311 |
RUNHEADER_TIME = absth; |
312 |
}; |
313 |
|
314 |
void GL_RUN::SetRUNTRAILER_TIME(UInt_t abstt){ |
315 |
RUNTRAILER_TIME = abstt; |
316 |
}; |
317 |
|
318 |
void GL_RUN::SetRUNHEADER_PKT(UInt_t absth){ |
319 |
RUNHEADER_PKT = absth; |
320 |
}; |
321 |
|
322 |
void GL_RUN::SetRUNTRAILER_PKT(UInt_t abstt){ |
323 |
RUNTRAILER_PKT = abstt; |
324 |
}; |
325 |
|
326 |
void GL_RUN::SetRUNHEADER_OBT(UInt_t absth){ |
327 |
RUNHEADER_OBT = absth; |
328 |
}; |
329 |
|
330 |
void GL_RUN::SetRUNTRAILER_OBT(UInt_t abstt){ |
331 |
RUNTRAILER_OBT = abstt; |
332 |
}; |
333 |
|
334 |
void GL_RUN::SetID_ROOT_L2(UInt_t idl2){ |
335 |
ID_ROOT_L2 = idl2; |
336 |
}; |
337 |
|
338 |
void GL_RUN::SetID_ROOT_L0(UInt_t idroot){ |
339 |
ID_ROOT_L0 = idroot; |
340 |
}; |
341 |
|
342 |
void GL_RUN::SetID_RUN_FRAG(UInt_t idfrag){ |
343 |
ID_RUN_FRAG = idfrag; |
344 |
}; |
345 |
|
346 |
void GL_RUN::SetVALIDATION(UInt_t valid){ |
347 |
VALIDATION = valid; |
348 |
}; |
349 |
|
350 |
void GL_RUN::SetLAST_TIMESYNC(UInt_t ts){ |
351 |
LAST_TIMESYNC = ts; |
352 |
}; |
353 |
|
354 |
void GL_RUN::SetOBT_TIMESYNC(UInt_t ts){ |
355 |
OBT_TIMESYNC = ts; |
356 |
}; |
357 |
|
358 |
void GL_RUN:: SetPKT_COUNTER(UInt_t value){ |
359 |
PKT_COUNTER = value; |
360 |
}; |
361 |
|
362 |
void GL_RUN:: SetPKT_READY_COUNTER(UInt_t value){ |
363 |
PKT_READY_COUNTER = value; |
364 |
}; |
365 |
|
366 |
void GL_RUN:: SetCOMPILATIONTIMESTAMP(UInt_t value){ |
367 |
COMPILATIONTIMESTAMP = value; |
368 |
}; |
369 |
|
370 |
void GL_RUN:: SetFAV_WRK_SCHEDULE(UInt_t value){ |
371 |
FAV_WRK_SCHEDULE = value; |
372 |
}; |
373 |
|
374 |
void GL_RUN:: SetEFF_WRK_SCHEDULE(UInt_t value){ |
375 |
EFF_WRK_SCHEDULE = value; |
376 |
}; |
377 |
|
378 |
void GL_RUN:: SetPRH_VAR_TRG_MODE_A(UInt_t value){ |
379 |
PRH_VAR_TRG_MODE_A = value; |
380 |
}; |
381 |
|
382 |
void GL_RUN:: SetPRH_VAR_TRG_MODE_B(UInt_t value){ |
383 |
PRH_VAR_TRG_MODE_B = value; |
384 |
}; |
385 |
|
386 |
void GL_RUN:: SetACQ_BUILD_INFO(UInt_t value){ |
387 |
ACQ_BUILD_INFO = value; |
388 |
}; |
389 |
|
390 |
void GL_RUN:: SetACQ_VAR_INFO(UInt_t value){ |
391 |
ACQ_VAR_INFO = value; |
392 |
}; |
393 |
|
394 |
void GL_RUN:: SetRM_ACQ_AFTER_CALIB(UInt_t value){ |
395 |
RM_ACQ_AFTER_CALIB = value; |
396 |
}; |
397 |
|
398 |
void GL_RUN:: SetRM_ACQ_SETTING_MODE(UInt_t value){ |
399 |
RM_ACQ_SETTING_MODE = value; |
400 |
}; |
401 |
|
402 |
void GL_RUN:: SetTRK_CALIB_USED(UInt_t value){ |
403 |
TRK_CALIB_USED = value; |
404 |
}; |
405 |
|
406 |
void GL_RUN:: SetCAL_DSP_MASK(UInt_t value){ |
407 |
CAL_DSP_MASK = value; |
408 |
}; |
409 |
|
410 |
void GL_RUN:: SetID(UInt_t value){ |
411 |
ID = value; |
412 |
}; |
413 |
|
414 |
void GL_RUN::Set_GL_RUNT(RunTrailerEvent *runt, PscuHeader *pht){ |
415 |
PKT_COUNTER = runt->PKT_COUNTER; |
416 |
PKT_READY_COUNTER = runt->PKT_ReadyCounter; |
417 |
RUNTRAILER_OBT = pht->GetOrbitalTime(); |
418 |
RUNTRAILER_PKT = pht->GetCounter(); |
419 |
}; |
420 |
|
421 |
void GL_RUN::Set_GL_RUNH(RunHeaderEvent *runh, PscuHeader *phh){ |
422 |
TRK_CALIB_USED = runh->TRK_CALIB_USED; |
423 |
PRH_VAR_TRG_MODE_A = runh->PRH_VAR_TRIGGER_MODE_A; |
424 |
PRH_VAR_TRG_MODE_B = runh->PRH_VAR_TRIGGER_MODE_B; |
425 |
ACQ_BUILD_INFO = runh->ACQ_BUILD_INFO; |
426 |
ACQ_VAR_INFO = runh->ACQ_VAR_INFO; |
427 |
RUNHEADER_OBT = phh->GetOrbitalTime(); |
428 |
RUNHEADER_PKT = phh->GetCounter(); |
429 |
LAST_TIMESYNC = runh->LAST_TIME_SYNC_INFO; |
430 |
OBT_TIMESYNC = runh->OBT_TIME_SYNC; |
431 |
COMPILATIONTIMESTAMP = runh->COMPILATIONTIMESTAMP; |
432 |
FAV_WRK_SCHEDULE = runh->FAVOURITE_WORKING_SCHEDULE; |
433 |
EFF_WRK_SCHEDULE = runh->EFFECTIVE_WORKING_SCHEDULE; |
434 |
RM_ACQ_AFTER_CALIB = runh->RM_ACQ_AFTER_CALIB; |
435 |
RM_ACQ_SETTING_MODE = runh->RM_ACQ_SETTING_MODE; |
436 |
TRK_CALIB_USED = runh->TRK_CALIB_USED; |
437 |
CAL_DSP_MASK = runh->CAL_DSP_MASK; |
438 |
}; |
439 |
|
440 |
void GL_RUN::Set_GL_RUNT0(){ |
441 |
PKT_COUNTER = 0; |
442 |
PKT_READY_COUNTER = 0; |
443 |
RUNTRAILER_OBT = 0; |
444 |
RUNTRAILER_PKT = 0; |
445 |
}; |
446 |
|
447 |
void GL_RUN::Set_GL_RUNH0(){ |
448 |
TRK_CALIB_USED = 0; |
449 |
PRH_VAR_TRG_MODE_A = 0; |
450 |
PRH_VAR_TRG_MODE_B = 0; |
451 |
ACQ_BUILD_INFO = 0; |
452 |
ACQ_VAR_INFO = 0; |
453 |
RUNHEADER_OBT = 0; |
454 |
RUNHEADER_PKT = 0; |
455 |
LAST_TIMESYNC = 0; |
456 |
OBT_TIMESYNC = 0; |
457 |
COMPILATIONTIMESTAMP = 0; |
458 |
FAV_WRK_SCHEDULE = 0; |
459 |
EFF_WRK_SCHEDULE = 0; |
460 |
RM_ACQ_AFTER_CALIB = 0; |
461 |
RM_ACQ_SETTING_MODE = 0; |
462 |
TRK_CALIB_USED = 0; |
463 |
CAL_DSP_MASK = 0; |
464 |
}; |
465 |
|
466 |
void GL_RUN::Set_GL_RUN(TSQLRow *Row){ |
467 |
for( Int_t t = 0; t < 30; t++){ |
468 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
469 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
470 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
471 |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
472 |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
473 |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
474 |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
475 |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
476 |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
477 |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
478 |
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
479 |
if (t==11) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
480 |
if (t==12) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
481 |
if (t==13) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
482 |
if (t==14) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
483 |
if (t==15) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
484 |
if (t==16) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
485 |
if (t==17) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
486 |
if (t==18) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
487 |
if (t==19) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
488 |
if (t==20) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
489 |
if (t==21) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
490 |
if (t==22) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
491 |
if (t==23) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
492 |
if (t==24) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
493 |
if (t==25) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
494 |
if (t==26) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
495 |
if (t==27) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
496 |
if (t==28) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
497 |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
498 |
}; |
499 |
|
500 |
} |
501 |
|
502 |
/** |
503 |
* This method delete the run from the "FromTable" table and store it in the GL_RUN_TRASH table |
504 |
* If IDRUN is 0 "this->ID" run is used. |
505 |
* |
506 |
**/ |
507 |
Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ |
508 |
// MySQL variables |
509 |
TSQLResult *pResult; |
510 |
TSQLRow *Row; |
511 |
stringstream myquery; |
512 |
// |
513 |
if ( !IDRUN ) IDRUN = ID; |
514 |
if ( !IDRUN ) return 1; |
515 |
// ---------------- |
516 |
myquery.str(""); |
517 |
myquery << " INSERT INTO GL_RUN_TRASH ("; |
518 |
myquery << "ID"; |
519 |
myquery << ",ID_RUN_FRAG"; |
520 |
myquery << ",ID_ROOT_L0"; |
521 |
myquery << ",ID_ROOT_L2"; |
522 |
myquery << ",RUNHEADER_TIME"; |
523 |
myquery << ",RUNTRAILER_TIME"; |
524 |
myquery << ",RUNHEADER_OBT"; |
525 |
myquery << ",RUNTRAILER_OBT"; |
526 |
myquery << ",RUNHEADER_PKT"; |
527 |
myquery << ",RUNTRAILER_PKT"; |
528 |
myquery << ",BOOT_NUMBER"; |
529 |
myquery << ",EV_FROM"; |
530 |
myquery << ",EV_TO"; |
531 |
myquery << ",NEVENTS"; |
532 |
myquery << ",PKT_COUNTER"; |
533 |
myquery << ",PKT_READY_COUNTER"; |
534 |
myquery << ",COMPILATIONTIMESTAMP"; |
535 |
myquery << ",FAV_WRK_SCHEDULE"; |
536 |
myquery << ",EFF_WRK_SCHEDULE"; |
537 |
myquery << ",PRH_VAR_TRG_MODE_A"; |
538 |
myquery << ",PRH_VAR_TRG_MODE_B"; |
539 |
myquery << ",ACQ_BUILD_INFO"; |
540 |
myquery << ",ACQ_VAR_INFO"; |
541 |
myquery << ",RM_ACQ_AFTER_CALIB"; |
542 |
myquery << ",RM_ACQ_SETTING_MODE"; |
543 |
myquery << ",TRK_CALIB_USED"; |
544 |
myquery << ",CAL_DSP_MASK"; |
545 |
myquery << ",LAST_TIMESYNC"; |
546 |
myquery << ",OBT_TIMESYNC"; |
547 |
myquery << ",VALIDATION"; |
548 |
myquery << ",INSERT_TIME"; |
549 |
myquery << ") SELECT * FROM "; |
550 |
myquery << FromTable.Data(); |
551 |
myquery << " WHERE ID="; |
552 |
myquery << (UInt_t)IDRUN << ";"; |
553 |
// |
554 |
// printf("1myquery is %s \n",myquery.str().c_str()); |
555 |
// |
556 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
557 |
this->GetGLTABLES()->AddQ(); |
558 |
dbc->Query(myquery.str().c_str()); |
559 |
// |
560 |
// retrieve this ID_TRASH |
561 |
// |
562 |
myquery.str(""); |
563 |
myquery << " SELECT ID_TRASH,ID_ROOT_L0,ID_ROOT_L2 FROM GL_RUN_TRASH ORDER BY ID_TRASH DESC LIMIT 1"; |
564 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
565 |
this->GetGLTABLES()->AddQ(); |
566 |
pResult = dbc->Query(myquery.str().c_str()); |
567 |
// |
568 |
UInt_t idtrash = 0; |
569 |
UInt_t idl0 = 0; |
570 |
UInt_t idl2 = 0; |
571 |
// |
572 |
Row = pResult->Next(); |
573 |
if( Row != NULL ){ |
574 |
idtrash = (UInt_t)atoll(Row->GetField(0)); |
575 |
idl0 = (UInt_t)atoll(Row->GetField(1)); |
576 |
idl2 = (UInt_t)atoll(Row->GetField(2)); |
577 |
}; |
578 |
// |
579 |
TString fileL0 = ""; |
580 |
TString fileL2 = ""; |
581 |
myquery.str(""); |
582 |
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
583 |
myquery << idl0 << ";"; |
584 |
// |
585 |
// printf("2myquery is %s \n",myquery.str().c_str()); |
586 |
// |
587 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
588 |
this->GetGLTABLES()->AddQ(); |
589 |
pResult = dbc->Query(myquery.str().c_str()); |
590 |
// |
591 |
Row = pResult->Next(); |
592 |
if( Row != NULL ){ |
593 |
fileL0 = (TString)Row->GetField(0); |
594 |
}; |
595 |
// |
596 |
// |
597 |
// |
598 |
myquery.str(""); |
599 |
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
600 |
myquery << idl2 << ";"; |
601 |
// |
602 |
// printf("3myquery is %s \n",myquery.str().c_str()); |
603 |
// |
604 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
605 |
this->GetGLTABLES()->AddQ(); |
606 |
pResult = dbc->Query(myquery.str().c_str()); |
607 |
// |
608 |
Row = pResult->Next(); |
609 |
if( Row != NULL ){ |
610 |
fileL2 = (TString)Row->GetField(0); |
611 |
}; |
612 |
// |
613 |
// |
614 |
// |
615 |
myquery.str(""); |
616 |
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL0='"; |
617 |
myquery << fileL0.Data() << "' where ID_TRASH="; |
618 |
myquery << idtrash << ";"; |
619 |
// |
620 |
// printf("4myquery is %s \n",myquery.str().c_str()); |
621 |
// |
622 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
623 |
this->GetGLTABLES()->AddQ(); |
624 |
dbc->Query(myquery.str().c_str()); |
625 |
// |
626 |
myquery.str(""); |
627 |
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='"; |
628 |
myquery << fileL2.Data() << "' where ID_TRASH="; |
629 |
myquery << idtrash << ";"; |
630 |
// |
631 |
// printf("4myquery is %s \n",myquery.str().c_str()); |
632 |
// |
633 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
634 |
this->GetGLTABLES()->AddQ(); |
635 |
dbc->Query(myquery.str().c_str()); |
636 |
// |
637 |
myquery.str(""); |
638 |
myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='"; |
639 |
myquery << FromTable.Data() << "' where ID_TRASH="; |
640 |
myquery << idtrash << ";"; |
641 |
// |
642 |
// printf("4myquery is %s \n",myquery.str().c_str()); |
643 |
// |
644 |
// |
645 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
646 |
this->GetGLTABLES()->AddQ(); |
647 |
dbc->Query(myquery.str().c_str()); |
648 |
// |
649 |
myquery.str(""); |
650 |
myquery << " DELETE FROM "; |
651 |
myquery << FromTable.Data() << " where ID="; |
652 |
myquery << IDRUN << ";"; |
653 |
// |
654 |
// printf("5myquery is %s \n",myquery.str().c_str()); |
655 |
// |
656 |
// |
657 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
658 |
this->GetGLTABLES()->AddQ(); |
659 |
dbc->Query(myquery.str().c_str()); |
660 |
// |
661 |
return 0; |
662 |
}; |
663 |
|
664 |
|
665 |
|
666 |
/** |
667 |
* This method restore a run from the GL_RUN_TRASH table. |
668 |
* If ID is 0 "this->ID" is used; if "ToTable" is empty BELONG_TO field of GL_RUN_TRASH is used. |
669 |
* |
670 |
**/ |
671 |
Int_t GL_RUN::RestoreRun(TSQLServer *dbc,UInt_t IDRUN,TString ToTable){ |
672 |
// insert into GL_RUN_FRAGMENTS select * FROM GL_RUN where ID=11; |
673 |
//insert into GL_RUN_TRASH VALUES (ID , ID_RUN_FRAG , ID_ROOT_L0 , ID_ROOT_L2 , RUNHEADER_TIME , RUNTRAILER_TIME , RUNHEADER_OBT , RUNTRAILER_OBT , RUNHEADER_PKT , RUNTRAILER_PKT , BOOT_NUMBER , EV_FROM , EV_TO , NEVENTS , PKT_COUNTER , PKT_READY_COUNTER , COMPILATIONTIMESTAMP , FAV_WRK_SCHEDULE , EFF_WRK_SCHEDULE , PRH_VAR_TRG_MODE_A , PRH_VAR_TRG_MODE_B , ACQ_BUILD_INFO , ACQ_VAR_INFO , RM_ACQ_AFTER_CALIB , RM_ACQ_SETTING_MODE, TRK_CALIB_USED,CAL_DSP_MASK, LAST_TIMESYNC, OBT_TIMESYNC, VALIDATION, INSERT_TIME) select * FROM GL_RUN where ID=11; |
674 |
// MySQL variables |
675 |
TSQLResult *pResult; |
676 |
TSQLRow *Row; |
677 |
stringstream myquery; |
678 |
// |
679 |
if ( !IDRUN ) IDRUN = ID; |
680 |
if ( !IDRUN ) return 1; |
681 |
// |
682 |
if ( !strcmp(ToTable.Data(),"") ){ |
683 |
// |
684 |
myquery.str(""); |
685 |
myquery << " SELECT BELONGED_TO FROM GL_RUN_TRASH WHERE ID="; |
686 |
myquery << (UInt_t)IDRUN << ";"; |
687 |
// |
688 |
printf(" qui? myquery is %s \n",myquery.str().c_str()); |
689 |
// |
690 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
691 |
this->GetGLTABLES()->AddQ(); |
692 |
pResult = dbc->Query(myquery.str().c_str()); |
693 |
// |
694 |
Row = pResult->Next(); |
695 |
if( Row != NULL ){ |
696 |
ToTable = (TString)Row->GetField(0); |
697 |
} else { |
698 |
return 1; |
699 |
}; |
700 |
}; |
701 |
// ---------------- |
702 |
myquery.str(""); |
703 |
myquery << " INSERT INTO "; |
704 |
myquery << ToTable.Data(); |
705 |
myquery << " ("; |
706 |
myquery << "ID"; |
707 |
myquery << ",ID_RUN_FRAG"; |
708 |
myquery << ",ID_ROOT_L0"; |
709 |
myquery << ",ID_ROOT_L2"; |
710 |
myquery << ",RUNHEADER_TIME"; |
711 |
myquery << ",RUNTRAILER_TIME"; |
712 |
myquery << ",RUNHEADER_OBT"; |
713 |
myquery << ",RUNTRAILER_OBT"; |
714 |
myquery << ",RUNHEADER_PKT"; |
715 |
myquery << ",RUNTRAILER_PKT"; |
716 |
myquery << ",BOOT_NUMBER"; |
717 |
myquery << ",EV_FROM"; |
718 |
myquery << ",EV_TO"; |
719 |
myquery << ",NEVENTS"; |
720 |
myquery << ",PKT_COUNTER"; |
721 |
myquery << ",PKT_READY_COUNTER"; |
722 |
myquery << ",COMPILATIONTIMESTAMP"; |
723 |
myquery << ",FAV_WRK_SCHEDULE"; |
724 |
myquery << ",EFF_WRK_SCHEDULE"; |
725 |
myquery << ",PRH_VAR_TRG_MODE_A"; |
726 |
myquery << ",PRH_VAR_TRG_MODE_B"; |
727 |
myquery << ",ACQ_BUILD_INFO"; |
728 |
myquery << ",ACQ_VAR_INFO"; |
729 |
myquery << ",RM_ACQ_AFTER_CALIB"; |
730 |
myquery << ",RM_ACQ_SETTING_MODE"; |
731 |
myquery << ",TRK_CALIB_USED"; |
732 |
myquery << ",CAL_DSP_MASK"; |
733 |
myquery << ",LAST_TIMESYNC"; |
734 |
myquery << ",OBT_TIMESYNC"; |
735 |
myquery << ",VALIDATION"; |
736 |
myquery << ",INSERT_TIME"; |
737 |
myquery << ") SELECT "; |
738 |
myquery << "ID"; |
739 |
myquery << ",ID_RUN_FRAG"; |
740 |
myquery << ",ID_ROOT_L0"; |
741 |
myquery << ",ID_ROOT_L2"; |
742 |
myquery << ",RUNHEADER_TIME"; |
743 |
myquery << ",RUNTRAILER_TIME"; |
744 |
myquery << ",RUNHEADER_OBT"; |
745 |
myquery << ",RUNTRAILER_OBT"; |
746 |
myquery << ",RUNHEADER_PKT"; |
747 |
myquery << ",RUNTRAILER_PKT"; |
748 |
myquery << ",BOOT_NUMBER"; |
749 |
myquery << ",EV_FROM"; |
750 |
myquery << ",EV_TO"; |
751 |
myquery << ",NEVENTS"; |
752 |
myquery << ",PKT_COUNTER"; |
753 |
myquery << ",PKT_READY_COUNTER"; |
754 |
myquery << ",COMPILATIONTIMESTAMP"; |
755 |
myquery << ",FAV_WRK_SCHEDULE"; |
756 |
myquery << ",EFF_WRK_SCHEDULE"; |
757 |
myquery << ",PRH_VAR_TRG_MODE_A"; |
758 |
myquery << ",PRH_VAR_TRG_MODE_B"; |
759 |
myquery << ",ACQ_BUILD_INFO"; |
760 |
myquery << ",ACQ_VAR_INFO"; |
761 |
myquery << ",RM_ACQ_AFTER_CALIB"; |
762 |
myquery << ",RM_ACQ_SETTING_MODE"; |
763 |
myquery << ",TRK_CALIB_USED"; |
764 |
myquery << ",CAL_DSP_MASK"; |
765 |
myquery << ",LAST_TIMESYNC"; |
766 |
myquery << ",OBT_TIMESYNC"; |
767 |
myquery << ",VALIDATION"; |
768 |
myquery << ",INSERT_TIME"; |
769 |
myquery << " FROM GL_RUN_TRASH "; |
770 |
myquery << " WHERE BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
771 |
myquery << (UInt_t)IDRUN << ";"; |
772 |
// |
773 |
// printf("5myquery is %s \n",myquery.str().c_str()); |
774 |
// |
775 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
776 |
this->GetGLTABLES()->AddQ(); |
777 |
dbc->Query(myquery.str().c_str()); |
778 |
// |
779 |
// |
780 |
myquery.str(""); |
781 |
myquery << " DELETE FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
782 |
myquery << IDRUN << ";"; |
783 |
// |
784 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
785 |
this->GetGLTABLES()->AddQ(); |
786 |
dbc->Query(myquery.str().c_str()); |
787 |
// |
788 |
return 0; |
789 |
}; |
790 |
|
791 |
/** |
792 |
* Function to fill the GL_RUN table of the DB. |
793 |
* |
794 |
* \param |
795 |
* |
796 |
*/ |
797 |
Int_t GL_RUN::Fill_GL_RUN(TSQLServer *dbc){ |
798 |
// MySQL variables |
799 |
stringstream myquery; |
800 |
// ---------------- |
801 |
myquery.str(""); |
802 |
myquery << " INSERT INTO GL_RUN ("; |
803 |
myquery << "ID"; |
804 |
myquery << ",ID_RUN_FRAG"; |
805 |
myquery << ",ID_ROOT_L0"; |
806 |
myquery << ",ID_ROOT_L2"; |
807 |
myquery << ",RUNHEADER_TIME"; |
808 |
myquery << ",RUNTRAILER_TIME"; |
809 |
myquery << ",RUNHEADER_OBT"; |
810 |
myquery << ",RUNTRAILER_OBT"; |
811 |
myquery << ",RUNHEADER_PKT"; |
812 |
myquery << ",RUNTRAILER_PKT"; |
813 |
myquery << ",EV_FROM"; |
814 |
myquery << ",EV_TO"; |
815 |
myquery << ",NEVENTS"; |
816 |
myquery << ",LAST_TIMESYNC"; |
817 |
myquery << ",OBT_TIMESYNC"; |
818 |
myquery << ",COMPILATIONTIMESTAMP"; |
819 |
myquery << ",FAV_WRK_SCHEDULE"; |
820 |
myquery << ",EFF_WRK_SCHEDULE"; |
821 |
myquery << ",PRH_VAR_TRG_MODE_A"; |
822 |
myquery << ",PRH_VAR_TRG_MODE_B"; |
823 |
myquery << ",ACQ_BUILD_INFO"; |
824 |
myquery << ",ACQ_VAR_INFO"; |
825 |
myquery << ",RM_ACQ_AFTER_CALIB"; |
826 |
myquery << ",RM_ACQ_SETTING_MODE"; |
827 |
myquery << ",PKT_COUNTER"; |
828 |
myquery << ",PKT_READY_COUNTER"; |
829 |
myquery << ",TRK_CALIB_USED"; |
830 |
myquery << ",CAL_DSP_MASK"; |
831 |
myquery << ",BOOT_NUMBER"; |
832 |
myquery << ",VALIDATION"; |
833 |
myquery << ") VALUES ('"; |
834 |
|
835 |
myquery << (UInt_t)ID << "','"; |
836 |
myquery << (UInt_t)ID_RUN_FRAG << "','"; |
837 |
myquery << (UInt_t)ID_ROOT_L0 << "','"; |
838 |
myquery << (UInt_t)ID_ROOT_L2 << "','"; |
839 |
myquery << (UInt_t)RUNHEADER_TIME << "','"; |
840 |
myquery << (UInt_t)RUNTRAILER_TIME << "','"; |
841 |
myquery << (UInt_t)RUNHEADER_OBT << "','"; |
842 |
myquery << (UInt_t)RUNTRAILER_OBT << "','"; |
843 |
myquery << (UInt_t)RUNHEADER_PKT << "','"; |
844 |
myquery << (UInt_t)RUNTRAILER_PKT << "','"; |
845 |
myquery << (UInt_t)EV_FROM << "','"; |
846 |
myquery << (UInt_t)EV_TO << "','"; |
847 |
myquery << (UInt_t)NEVENTS << "','"; |
848 |
myquery << (UInt_t)LAST_TIMESYNC << "','"; |
849 |
myquery << (UInt_t)OBT_TIMESYNC << "','"; |
850 |
myquery << (UInt_t)COMPILATIONTIMESTAMP << "','"; |
851 |
myquery << (UInt_t)FAV_WRK_SCHEDULE << "','"; |
852 |
myquery << (UInt_t)EFF_WRK_SCHEDULE << "','"; |
853 |
myquery << (UInt_t)PRH_VAR_TRG_MODE_A << "','"; |
854 |
myquery << (UInt_t)PRH_VAR_TRG_MODE_B << "','"; |
855 |
myquery << (UInt_t)ACQ_BUILD_INFO << "','"; |
856 |
myquery << (UInt_t)ACQ_VAR_INFO << "','"; |
857 |
myquery << (UInt_t)RM_ACQ_AFTER_CALIB << "','"; |
858 |
myquery << (UInt_t)RM_ACQ_SETTING_MODE << "','"; |
859 |
myquery << (UInt_t)PKT_COUNTER << "','"; |
860 |
myquery << (UInt_t)PKT_READY_COUNTER << "','"; |
861 |
myquery << (UInt_t)TRK_CALIB_USED << "','"; |
862 |
myquery << (UInt_t)CAL_DSP_MASK << "','"; |
863 |
myquery << (UInt_t)BOOT_NUMBER << "','"; |
864 |
myquery << (UInt_t)VALIDATION << "');"; |
865 |
// |
866 |
// printf("myquery is %s \n",myquery.str().c_str()); |
867 |
// |
868 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
869 |
this->GetGLTABLES()->AddQ(); |
870 |
dbc->Query(myquery.str().c_str()); |
871 |
// |
872 |
return 0; |
873 |
|
874 |
};// **************************************************** |
875 |
|
876 |
/** |
877 |
* Function to fill the GL_RUN table of the DB. |
878 |
* |
879 |
* \param |
880 |
* |
881 |
*/ |
882 |
Int_t GL_RUN::Fill_GL_RUN_FRAGMENTS(TSQLServer *dbc){ |
883 |
// MySQL variables |
884 |
stringstream myquery; |
885 |
// ---------------- |
886 |
myquery.str(""); |
887 |
myquery << " INSERT INTO GL_RUN_FRAGMENTS ("; |
888 |
myquery << "ID"; |
889 |
myquery << ",ID_ROOT_L0"; |
890 |
myquery << ",RUNHEADER_TIME"; |
891 |
myquery << ",RUNTRAILER_TIME"; |
892 |
myquery << ",RUNHEADER_OBT"; |
893 |
myquery << ",RUNTRAILER_OBT"; |
894 |
myquery << ",RUNHEADER_PKT"; |
895 |
myquery << ",RUNTRAILER_PKT"; |
896 |
myquery << ",EV_FROM"; |
897 |
myquery << ",EV_TO"; |
898 |
myquery << ",NEVENTS"; |
899 |
myquery << ",LAST_TIMESYNC"; |
900 |
myquery << ",OBT_TIMESYNC"; |
901 |
myquery << ",COMPILATIONTIMESTAMP"; |
902 |
myquery << ",FAV_WRK_SCHEDULE"; |
903 |
myquery << ",EFF_WRK_SCHEDULE"; |
904 |
myquery << ",PRH_VAR_TRG_MODE_A"; |
905 |
myquery << ",PRH_VAR_TRG_MODE_B"; |
906 |
myquery << ",ACQ_BUILD_INFO"; |
907 |
myquery << ",ACQ_VAR_INFO"; |
908 |
myquery << ",RM_ACQ_AFTER_CALIB"; |
909 |
myquery << ",RM_ACQ_SETTING_MODE"; |
910 |
myquery << ",PKT_COUNTER"; |
911 |
myquery << ",PKT_READY_COUNTER"; |
912 |
myquery << ",TRK_CALIB_USED"; |
913 |
myquery << ",CAL_DSP_MASK"; |
914 |
myquery << ",BOOT_NUMBER"; |
915 |
myquery << ") VALUES ('"; |
916 |
myquery << (UInt_t)ID << "','"; |
917 |
myquery << (UInt_t)ID_ROOT_L0 << "','"; |
918 |
myquery << (UInt_t)RUNHEADER_TIME << "','"; |
919 |
myquery << (UInt_t)RUNTRAILER_TIME << "','"; |
920 |
myquery << (UInt_t)RUNHEADER_OBT << "','"; |
921 |
myquery << (UInt_t)RUNTRAILER_OBT << "','"; |
922 |
myquery << (UInt_t)RUNHEADER_PKT << "','"; |
923 |
myquery << (UInt_t)RUNTRAILER_PKT << "','"; |
924 |
myquery << (UInt_t)EV_FROM << "','"; |
925 |
myquery << (UInt_t)EV_TO << "','"; |
926 |
myquery << (UInt_t)NEVENTS << "','"; |
927 |
myquery << (UInt_t)LAST_TIMESYNC << "','"; |
928 |
myquery << (UInt_t)OBT_TIMESYNC << "','"; |
929 |
myquery << (UInt_t)COMPILATIONTIMESTAMP << "','"; |
930 |
myquery << (UInt_t)FAV_WRK_SCHEDULE << "','"; |
931 |
myquery << (UInt_t)EFF_WRK_SCHEDULE << "','"; |
932 |
myquery << (UInt_t)PRH_VAR_TRG_MODE_A << "','"; |
933 |
myquery << (UInt_t)PRH_VAR_TRG_MODE_B << "','"; |
934 |
myquery << (UInt_t)ACQ_BUILD_INFO << "','"; |
935 |
myquery << (UInt_t)ACQ_VAR_INFO << "','"; |
936 |
myquery << (UInt_t)RM_ACQ_AFTER_CALIB << "','"; |
937 |
myquery << (UInt_t)RM_ACQ_SETTING_MODE << "','"; |
938 |
myquery << (UInt_t)PKT_COUNTER << "','"; |
939 |
myquery << (UInt_t)PKT_READY_COUNTER << "','"; |
940 |
myquery << (UInt_t)TRK_CALIB_USED << "','"; |
941 |
myquery << (UInt_t)CAL_DSP_MASK << "','"; |
942 |
myquery << (UInt_t)BOOT_NUMBER << "');"; |
943 |
// |
944 |
// printf("myquery is %s \n",myquery.str().c_str()); |
945 |
// |
946 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
947 |
this->GetGLTABLES()->AddQ(); |
948 |
dbc->Query(myquery.str().c_str()); |
949 |
// |
950 |
return 0; |
951 |
|
952 |
};// **************************************************** |
953 |
|
954 |
|
955 |
/** |
956 |
* Function to query the GL_RUN table of the DB. |
957 |
* |
958 |
* \param RUN id |
959 |
* \return struct of type GL_RUN _data, which stores the query result |
960 |
* |
961 |
*/ |
962 |
Int_t GL_RUN::Query_GL_RUN(UInt_t run, TSQLServer *dbc){ |
963 |
// MySQL variables |
964 |
TSQLResult *pResult; |
965 |
TSQLRow *Row; |
966 |
int t; |
967 |
int r; |
968 |
stringstream myquery; |
969 |
// ---------------- |
970 |
myquery.str(""); |
971 |
myquery << " select "; |
972 |
myquery << "ID"; |
973 |
myquery << ",ID_RUN_FRAG"; |
974 |
myquery << ",ID_ROOT_L0"; |
975 |
myquery << ",ID_ROOT_L2"; |
976 |
myquery << ",RUNHEADER_TIME"; |
977 |
myquery << ",RUNTRAILER_TIME"; |
978 |
myquery << ",RUNHEADER_OBT"; |
979 |
myquery << ",RUNTRAILER_OBT"; |
980 |
myquery << ",RUNHEADER_PKT"; |
981 |
myquery << ",RUNTRAILER_PKT"; |
982 |
myquery << ",EV_FROM"; |
983 |
myquery << ",EV_TO"; |
984 |
myquery << ",NEVENTS"; |
985 |
myquery << ",LAST_TIMESYNC"; |
986 |
myquery << ",OBT_TIMESYNC"; |
987 |
myquery << ",COMPILATIONTIMESTAMP"; |
988 |
myquery << ",FAV_WRK_SCHEDULE"; |
989 |
myquery << ",EFF_WRK_SCHEDULE"; |
990 |
myquery << ",PRH_VAR_TRG_MODE_A"; |
991 |
myquery << ",PRH_VAR_TRG_MODE_B"; |
992 |
myquery << ",ACQ_BUILD_INFO"; |
993 |
myquery << ",ACQ_VAR_INFO"; |
994 |
myquery << ",RM_ACQ_AFTER_CALIB"; |
995 |
myquery << ",RM_ACQ_SETTING_MODE"; |
996 |
myquery << ",PKT_COUNTER"; |
997 |
myquery << ",PKT_READY_COUNTER"; |
998 |
myquery << ",TRK_CALIB_USED"; |
999 |
myquery << ",CAL_DSP_MASK"; |
1000 |
myquery << ",BOOT_NUMBER"; |
1001 |
myquery << ",VALIDATION"; |
1002 |
myquery << " from GL_RUN where ID=" << run << ";"; |
1003 |
// |
1004 |
// printf(" myquery is %s \n",myquery.str().c_str()); |
1005 |
if ( !this->IsConnected(dbc) ) return -57; |
1006 |
this->AddQ(); |
1007 |
pResult = dbc->Query(myquery.str().c_str()); |
1008 |
// |
1009 |
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
1010 |
// |
1011 |
if( !pResult->GetRowCount() ) return(-50); |
1012 |
// |
1013 |
for( r=0; r < 1000; r++){ |
1014 |
Row = pResult->Next(); |
1015 |
if( Row == NULL ) break; |
1016 |
// Set_GL_RUN(Row); |
1017 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1018 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
1019 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
1020 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1021 |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
1022 |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
1023 |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
1024 |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
1025 |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
1026 |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
1027 |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
1028 |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
1029 |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
1030 |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
1031 |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1032 |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1033 |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
1034 |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
1035 |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
1036 |
if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
1037 |
if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
1038 |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
1039 |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
1040 |
if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
1041 |
if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
1042 |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
1043 |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
1044 |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
1045 |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
1046 |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
1047 |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
1048 |
}; |
1049 |
}; |
1050 |
// delete pResult; |
1051 |
return(0); |
1052 |
}; |
1053 |
|
1054 |
/** |
1055 |
* Function to query the GL_RUN table of the DB. |
1056 |
* |
1057 |
* \param where = condition string |
1058 |
* \return struct of type GL_RUN _data, which stores the query result |
1059 |
* |
1060 |
*/ |
1061 |
Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TString where, TSQLServer *dbc){ |
1062 |
// MySQL variables |
1063 |
TSQLResult *pResult; |
1064 |
TSQLRow *Row; |
1065 |
int t; |
1066 |
int r; |
1067 |
stringstream myquery; |
1068 |
// ---------------- |
1069 |
myquery.str(""); |
1070 |
myquery << " select "; |
1071 |
myquery << "ID"; |
1072 |
myquery << ",ID_RUN_FRAG"; |
1073 |
myquery << ",ID_ROOT_L0"; |
1074 |
myquery << ",ID_ROOT_L2"; |
1075 |
myquery << ",RUNHEADER_TIME"; |
1076 |
myquery << ",RUNTRAILER_TIME"; |
1077 |
myquery << ",RUNHEADER_OBT"; |
1078 |
myquery << ",RUNTRAILER_OBT"; |
1079 |
myquery << ",RUNHEADER_PKT"; |
1080 |
myquery << ",RUNTRAILER_PKT"; |
1081 |
myquery << ",EV_FROM"; |
1082 |
myquery << ",EV_TO"; |
1083 |
myquery << ",NEVENTS"; |
1084 |
myquery << ",LAST_TIMESYNC"; |
1085 |
myquery << ",OBT_TIMESYNC"; |
1086 |
myquery << ",COMPILATIONTIMESTAMP"; |
1087 |
myquery << ",FAV_WRK_SCHEDULE"; |
1088 |
myquery << ",EFF_WRK_SCHEDULE"; |
1089 |
myquery << ",PRH_VAR_TRG_MODE_A"; |
1090 |
myquery << ",PRH_VAR_TRG_MODE_B"; |
1091 |
myquery << ",ACQ_BUILD_INFO"; |
1092 |
myquery << ",ACQ_VAR_INFO"; |
1093 |
myquery << ",RM_ACQ_AFTER_CALIB"; |
1094 |
myquery << ",RM_ACQ_SETTING_MODE"; |
1095 |
myquery << ",PKT_COUNTER"; |
1096 |
myquery << ",PKT_READY_COUNTER"; |
1097 |
myquery << ",TRK_CALIB_USED"; |
1098 |
myquery << ",CAL_DSP_MASK"; |
1099 |
myquery << ",BOOT_NUMBER"; |
1100 |
myquery << ",VALIDATION"; |
1101 |
myquery << " from GL_RUN_FRAGMENTS where " << where.Data() << ";"; |
1102 |
// |
1103 |
// printf(" query is %s \n",myquery.str().c_str()); |
1104 |
// |
1105 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1106 |
this->GetGLTABLES()->AddQ(); |
1107 |
pResult = dbc->Query(myquery.str().c_str()); |
1108 |
if(!pResult->GetRowCount())return(-50); |
1109 |
for( r=0; r < 1000; r++){ |
1110 |
Row = pResult->Next(); |
1111 |
if( Row == NULL ) break; |
1112 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1113 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
1114 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
1115 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1116 |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
1117 |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
1118 |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
1119 |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
1120 |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
1121 |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
1122 |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
1123 |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
1124 |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
1125 |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
1126 |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1127 |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1128 |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
1129 |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
1130 |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
1131 |
if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
1132 |
if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
1133 |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
1134 |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
1135 |
if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
1136 |
if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
1137 |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
1138 |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
1139 |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
1140 |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
1141 |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
1142 |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
1143 |
}; |
1144 |
}; |
1145 |
// delete pResult; |
1146 |
return(0); |
1147 |
};// **************************************************** |
1148 |
|
1149 |
/** |
1150 |
* Function to query the GL_ROOT table of the DB. |
1151 |
* |
1152 |
* \param entry ID |
1153 |
* \return struct of type GL_ROOT_data, which stores the query result |
1154 |
*/ |
1155 |
Int_t GL_ROOT::Query_GL_ROOT(UInt_t id, TSQLServer *dbc){ |
1156 |
// MySQL variables |
1157 |
TSQLResult *pResult; |
1158 |
TSQLRow *Row; |
1159 |
int t; |
1160 |
int r; |
1161 |
stringstream myquery; |
1162 |
// ---------------- |
1163 |
myquery.str(""); |
1164 |
myquery << "select "; |
1165 |
myquery << " ID"; |
1166 |
myquery << ",ID_RAW"; |
1167 |
myquery << ",ID_TIMESYNC"; |
1168 |
myquery << ",PATH"; |
1169 |
myquery << ",NAME"; |
1170 |
myquery << " from GL_ROOT where ID=" << id << ";"; |
1171 |
// |
1172 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1173 |
this->GetGLTABLES()->AddQ(); |
1174 |
pResult = dbc->Query(myquery.str().c_str()); |
1175 |
if(!pResult->GetRowCount())return (-51); |
1176 |
for( r=0; r < 1000; r++){ |
1177 |
Row = pResult->Next(); |
1178 |
if( Row == NULL ) break; |
1179 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1180 |
if(t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1181 |
if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t)); |
1182 |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1183 |
if(t==3) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/'; |
1184 |
if(t==4) NAME = Row->GetField(t); |
1185 |
}; |
1186 |
}; |
1187 |
delete pResult; |
1188 |
return 0; |
1189 |
}; |
1190 |
// **************************************************** |
1191 |
/** |
1192 |
* Function to query the GL_TRK_CALIB table of the DB. |
1193 |
* |
1194 |
* \param run starting time |
1195 |
* \param dbc DB server |
1196 |
* \return struct of type GL_TRK_CALIB_data, which stores the query result |
1197 |
*/ |
1198 |
Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(UInt_t time, TSQLServer *dbc){ |
1199 |
// MySQL variables |
1200 |
TSQLResult *pResult; |
1201 |
TSQLRow *Row; |
1202 |
int t; |
1203 |
int r; |
1204 |
stringstream myquery; |
1205 |
// ---------------- |
1206 |
myquery.str(""); |
1207 |
myquery << "select ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,OBT2,PKT1,PKT2,BOOT_NUMBER,VALIDATION from GL_TRK_CALIB where FROM_TIME <= "<< time; |
1208 |
// myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; // RIVEDERE LA VALIDAZIONE!!! |
1209 |
myquery << " and EV_ROOT_CALIBTRK1>=0 and EV_ROOT_CALIBTRK2>=0 "; // EM! SE MANCA UN PACCHETTO DEI DUE IL PROCESSAMENTO CRASHA... DA RIVEDERE LA VALIDAZIONE |
1210 |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1211 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1212 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1213 |
this->GetGLTABLES()->AddQ(); |
1214 |
pResult = dbc->Query(myquery.str().c_str()); |
1215 |
if(!pResult->GetRowCount())return (-53); |
1216 |
for( r=0; r < 1000; r++){ |
1217 |
Row = pResult->Next(); |
1218 |
if( Row == NULL ) break; |
1219 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1220 |
stringstream row; |
1221 |
row.str(""); |
1222 |
row << "0" << Row->GetField(t); // add leading 0 since we have two fields that could be "null" and we want to avoid crashes due to atoll |
1223 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1224 |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1225 |
if (t==2) EV_ROOT_CALIBTRK1 = (UInt_t)atoll(row.str().c_str()); |
1226 |
if (t==3) EV_ROOT_CALIBTRK2 = (UInt_t)atoll(row.str().c_str()); |
1227 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1228 |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
1229 |
// |
1230 |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
1231 |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
1232 |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
1233 |
if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t)); |
1234 |
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
1235 |
if (t==11) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
1236 |
}; |
1237 |
}; |
1238 |
delete pResult; |
1239 |
// |
1240 |
// if ( TO_TIME < time ) return(51); |
1241 |
// |
1242 |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
1243 |
// |
1244 |
return 0; |
1245 |
}; |
1246 |
|
1247 |
// **************************************************** |
1248 |
/** |
1249 |
* Function to query the GL_CALO_CALIB table of the DB. |
1250 |
* |
1251 |
* \param run starting time |
1252 |
* \return struct of type GL_CALO_CALIB_data, which stores the query result |
1253 |
*/ |
1254 |
Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t &uptime, UInt_t section, TSQLServer *dbc){ |
1255 |
// MySQL variables |
1256 |
TSQLResult *pResult; |
1257 |
TSQLRow *Row; |
1258 |
int t; |
1259 |
stringstream myquery; |
1260 |
uptime = 0; |
1261 |
// |
1262 |
// select the correct calibration |
1263 |
// |
1264 |
myquery.str(""); |
1265 |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section; |
1266 |
myquery << " and FROM_TIME <= " << time; |
1267 |
myquery << " and TO_TIME > " << time; |
1268 |
myquery << " ;"; |
1269 |
//myquery << " and VALIDATION=1;"; |
1270 |
// |
1271 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1272 |
this->GetGLTABLES()->AddQ(); |
1273 |
pResult = dbc->Query(myquery.str().c_str()); |
1274 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1275 |
// |
1276 |
if( !pResult->GetRowCount() ) return(-54); |
1277 |
Row = pResult->Next(); |
1278 |
if( Row == NULL ) return (-54); |
1279 |
// |
1280 |
uptime = (UInt_t)atoll(Row->GetField(2)); |
1281 |
// |
1282 |
// if it is corrupted validation is 0 and we have no results from the query... |
1283 |
// |
1284 |
if( atoi(Row->GetField(4)) == 0 ){ // if validation = 0 |
1285 |
// |
1286 |
// in this case take relax the conditions and take the valid calibration that preceed the correct one |
1287 |
// |
1288 |
myquery.str(""); |
1289 |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section; |
1290 |
myquery << " and FROM_TIME <= " << time; |
1291 |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
1292 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1293 |
this->GetGLTABLES()->AddQ(); |
1294 |
pResult = dbc->Query(myquery.str().c_str()); |
1295 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1296 |
// |
1297 |
// if no results yet quit with error |
1298 |
// |
1299 |
if( !pResult->GetRowCount() ) return (-54); |
1300 |
// |
1301 |
Row = pResult->Next(); |
1302 |
// |
1303 |
}; |
1304 |
// |
1305 |
// store infos and exit |
1306 |
// |
1307 |
if( Row == NULL ) return (-54); |
1308 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1309 |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1310 |
if (t==1) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1311 |
if (t==2) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
1312 |
if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
1313 |
}; |
1314 |
pResult->Delete(); |
1315 |
return 0; |
1316 |
}; |
1317 |
|
1318 |
|
1319 |
// **************************************************** |
1320 |
/** |
1321 |
* Function to query the GL_CALOPULSE_CALIB table of the DB. |
1322 |
* |
1323 |
* \param run starting time |
1324 |
* \return struct of type GL_CALOPULSE_CALIB_data, which stores the query result |
1325 |
*/ |
1326 |
Int_t GL_CALOPULSE_CALIB::Query_GL_CALOPULSE_CALIB(UInt_t time, UInt_t section, UInt_t pampli, TSQLServer *dbc){ |
1327 |
// MySQL variables |
1328 |
TSQLResult *pResult; |
1329 |
TSQLRow *Row; |
1330 |
int t; |
1331 |
stringstream myquery; |
1332 |
// |
1333 |
// select the correct calibration i.e. the closest to our time |
1334 |
// |
1335 |
myquery.str(""); |
1336 |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALOPULSE_CALIB where SECTION=" << section; |
1337 |
myquery << " and PULSE_AMPLITUDE=" << pampli; |
1338 |
myquery << " and VALIDATION=1 and (PULSED_STRIP IS NULL OR PULSED_STRIP<100) ORDER BY ABS(" << time << "-FROM_TIME) asc limit 1;"; |
1339 |
// printf(" myq is %s \n",myquery.str().c_str()); |
1340 |
// |
1341 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1342 |
this->GetGLTABLES()->AddQ(); |
1343 |
pResult = dbc->Query(myquery.str().c_str()); |
1344 |
// |
1345 |
if( !pResult ) return(-54); |
1346 |
// |
1347 |
Row = pResult->Next(); |
1348 |
// |
1349 |
if( !Row ) return (-54); |
1350 |
// |
1351 |
// store infos and exit |
1352 |
// |
1353 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1354 |
// printf(" field %i is %s \n",t,Row->GetField(t)); |
1355 |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1356 |
if (t==1) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1357 |
if (t==2) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
1358 |
if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
1359 |
}; |
1360 |
pResult->Delete(); |
1361 |
return 0; |
1362 |
}; |
1363 |
|
1364 |
|
1365 |
// **************************************************** |
1366 |
/** |
1367 |
* Function to query the GL_S4_CALIB table of the DB. |
1368 |
* |
1369 |
* \param run starting time |
1370 |
* \return struct of type GL_S4_CALIB_data, which stores the query result |
1371 |
*/ |
1372 |
Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UInt_t time, TSQLServer *dbc){ |
1373 |
// MySQL variables |
1374 |
TSQLResult *pResult; |
1375 |
TSQLRow *Row; |
1376 |
int t; |
1377 |
int r; |
1378 |
stringstream myquery; |
1379 |
// ---------------- |
1380 |
myquery.str(""); |
1381 |
myquery << "select ID,ID_ROOT_L0,EV_ROOT,FROM_TIME,TO_TIME from GL_S4_CALIB where FROM_TIME <= "<< time; |
1382 |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1383 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1384 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1385 |
this->GetGLTABLES()->AddQ(); |
1386 |
pResult = dbc->Query(myquery.str().c_str()); |
1387 |
if(!pResult->GetRowCount())return (-55);//throw -55; |
1388 |
for( r=0; r < 1000; r++){ |
1389 |
Row = pResult->Next(); |
1390 |
if( Row == NULL ) break; |
1391 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1392 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1393 |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1394 |
if (t==2) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
1395 |
if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1396 |
if (t==4) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
1397 |
}; |
1398 |
}; |
1399 |
delete pResult; |
1400 |
// |
1401 |
if(TO_TIME < time)return(51); |
1402 |
// |
1403 |
return 0; |
1404 |
}; |
1405 |
// **************************************************** |
1406 |
/** |
1407 |
* Function to query the GL_PARAM table of the DB. |
1408 |
* |
1409 |
* \param run starting time |
1410 |
* \param parameter description (DESCR) |
1411 |
* \return struct of type GL_ROOT_data, which stores the query result |
1412 |
*/ |
1413 |
Int_t GL_PARAM::Query_GL_PARAM(UInt_t time, UInt_t type, TSQLServer *dbc){ |
1414 |
// Bool_t debug = 1; |
1415 |
// MySQL variables |
1416 |
TSQLResult *pResult; |
1417 |
TSQLRow *Row; |
1418 |
int t; |
1419 |
int r; |
1420 |
stringstream myquery; |
1421 |
// ---------------- |
1422 |
myquery.str(""); |
1423 |
myquery << " select "; |
1424 |
myquery << " ID, PATH, NAME, DESCR, FROM_TIME,TO_TIME, TYPE "; |
1425 |
myquery << " from GL_PARAM "; |
1426 |
myquery << " where TYPE = '"<<type<<"' "; |
1427 |
myquery << " and FROM_TIME <= " << time; |
1428 |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
1429 |
// |
1430 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1431 |
this->GetGLTABLES()->AddQ(); |
1432 |
pResult = dbc->Query(myquery.str().c_str()); |
1433 |
if(!pResult->GetRowCount())return (-52); |
1434 |
for( r=0; r < 1000; r++){ |
1435 |
Row = pResult->Next(); |
1436 |
if( Row == NULL ) break; |
1437 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1438 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1439 |
if (t==1) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/';// put in fpath the path to that file |
1440 |
if (t==2) NAME = Row->GetField(t); |
1441 |
if (t==3) DESCR = Row->GetField(t); |
1442 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1443 |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
1444 |
if (t==6) TYPE = (UInt_t)atoll(Row->GetField(t)); |
1445 |
}; |
1446 |
}; |
1447 |
delete pResult; |
1448 |
// |
1449 |
if(TO_TIME==0) TO_TIME = numeric_limits<UInt_t>::max(); |
1450 |
// |
1451 |
if(TO_TIME < time) return(51); |
1452 |
// |
1453 |
return 0; |
1454 |
}; |
1455 |
|
1456 |
|
1457 |
/** |
1458 |
* Fills a struct cGLRun with values from a GLRun object (to put data into a F77 common). |
1459 |
*/ |
1460 |
|
1461 |
void GL_RUN::GetLevel2Struct(cGLRun *l2) const{ |
1462 |
l2->id = ID; |
1463 |
l2->id_reg_run = ID_ROOT_L0; |
1464 |
l2->id_reg_run_l2 = ID_ROOT_L2; |
1465 |
l2->runheader_time = RUNHEADER_TIME; |
1466 |
l2->runtrailer_time = RUNTRAILER_TIME; |
1467 |
l2->ev_from = EV_FROM; |
1468 |
l2->trk_calib_used = TRK_CALIB_USED; |
1469 |
l2->eff_wrk_schedule = EFF_WRK_SCHEDULE; |
1470 |
l2->prh_var_trg_mode_a = PRH_VAR_TRG_MODE_A; |
1471 |
l2->prh_var_trg_mode_b = PRH_VAR_TRG_MODE_B; |
1472 |
l2->acq_build_info = ACQ_BUILD_INFO; |
1473 |
l2->acq_var_info = ACQ_VAR_INFO; |
1474 |
}; |
1475 |
|
1476 |
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){ |
1477 |
// MySQL variables |
1478 |
TFile *file = 0; |
1479 |
UInt_t idraw = 0; |
1480 |
// |
1481 |
TSQLResult *pResult; |
1482 |
TSQLRow *Row; |
1483 |
stringstream myquery; |
1484 |
stringstream rname; |
1485 |
// pcksList packetsNames; |
1486 |
// pcksList::iterator Iter; |
1487 |
// getPacketsNames(packetsNames); |
1488 |
rname.str(""); |
1489 |
// ---------------- |
1490 |
myquery.str(""); |
1491 |
myquery << "select "; |
1492 |
myquery << "PATH"; |
1493 |
myquery << ",NAME,ID_RAW"; |
1494 |
myquery << " from GL_ROOT where "; |
1495 |
myquery << type.Data(); |
1496 |
myquery << "=" << id << ";"; |
1497 |
// |
1498 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1499 |
this->GetGLTABLES()->AddQ(); |
1500 |
pResult = dbc->Query(myquery.str().c_str()); |
1501 |
if( pResult->GetRowCount() ){ |
1502 |
Row = pResult->Next(); |
1503 |
if( Row ){ |
1504 |
stringstream fname; |
1505 |
fname.str(""); |
1506 |
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
1507 |
rname << Row->GetField(1); |
1508 |
file = new TFile(fname.str().c_str(),"READ"); |
1509 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
1510 |
}; |
1511 |
}; |
1512 |
// |
1513 |
if ( file && file->IsOpen() ){ |
1514 |
TTree *T=(TTree*)file->Get("Physics"); |
1515 |
pamela::EventHeader *eh = 0; |
1516 |
pamela::PscuHeader *ph = 0; |
1517 |
T->SetBranchAddress("Header", &eh); |
1518 |
// |
1519 |
T->GetEntry(0); |
1520 |
ph = eh->GetPscuHeader(); |
1521 |
pktfirst = ph->GetCounter(); |
1522 |
obtfirst = ph->GetOrbitalTime(); |
1523 |
// |
1524 |
// code = eh->GetCounter(); |
1525 |
// UInt_t en = 0; |
1526 |
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
1527 |
// en = code->Get(GetPacketType(*Iter)); |
1528 |
// if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){ |
1529 |
// // |
1530 |
// TTree *TC = 0; |
1531 |
// TC = (TTree*)file->Get("CalibCalPed"); |
1532 |
// if ( !TC || TC->IsZombie() ) return; |
1533 |
// EventHeader *ehc = 0; |
1534 |
// PscuHeader *phc = 0; |
1535 |
// TC->SetBranchAddress("Header", &ehc); |
1536 |
// TC->GetEntry(0); |
1537 |
// phc = ehc->GetPscuHeader(); |
1538 |
// pktfirst = phc->GetCounter(); |
1539 |
// obtfirst = phc->GetOrbitalTime(); |
1540 |
// // |
1541 |
// }; |
1542 |
// }; |
1543 |
// |
1544 |
}; |
1545 |
// |
1546 |
// look for Resurs offset |
1547 |
// |
1548 |
T0 = 0; |
1549 |
// |
1550 |
// |
1551 |
stringstream oss; |
1552 |
TString frn = rname.str().c_str(); |
1553 |
frn = frn.ReplaceAll(".root",5,".pam",4); |
1554 |
oss.str(""); |
1555 |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='" |
1556 |
<< frn.Data() << "';"; |
1557 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1558 |
this->GetGLTABLES()->AddQ(); |
1559 |
pResult = dbc->Query(oss.str().c_str()); |
1560 |
Row = pResult->Next(); |
1561 |
// |
1562 |
TString name=rname.str().c_str(); |
1563 |
UInt_t dworbit = 0; |
1564 |
Int_t nlength = name.Length(); |
1565 |
// |
1566 |
// Is not a special file |
1567 |
// |
1568 |
if ( !Row ){ |
1569 |
delete pResult; |
1570 |
// |
1571 |
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
1572 |
// |
1573 |
oss.str(""); |
1574 |
oss << "SELECT ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";"; |
1575 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1576 |
this->GetGLTABLES()->AddQ(); |
1577 |
pResult = dbc->Query(oss.str().c_str()); |
1578 |
Bool_t fndit = false; |
1579 |
if ( pResult ){ |
1580 |
Row = pResult->Next(); |
1581 |
if ( Row ){ |
1582 |
oss.str(""); |
1583 |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE ID=" |
1584 |
<< Row->GetField(0) << ";"; |
1585 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1586 |
this->GetGLTABLES()->AddQ(); |
1587 |
pResult = dbc->Query(oss.str().c_str()); |
1588 |
if ( pResult ){ |
1589 |
Row = pResult->Next(); |
1590 |
if ( Row ){ |
1591 |
// printf(" GREAT! the DB structure is the new one! \n"); |
1592 |
fndit = true; |
1593 |
dworbit = 1; |
1594 |
}; |
1595 |
}; |
1596 |
}; |
1597 |
}; |
1598 |
if ( !fndit ){ |
1599 |
delete pResult; |
1600 |
// |
1601 |
printf(" OK, you got an error because this is the old database\n Using backward compability code, hence you can continue safetly \n"); |
1602 |
// |
1603 |
// Old code, we must trust the filename |
1604 |
// |
1605 |
if ( nlength < 5 ) return; |
1606 |
TString dwo = 0; |
1607 |
for (Int_t i = 0; i<5; i++){ |
1608 |
dwo.Append(name[i],1); |
1609 |
}; |
1610 |
if ( dwo.IsDigit() ){ |
1611 |
dworbit = (UInt_t)dwo.Atoi(); |
1612 |
} else { |
1613 |
dwo=""; |
1614 |
for (Int_t i = 8; i<13; i++){ |
1615 |
dwo.Append(name[i],1); |
1616 |
}; |
1617 |
if ( dwo.IsDigit() ){ |
1618 |
dworbit = (UInt_t)dwo.Atoi(); |
1619 |
} else { |
1620 |
dworbit = 1; |
1621 |
}; |
1622 |
}; |
1623 |
// |
1624 |
oss.str(""); |
1625 |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " |
1626 |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
1627 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1628 |
this->GetGLTABLES()->AddQ(); |
1629 |
pResult = dbc->Query(oss.str().c_str()); |
1630 |
Row = pResult->Next(); |
1631 |
if ( !Row ){ |
1632 |
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
1633 |
return; |
1634 |
}; |
1635 |
}; |
1636 |
}; |
1637 |
// |
1638 |
TTimeStamp tu = TTimeStamp((UInt_t)atoi(Row->GetField(0)),(UInt_t)atoi(Row->GetField(1)),(UInt_t)atoi(Row->GetField(2)),(UInt_t)atoi(Row->GetField(3)),(UInt_t)atoi(Row->GetField(4)),(UInt_t)atoi(Row->GetField(5)),0,true,0); |
1639 |
T0 = (UInt_t)tu.GetSec(); |
1640 |
// |
1641 |
// look for the correct timesync entry |
1642 |
// |
1643 |
myquery.str(""); |
1644 |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
1645 |
<< " WHERE ID_RAW = " << idraw |
1646 |
<< ";"; |
1647 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1648 |
this->GetGLTABLES()->AddQ(); |
1649 |
pResult = dbc->Query(myquery.str().c_str()); |
1650 |
if ( pResult ){ |
1651 |
Row = pResult->Next(); |
1652 |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
1653 |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
1654 |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
1655 |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
1656 |
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; |
1657 |
}; |
1658 |
}; |
1659 |
// |
1660 |
file->Close(); |
1661 |
delete pResult; |
1662 |
}; |
1663 |
|
1664 |
/** |
1665 |
* |
1666 |
* Returns the DB absolute time needed to associate calibrations to data |
1667 |
* |
1668 |
*/ |
1669 |
UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){ |
1670 |
// |
1671 |
return(((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
1672 |
// |
1673 |
}; |
1674 |
|
1675 |
/** |
1676 |
* |
1677 |
* Returns the Resurs time given the OBT needed to process inclination and orbital infos |
1678 |
* |
1679 |
*/ |
1680 |
UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){ |
1681 |
// |
1682 |
return(((UInt_t)((Int_t)(this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC)); |
1683 |
// |
1684 |
}; |
1685 |
|
1686 |
|
1687 |
/** |
1688 |
* Return the correct packet number if we went back to zero |
1689 |
*/ |
1690 |
Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
1691 |
// |
1692 |
if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ){ |
1693 |
return((Long64_t)pkt_num+16777215LL); |
1694 |
}; |
1695 |
// |
1696 |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
1697 |
return((Long64_t)pkt_num-16777215LL); |
1698 |
}; |
1699 |
// |
1700 |
return((Long64_t)pkt_num); |
1701 |
// |
1702 |
}; |
1703 |
|
1704 |
/** |
1705 |
* Return the correct On Board Time if we went back to zero |
1706 |
*/ |
1707 |
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1708 |
// |
1709 |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((Long64_t)(obt+numeric_limits<UInt_t>::max())); |
1710 |
// |
1711 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1712 |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
1713 |
}; |
1714 |
// |
1715 |
return((Long64_t)obt); |
1716 |
}; |
1717 |
|
1718 |
|
1719 |
|
1720 |
// ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1721 |
// // |
1722 |
// if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
1723 |
// // |
1724 |
// if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1725 |
// if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
1726 |
// return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
1727 |
// } else { |
1728 |
// return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
1729 |
// }; |
1730 |
// }; |
1731 |
// // |
1732 |
// return((ULong64_t)obt); |
1733 |
// // |
1734 |
// }; |
1735 |
|
1736 |
// UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
1737 |
// // |
1738 |
// if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
1739 |
// // |
1740 |
// if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
1741 |
// if ( (pkt_num-16777215) < 0 ){ |
1742 |
// return((16777215-pkt_num)); |
1743 |
// } else { |
1744 |
// return((pkt_num-16777215)); |
1745 |
// }; |
1746 |
// }; |
1747 |
// // |
1748 |
// return(pkt_num); |
1749 |
// // |
1750 |
// }; |
1751 |
|
1752 |
/* |
1753 |
* |
1754 |
* Convert the time in the DB from UInt_t to a string |
1755 |
* |
1756 |
* @param dbt time in the DB |
1757 |
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
1758 |
* |
1759 |
*/ |
1760 |
TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){ |
1761 |
// |
1762 |
Int_t offset = 0; |
1763 |
TString rtime; |
1764 |
Bool_t found = false; |
1765 |
// |
1766 |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
1767 |
// |
1768 |
offset = 60*60*3; // UTC (Coordinated Universal Time) + 3hs = Moscow Winter Time |
1769 |
found = true; |
1770 |
// |
1771 |
}; |
1772 |
// |
1773 |
if ( !strcmp(tzone.Data(),"CET") ){ |
1774 |
// |
1775 |
offset = 60*60*1; // CET (Central European Time) = UTC + 1 hs |
1776 |
found = true; |
1777 |
// |
1778 |
}; |
1779 |
// |
1780 |
if ( !strcmp(tzone.Data(),"CEST") ){ |
1781 |
// |
1782 |
offset = 60*60*2; // CEST (Central European Summer Time) = UTC + 2 h |
1783 |
found = true; |
1784 |
// |
1785 |
}; |
1786 |
// |
1787 |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){ |
1788 |
// |
1789 |
offset = 60*60*4; // MSD (Moscow Summer Time) = UTC + 4 h |
1790 |
found = true; |
1791 |
// |
1792 |
}; |
1793 |
// |
1794 |
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
1795 |
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
1796 |
tzone = "UTC"; |
1797 |
}; |
1798 |
// |
1799 |
dbt += offset; |
1800 |
// |
1801 |
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
1802 |
// |
1803 |
rtime = time->AsString("s"); |
1804 |
// |
1805 |
delete time; |
1806 |
// |
1807 |
return(rtime); |
1808 |
} |
1809 |
|
1810 |
/* |
1811 |
* |
1812 |
* Convert the time from TZONE to UTC |
1813 |
* |
1814 |
* @param dbt time in the DB |
1815 |
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
1816 |
* |
1817 |
*/ |
1818 |
TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){ |
1819 |
// |
1820 |
Int_t offset = 0; |
1821 |
TString rtime; |
1822 |
// |
1823 |
Bool_t found = false; |
1824 |
// |
1825 |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
1826 |
// |
1827 |
offset = -60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3hs |
1828 |
found = true; |
1829 |
// |
1830 |
}; |
1831 |
// |
1832 |
if ( !strcmp(tzone.Data(),"CET") ){ |
1833 |
// |
1834 |
offset = -60*60*1; // CET (Central European Time) - 1 hs = UTC |
1835 |
found = true; |
1836 |
// |
1837 |
}; |
1838 |
// |
1839 |
if ( !strcmp(tzone.Data(),"CEST") ){ |
1840 |
// |
1841 |
offset = -60*60*2; // CEST (Central European Summer Time) - 2 h = UTC |
1842 |
found = true; |
1843 |
// |
1844 |
}; |
1845 |
// |
1846 |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){ |
1847 |
// |
1848 |
offset = -60*60*4; // MSD (Moscow Summer Time) - 4 h = UTC |
1849 |
found = true; |
1850 |
// |
1851 |
}; |
1852 |
// |
1853 |
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
1854 |
// |
1855 |
offset = 0; |
1856 |
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
1857 |
tzone = "UTC"; |
1858 |
}; |
1859 |
// |
1860 |
dbt += offset; |
1861 |
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
1862 |
// |
1863 |
rtime = time->AsString("s"); |
1864 |
// |
1865 |
return(rtime); |
1866 |
} |
1867 |
|
1868 |
|
1869 |
// |
1870 |
// Build a query and call DoQuery. |
1871 |
// |
1872 |
// date it's an SQL datetime date and dbc is the connection to be |
1873 |
// used. It will query for the tle with the nearest but previous date |
1874 |
// and the immediatly next one. |
1875 |
// |
1876 |
Int_t GL_TLE::Query(TString date, TSQLServer *dbc){ |
1877 |
stringstream myquery; |
1878 |
myquery.str(""); |
1879 |
|
1880 |
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1881 |
<< "WHERE FROM_TIME <= '" << date.Data() |
1882 |
<< "' ORDER BY FROM_TIME DESC LIMIT 1) " |
1883 |
<< "UNION " |
1884 |
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1885 |
<< "WHERE FROM_TIME > '" << date.Data() |
1886 |
<< "' ORDER BY FROM_TIME ASC LIMIT 1)"; |
1887 |
|
1888 |
return DoQuery(myquery.str().c_str(), dbc); |
1889 |
} |
1890 |
|
1891 |
|
1892 |
// |
1893 |
// Build a query and call DoQuery. |
1894 |
// |
1895 |
// time is the UTC date in unix time (UTC) and dbc is the connection |
1896 |
// to be used. It will query for the tle with the nearest but |
1897 |
// previous date and the immediatly next one. |
1898 |
// |
1899 |
// Returns the value returned by DoQuery(). |
1900 |
// |
1901 |
Int_t GL_TLE::Query(UInt_t time, TSQLServer *dbc){ |
1902 |
stringstream myquery; |
1903 |
myquery.str(""); |
1904 |
|
1905 |
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1906 |
<< "WHERE FROM_TIME <= FROM_UNIXTIME('" << time |
1907 |
<< "') ORDER BY FROM_TIME DESC LIMIT 1) " |
1908 |
<< "UNION " |
1909 |
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1910 |
<< "WHERE FROM_TIME > FROM_UNIXTIME('" << time |
1911 |
<< "') ORDER BY FROM_TIME ASC LIMIT 1)"; |
1912 |
|
1913 |
return DoQuery(myquery.str().c_str(), dbc); |
1914 |
} |
1915 |
|
1916 |
|
1917 |
// |
1918 |
// Do the query myquery on the connectio dbc. Initialize tle, |
1919 |
// tleFromTime and tleToTime. |
1920 |
// |
1921 |
// We should have two rows (unless the table is old). From the last |
1922 |
// one we only take tleToTime. |
1923 |
// |
1924 |
// Returns 0 for success, 1 for failure. |
1925 |
// |
1926 |
Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){ |
1927 |
TSQLResult *result; |
1928 |
TSQLRow *row; |
1929 |
|
1930 |
// Set the right time_zone (otherwise horrible things will occur! :) |
1931 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1932 |
dbc->Query("SET time_zone = '+0:00'"); |
1933 |
|
1934 |
// Do the query |
1935 |
this->GetGLTABLES()->AddQ(); |
1936 |
result = dbc->Query(myquery.Data()); |
1937 |
if(! result->GetRowCount() ) { |
1938 |
cerr << "GL_TLE: query failed: " << myquery.Data() << endl; |
1939 |
return 1; |
1940 |
} |
1941 |
|
1942 |
// Get results |
1943 |
row = result->Next(); // first tle row |
1944 |
tle = GiveTle(row); |
1945 |
|
1946 |
tleFromTime = strtol(row->GetField(4), NULL, 10); |
1947 |
|
1948 |
row = result->Next(); // second tle row |
1949 |
if(row) |
1950 |
tleToTime = strtol(row->GetField(4), NULL, 10); |
1951 |
else { |
1952 |
cerr << "GL_TLE: Warning: using last avaible TLE. Please update GL_TLE table!\n"; |
1953 |
tleToTime = UINT_MAX; |
1954 |
} |
1955 |
|
1956 |
delete row; |
1957 |
delete result; |
1958 |
|
1959 |
return 0; |
1960 |
} |
1961 |
|
1962 |
|
1963 |
// |
1964 |
// Build a cTle object from the GL_TLE row. |
1965 |
// |
1966 |
cTle* GL_TLE::GiveTle(TSQLRow *row) { |
1967 |
cTle *thistle = NULL; |
1968 |
string tle1, tle2, tle3; |
1969 |
|
1970 |
// Build cTle object |
1971 |
tle1 = row->GetField(1); |
1972 |
tle2 = row->GetField(2); |
1973 |
tle3 = row->GetField(3); |
1974 |
|
1975 |
thistle = new cTle(tle1, tle2, tle3); |
1976 |
|
1977 |
return thistle; |
1978 |
} |