6 |
*/ |
*/ |
7 |
// |
// |
8 |
#include <sstream> |
#include <sstream> |
9 |
|
#include <iostream> |
10 |
// |
// |
11 |
#include <TFile.h> |
#include <TFile.h> |
12 |
#include <TTree.h> |
#include <TTree.h> |
13 |
|
#include <TTimeStamp.h> |
14 |
#include <EventHeader.h> |
#include <EventHeader.h> |
15 |
#include <PscuHeader.h> |
#include <PscuHeader.h> |
16 |
// |
// |
17 |
#include <GLTables.h> |
#include <GLTables.h> |
18 |
|
#include <sgp4.h> |
19 |
// |
// |
20 |
|
ClassImp(GL_TABLES); |
21 |
ClassImp(GL_TRK_CALIB); |
ClassImp(GL_TRK_CALIB); |
22 |
ClassImp(GL_RUN); |
ClassImp(GL_RUN); |
23 |
ClassImp(GL_ROOT); |
ClassImp(GL_ROOT); |
25 |
ClassImp(GL_S4_CALIB); |
ClassImp(GL_S4_CALIB); |
26 |
ClassImp(GL_CALO_CALIB); |
ClassImp(GL_CALO_CALIB); |
27 |
ClassImp(GL_TIMESYNC); |
ClassImp(GL_TIMESYNC); |
28 |
|
ClassImp(GL_TLE); |
29 |
// |
// |
30 |
using namespace std; |
using namespace std; |
31 |
|
|
32 |
|
GL_TABLES::GL_TABLES(){ |
33 |
|
}; |
34 |
|
|
35 |
|
GL_TABLES::GL_TABLES(TString host, TString user, TString psw){ |
36 |
|
fHost = new TString(host.Data()); |
37 |
|
fUser = new TString(user.Data()); |
38 |
|
fPsw = new TString(psw.Data()); |
39 |
|
fSet = true; |
40 |
|
fNquery = 0; |
41 |
|
mh = host.Data(); |
42 |
|
mu = user.Data(); |
43 |
|
mp = psw.Data(); |
44 |
|
}; |
45 |
|
|
46 |
|
|
47 |
|
void GL_TABLES::Set(TString host, TString user, TString psw){ |
48 |
|
fHost = new TString(host.Data()); |
49 |
|
fUser = new TString(user.Data()); |
50 |
|
fPsw = new TString(psw.Data()); |
51 |
|
fSet = true; |
52 |
|
fNquery = 0; |
53 |
|
mh = host.Data(); |
54 |
|
mu = user.Data(); |
55 |
|
mp = psw.Data(); |
56 |
|
}; |
57 |
|
|
58 |
|
Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
59 |
|
// |
60 |
|
// |
61 |
|
// |
62 |
|
if ( !fSet ){ |
63 |
|
return true; |
64 |
|
}; |
65 |
|
// |
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 |
|
// printf("porca di quella \n"); |
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 |
|
delete dbc; |
97 |
|
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
98 |
|
// |
99 |
|
myquery.str(""); |
100 |
|
myquery << "show databases;"; |
101 |
|
dbc->Query(myquery.str().c_str()); |
102 |
|
fNquery++; |
103 |
|
// printf(" e riporca di quella \n"); |
104 |
|
// |
105 |
|
// if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ |
106 |
|
if ( !(dbc->GetErrorCode()) ){ |
107 |
|
// |
108 |
|
printf(" ...connection recovered, I can continue! \n"); |
109 |
|
// |
110 |
|
myquery.str(""); |
111 |
|
myquery << "SET time_zone='+0:00'"; |
112 |
|
dbc->Query(myquery.str().c_str()); |
113 |
|
fNquery++; |
114 |
|
myquery.str(""); |
115 |
|
myquery << "SET wait_timeout=173000;"; |
116 |
|
dbc->Query(myquery.str().c_str()); |
117 |
|
fNquery++; |
118 |
|
return true; |
119 |
|
}; |
120 |
|
}; |
121 |
|
// |
122 |
|
printf(" GLTABLES: connection is gone away, query will fail\n"); |
123 |
|
// |
124 |
|
return false; |
125 |
|
// |
126 |
|
}; |
127 |
|
|
128 |
|
void GL_TABLES::ResetCounters(){ |
129 |
|
fNquery = 0; |
130 |
|
}; |
131 |
|
|
132 |
|
void GL_TABLES::AddQ(){ |
133 |
|
if ( fSet ) fNquery++; |
134 |
|
}; |
135 |
|
|
136 |
|
UInt_t GL_TABLES::GetNqueries(){ |
137 |
|
UInt_t rn = 0; |
138 |
|
rn += (UInt_t&)fNquery; |
139 |
|
return(rn); |
140 |
|
}; |
141 |
|
|
142 |
GL_RUN::GL_RUN() { |
GL_RUN::GL_RUN() { |
143 |
ID = 0; |
ID = 0; |
144 |
ID_RUN_FRAG = 0; |
ID_RUN_FRAG = 0; |
173 |
VALIDATION = 0; |
VALIDATION = 0; |
174 |
} |
} |
175 |
|
|
176 |
|
|
177 |
void GL_RUN::Clear() { |
void GL_RUN::Clear() { |
178 |
ID = 0; |
ID = 0; |
179 |
ID_RUN_FRAG = 0; |
ID_RUN_FRAG = 0; |
238 |
OBT2 = 0; |
OBT2 = 0; |
239 |
PKT1 = 0; |
PKT1 = 0; |
240 |
PKT2 = 0; |
PKT2 = 0; |
241 |
|
BOOT_NUMBER = 0; |
242 |
|
VALIDATION = 0; |
243 |
} |
} |
244 |
|
|
245 |
GL_CALO_CALIB::GL_CALO_CALIB(){ |
GL_CALO_CALIB::GL_CALO_CALIB(){ |
264 |
GL_TIMESYNC::GL_TIMESYNC(){ |
GL_TIMESYNC::GL_TIMESYNC(){ |
265 |
obtfirst = 0; |
obtfirst = 0; |
266 |
pktfirst = 0; |
pktfirst = 0; |
267 |
toffset = 0; |
ID_RESURS_OFFSET = 0; |
268 |
ID = 0; |
ID = 0; |
269 |
ID_RAW = 0; |
ID_RAW = 0; |
270 |
OBT0 = 0; |
OBT0 = 0; |
271 |
TIMESYNC = 0; |
TIMESYNC = 0; |
272 |
TYPE = 0; |
TYPE = 0; |
273 |
}// **************************************************** |
} |
274 |
|
|
275 |
|
// **************************************************** |
276 |
|
|
277 |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
278 |
EV_FROM = evfrom; |
EV_FROM = evfrom; |
446 |
CAL_DSP_MASK = 0; |
CAL_DSP_MASK = 0; |
447 |
}; |
}; |
448 |
|
|
449 |
|
void GL_RUN::Set_GL_RUN(TSQLRow *Row){ |
450 |
|
for( Int_t t = 0; t < 30; t++){ |
451 |
|
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
452 |
|
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
453 |
|
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
454 |
|
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
455 |
|
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
456 |
|
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
457 |
|
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
458 |
|
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
459 |
|
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
460 |
|
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
461 |
|
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
462 |
|
if (t==11) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
463 |
|
if (t==12) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
464 |
|
if (t==13) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
465 |
|
if (t==14) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
466 |
|
if (t==15) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
467 |
|
if (t==16) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
468 |
|
if (t==17) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
469 |
|
if (t==18) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
470 |
|
if (t==19) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
471 |
|
if (t==20) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
472 |
|
if (t==21) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
473 |
|
if (t==22) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
474 |
|
if (t==23) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
475 |
|
if (t==24) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
476 |
|
if (t==25) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
477 |
|
if (t==26) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
478 |
|
if (t==27) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
479 |
|
if (t==28) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
480 |
|
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
481 |
|
}; |
482 |
|
|
483 |
|
} |
484 |
|
|
485 |
|
/** |
486 |
|
* This method delete the run from the "FromTable" table and store it in the GL_RUN_TRASH table |
487 |
|
* If IDRUN is 0 "this->ID" run is used. |
488 |
|
* |
489 |
|
**/ |
490 |
|
Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ |
491 |
|
// MySQL variables |
492 |
|
TSQLResult *pResult; |
493 |
|
TSQLRow *Row; |
494 |
|
stringstream myquery; |
495 |
|
// |
496 |
|
if ( !IDRUN ) IDRUN = ID; |
497 |
|
if ( !IDRUN ) return 1; |
498 |
|
// ---------------- |
499 |
|
myquery.str(""); |
500 |
|
myquery << " INSERT INTO GL_RUN_TRASH ("; |
501 |
|
myquery << "ID"; |
502 |
|
myquery << ",ID_RUN_FRAG"; |
503 |
|
myquery << ",ID_ROOT_L0"; |
504 |
|
myquery << ",ID_ROOT_L2"; |
505 |
|
myquery << ",RUNHEADER_TIME"; |
506 |
|
myquery << ",RUNTRAILER_TIME"; |
507 |
|
myquery << ",RUNHEADER_OBT"; |
508 |
|
myquery << ",RUNTRAILER_OBT"; |
509 |
|
myquery << ",RUNHEADER_PKT"; |
510 |
|
myquery << ",RUNTRAILER_PKT"; |
511 |
|
myquery << ",BOOT_NUMBER"; |
512 |
|
myquery << ",EV_FROM"; |
513 |
|
myquery << ",EV_TO"; |
514 |
|
myquery << ",NEVENTS"; |
515 |
|
myquery << ",PKT_COUNTER"; |
516 |
|
myquery << ",PKT_READY_COUNTER"; |
517 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
518 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
519 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
520 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
521 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
522 |
|
myquery << ",ACQ_BUILD_INFO"; |
523 |
|
myquery << ",ACQ_VAR_INFO"; |
524 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
525 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
526 |
|
myquery << ",TRK_CALIB_USED"; |
527 |
|
myquery << ",CAL_DSP_MASK"; |
528 |
|
myquery << ",LAST_TIMESYNC"; |
529 |
|
myquery << ",OBT_TIMESYNC"; |
530 |
|
myquery << ",VALIDATION"; |
531 |
|
myquery << ",INSERT_TIME"; |
532 |
|
myquery << ") SELECT * FROM "; |
533 |
|
myquery << FromTable.Data(); |
534 |
|
myquery << " WHERE ID="; |
535 |
|
myquery << (UInt_t)IDRUN << ";"; |
536 |
|
// |
537 |
|
// printf("1myquery is %s \n",myquery.str().c_str()); |
538 |
|
// |
539 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
540 |
|
this->GetGLTABLES()->AddQ(); |
541 |
|
dbc->Query(myquery.str().c_str()); |
542 |
|
// |
543 |
|
// retrieve this ID_TRASH |
544 |
|
// |
545 |
|
myquery.str(""); |
546 |
|
myquery << " SELECT ID_TRASH,ID_ROOT_L0,ID_ROOT_L2 FROM GL_RUN_TRASH ORDER BY ID_TRASH DESC LIMIT 1"; |
547 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
548 |
|
this->GetGLTABLES()->AddQ(); |
549 |
|
pResult = dbc->Query(myquery.str().c_str()); |
550 |
|
// |
551 |
|
UInt_t idtrash = 0; |
552 |
|
UInt_t idl0 = 0; |
553 |
|
UInt_t idl2 = 0; |
554 |
|
// |
555 |
|
Row = pResult->Next(); |
556 |
|
if( Row != NULL ){ |
557 |
|
idtrash = (UInt_t)atoll(Row->GetField(0)); |
558 |
|
idl0 = (UInt_t)atoll(Row->GetField(1)); |
559 |
|
idl2 = (UInt_t)atoll(Row->GetField(2)); |
560 |
|
}; |
561 |
|
// |
562 |
|
TString fileL0 = ""; |
563 |
|
TString fileL2 = ""; |
564 |
|
myquery.str(""); |
565 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
566 |
|
myquery << idl0 << ";"; |
567 |
|
// |
568 |
|
// printf("2myquery is %s \n",myquery.str().c_str()); |
569 |
|
// |
570 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
571 |
|
this->GetGLTABLES()->AddQ(); |
572 |
|
pResult = dbc->Query(myquery.str().c_str()); |
573 |
|
// |
574 |
|
Row = pResult->Next(); |
575 |
|
if( Row != NULL ){ |
576 |
|
fileL0 = (TString)Row->GetField(0); |
577 |
|
}; |
578 |
|
// |
579 |
|
// |
580 |
|
// |
581 |
|
myquery.str(""); |
582 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
583 |
|
myquery << idl2 << ";"; |
584 |
|
// |
585 |
|
// printf("3myquery is %s \n",myquery.str().c_str()); |
586 |
|
// |
587 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
588 |
|
this->GetGLTABLES()->AddQ(); |
589 |
|
pResult = dbc->Query(myquery.str().c_str()); |
590 |
|
// |
591 |
|
Row = pResult->Next(); |
592 |
|
if( Row != NULL ){ |
593 |
|
fileL2 = (TString)Row->GetField(0); |
594 |
|
}; |
595 |
|
// |
596 |
|
// |
597 |
|
// |
598 |
|
myquery.str(""); |
599 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL0='"; |
600 |
|
myquery << fileL0.Data() << "' where ID_TRASH="; |
601 |
|
myquery << idtrash << ";"; |
602 |
|
// |
603 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
604 |
|
// |
605 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
606 |
|
this->GetGLTABLES()->AddQ(); |
607 |
|
dbc->Query(myquery.str().c_str()); |
608 |
|
// |
609 |
|
myquery.str(""); |
610 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='"; |
611 |
|
myquery << fileL2.Data() << "' where ID_TRASH="; |
612 |
|
myquery << idtrash << ";"; |
613 |
|
// |
614 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
615 |
|
// |
616 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
617 |
|
this->GetGLTABLES()->AddQ(); |
618 |
|
dbc->Query(myquery.str().c_str()); |
619 |
|
// |
620 |
|
myquery.str(""); |
621 |
|
myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='"; |
622 |
|
myquery << FromTable.Data() << "' where ID_TRASH="; |
623 |
|
myquery << idtrash << ";"; |
624 |
|
// |
625 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
626 |
|
// |
627 |
|
// |
628 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
629 |
|
this->GetGLTABLES()->AddQ(); |
630 |
|
dbc->Query(myquery.str().c_str()); |
631 |
|
// |
632 |
|
myquery.str(""); |
633 |
|
myquery << " DELETE FROM "; |
634 |
|
myquery << FromTable.Data() << " where ID="; |
635 |
|
myquery << IDRUN << ";"; |
636 |
|
// |
637 |
|
// printf("5myquery is %s \n",myquery.str().c_str()); |
638 |
|
// |
639 |
|
// |
640 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
641 |
|
this->GetGLTABLES()->AddQ(); |
642 |
|
dbc->Query(myquery.str().c_str()); |
643 |
|
// |
644 |
|
return 0; |
645 |
|
}; |
646 |
|
|
647 |
|
|
648 |
|
|
649 |
|
/** |
650 |
|
* This method restore a run from the GL_RUN_TRASH table. |
651 |
|
* If ID is 0 "this->ID" is used; if "ToTable" is empty BELONG_TO field of GL_RUN_TRASH is used. |
652 |
|
* |
653 |
|
**/ |
654 |
|
Int_t GL_RUN::RestoreRun(TSQLServer *dbc,UInt_t IDRUN,TString ToTable){ |
655 |
|
// insert into GL_RUN_FRAGMENTS select * FROM GL_RUN where ID=11; |
656 |
|
//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; |
657 |
|
// MySQL variables |
658 |
|
TSQLResult *pResult; |
659 |
|
TSQLRow *Row; |
660 |
|
stringstream myquery; |
661 |
|
// |
662 |
|
if ( !IDRUN ) IDRUN = ID; |
663 |
|
if ( !IDRUN ) return 1; |
664 |
|
// |
665 |
|
if ( !strcmp(ToTable.Data(),"") ){ |
666 |
|
// |
667 |
|
myquery.str(""); |
668 |
|
myquery << " SELECT BELONGED_TO FROM GL_RUN_TRASH WHERE ID="; |
669 |
|
myquery << (UInt_t)IDRUN << ";"; |
670 |
|
// |
671 |
|
printf(" qui? myquery is %s \n",myquery.str().c_str()); |
672 |
|
// |
673 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
674 |
|
this->GetGLTABLES()->AddQ(); |
675 |
|
pResult = dbc->Query(myquery.str().c_str()); |
676 |
|
// |
677 |
|
Row = pResult->Next(); |
678 |
|
if( Row != NULL ){ |
679 |
|
ToTable = (TString)Row->GetField(0); |
680 |
|
} else { |
681 |
|
return 1; |
682 |
|
}; |
683 |
|
}; |
684 |
|
// ---------------- |
685 |
|
myquery.str(""); |
686 |
|
myquery << " INSERT INTO "; |
687 |
|
myquery << ToTable.Data(); |
688 |
|
myquery << " ("; |
689 |
|
myquery << "ID"; |
690 |
|
myquery << ",ID_RUN_FRAG"; |
691 |
|
myquery << ",ID_ROOT_L0"; |
692 |
|
myquery << ",ID_ROOT_L2"; |
693 |
|
myquery << ",RUNHEADER_TIME"; |
694 |
|
myquery << ",RUNTRAILER_TIME"; |
695 |
|
myquery << ",RUNHEADER_OBT"; |
696 |
|
myquery << ",RUNTRAILER_OBT"; |
697 |
|
myquery << ",RUNHEADER_PKT"; |
698 |
|
myquery << ",RUNTRAILER_PKT"; |
699 |
|
myquery << ",BOOT_NUMBER"; |
700 |
|
myquery << ",EV_FROM"; |
701 |
|
myquery << ",EV_TO"; |
702 |
|
myquery << ",NEVENTS"; |
703 |
|
myquery << ",PKT_COUNTER"; |
704 |
|
myquery << ",PKT_READY_COUNTER"; |
705 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
706 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
707 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
708 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
709 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
710 |
|
myquery << ",ACQ_BUILD_INFO"; |
711 |
|
myquery << ",ACQ_VAR_INFO"; |
712 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
713 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
714 |
|
myquery << ",TRK_CALIB_USED"; |
715 |
|
myquery << ",CAL_DSP_MASK"; |
716 |
|
myquery << ",LAST_TIMESYNC"; |
717 |
|
myquery << ",OBT_TIMESYNC"; |
718 |
|
myquery << ",VALIDATION"; |
719 |
|
myquery << ",INSERT_TIME"; |
720 |
|
myquery << ") SELECT "; |
721 |
|
myquery << "ID"; |
722 |
|
myquery << ",ID_RUN_FRAG"; |
723 |
|
myquery << ",ID_ROOT_L0"; |
724 |
|
myquery << ",ID_ROOT_L2"; |
725 |
|
myquery << ",RUNHEADER_TIME"; |
726 |
|
myquery << ",RUNTRAILER_TIME"; |
727 |
|
myquery << ",RUNHEADER_OBT"; |
728 |
|
myquery << ",RUNTRAILER_OBT"; |
729 |
|
myquery << ",RUNHEADER_PKT"; |
730 |
|
myquery << ",RUNTRAILER_PKT"; |
731 |
|
myquery << ",BOOT_NUMBER"; |
732 |
|
myquery << ",EV_FROM"; |
733 |
|
myquery << ",EV_TO"; |
734 |
|
myquery << ",NEVENTS"; |
735 |
|
myquery << ",PKT_COUNTER"; |
736 |
|
myquery << ",PKT_READY_COUNTER"; |
737 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
738 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
739 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
740 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
741 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
742 |
|
myquery << ",ACQ_BUILD_INFO"; |
743 |
|
myquery << ",ACQ_VAR_INFO"; |
744 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
745 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
746 |
|
myquery << ",TRK_CALIB_USED"; |
747 |
|
myquery << ",CAL_DSP_MASK"; |
748 |
|
myquery << ",LAST_TIMESYNC"; |
749 |
|
myquery << ",OBT_TIMESYNC"; |
750 |
|
myquery << ",VALIDATION"; |
751 |
|
myquery << ",INSERT_TIME"; |
752 |
|
myquery << " FROM GL_RUN_TRASH "; |
753 |
|
myquery << " WHERE BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
754 |
|
myquery << (UInt_t)IDRUN << ";"; |
755 |
|
// |
756 |
|
// printf("5myquery is %s \n",myquery.str().c_str()); |
757 |
|
// |
758 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
759 |
|
this->GetGLTABLES()->AddQ(); |
760 |
|
dbc->Query(myquery.str().c_str()); |
761 |
|
// |
762 |
|
// |
763 |
|
myquery.str(""); |
764 |
|
myquery << " DELETE FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
765 |
|
myquery << IDRUN << ";"; |
766 |
|
// |
767 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
768 |
|
this->GetGLTABLES()->AddQ(); |
769 |
|
dbc->Query(myquery.str().c_str()); |
770 |
|
// |
771 |
|
return 0; |
772 |
|
}; |
773 |
|
|
774 |
/** |
/** |
775 |
* Function to fill the GL_RUN table of the DB. |
* Function to fill the GL_RUN table of the DB. |
848 |
// |
// |
849 |
// printf("myquery is %s \n",myquery.str().c_str()); |
// printf("myquery is %s \n",myquery.str().c_str()); |
850 |
// |
// |
851 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
852 |
|
this->GetGLTABLES()->AddQ(); |
853 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
854 |
// |
// |
855 |
return 0; |
return 0; |
926 |
// |
// |
927 |
// printf("myquery is %s \n",myquery.str().c_str()); |
// printf("myquery is %s \n",myquery.str().c_str()); |
928 |
// |
// |
929 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
930 |
|
this->GetGLTABLES()->AddQ(); |
931 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
932 |
// |
// |
933 |
return 0; |
return 0; |
985 |
myquery << " from GL_RUN where ID=" << run << ";"; |
myquery << " from GL_RUN where ID=" << run << ";"; |
986 |
// |
// |
987 |
// printf(" myquery is %s \n",myquery.str().c_str()); |
// printf(" myquery is %s \n",myquery.str().c_str()); |
988 |
|
if ( !this->IsConnected(dbc) ) return -57; |
989 |
|
this->AddQ(); |
990 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
991 |
// |
// |
992 |
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
996 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
997 |
Row = pResult->Next(); |
Row = pResult->Next(); |
998 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
999 |
|
// Set_GL_RUN(Row); |
1000 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1001 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
1002 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
1003 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1004 |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
1005 |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
1006 |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
1007 |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
1008 |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
1009 |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
1010 |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
1011 |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
1012 |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
1013 |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
1014 |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1015 |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1016 |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
1017 |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
1018 |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
1019 |
if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
1020 |
if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
1021 |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
1022 |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
1023 |
if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
1024 |
if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
1025 |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
1026 |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
1027 |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
1028 |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
1029 |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
1030 |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
1031 |
}; |
}; |
1032 |
}; |
}; |
1033 |
// delete pResult; |
// delete pResult; |
1085 |
// |
// |
1086 |
// printf(" query is %s \n",myquery.str().c_str()); |
// printf(" query is %s \n",myquery.str().c_str()); |
1087 |
// |
// |
1088 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1089 |
|
this->GetGLTABLES()->AddQ(); |
1090 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1091 |
if(!pResult->GetRowCount())return(-50); |
if(!pResult->GetRowCount())return(-50); |
1092 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1152 |
myquery << ",NAME"; |
myquery << ",NAME"; |
1153 |
myquery << " from GL_ROOT where ID=" << id << ";"; |
myquery << " from GL_ROOT where ID=" << id << ";"; |
1154 |
// |
// |
1155 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1156 |
|
this->GetGLTABLES()->AddQ(); |
1157 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1158 |
if(!pResult->GetRowCount())return (-51); |
if(!pResult->GetRowCount())return (-51); |
1159 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1163 |
if(t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if(t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1164 |
if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t)); |
if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t)); |
1165 |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1166 |
if(t==3) PATH = Row->GetField(t); |
if(t==3) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/'; |
1167 |
if(t==4) NAME = Row->GetField(t); |
if(t==4) NAME = Row->GetField(t); |
1168 |
}; |
}; |
1169 |
}; |
}; |
1175 |
* Function to query the GL_TRK_CALIB table of the DB. |
* Function to query the GL_TRK_CALIB table of the DB. |
1176 |
* |
* |
1177 |
* \param run starting time |
* \param run starting time |
1178 |
|
* \param dbc DB server |
1179 |
* \return struct of type GL_TRK_CALIB_data, which stores the query result |
* \return struct of type GL_TRK_CALIB_data, which stores the query result |
1180 |
*/ |
*/ |
1181 |
Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(UInt_t time, TSQLServer *dbc){ |
Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(UInt_t time, TSQLServer *dbc){ |
1187 |
stringstream myquery; |
stringstream myquery; |
1188 |
// ---------------- |
// ---------------- |
1189 |
myquery.str(""); |
myquery.str(""); |
1190 |
myquery << "select ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,OBT2,PKT1,PKT2 from GL_TRK_CALIB where FROM_TIME <= "<< time; |
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; |
1191 |
myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; // RIVEDERE LA VALIDAZIONE!!! |
1192 |
|
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 |
1193 |
|
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1194 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1195 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1196 |
|
this->GetGLTABLES()->AddQ(); |
1197 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1198 |
if(!pResult->GetRowCount())return (-53); |
if(!pResult->GetRowCount())return (-53); |
1199 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1203 |
stringstream row; |
stringstream row; |
1204 |
row.str(""); |
row.str(""); |
1205 |
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 |
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 |
1206 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1207 |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1208 |
if (t==2) EV_ROOT_CALIBTRK1 = (UInt_t)atoll(row.str().c_str()); |
if (t==2) EV_ROOT_CALIBTRK1 = (UInt_t)atoll(row.str().c_str()); |
1209 |
if (t==3) EV_ROOT_CALIBTRK2 = (UInt_t)atoll(row.str().c_str()); |
if (t==3) EV_ROOT_CALIBTRK2 = (UInt_t)atoll(row.str().c_str()); |
1210 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1211 |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
1212 |
// |
// |
1213 |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
1214 |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
1215 |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
1216 |
if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t)); |
if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t)); |
1217 |
}; |
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
1218 |
|
if (t==11) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
1219 |
|
}; |
1220 |
}; |
}; |
1221 |
delete pResult; |
delete pResult; |
1222 |
|
// |
1223 |
|
// if ( TO_TIME < time ) return(51); |
1224 |
// |
// |
|
if(TO_TIME < time)return(51); |
|
1225 |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
1226 |
// |
// |
1227 |
return 0; |
return 0; |
1234 |
* \param run starting time |
* \param run starting time |
1235 |
* \return struct of type GL_CALO_CALIB_data, which stores the query result |
* \return struct of type GL_CALO_CALIB_data, which stores the query result |
1236 |
*/ |
*/ |
1237 |
Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t section, TSQLServer *dbc){ |
Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t &uptime, UInt_t section, TSQLServer *dbc){ |
1238 |
// MySQL variables |
// MySQL variables |
1239 |
TSQLResult *pResult; |
TSQLResult *pResult; |
1240 |
TSQLRow *Row; |
TSQLRow *Row; |
1241 |
int t; |
int t; |
1242 |
stringstream myquery; |
stringstream myquery; |
1243 |
|
uptime = 0; |
1244 |
// |
// |
1245 |
// select the correct calibration |
// select the correct calibration |
1246 |
// |
// |
1248 |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section; |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section; |
1249 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1250 |
myquery << " and TO_TIME > " << time; |
myquery << " and TO_TIME > " << time; |
1251 |
myquery << " and VALIDATION=1;"; |
myquery << " ;"; |
1252 |
|
//myquery << " and VALIDATION=1;"; |
1253 |
// |
// |
1254 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1255 |
|
this->GetGLTABLES()->AddQ(); |
1256 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1257 |
|
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1258 |
|
// |
1259 |
|
if( !pResult->GetRowCount() ) return(-54); |
1260 |
|
Row = pResult->Next(); |
1261 |
|
if( Row == NULL ) return (-54); |
1262 |
|
// |
1263 |
|
uptime = (UInt_t)atoll(Row->GetField(2)); |
1264 |
// |
// |
1265 |
// if it is corrupted validation is 0 and we have no results from the query... |
// if it is corrupted validation is 0 and we have no results from the query... |
1266 |
// |
// |
1267 |
if( !pResult->GetRowCount() ){ |
if( atoi(Row->GetField(4)) == 0 ){ // if validation = 0 |
|
// pResult->Delete(); |
|
1268 |
// |
// |
1269 |
// in this case take relax the conditions and take the valid calibration that preceed the correct one |
// in this case take relax the conditions and take the valid calibration that preceed the correct one |
1270 |
// |
// |
1272 |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section; |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section; |
1273 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1274 |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
1275 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1276 |
|
this->GetGLTABLES()->AddQ(); |
1277 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1278 |
|
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1279 |
// |
// |
1280 |
// if no results yet quit with error |
// if no results yet quit with error |
1281 |
// |
// |
1282 |
if( !pResult->GetRowCount() ) return (-54); |
if( !pResult->GetRowCount() ) return (-54); |
1283 |
|
// |
1284 |
|
Row = pResult->Next(); |
1285 |
|
// |
1286 |
}; |
}; |
1287 |
// |
// |
1288 |
// store infos and exit |
// store infos and exit |
1289 |
// |
// |
|
Row = pResult->Next(); |
|
1290 |
if( Row == NULL ) return (-54); |
if( Row == NULL ) return (-54); |
1291 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1292 |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1314 |
// ---------------- |
// ---------------- |
1315 |
myquery.str(""); |
myquery.str(""); |
1316 |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
1317 |
myquery << " AND VALIDATION = 1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1318 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1319 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1320 |
|
this->GetGLTABLES()->AddQ(); |
1321 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1322 |
if(!pResult->GetRowCount())return (-55);//throw -55; |
if(!pResult->GetRowCount())return (-55);//throw -55; |
1323 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1358 |
// ---------------- |
// ---------------- |
1359 |
myquery.str(""); |
myquery.str(""); |
1360 |
myquery << " select "; |
myquery << " select "; |
1361 |
myquery << " ID, PATH, NAME, DESCR, TYPE, FROM_TIME,TO_TIME "; |
myquery << " ID, PATH, NAME, DESCR, FROM_TIME,TO_TIME, TYPE "; |
1362 |
myquery << " from GL_PARAM "; |
myquery << " from GL_PARAM "; |
1363 |
myquery << " where TYPE = '"<<type<<"' "; |
myquery << " where TYPE = '"<<type<<"' "; |
1364 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1365 |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
1366 |
// |
// |
1367 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1368 |
|
this->GetGLTABLES()->AddQ(); |
1369 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1370 |
if(!pResult->GetRowCount())return (-52); |
if(!pResult->GetRowCount())return (-52); |
1371 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1373 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
1374 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1375 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1376 |
if (t==1) PATH = Row->GetField(t);// put in fpath the path to that file |
if (t==1) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/';// put in fpath the path to that file |
1377 |
if (t==2) NAME = Row->GetField(t); |
if (t==2) NAME = Row->GetField(t); |
1378 |
if (t==3) DESCR = Row->GetField(t); |
if (t==3) DESCR = Row->GetField(t); |
1379 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1418 |
TSQLResult *pResult; |
TSQLResult *pResult; |
1419 |
TSQLRow *Row; |
TSQLRow *Row; |
1420 |
stringstream myquery; |
stringstream myquery; |
1421 |
|
stringstream rname; |
1422 |
|
// pcksList packetsNames; |
1423 |
|
// pcksList::iterator Iter; |
1424 |
|
// getPacketsNames(packetsNames); |
1425 |
|
rname.str(""); |
1426 |
// ---------------- |
// ---------------- |
1427 |
myquery.str(""); |
myquery.str(""); |
1428 |
myquery << "select "; |
myquery << "select "; |
1432 |
myquery << type.Data(); |
myquery << type.Data(); |
1433 |
myquery << "=" << id << ";"; |
myquery << "=" << id << ";"; |
1434 |
// |
// |
1435 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1436 |
|
this->GetGLTABLES()->AddQ(); |
1437 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1438 |
if( pResult->GetRowCount() ){ |
if( pResult->GetRowCount() ){ |
1439 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1440 |
if( Row ){ |
if( Row ){ |
1441 |
stringstream fname; |
stringstream fname; |
1442 |
fname.str(""); |
fname.str(""); |
1443 |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
1444 |
|
rname << Row->GetField(1); |
1445 |
file = new TFile(fname.str().c_str(),"READ"); |
file = new TFile(fname.str().c_str(),"READ"); |
1446 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
idraw = (UInt_t)atoll(Row->GetField(2)); |
1447 |
}; |
}; |
1457 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
1458 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
1459 |
obtfirst = ph->GetOrbitalTime(); |
obtfirst = ph->GetOrbitalTime(); |
1460 |
|
// |
1461 |
|
// code = eh->GetCounter(); |
1462 |
|
// UInt_t en = 0; |
1463 |
|
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
1464 |
|
// en = code->Get(GetPacketType(*Iter)); |
1465 |
|
// if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){ |
1466 |
|
// // |
1467 |
|
// TTree *TC = 0; |
1468 |
|
// TC = (TTree*)file->Get("CalibCalPed"); |
1469 |
|
// if ( !TC || TC->IsZombie() ) return; |
1470 |
|
// EventHeader *ehc = 0; |
1471 |
|
// PscuHeader *phc = 0; |
1472 |
|
// TC->SetBranchAddress("Header", &ehc); |
1473 |
|
// TC->GetEntry(0); |
1474 |
|
// phc = ehc->GetPscuHeader(); |
1475 |
|
// pktfirst = phc->GetCounter(); |
1476 |
|
// obtfirst = phc->GetOrbitalTime(); |
1477 |
|
// // |
1478 |
|
// }; |
1479 |
|
// }; |
1480 |
|
// |
1481 |
}; |
}; |
1482 |
// |
// |
1483 |
// look for Resurs offset |
// look for Resurs offset |
1484 |
// |
// |
1485 |
UInt_t t0 = 0; |
T0 = 0; |
1486 |
// |
// |
1487 |
myquery.str(""); |
// |
1488 |
myquery << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= " |
stringstream oss; |
1489 |
<< idraw << " AND TO_ID_RAW >= " |
TString frn = rname.str().c_str(); |
1490 |
<< idraw << ";"; |
frn = frn.ReplaceAll(".root",5,".pam",4); |
1491 |
pResult = dbc->Query(myquery.str().c_str()); |
oss.str(""); |
1492 |
if ( pResult ){ |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='" |
1493 |
Row = pResult->Next(); |
<< frn.Data() << "';"; |
1494 |
if ( Row ){ |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1495 |
|
this->GetGLTABLES()->AddQ(); |
1496 |
|
pResult = dbc->Query(oss.str().c_str()); |
1497 |
|
Row = pResult->Next(); |
1498 |
|
// |
1499 |
|
TString name=rname.str().c_str(); |
1500 |
|
UInt_t dworbit = 0; |
1501 |
|
Int_t nlength = name.Length(); |
1502 |
|
// |
1503 |
|
// Is not a special file |
1504 |
|
// |
1505 |
|
if ( !Row ){ |
1506 |
|
delete pResult; |
1507 |
|
// |
1508 |
|
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
1509 |
|
// |
1510 |
|
oss.str(""); |
1511 |
|
oss << "SELECT ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";"; |
1512 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1513 |
|
this->GetGLTABLES()->AddQ(); |
1514 |
|
pResult = dbc->Query(oss.str().c_str()); |
1515 |
|
Bool_t fndit = false; |
1516 |
|
if ( pResult ){ |
1517 |
|
Row = pResult->Next(); |
1518 |
|
if ( Row ){ |
1519 |
|
oss.str(""); |
1520 |
|
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=" |
1521 |
|
<< Row->GetField(0) << ";"; |
1522 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1523 |
|
this->GetGLTABLES()->AddQ(); |
1524 |
|
pResult = dbc->Query(oss.str().c_str()); |
1525 |
|
if ( pResult ){ |
1526 |
|
Row = pResult->Next(); |
1527 |
|
if ( Row ){ |
1528 |
|
printf(" GREAT! the DB structure is the new one! \n"); |
1529 |
|
fndit = true; |
1530 |
|
dworbit = 1; |
1531 |
|
}; |
1532 |
|
}; |
1533 |
|
}; |
1534 |
|
}; |
1535 |
|
if ( !fndit ){ |
1536 |
|
delete pResult; |
1537 |
|
// |
1538 |
|
printf(" OK, you got an error because this is the old database\n Using backward compability code, hence you can continue safetly \n"); |
1539 |
// |
// |
1540 |
t0 = (UInt_t)TDatime(Row->GetField(0)).Convert(); |
// Old code, we must trust the filename |
1541 |
// |
// |
1542 |
|
if ( nlength < 5 ) return; |
1543 |
|
TString dwo = 0; |
1544 |
|
for (Int_t i = 0; i<5; i++){ |
1545 |
|
dwo.Append(name[i],1); |
1546 |
|
}; |
1547 |
|
if ( dwo.IsDigit() ){ |
1548 |
|
dworbit = (UInt_t)dwo.Atoi(); |
1549 |
|
} else { |
1550 |
|
dwo=""; |
1551 |
|
for (Int_t i = 8; i<13; i++){ |
1552 |
|
dwo.Append(name[i],1); |
1553 |
|
}; |
1554 |
|
if ( dwo.IsDigit() ){ |
1555 |
|
dworbit = (UInt_t)dwo.Atoi(); |
1556 |
|
} else { |
1557 |
|
dworbit = 1; |
1558 |
|
}; |
1559 |
|
}; |
1560 |
|
// |
1561 |
|
oss.str(""); |
1562 |
|
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " |
1563 |
|
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
1564 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1565 |
|
this->GetGLTABLES()->AddQ(); |
1566 |
|
pResult = dbc->Query(oss.str().c_str()); |
1567 |
|
Row = pResult->Next(); |
1568 |
|
if ( !Row ){ |
1569 |
|
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
1570 |
|
return; |
1571 |
|
}; |
1572 |
}; |
}; |
1573 |
}; |
}; |
1574 |
// |
// |
1575 |
|
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); |
1576 |
|
T0 = (UInt_t)tu.GetSec(); |
1577 |
// |
// |
1578 |
// look for the correct timesync entry |
// look for the correct timesync entry |
1579 |
// |
// |
1580 |
myquery.str(""); |
myquery.str(""); |
1581 |
myquery << " SELECT OBT0,TIMESYNC FROM GL_TIMESYNC " |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
1582 |
<< " WHERE ID_RAW = " << idraw |
<< " WHERE ID_RAW = " << idraw |
1583 |
<< ";"; |
<< ";"; |
1584 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1585 |
|
this->GetGLTABLES()->AddQ(); |
1586 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1587 |
if ( pResult ){ |
if ( pResult ){ |
1588 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1589 |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
1590 |
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + t0; |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
1591 |
|
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
1592 |
|
TYPE = (UInt_t)atoll(Row->GetField(2)); |
1593 |
|
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; |
1594 |
}; |
}; |
1595 |
}; |
}; |
1596 |
// |
// |
1609 |
// |
// |
1610 |
}; |
}; |
1611 |
|
|
1612 |
|
/** |
1613 |
|
* |
1614 |
|
* Returns the Resurs time given the OBT needed to process inclination and orbital infos |
1615 |
|
* |
1616 |
|
*/ |
1617 |
|
UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){ |
1618 |
|
// |
1619 |
|
return(((UInt_t)((Int_t)(this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC)); |
1620 |
|
// |
1621 |
|
}; |
1622 |
|
|
1623 |
|
|
1624 |
ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
/** |
1625 |
|
* Return the correct packet number if we went back to zero |
1626 |
|
*/ |
1627 |
|
Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
1628 |
// |
// |
1629 |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ){ |
1630 |
|
return((Long64_t)pkt_num+16777215LL); |
1631 |
|
}; |
1632 |
// |
// |
1633 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
1634 |
if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
return((Long64_t)pkt_num-16777215LL); |
|
return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
|
|
} else { |
|
|
return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
|
|
}; |
|
1635 |
}; |
}; |
1636 |
// |
// |
1637 |
return((ULong64_t)obt); |
return((Long64_t)pkt_num); |
1638 |
// |
// |
1639 |
}; |
}; |
1640 |
|
|
1641 |
UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
/** |
1642 |
|
* Return the correct On Board Time if we went back to zero |
1643 |
|
*/ |
1644 |
|
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1645 |
// |
// |
1646 |
if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((Long64_t)(obt+numeric_limits<UInt_t>::max())); |
1647 |
// |
// |
1648 |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1649 |
if ( (pkt_num-16777215) < 0 ){ |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
|
return((16777215-pkt_num)); |
|
|
} else { |
|
|
return((pkt_num-16777215)); |
|
|
}; |
|
1650 |
}; |
}; |
1651 |
// |
// |
1652 |
return(pkt_num); |
return((Long64_t)obt); |
|
// |
|
1653 |
}; |
}; |
1654 |
|
|
1655 |
|
|
1656 |
|
|
1657 |
|
// ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1658 |
|
// // |
1659 |
|
// if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
1660 |
|
// // |
1661 |
|
// if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1662 |
|
// if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
1663 |
|
// return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
1664 |
|
// } else { |
1665 |
|
// return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
1666 |
|
// }; |
1667 |
|
// }; |
1668 |
|
// // |
1669 |
|
// return((ULong64_t)obt); |
1670 |
|
// // |
1671 |
|
// }; |
1672 |
|
|
1673 |
|
// UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
1674 |
|
// // |
1675 |
|
// if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
1676 |
|
// // |
1677 |
|
// if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
1678 |
|
// if ( (pkt_num-16777215) < 0 ){ |
1679 |
|
// return((16777215-pkt_num)); |
1680 |
|
// } else { |
1681 |
|
// return((pkt_num-16777215)); |
1682 |
|
// }; |
1683 |
|
// }; |
1684 |
|
// // |
1685 |
|
// return(pkt_num); |
1686 |
|
// // |
1687 |
|
// }; |
1688 |
|
|
1689 |
|
/* |
1690 |
|
* |
1691 |
|
* Convert the time in the DB from UInt_t to a string |
1692 |
|
* |
1693 |
|
* @param dbt time in the DB |
1694 |
|
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
1695 |
|
* |
1696 |
|
*/ |
1697 |
|
TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){ |
1698 |
|
// |
1699 |
|
Int_t offset = 0; |
1700 |
|
TString rtime; |
1701 |
|
Bool_t found = false; |
1702 |
|
// |
1703 |
|
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
1704 |
|
// |
1705 |
|
offset = 60*60*3; // UTC (Coordinated Universal Time) + 3hs = Moscow Winter Time |
1706 |
|
found = true; |
1707 |
|
// |
1708 |
|
}; |
1709 |
|
// |
1710 |
|
if ( !strcmp(tzone.Data(),"CET") ){ |
1711 |
|
// |
1712 |
|
offset = 60*60*1; // CET (Central European Time) = UTC + 1 hs |
1713 |
|
found = true; |
1714 |
|
// |
1715 |
|
}; |
1716 |
|
// |
1717 |
|
if ( !strcmp(tzone.Data(),"CEST") ){ |
1718 |
|
// |
1719 |
|
offset = 60*60*2; // CEST (Central European Summer Time) = UTC + 2 h |
1720 |
|
found = true; |
1721 |
|
// |
1722 |
|
}; |
1723 |
|
// |
1724 |
|
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){ |
1725 |
|
// |
1726 |
|
offset = 60*60*4; // MSD (Moscow Summer Time) = UTC + 4 h |
1727 |
|
found = true; |
1728 |
|
// |
1729 |
|
}; |
1730 |
|
// |
1731 |
|
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
1732 |
|
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
1733 |
|
tzone = "UTC"; |
1734 |
|
}; |
1735 |
|
// |
1736 |
|
dbt += offset; |
1737 |
|
// |
1738 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
1739 |
|
// |
1740 |
|
rtime = time->AsString("s"); |
1741 |
|
// |
1742 |
|
delete time; |
1743 |
|
// |
1744 |
|
return(rtime); |
1745 |
|
} |
1746 |
|
|
1747 |
|
/* |
1748 |
|
* |
1749 |
|
* Convert the time from TZONE to UTC |
1750 |
|
* |
1751 |
|
* @param dbt time in the DB |
1752 |
|
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
1753 |
|
* |
1754 |
|
*/ |
1755 |
|
TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){ |
1756 |
|
// |
1757 |
|
Int_t offset = 0; |
1758 |
|
TString rtime; |
1759 |
|
// |
1760 |
|
Bool_t found = false; |
1761 |
|
// |
1762 |
|
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
1763 |
|
// |
1764 |
|
offset = -60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3hs |
1765 |
|
found = true; |
1766 |
|
// |
1767 |
|
}; |
1768 |
|
// |
1769 |
|
if ( !strcmp(tzone.Data(),"CET") ){ |
1770 |
|
// |
1771 |
|
offset = -60*60*1; // CET (Central European Time) - 1 hs = UTC |
1772 |
|
found = true; |
1773 |
|
// |
1774 |
|
}; |
1775 |
|
// |
1776 |
|
if ( !strcmp(tzone.Data(),"CEST") ){ |
1777 |
|
// |
1778 |
|
offset = -60*60*2; // CEST (Central European Summer Time) - 2 h = UTC |
1779 |
|
found = true; |
1780 |
|
// |
1781 |
|
}; |
1782 |
|
// |
1783 |
|
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){ |
1784 |
|
// |
1785 |
|
offset = -60*60*4; // MSD (Moscow Summer Time) - 4 h = UTC |
1786 |
|
found = true; |
1787 |
|
// |
1788 |
|
}; |
1789 |
|
// |
1790 |
|
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
1791 |
|
// |
1792 |
|
offset = 0; |
1793 |
|
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
1794 |
|
tzone = "UTC"; |
1795 |
|
}; |
1796 |
|
// |
1797 |
|
dbt += offset; |
1798 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
1799 |
|
// |
1800 |
|
rtime = time->AsString("s"); |
1801 |
|
// |
1802 |
|
return(rtime); |
1803 |
|
} |
1804 |
|
|
1805 |
|
|
1806 |
|
// |
1807 |
|
// Build a query and call DoQuery. |
1808 |
|
// |
1809 |
|
// date it's an SQL datetime date and dbc is the connection to be |
1810 |
|
// used. It will query for the tle with the nearest but previous date |
1811 |
|
// and the immediatly next one. |
1812 |
|
// |
1813 |
|
Int_t GL_TLE::Query(TString date, TSQLServer *dbc){ |
1814 |
|
stringstream myquery; |
1815 |
|
myquery.str(""); |
1816 |
|
|
1817 |
|
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1818 |
|
<< "WHERE FROM_TIME <= '" << date.Data() |
1819 |
|
<< "' ORDER BY FROM_TIME DESC LIMIT 1) " |
1820 |
|
<< "UNION " |
1821 |
|
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1822 |
|
<< "WHERE FROM_TIME > '" << date.Data() |
1823 |
|
<< "' ORDER BY FROM_TIME ASC LIMIT 1)"; |
1824 |
|
|
1825 |
|
return DoQuery(myquery.str().c_str(), dbc); |
1826 |
|
} |
1827 |
|
|
1828 |
|
|
1829 |
|
// |
1830 |
|
// Build a query and call DoQuery. |
1831 |
|
// |
1832 |
|
// time is the UTC date in unix time (UTC) and dbc is the connection |
1833 |
|
// to be used. It will query for the tle with the nearest but |
1834 |
|
// previous date and the immediatly next one. |
1835 |
|
// |
1836 |
|
// Returns the value returned by DoQuery(). |
1837 |
|
// |
1838 |
|
Int_t GL_TLE::Query(UInt_t time, TSQLServer *dbc){ |
1839 |
|
stringstream myquery; |
1840 |
|
myquery.str(""); |
1841 |
|
|
1842 |
|
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1843 |
|
<< "WHERE FROM_TIME <= FROM_UNIXTIME('" << time |
1844 |
|
<< "') ORDER BY FROM_TIME DESC LIMIT 1) " |
1845 |
|
<< "UNION " |
1846 |
|
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1847 |
|
<< "WHERE FROM_TIME > FROM_UNIXTIME('" << time |
1848 |
|
<< "') ORDER BY FROM_TIME ASC LIMIT 1)"; |
1849 |
|
|
1850 |
|
return DoQuery(myquery.str().c_str(), dbc); |
1851 |
|
} |
1852 |
|
|
1853 |
|
|
1854 |
|
// |
1855 |
|
// Do the query myquery on the connectio dbc. Initialize tle, |
1856 |
|
// tleFromTime and tleToTime. |
1857 |
|
// |
1858 |
|
// We should have two rows (unless the table is old). From the last |
1859 |
|
// one we only take tleToTime. |
1860 |
|
// |
1861 |
|
// Returns 0 for success, 1 for failure. |
1862 |
|
// |
1863 |
|
Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){ |
1864 |
|
TSQLResult *result; |
1865 |
|
TSQLRow *row; |
1866 |
|
|
1867 |
|
// Set the right time_zone (otherwise horrible things will occur! :) |
1868 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1869 |
|
dbc->Query("SET time_zone = '+0:00'"); |
1870 |
|
|
1871 |
|
// Do the query |
1872 |
|
this->GetGLTABLES()->AddQ(); |
1873 |
|
result = dbc->Query(myquery.Data()); |
1874 |
|
if(! result->GetRowCount() ) { |
1875 |
|
cerr << "GL_TLE: query failed: " << myquery.Data() << endl; |
1876 |
|
return 1; |
1877 |
|
} |
1878 |
|
|
1879 |
|
// Get results |
1880 |
|
row = result->Next(); // first tle row |
1881 |
|
tle = GiveTle(row); |
1882 |
|
|
1883 |
|
tleFromTime = strtol(row->GetField(4), NULL, 10); |
1884 |
|
|
1885 |
|
row = result->Next(); // second tle row |
1886 |
|
if(row) |
1887 |
|
tleToTime = strtol(row->GetField(4), NULL, 10); |
1888 |
|
else { |
1889 |
|
cerr << "GL_TLE: Warning: using last avaible TLE. Please update GL_TLE table!\n"; |
1890 |
|
tleToTime = UINT_MAX; |
1891 |
|
} |
1892 |
|
|
1893 |
|
delete row; |
1894 |
|
delete result; |
1895 |
|
|
1896 |
|
return 0; |
1897 |
|
} |
1898 |
|
|
1899 |
|
|
1900 |
|
// |
1901 |
|
// Build a cTle object from the GL_TLE row. |
1902 |
|
// |
1903 |
|
cTle* GL_TLE::GiveTle(TSQLRow *row) { |
1904 |
|
cTle *thistle = NULL; |
1905 |
|
string tle1, tle2, tle3; |
1906 |
|
|
1907 |
|
// Build cTle object |
1908 |
|
tle1 = row->GetField(1); |
1909 |
|
tle2 = row->GetField(2); |
1910 |
|
tle3 = row->GetField(3); |
1911 |
|
|
1912 |
|
thistle = new cTle(tle1, tle2, tle3); |
1913 |
|
|
1914 |
|
return thistle; |
1915 |
|
} |