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