/[PAMELA software]/chewbacca/YodaProfiler/src/GLTables.cpp
ViewVC logotype

Contents of /chewbacca/YodaProfiler/src/GLTables.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations) (download)
Tue Aug 4 13:58:15 2009 UTC (15 years, 4 months ago) by mocchiut
Branch: MAIN
Changes since 1.8: +2 -1 lines
Changed to work with GCC 4.x (gfortran) + ROOT >= 5.24

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

  ViewVC Help
Powered by ViewVC 1.1.23