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