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); |
24 |
ClassImp(GL_PARAM); |
ClassImp(GL_PARAM); |
25 |
ClassImp(GL_S4_CALIB); |
ClassImp(GL_S4_CALIB); |
26 |
ClassImp(GL_CALO_CALIB); |
ClassImp(GL_CALO_CALIB); |
27 |
|
ClassImp(GL_CALOPULSE_CALIB); |
28 |
ClassImp(GL_TIMESYNC); |
ClassImp(GL_TIMESYNC); |
29 |
|
ClassImp(GL_TLE); |
30 |
// |
// |
31 |
using namespace std; |
using namespace std; |
32 |
|
|
33 |
|
GL_TABLES::GL_TABLES(){ |
34 |
|
}; |
35 |
|
|
36 |
|
GL_TABLES::GL_TABLES(TString host, TString user, TString psw){ |
37 |
|
fHost = new TString(host.Data()); |
38 |
|
fUser = new TString(user.Data()); |
39 |
|
fPsw = new TString(psw.Data()); |
40 |
|
fSet = true; |
41 |
|
fNquery = 0; |
42 |
|
mh = host.Data(); |
43 |
|
mu = user.Data(); |
44 |
|
mp = psw.Data(); |
45 |
|
}; |
46 |
|
|
47 |
|
|
48 |
|
void GL_TABLES::Set(TString host, TString user, TString psw){ |
49 |
|
fHost = new TString(host.Data()); |
50 |
|
fUser = new TString(user.Data()); |
51 |
|
fPsw = new TString(psw.Data()); |
52 |
|
fSet = true; |
53 |
|
fNquery = 0; |
54 |
|
mh = host.Data(); |
55 |
|
mu = user.Data(); |
56 |
|
mp = psw.Data(); |
57 |
|
}; |
58 |
|
|
59 |
|
Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
60 |
|
// |
61 |
|
// |
62 |
|
// |
63 |
|
if ( !fSet ){ |
64 |
|
return true; |
65 |
|
}; |
66 |
|
// |
67 |
|
// printf(" host is %s \n",fHost->Data()); |
68 |
|
// |
69 |
|
stringstream myquery; |
70 |
|
myquery.str(""); |
71 |
|
myquery << "show databases;"; |
72 |
|
if ( dbc ){ |
73 |
|
if ( dbc->IsConnected() ){ |
74 |
|
dbc->Query(myquery.str().c_str()); |
75 |
|
fNquery++; |
76 |
|
if ( !(dbc->GetErrorCode()) ){ |
77 |
|
// printf("ok\n"); |
78 |
|
// |
79 |
|
// if ( (dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006) ){ |
80 |
|
// if ( !(dbc->GetErrorCode()) ){ |
81 |
|
// is connected |
82 |
|
return true; |
83 |
|
// }; |
84 |
|
}; |
85 |
|
}; |
86 |
|
}; |
87 |
|
// |
88 |
|
if ( true ) { |
89 |
|
// |
90 |
|
printf(" WARNING: Lost connection to DB! try to recover... \n"); |
91 |
|
// |
92 |
|
TString host = fHost->Data(); |
93 |
|
TString user = fUser->Data(); |
94 |
|
TString psw = fPsw->Data(); |
95 |
|
dbc->Close(); |
96 |
|
delete dbc; |
97 |
|
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
98 |
|
// |
99 |
|
myquery.str(""); |
100 |
|
myquery << "show databases;"; |
101 |
|
dbc->Query(myquery.str().c_str()); |
102 |
|
fNquery++; |
103 |
|
// if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ |
104 |
|
if ( !(dbc->GetErrorCode()) ){ |
105 |
|
// |
106 |
|
printf(" ...connection recovered, I can continue! \n"); |
107 |
|
// |
108 |
|
myquery.str(""); |
109 |
|
myquery << "SET time_zone='+0:00'"; |
110 |
|
dbc->Query(myquery.str().c_str()); |
111 |
|
fNquery++; |
112 |
|
myquery.str(""); |
113 |
|
myquery << "SET wait_timeout=173000;"; |
114 |
|
dbc->Query(myquery.str().c_str()); |
115 |
|
fNquery++; |
116 |
|
return true; |
117 |
|
}; |
118 |
|
}; |
119 |
|
// |
120 |
|
printf(" GLTABLES: connection is gone away, query will fail\n"); |
121 |
|
// |
122 |
|
return false; |
123 |
|
// |
124 |
|
}; |
125 |
|
|
126 |
|
void GL_TABLES::ResetCounters(){ |
127 |
|
fNquery = 0; |
128 |
|
}; |
129 |
|
|
130 |
|
void GL_TABLES::AddQ(){ |
131 |
|
if ( fSet ) fNquery++; |
132 |
|
}; |
133 |
|
|
134 |
|
UInt_t GL_TABLES::GetNqueries(){ |
135 |
|
UInt_t rn = 0; |
136 |
|
rn += (UInt_t&)fNquery; |
137 |
|
return(rn); |
138 |
|
}; |
139 |
|
|
140 |
GL_RUN::GL_RUN() { |
GL_RUN::GL_RUN() { |
141 |
ID = 0; |
ID = 0; |
142 |
ID_RUN_FRAG = 0; |
ID_RUN_FRAG = 0; |
171 |
VALIDATION = 0; |
VALIDATION = 0; |
172 |
} |
} |
173 |
|
|
174 |
void GL_RUN::Clear() { |
|
175 |
|
void GL_RUN::Clear(Option_t *t) { |
176 |
ID = 0; |
ID = 0; |
177 |
ID_RUN_FRAG = 0; |
ID_RUN_FRAG = 0; |
178 |
ID_ROOT_L0 = 0; |
ID_ROOT_L0 = 0; |
236 |
OBT2 = 0; |
OBT2 = 0; |
237 |
PKT1 = 0; |
PKT1 = 0; |
238 |
PKT2 = 0; |
PKT2 = 0; |
239 |
|
BOOT_NUMBER = 0; |
240 |
|
VALIDATION = 0; |
241 |
} |
} |
242 |
|
|
243 |
GL_CALO_CALIB::GL_CALO_CALIB(){ |
GL_CALO_CALIB::GL_CALO_CALIB(){ |
247 |
FROM_TIME = 0; |
FROM_TIME = 0; |
248 |
TO_TIME = 0; |
TO_TIME = 0; |
249 |
SECTION = 0; |
SECTION = 0; |
250 |
|
OBT = 0; |
251 |
|
PKT = 0; |
252 |
|
BOOT_NUMBER = 0; |
253 |
|
VALIDATION = 0; |
254 |
|
} |
255 |
|
|
256 |
|
GL_CALOPULSE_CALIB::GL_CALOPULSE_CALIB(){ |
257 |
|
ID = 0; |
258 |
|
ID_ROOT_L0 = 0; |
259 |
|
EV_ROOT = 0; |
260 |
|
FROM_TIME = 0; |
261 |
|
TO_TIME = 0; |
262 |
|
SECTION = 0; |
263 |
|
PULSED_STRIP = 0; |
264 |
|
PULSE_AMPLITUDE = 0; |
265 |
|
OBT = 0; |
266 |
|
PKT = 0; |
267 |
|
BOOT_NUMBER = 0; |
268 |
|
VALIDATION = 0; |
269 |
} |
} |
270 |
|
|
271 |
GL_S4_CALIB::GL_S4_CALIB(){ |
GL_S4_CALIB::GL_S4_CALIB(){ |
274 |
EV_ROOT = 0; |
EV_ROOT = 0; |
275 |
FROM_TIME = 0; |
FROM_TIME = 0; |
276 |
TO_TIME = 0; |
TO_TIME = 0; |
277 |
PARAM_FIT0 = 0.; |
OBT = 0; |
278 |
PARAM_FIT1 = 0.; |
PKT = 0; |
279 |
|
BOOT_NUMBER = 0; |
280 |
} |
} |
281 |
|
|
282 |
GL_TIMESYNC::GL_TIMESYNC(){ |
GL_TIMESYNC::GL_TIMESYNC(){ |
283 |
obtfirst = 0; |
obtfirst = 0; |
284 |
pktfirst = 0; |
pktfirst = 0; |
285 |
toffset = 0; |
ID_RESURS_OFFSET = 0; |
286 |
ID = 0; |
ID = 0; |
287 |
ID_RAW = 0; |
ID_RAW = 0; |
288 |
OBT0 = 0; |
OBT0 = 0; |
289 |
TIMESYNC = 0; |
TIMESYNC = 0; |
290 |
TYPE = 0; |
TYPE = 0; |
291 |
}// **************************************************** |
} |
292 |
|
|
293 |
|
// **************************************************** |
294 |
|
|
295 |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
296 |
EV_FROM = evfrom; |
EV_FROM = evfrom; |
464 |
CAL_DSP_MASK = 0; |
CAL_DSP_MASK = 0; |
465 |
}; |
}; |
466 |
|
|
467 |
|
void GL_RUN::Set_GL_RUN(TSQLRow *Row){ |
468 |
|
for( Int_t t = 0; t < 30; t++){ |
469 |
|
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
470 |
|
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
471 |
|
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
472 |
|
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
473 |
|
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
474 |
|
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
475 |
|
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
476 |
|
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
477 |
|
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
478 |
|
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
479 |
|
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
480 |
|
if (t==11) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
481 |
|
if (t==12) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
482 |
|
if (t==13) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
483 |
|
if (t==14) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
484 |
|
if (t==15) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
485 |
|
if (t==16) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
486 |
|
if (t==17) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
487 |
|
if (t==18) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
488 |
|
if (t==19) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
489 |
|
if (t==20) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
490 |
|
if (t==21) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
491 |
|
if (t==22) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
492 |
|
if (t==23) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
493 |
|
if (t==24) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
494 |
|
if (t==25) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
495 |
|
if (t==26) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
496 |
|
if (t==27) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
497 |
|
if (t==28) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
498 |
|
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
499 |
|
}; |
500 |
|
|
501 |
|
} |
502 |
|
|
503 |
|
/** |
504 |
|
* This method delete the run from the "FromTable" table and store it in the GL_RUN_TRASH table |
505 |
|
* If IDRUN is 0 "this->ID" run is used. |
506 |
|
* |
507 |
|
**/ |
508 |
|
Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ |
509 |
|
// MySQL variables |
510 |
|
TSQLResult *pResult; |
511 |
|
TSQLRow *Row; |
512 |
|
stringstream myquery; |
513 |
|
// |
514 |
|
if ( !IDRUN ) IDRUN = ID; |
515 |
|
if ( !IDRUN ) return 1; |
516 |
|
// ---------------- |
517 |
|
myquery.str(""); |
518 |
|
myquery << " INSERT INTO GL_RUN_TRASH ("; |
519 |
|
myquery << "ID"; |
520 |
|
myquery << ",ID_RUN_FRAG"; |
521 |
|
myquery << ",ID_ROOT_L0"; |
522 |
|
myquery << ",ID_ROOT_L2"; |
523 |
|
myquery << ",RUNHEADER_TIME"; |
524 |
|
myquery << ",RUNTRAILER_TIME"; |
525 |
|
myquery << ",RUNHEADER_OBT"; |
526 |
|
myquery << ",RUNTRAILER_OBT"; |
527 |
|
myquery << ",RUNHEADER_PKT"; |
528 |
|
myquery << ",RUNTRAILER_PKT"; |
529 |
|
myquery << ",BOOT_NUMBER"; |
530 |
|
myquery << ",EV_FROM"; |
531 |
|
myquery << ",EV_TO"; |
532 |
|
myquery << ",NEVENTS"; |
533 |
|
myquery << ",PKT_COUNTER"; |
534 |
|
myquery << ",PKT_READY_COUNTER"; |
535 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
536 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
537 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
538 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
539 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
540 |
|
myquery << ",ACQ_BUILD_INFO"; |
541 |
|
myquery << ",ACQ_VAR_INFO"; |
542 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
543 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
544 |
|
myquery << ",TRK_CALIB_USED"; |
545 |
|
myquery << ",CAL_DSP_MASK"; |
546 |
|
myquery << ",LAST_TIMESYNC"; |
547 |
|
myquery << ",OBT_TIMESYNC"; |
548 |
|
myquery << ",VALIDATION"; |
549 |
|
myquery << ",INSERT_TIME"; |
550 |
|
myquery << ") SELECT * FROM "; |
551 |
|
myquery << FromTable.Data(); |
552 |
|
myquery << " WHERE ID="; |
553 |
|
myquery << (UInt_t)IDRUN << ";"; |
554 |
|
// |
555 |
|
// printf("1myquery is %s \n",myquery.str().c_str()); |
556 |
|
// |
557 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
558 |
|
this->GetGLTABLES()->AddQ(); |
559 |
|
dbc->Query(myquery.str().c_str()); |
560 |
|
// |
561 |
|
// retrieve this ID_TRASH |
562 |
|
// |
563 |
|
myquery.str(""); |
564 |
|
myquery << " SELECT ID_TRASH,ID_ROOT_L0,ID_ROOT_L2 FROM GL_RUN_TRASH ORDER BY ID_TRASH DESC LIMIT 1"; |
565 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
566 |
|
this->GetGLTABLES()->AddQ(); |
567 |
|
pResult = dbc->Query(myquery.str().c_str()); |
568 |
|
// |
569 |
|
UInt_t idtrash = 0; |
570 |
|
UInt_t idl0 = 0; |
571 |
|
UInt_t idl2 = 0; |
572 |
|
// |
573 |
|
Row = pResult->Next(); |
574 |
|
if( Row != NULL ){ |
575 |
|
idtrash = (UInt_t)atoll(Row->GetField(0)); |
576 |
|
idl0 = (UInt_t)atoll(Row->GetField(1)); |
577 |
|
idl2 = (UInt_t)atoll(Row->GetField(2)); |
578 |
|
}; |
579 |
|
// |
580 |
|
TString fileL0 = ""; |
581 |
|
TString fileL2 = ""; |
582 |
|
myquery.str(""); |
583 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
584 |
|
myquery << idl0 << ";"; |
585 |
|
// |
586 |
|
// printf("2myquery is %s \n",myquery.str().c_str()); |
587 |
|
// |
588 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
589 |
|
this->GetGLTABLES()->AddQ(); |
590 |
|
pResult = dbc->Query(myquery.str().c_str()); |
591 |
|
// |
592 |
|
Row = pResult->Next(); |
593 |
|
if( Row != NULL ){ |
594 |
|
fileL0 = (TString)Row->GetField(0); |
595 |
|
}; |
596 |
|
// |
597 |
|
// |
598 |
|
// |
599 |
|
myquery.str(""); |
600 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
601 |
|
myquery << idl2 << ";"; |
602 |
|
// |
603 |
|
// printf("3myquery is %s \n",myquery.str().c_str()); |
604 |
|
// |
605 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
606 |
|
this->GetGLTABLES()->AddQ(); |
607 |
|
pResult = dbc->Query(myquery.str().c_str()); |
608 |
|
// |
609 |
|
Row = pResult->Next(); |
610 |
|
if( Row != NULL ){ |
611 |
|
fileL2 = (TString)Row->GetField(0); |
612 |
|
}; |
613 |
|
// |
614 |
|
// |
615 |
|
// |
616 |
|
myquery.str(""); |
617 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL0='"; |
618 |
|
myquery << fileL0.Data() << "' where ID_TRASH="; |
619 |
|
myquery << idtrash << ";"; |
620 |
|
// |
621 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
622 |
|
// |
623 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
624 |
|
this->GetGLTABLES()->AddQ(); |
625 |
|
dbc->Query(myquery.str().c_str()); |
626 |
|
// |
627 |
|
myquery.str(""); |
628 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='"; |
629 |
|
myquery << fileL2.Data() << "' where ID_TRASH="; |
630 |
|
myquery << idtrash << ";"; |
631 |
|
// |
632 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
633 |
|
// |
634 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
635 |
|
this->GetGLTABLES()->AddQ(); |
636 |
|
dbc->Query(myquery.str().c_str()); |
637 |
|
// |
638 |
|
myquery.str(""); |
639 |
|
myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='"; |
640 |
|
myquery << FromTable.Data() << "' where ID_TRASH="; |
641 |
|
myquery << idtrash << ";"; |
642 |
|
// |
643 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
644 |
|
// |
645 |
|
// |
646 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
647 |
|
this->GetGLTABLES()->AddQ(); |
648 |
|
dbc->Query(myquery.str().c_str()); |
649 |
|
// |
650 |
|
myquery.str(""); |
651 |
|
myquery << " DELETE FROM "; |
652 |
|
myquery << FromTable.Data() << " where ID="; |
653 |
|
myquery << IDRUN << ";"; |
654 |
|
// |
655 |
|
// printf("5myquery is %s \n",myquery.str().c_str()); |
656 |
|
// |
657 |
|
// |
658 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
659 |
|
this->GetGLTABLES()->AddQ(); |
660 |
|
dbc->Query(myquery.str().c_str()); |
661 |
|
// |
662 |
|
return 0; |
663 |
|
}; |
664 |
|
|
665 |
|
|
666 |
|
|
667 |
|
/** |
668 |
|
* This method restore a run from the GL_RUN_TRASH table. |
669 |
|
* If ID is 0 "this->ID" is used; if "ToTable" is empty BELONG_TO field of GL_RUN_TRASH is used. |
670 |
|
* |
671 |
|
**/ |
672 |
|
Int_t GL_RUN::RestoreRun(TSQLServer *dbc,UInt_t IDRUN,TString ToTable){ |
673 |
|
// insert into GL_RUN_FRAGMENTS select * FROM GL_RUN where ID=11; |
674 |
|
//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; |
675 |
|
// MySQL variables |
676 |
|
TSQLResult *pResult; |
677 |
|
TSQLRow *Row; |
678 |
|
stringstream myquery; |
679 |
|
// |
680 |
|
if ( !IDRUN ) IDRUN = ID; |
681 |
|
if ( !IDRUN ) return 1; |
682 |
|
// |
683 |
|
if ( !strcmp(ToTable.Data(),"") ){ |
684 |
|
// |
685 |
|
myquery.str(""); |
686 |
|
myquery << " SELECT BELONGED_TO FROM GL_RUN_TRASH WHERE ID="; |
687 |
|
myquery << (UInt_t)IDRUN << ";"; |
688 |
|
// |
689 |
|
printf(" qui? myquery is %s \n",myquery.str().c_str()); |
690 |
|
// |
691 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
692 |
|
this->GetGLTABLES()->AddQ(); |
693 |
|
pResult = dbc->Query(myquery.str().c_str()); |
694 |
|
// |
695 |
|
Row = pResult->Next(); |
696 |
|
if( Row != NULL ){ |
697 |
|
ToTable = (TString)Row->GetField(0); |
698 |
|
} else { |
699 |
|
return 1; |
700 |
|
}; |
701 |
|
}; |
702 |
|
// ---------------- |
703 |
|
myquery.str(""); |
704 |
|
myquery << " INSERT INTO "; |
705 |
|
myquery << ToTable.Data(); |
706 |
|
myquery << " ("; |
707 |
|
myquery << "ID"; |
708 |
|
myquery << ",ID_RUN_FRAG"; |
709 |
|
myquery << ",ID_ROOT_L0"; |
710 |
|
myquery << ",ID_ROOT_L2"; |
711 |
|
myquery << ",RUNHEADER_TIME"; |
712 |
|
myquery << ",RUNTRAILER_TIME"; |
713 |
|
myquery << ",RUNHEADER_OBT"; |
714 |
|
myquery << ",RUNTRAILER_OBT"; |
715 |
|
myquery << ",RUNHEADER_PKT"; |
716 |
|
myquery << ",RUNTRAILER_PKT"; |
717 |
|
myquery << ",BOOT_NUMBER"; |
718 |
|
myquery << ",EV_FROM"; |
719 |
|
myquery << ",EV_TO"; |
720 |
|
myquery << ",NEVENTS"; |
721 |
|
myquery << ",PKT_COUNTER"; |
722 |
|
myquery << ",PKT_READY_COUNTER"; |
723 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
724 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
725 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
726 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
727 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
728 |
|
myquery << ",ACQ_BUILD_INFO"; |
729 |
|
myquery << ",ACQ_VAR_INFO"; |
730 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
731 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
732 |
|
myquery << ",TRK_CALIB_USED"; |
733 |
|
myquery << ",CAL_DSP_MASK"; |
734 |
|
myquery << ",LAST_TIMESYNC"; |
735 |
|
myquery << ",OBT_TIMESYNC"; |
736 |
|
myquery << ",VALIDATION"; |
737 |
|
myquery << ",INSERT_TIME"; |
738 |
|
myquery << ") SELECT "; |
739 |
|
myquery << "ID"; |
740 |
|
myquery << ",ID_RUN_FRAG"; |
741 |
|
myquery << ",ID_ROOT_L0"; |
742 |
|
myquery << ",ID_ROOT_L2"; |
743 |
|
myquery << ",RUNHEADER_TIME"; |
744 |
|
myquery << ",RUNTRAILER_TIME"; |
745 |
|
myquery << ",RUNHEADER_OBT"; |
746 |
|
myquery << ",RUNTRAILER_OBT"; |
747 |
|
myquery << ",RUNHEADER_PKT"; |
748 |
|
myquery << ",RUNTRAILER_PKT"; |
749 |
|
myquery << ",BOOT_NUMBER"; |
750 |
|
myquery << ",EV_FROM"; |
751 |
|
myquery << ",EV_TO"; |
752 |
|
myquery << ",NEVENTS"; |
753 |
|
myquery << ",PKT_COUNTER"; |
754 |
|
myquery << ",PKT_READY_COUNTER"; |
755 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
756 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
757 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
758 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
759 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
760 |
|
myquery << ",ACQ_BUILD_INFO"; |
761 |
|
myquery << ",ACQ_VAR_INFO"; |
762 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
763 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
764 |
|
myquery << ",TRK_CALIB_USED"; |
765 |
|
myquery << ",CAL_DSP_MASK"; |
766 |
|
myquery << ",LAST_TIMESYNC"; |
767 |
|
myquery << ",OBT_TIMESYNC"; |
768 |
|
myquery << ",VALIDATION"; |
769 |
|
myquery << ",INSERT_TIME"; |
770 |
|
myquery << " FROM GL_RUN_TRASH "; |
771 |
|
myquery << " WHERE BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
772 |
|
myquery << (UInt_t)IDRUN << ";"; |
773 |
|
// |
774 |
|
// printf("5myquery is %s \n",myquery.str().c_str()); |
775 |
|
// |
776 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
777 |
|
this->GetGLTABLES()->AddQ(); |
778 |
|
dbc->Query(myquery.str().c_str()); |
779 |
|
// |
780 |
|
// |
781 |
|
myquery.str(""); |
782 |
|
myquery << " DELETE FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
783 |
|
myquery << IDRUN << ";"; |
784 |
|
// |
785 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
786 |
|
this->GetGLTABLES()->AddQ(); |
787 |
|
dbc->Query(myquery.str().c_str()); |
788 |
|
// |
789 |
|
return 0; |
790 |
|
}; |
791 |
|
|
792 |
/** |
/** |
793 |
* Function to fill the GL_RUN table of the DB. |
* Function to fill the GL_RUN table of the DB. |
866 |
// |
// |
867 |
// printf("myquery is %s \n",myquery.str().c_str()); |
// printf("myquery is %s \n",myquery.str().c_str()); |
868 |
// |
// |
869 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
870 |
|
this->GetGLTABLES()->AddQ(); |
871 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
872 |
// |
// |
873 |
return 0; |
return 0; |
944 |
// |
// |
945 |
// printf("myquery is %s \n",myquery.str().c_str()); |
// printf("myquery is %s \n",myquery.str().c_str()); |
946 |
// |
// |
947 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
948 |
|
this->GetGLTABLES()->AddQ(); |
949 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
950 |
// |
// |
951 |
return 0; |
return 0; |
1003 |
myquery << " from GL_RUN where ID=" << run << ";"; |
myquery << " from GL_RUN where ID=" << run << ";"; |
1004 |
// |
// |
1005 |
// printf(" myquery is %s \n",myquery.str().c_str()); |
// printf(" myquery is %s \n",myquery.str().c_str()); |
1006 |
|
if ( !this->IsConnected(dbc) ) return -57; |
1007 |
|
this->AddQ(); |
1008 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1009 |
// |
// |
1010 |
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
1014 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1015 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1016 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
1017 |
|
// Set_GL_RUN(Row); |
1018 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1019 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
1020 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
1021 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1022 |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
1023 |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
1024 |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
1025 |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
1026 |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
1027 |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
1028 |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
1029 |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
1030 |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
1031 |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
1032 |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1033 |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1034 |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
1035 |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
1036 |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
1037 |
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)); |
1038 |
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)); |
1039 |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
1040 |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
1041 |
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)); |
1042 |
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)); |
1043 |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
1044 |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
1045 |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
1046 |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
1047 |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
1048 |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
1049 |
}; |
}; |
1050 |
}; |
}; |
1051 |
// delete pResult; |
// delete pResult; |
1103 |
// |
// |
1104 |
// printf(" query is %s \n",myquery.str().c_str()); |
// printf(" query is %s \n",myquery.str().c_str()); |
1105 |
// |
// |
1106 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1107 |
|
this->GetGLTABLES()->AddQ(); |
1108 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1109 |
if(!pResult->GetRowCount())return(-50); |
if(!pResult->GetRowCount())return(-50); |
1110 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1170 |
myquery << ",NAME"; |
myquery << ",NAME"; |
1171 |
myquery << " from GL_ROOT where ID=" << id << ";"; |
myquery << " from GL_ROOT where ID=" << id << ";"; |
1172 |
// |
// |
1173 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1174 |
|
this->GetGLTABLES()->AddQ(); |
1175 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1176 |
if(!pResult->GetRowCount())return (-51); |
if(!pResult->GetRowCount())return (-51); |
1177 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1181 |
if(t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if(t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1182 |
if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t)); |
if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t)); |
1183 |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1184 |
if(t==3) PATH = Row->GetField(t); |
if(t==3) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/'; |
1185 |
if(t==4) NAME = Row->GetField(t); |
if(t==4) NAME = Row->GetField(t); |
1186 |
}; |
}; |
1187 |
}; |
}; |
1193 |
* Function to query the GL_TRK_CALIB table of the DB. |
* Function to query the GL_TRK_CALIB table of the DB. |
1194 |
* |
* |
1195 |
* \param run starting time |
* \param run starting time |
1196 |
|
* \param dbc DB server |
1197 |
* \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 |
1198 |
*/ |
*/ |
1199 |
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){ |
1205 |
stringstream myquery; |
stringstream myquery; |
1206 |
// ---------------- |
// ---------------- |
1207 |
myquery.str(""); |
myquery.str(""); |
1208 |
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; |
1209 |
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!!! |
1210 |
|
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 |
1211 |
|
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1212 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1213 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1214 |
|
this->GetGLTABLES()->AddQ(); |
1215 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1216 |
if(!pResult->GetRowCount())return (-53); |
if(!pResult->GetRowCount())return (-53); |
1217 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1221 |
stringstream row; |
stringstream row; |
1222 |
row.str(""); |
row.str(""); |
1223 |
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 |
1224 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1225 |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1226 |
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()); |
1227 |
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()); |
1228 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1229 |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
1230 |
// |
// |
1231 |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
1232 |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
1233 |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
1234 |
if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t)); |
if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t)); |
1235 |
}; |
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
1236 |
|
if (t==11) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
1237 |
|
}; |
1238 |
}; |
}; |
1239 |
delete pResult; |
delete pResult; |
1240 |
|
// |
1241 |
|
// if ( TO_TIME < time ) return(51); |
1242 |
// |
// |
|
if(TO_TIME < time)return(51); |
|
1243 |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
1244 |
// |
// |
1245 |
return 0; |
return 0; |
1269 |
myquery << " ;"; |
myquery << " ;"; |
1270 |
//myquery << " and VALIDATION=1;"; |
//myquery << " and VALIDATION=1;"; |
1271 |
// |
// |
1272 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1273 |
|
this->GetGLTABLES()->AddQ(); |
1274 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1275 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1276 |
// |
// |
1290 |
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; |
1291 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1292 |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
1293 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1294 |
|
this->GetGLTABLES()->AddQ(); |
1295 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1296 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1297 |
// |
// |
1315 |
pResult->Delete(); |
pResult->Delete(); |
1316 |
return 0; |
return 0; |
1317 |
}; |
}; |
1318 |
|
|
1319 |
|
|
1320 |
|
// **************************************************** |
1321 |
|
/** |
1322 |
|
* Function to query the GL_CALOPULSE_CALIB table of the DB. |
1323 |
|
* |
1324 |
|
* \param run starting time |
1325 |
|
* \return struct of type GL_CALOPULSE_CALIB_data, which stores the query result |
1326 |
|
*/ |
1327 |
|
Int_t GL_CALOPULSE_CALIB::Query_GL_CALOPULSE_CALIB(UInt_t time, UInt_t section, UInt_t pampli, TSQLServer *dbc){ |
1328 |
|
// MySQL variables |
1329 |
|
TSQLResult *pResult; |
1330 |
|
TSQLRow *Row; |
1331 |
|
int t; |
1332 |
|
stringstream myquery; |
1333 |
|
// |
1334 |
|
// select the correct calibration i.e. the closest to our time |
1335 |
|
// |
1336 |
|
myquery.str(""); |
1337 |
|
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALOPULSE_CALIB where SECTION=" << section; |
1338 |
|
myquery << " and PULSE_AMPLITUDE=" << pampli; |
1339 |
|
myquery << " and VALIDATION=1 and (PULSED_STRIP IS NULL OR PULSED_STRIP<100) ORDER BY ABS(" << time << "-FROM_TIME) asc limit 1;"; |
1340 |
|
// printf(" myq is %s \n",myquery.str().c_str()); |
1341 |
|
// |
1342 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1343 |
|
this->GetGLTABLES()->AddQ(); |
1344 |
|
pResult = dbc->Query(myquery.str().c_str()); |
1345 |
|
// |
1346 |
|
if( !pResult ) return(-54); |
1347 |
|
// |
1348 |
|
Row = pResult->Next(); |
1349 |
|
// |
1350 |
|
if( !Row ) return (-54); |
1351 |
|
// |
1352 |
|
// store infos and exit |
1353 |
|
// |
1354 |
|
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1355 |
|
// printf(" field %i is %s \n",t,Row->GetField(t)); |
1356 |
|
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1357 |
|
if (t==1) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1358 |
|
if (t==2) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
1359 |
|
if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
1360 |
|
}; |
1361 |
|
pResult->Delete(); |
1362 |
|
return 0; |
1363 |
|
}; |
1364 |
|
|
1365 |
|
|
1366 |
// **************************************************** |
// **************************************************** |
1367 |
/** |
/** |
1368 |
* Function to query the GL_S4_CALIB table of the DB. |
* Function to query the GL_S4_CALIB table of the DB. |
1379 |
stringstream myquery; |
stringstream myquery; |
1380 |
// ---------------- |
// ---------------- |
1381 |
myquery.str(""); |
myquery.str(""); |
1382 |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
myquery << "select ID,ID_ROOT_L0,EV_ROOT,FROM_TIME,TO_TIME from GL_S4_CALIB where FROM_TIME <= "<< time; |
1383 |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1384 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1385 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1386 |
|
this->GetGLTABLES()->AddQ(); |
1387 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1388 |
if(!pResult->GetRowCount())return (-55);//throw -55; |
if(!pResult->GetRowCount())return (-55);//throw -55; |
1389 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1391 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
1392 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1393 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1394 |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1395 |
if (t==2) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
if (t==2) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
1396 |
if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1397 |
if (t==4) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==4) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
|
if (t==5) PARAM_FIT0 = atof(Row->GetField(t)); |
|
|
if (t==6) PARAM_FIT1 = atof(Row->GetField(t)); |
|
1398 |
}; |
}; |
1399 |
}; |
}; |
1400 |
delete pResult; |
delete pResult; |
1422 |
// ---------------- |
// ---------------- |
1423 |
myquery.str(""); |
myquery.str(""); |
1424 |
myquery << " select "; |
myquery << " select "; |
1425 |
myquery << " ID, PATH, NAME, DESCR, TYPE, FROM_TIME,TO_TIME "; |
myquery << " ID, PATH, NAME, DESCR, FROM_TIME,TO_TIME, TYPE "; |
1426 |
myquery << " from GL_PARAM "; |
myquery << " from GL_PARAM "; |
1427 |
myquery << " where TYPE = '"<<type<<"' "; |
myquery << " where TYPE = '"<<type<<"' "; |
1428 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1429 |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
1430 |
// |
// |
1431 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1432 |
|
this->GetGLTABLES()->AddQ(); |
1433 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1434 |
if(!pResult->GetRowCount())return (-52); |
if(!pResult->GetRowCount())return (-52); |
1435 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1437 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
1438 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1439 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1440 |
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 |
1441 |
if (t==2) NAME = Row->GetField(t); |
if (t==2) NAME = Row->GetField(t); |
1442 |
if (t==3) DESCR = Row->GetField(t); |
if (t==3) DESCR = Row->GetField(t); |
1443 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1482 |
TSQLResult *pResult; |
TSQLResult *pResult; |
1483 |
TSQLRow *Row; |
TSQLRow *Row; |
1484 |
stringstream myquery; |
stringstream myquery; |
1485 |
|
stringstream rname; |
1486 |
|
// pcksList packetsNames; |
1487 |
|
// pcksList::iterator Iter; |
1488 |
|
// getPacketsNames(packetsNames); |
1489 |
|
rname.str(""); |
1490 |
// ---------------- |
// ---------------- |
1491 |
myquery.str(""); |
myquery.str(""); |
1492 |
myquery << "select "; |
myquery << "select "; |
1496 |
myquery << type.Data(); |
myquery << type.Data(); |
1497 |
myquery << "=" << id << ";"; |
myquery << "=" << id << ";"; |
1498 |
// |
// |
1499 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1500 |
|
this->GetGLTABLES()->AddQ(); |
1501 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1502 |
if( pResult->GetRowCount() ){ |
if( pResult->GetRowCount() ){ |
1503 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1504 |
if( Row ){ |
if( Row ){ |
1505 |
stringstream fname; |
stringstream fname; |
1506 |
fname.str(""); |
fname.str(""); |
1507 |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
1508 |
|
rname << Row->GetField(1); |
1509 |
file = new TFile(fname.str().c_str(),"READ"); |
file = new TFile(fname.str().c_str(),"READ"); |
1510 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
idraw = (UInt_t)atoll(Row->GetField(2)); |
1511 |
}; |
}; |
1521 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
1522 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
1523 |
obtfirst = ph->GetOrbitalTime(); |
obtfirst = ph->GetOrbitalTime(); |
1524 |
|
// |
1525 |
|
// code = eh->GetCounter(); |
1526 |
|
// UInt_t en = 0; |
1527 |
|
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
1528 |
|
// en = code->Get(GetPacketType(*Iter)); |
1529 |
|
// if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){ |
1530 |
|
// // |
1531 |
|
// TTree *TC = 0; |
1532 |
|
// TC = (TTree*)file->Get("CalibCalPed"); |
1533 |
|
// if ( !TC || TC->IsZombie() ) return; |
1534 |
|
// EventHeader *ehc = 0; |
1535 |
|
// PscuHeader *phc = 0; |
1536 |
|
// TC->SetBranchAddress("Header", &ehc); |
1537 |
|
// TC->GetEntry(0); |
1538 |
|
// phc = ehc->GetPscuHeader(); |
1539 |
|
// pktfirst = phc->GetCounter(); |
1540 |
|
// obtfirst = phc->GetOrbitalTime(); |
1541 |
|
// // |
1542 |
|
// }; |
1543 |
|
// }; |
1544 |
|
// |
1545 |
}; |
}; |
1546 |
// |
// |
1547 |
// look for Resurs offset |
// look for Resurs offset |
1548 |
// |
// |
1549 |
UInt_t t0 = 0; |
T0 = 0; |
1550 |
// |
// |
1551 |
myquery.str(""); |
// |
1552 |
myquery << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= " |
stringstream oss; |
1553 |
<< idraw << " AND TO_ID_RAW >= " |
TString frn = rname.str().c_str(); |
1554 |
<< idraw << ";"; |
frn = frn.ReplaceAll(".root",5,".pam",4); |
1555 |
pResult = dbc->Query(myquery.str().c_str()); |
oss.str(""); |
1556 |
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='" |
1557 |
Row = pResult->Next(); |
<< frn.Data() << "';"; |
1558 |
if ( Row ){ |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1559 |
|
this->GetGLTABLES()->AddQ(); |
1560 |
|
pResult = dbc->Query(oss.str().c_str()); |
1561 |
|
Row = pResult->Next(); |
1562 |
|
// |
1563 |
|
TString name=rname.str().c_str(); |
1564 |
|
UInt_t dworbit = 0; |
1565 |
|
Int_t nlength = name.Length(); |
1566 |
|
// |
1567 |
|
// Is not a special file |
1568 |
|
// |
1569 |
|
if ( !Row ){ |
1570 |
|
delete pResult; |
1571 |
|
// |
1572 |
|
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
1573 |
|
// |
1574 |
|
oss.str(""); |
1575 |
|
oss << "SELECT ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";"; |
1576 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1577 |
|
this->GetGLTABLES()->AddQ(); |
1578 |
|
pResult = dbc->Query(oss.str().c_str()); |
1579 |
|
Bool_t fndit = false; |
1580 |
|
if ( pResult ){ |
1581 |
|
Row = pResult->Next(); |
1582 |
|
if ( Row ){ |
1583 |
|
oss.str(""); |
1584 |
|
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=" |
1585 |
|
<< Row->GetField(0) << ";"; |
1586 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1587 |
|
this->GetGLTABLES()->AddQ(); |
1588 |
|
pResult = dbc->Query(oss.str().c_str()); |
1589 |
|
if ( pResult ){ |
1590 |
|
Row = pResult->Next(); |
1591 |
|
if ( Row ){ |
1592 |
|
// printf(" GREAT! the DB structure is the new one! \n"); |
1593 |
|
fndit = true; |
1594 |
|
dworbit = 1; |
1595 |
|
}; |
1596 |
|
}; |
1597 |
|
}; |
1598 |
|
}; |
1599 |
|
if ( !fndit ){ |
1600 |
|
delete pResult; |
1601 |
// |
// |
1602 |
t0 = (UInt_t)TDatime(Row->GetField(0)).Convert(); |
printf(" OK, you got an error because this is the old database\n Using backward compability code, hence you can continue safetly \n"); |
1603 |
|
// |
1604 |
|
// Old code, we must trust the filename |
1605 |
|
// |
1606 |
|
if ( nlength < 5 ) return; |
1607 |
|
TString dwo = 0; |
1608 |
|
for (Int_t i = 0; i<5; i++){ |
1609 |
|
dwo.Append(name[i],1); |
1610 |
|
}; |
1611 |
|
if ( dwo.IsDigit() ){ |
1612 |
|
dworbit = (UInt_t)dwo.Atoi(); |
1613 |
|
} else { |
1614 |
|
dwo=""; |
1615 |
|
for (Int_t i = 8; i<13; i++){ |
1616 |
|
dwo.Append(name[i],1); |
1617 |
|
}; |
1618 |
|
if ( dwo.IsDigit() ){ |
1619 |
|
dworbit = (UInt_t)dwo.Atoi(); |
1620 |
|
} else { |
1621 |
|
dworbit = 1; |
1622 |
|
}; |
1623 |
|
}; |
1624 |
// |
// |
1625 |
|
oss.str(""); |
1626 |
|
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< " |
1627 |
|
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
1628 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1629 |
|
this->GetGLTABLES()->AddQ(); |
1630 |
|
pResult = dbc->Query(oss.str().c_str()); |
1631 |
|
Row = pResult->Next(); |
1632 |
|
if ( !Row ){ |
1633 |
|
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
1634 |
|
return; |
1635 |
|
}; |
1636 |
}; |
}; |
1637 |
}; |
}; |
1638 |
// |
// |
1639 |
|
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); |
1640 |
|
T0 = (UInt_t)tu.GetSec(); |
1641 |
// |
// |
1642 |
// look for the correct timesync entry |
// look for the correct timesync entry |
1643 |
// |
// |
1644 |
myquery.str(""); |
myquery.str(""); |
1645 |
myquery << " SELECT OBT0,TIMESYNC FROM GL_TIMESYNC " |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
1646 |
<< " WHERE ID_RAW = " << idraw |
<< " WHERE ID_RAW = " << idraw |
1647 |
<< ";"; |
<< ";"; |
1648 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1649 |
|
this->GetGLTABLES()->AddQ(); |
1650 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1651 |
if ( pResult ){ |
if ( pResult ){ |
1652 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1653 |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
1654 |
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)); |
1655 |
|
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
1656 |
|
TYPE = (UInt_t)atoll(Row->GetField(2)); |
1657 |
|
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; |
1658 |
}; |
}; |
1659 |
}; |
}; |
1660 |
// |
// |
1673 |
// |
// |
1674 |
}; |
}; |
1675 |
|
|
1676 |
|
/** |
1677 |
|
* |
1678 |
|
* Returns the Resurs time given the OBT needed to process inclination and orbital infos |
1679 |
|
* |
1680 |
|
*/ |
1681 |
|
UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){ |
1682 |
|
// |
1683 |
|
return(((UInt_t)((Int_t)(this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC)); |
1684 |
|
// |
1685 |
|
}; |
1686 |
|
|
1687 |
|
|
1688 |
ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
/** |
1689 |
|
* Return the correct packet number if we went back to zero |
1690 |
|
*/ |
1691 |
|
Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
1692 |
// |
// |
1693 |
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) ){ |
1694 |
|
return((Long64_t)pkt_num+16777215LL); |
1695 |
|
}; |
1696 |
// |
// |
1697 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
1698 |
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())); |
|
|
}; |
|
1699 |
}; |
}; |
1700 |
// |
// |
1701 |
return((ULong64_t)obt); |
return((Long64_t)pkt_num); |
1702 |
// |
// |
1703 |
}; |
}; |
1704 |
|
|
1705 |
UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
/** |
1706 |
|
* Return the correct On Board Time if we went back to zero |
1707 |
|
*/ |
1708 |
|
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1709 |
// |
// |
1710 |
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())); |
1711 |
// |
// |
1712 |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1713 |
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)); |
|
|
}; |
|
1714 |
}; |
}; |
1715 |
// |
// |
1716 |
return(pkt_num); |
return((Long64_t)obt); |
|
// |
|
1717 |
}; |
}; |
1718 |
|
|
1719 |
|
|
1720 |
|
|
1721 |
|
// ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1722 |
|
// // |
1723 |
|
// if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
1724 |
|
// // |
1725 |
|
// if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1726 |
|
// if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
1727 |
|
// return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
1728 |
|
// } else { |
1729 |
|
// return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
1730 |
|
// }; |
1731 |
|
// }; |
1732 |
|
// // |
1733 |
|
// return((ULong64_t)obt); |
1734 |
|
// // |
1735 |
|
// }; |
1736 |
|
|
1737 |
|
// UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
1738 |
|
// // |
1739 |
|
// if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
1740 |
|
// // |
1741 |
|
// if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
1742 |
|
// if ( (pkt_num-16777215) < 0 ){ |
1743 |
|
// return((16777215-pkt_num)); |
1744 |
|
// } else { |
1745 |
|
// return((pkt_num-16777215)); |
1746 |
|
// }; |
1747 |
|
// }; |
1748 |
|
// // |
1749 |
|
// return(pkt_num); |
1750 |
|
// // |
1751 |
|
// }; |
1752 |
|
|
1753 |
/* |
/* |
1754 |
* |
* |
1755 |
* Convert the time in the DB from UInt_t to a string |
* Convert the time in the DB from UInt_t to a string |
1758 |
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
1759 |
* |
* |
1760 |
*/ |
*/ |
1761 |
TString GL_TIMESYNC::ConvertTime(TString tzone, UInt_t dbt){ |
TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){ |
1762 |
// |
// |
1763 |
TDatime *time = new TDatime(); |
Int_t offset = 0; |
1764 |
TString rtime; |
TString rtime; |
1765 |
|
Bool_t found = false; |
1766 |
// |
// |
1767 |
time->Set(dbt,false); // MSK = Moscow Winter Time |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
|
// |
|
|
if ( !strcmp(tzone.Data(),"UTC") || !strcmp(tzone.Data(),"GMT") ){ |
|
1768 |
// |
// |
1769 |
UInt_t timeUTC = time->Convert() - 60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3 hs |
offset = 60*60*3; // UTC (Coordinated Universal Time) + 3hs = Moscow Winter Time |
1770 |
time->Set(timeUTC,false); |
found = true; |
1771 |
// |
// |
1772 |
}; |
}; |
1773 |
// |
// |
1774 |
if ( !strcmp(tzone.Data(),"CET") ){ |
if ( !strcmp(tzone.Data(),"CET") ){ |
1775 |
// |
// |
1776 |
UInt_t timeCET = time->Convert() - 60*60*2; // CET (Central European Time) = Moscow Winter Time - 2 hs |
offset = 60*60*1; // CET (Central European Time) = UTC + 1 hs |
1777 |
time->Set(timeCET,false); |
found = true; |
1778 |
// |
// |
1779 |
}; |
}; |
1780 |
// |
// |
1781 |
if ( !strcmp(tzone.Data(),"CEST") ){ |
if ( !strcmp(tzone.Data(),"CEST") ){ |
1782 |
// |
// |
1783 |
UInt_t timeCEST = time->Convert() - 60*60*1; // CEST (Central European Summer Time) = Moscow Winter Time - 1 h |
offset = 60*60*2; // CEST (Central European Summer Time) = UTC + 2 h |
1784 |
time->Set(timeCEST,false); |
found = true; |
1785 |
// |
// |
1786 |
}; |
}; |
1787 |
// |
// |
1788 |
if ( !strcmp(tzone.Data(),"MSD") ){ |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){ |
1789 |
// |
// |
1790 |
UInt_t timeMSD = time->Convert() + 60*60*1; // MSD (Moscow Summer Time) = Moscow Winter Time + 1 h |
offset = 60*60*4; // MSD (Moscow Summer Time) = UTC + 4 h |
1791 |
time->Set(timeMSD,false); |
found = true; |
1792 |
// |
// |
1793 |
}; |
}; |
1794 |
// |
// |
1795 |
rtime = time->AsSQLString(); |
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
1796 |
|
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
1797 |
|
tzone = "UTC"; |
1798 |
|
}; |
1799 |
|
// |
1800 |
|
dbt += offset; |
1801 |
|
// |
1802 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
1803 |
|
// |
1804 |
|
rtime = time->AsString("s"); |
1805 |
|
// |
1806 |
|
delete time; |
1807 |
// |
// |
1808 |
return(rtime); |
return(rtime); |
1809 |
} |
} |
1810 |
|
|
1811 |
/* |
/* |
1812 |
* |
* |
1813 |
* Convert the time in the DB from UInt_t to a string |
* Convert the time from TZONE to UTC |
1814 |
* |
* |
1815 |
* @param dbt time in the DB |
* @param dbt time in the DB |
1816 |
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
1817 |
* |
* |
1818 |
*/ |
*/ |
1819 |
TString GL_TIMESYNC::UnConvertTime(TString tzone, UInt_t dbt){ |
TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){ |
1820 |
// |
// |
1821 |
TDatime *time = new TDatime(); |
Int_t offset = 0; |
1822 |
TString rtime; |
TString rtime; |
1823 |
// |
// |
1824 |
time->Set(dbt,false); // MSK = Moscow Winter Time |
Bool_t found = false; |
1825 |
// |
// |
1826 |
if ( !strcmp(tzone.Data(),"UTC") || !strcmp(tzone.Data(),"GMT") ){ |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
1827 |
// |
// |
1828 |
UInt_t timeUTC = time->Convert() + 60*60*3; // UTC (Coordinated Universal Time) +3 hs = Moscow Winter Time |
offset = -60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3hs |
1829 |
time->Set(timeUTC,false); |
found = true; |
1830 |
// |
// |
1831 |
}; |
}; |
1832 |
// |
// |
1833 |
if ( !strcmp(tzone.Data(),"CET") ){ |
if ( !strcmp(tzone.Data(),"CET") ){ |
1834 |
// |
// |
1835 |
UInt_t timeCET = time->Convert() + 60*60*2; // CET (Central European Time) + 2 hs = Moscow Winter Time |
offset = -60*60*1; // CET (Central European Time) - 1 hs = UTC |
1836 |
time->Set(timeCET,false); |
found = true; |
1837 |
// |
// |
1838 |
}; |
}; |
1839 |
// |
// |
1840 |
if ( !strcmp(tzone.Data(),"CEST") ){ |
if ( !strcmp(tzone.Data(),"CEST") ){ |
1841 |
// |
// |
1842 |
UInt_t timeCEST = time->Convert() + 60*60*1; // CEST (Central European Summer Time) + 1 h = Moscow Winter Time |
offset = -60*60*2; // CEST (Central European Summer Time) - 2 h = UTC |
1843 |
time->Set(timeCEST,false); |
found = true; |
1844 |
// |
// |
1845 |
}; |
}; |
1846 |
// |
// |
1847 |
if ( !strcmp(tzone.Data(),"MSD") ){ |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){ |
1848 |
|
// |
1849 |
|
offset = -60*60*4; // MSD (Moscow Summer Time) - 4 h = UTC |
1850 |
|
found = true; |
1851 |
// |
// |
1852 |
UInt_t timeMSD = time->Convert() - 60*60*1; // MSD (Moscow Summer Time) - 1 h = Moscow Winter Time |
}; |
1853 |
time->Set(timeMSD,false); |
// |
1854 |
|
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
1855 |
// |
// |
1856 |
|
offset = 0; |
1857 |
|
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
1858 |
|
tzone = "UTC"; |
1859 |
}; |
}; |
1860 |
// |
// |
1861 |
rtime = time->AsSQLString(); |
dbt += offset; |
1862 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
1863 |
|
// |
1864 |
|
rtime = time->AsString("s"); |
1865 |
// |
// |
1866 |
return(rtime); |
return(rtime); |
1867 |
} |
} |
1868 |
|
|
1869 |
|
|
1870 |
|
// |
1871 |
|
// Build a query and call DoQuery. |
1872 |
|
// |
1873 |
|
// date it's an SQL datetime date and dbc is the connection to be |
1874 |
|
// used. It will query for the tle with the nearest but previous date |
1875 |
|
// and the immediatly next one. |
1876 |
|
// |
1877 |
|
Int_t GL_TLE::Query(TString date, TSQLServer *dbc){ |
1878 |
|
stringstream myquery; |
1879 |
|
myquery.str(""); |
1880 |
|
|
1881 |
|
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1882 |
|
<< "WHERE FROM_TIME <= '" << date.Data() |
1883 |
|
<< "' ORDER BY FROM_TIME DESC LIMIT 1) " |
1884 |
|
<< "UNION " |
1885 |
|
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1886 |
|
<< "WHERE FROM_TIME > '" << date.Data() |
1887 |
|
<< "' ORDER BY FROM_TIME ASC LIMIT 1)"; |
1888 |
|
|
1889 |
|
return DoQuery(myquery.str().c_str(), dbc); |
1890 |
|
} |
1891 |
|
|
1892 |
|
|
1893 |
|
// |
1894 |
|
// Build a query and call DoQuery. |
1895 |
|
// |
1896 |
|
// time is the UTC date in unix time (UTC) and dbc is the connection |
1897 |
|
// to be used. It will query for the tle with the nearest but |
1898 |
|
// previous date and the immediatly next one. |
1899 |
|
// |
1900 |
|
// Returns the value returned by DoQuery(). |
1901 |
|
// |
1902 |
|
Int_t GL_TLE::Query(UInt_t time, TSQLServer *dbc){ |
1903 |
|
stringstream myquery; |
1904 |
|
myquery.str(""); |
1905 |
|
|
1906 |
|
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1907 |
|
<< "WHERE FROM_TIME <= FROM_UNIXTIME('" << time |
1908 |
|
<< "') ORDER BY FROM_TIME DESC LIMIT 1) " |
1909 |
|
<< "UNION " |
1910 |
|
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1911 |
|
<< "WHERE FROM_TIME > FROM_UNIXTIME('" << time |
1912 |
|
<< "') ORDER BY FROM_TIME ASC LIMIT 1)"; |
1913 |
|
|
1914 |
|
return DoQuery(myquery.str().c_str(), dbc); |
1915 |
|
} |
1916 |
|
|
1917 |
|
|
1918 |
|
// |
1919 |
|
// Do the query myquery on the connectio dbc. Initialize tle, |
1920 |
|
// tleFromTime and tleToTime. |
1921 |
|
// |
1922 |
|
// We should have two rows (unless the table is old). From the last |
1923 |
|
// one we only take tleToTime. |
1924 |
|
// |
1925 |
|
// Returns 0 for success, 1 for failure. |
1926 |
|
// |
1927 |
|
Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){ |
1928 |
|
TSQLResult *result; |
1929 |
|
TSQLRow *row; |
1930 |
|
|
1931 |
|
// Set the right time_zone (otherwise horrible things will occur! :) |
1932 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1933 |
|
dbc->Query("SET time_zone = '+0:00'"); |
1934 |
|
|
1935 |
|
// Do the query |
1936 |
|
this->GetGLTABLES()->AddQ(); |
1937 |
|
result = dbc->Query(myquery.Data()); |
1938 |
|
if(! result->GetRowCount() ) { |
1939 |
|
cerr << "GL_TLE: query failed: " << myquery.Data() << endl; |
1940 |
|
return 1; |
1941 |
|
} |
1942 |
|
|
1943 |
|
// Get results |
1944 |
|
row = result->Next(); // first tle row |
1945 |
|
tle = GiveTle(row); |
1946 |
|
|
1947 |
|
tleFromTime = strtol(row->GetField(4), NULL, 10); |
1948 |
|
|
1949 |
|
row = result->Next(); // second tle row |
1950 |
|
if(row) |
1951 |
|
tleToTime = strtol(row->GetField(4), NULL, 10); |
1952 |
|
else { |
1953 |
|
cerr << "GL_TLE: Warning: using last avaible TLE. Please update GL_TLE table!\n"; |
1954 |
|
tleToTime = UINT_MAX; |
1955 |
|
} |
1956 |
|
|
1957 |
|
delete row; |
1958 |
|
delete result; |
1959 |
|
|
1960 |
|
return 0; |
1961 |
|
} |
1962 |
|
|
1963 |
|
|
1964 |
|
// |
1965 |
|
// Build a cTle object from the GL_TLE row. |
1966 |
|
// |
1967 |
|
cTle* GL_TLE::GiveTle(TSQLRow *row) { |
1968 |
|
cTle *thistle = NULL; |
1969 |
|
string tle1, tle2, tle3; |
1970 |
|
|
1971 |
|
// Build cTle object |
1972 |
|
tle1 = row->GetField(1); |
1973 |
|
tle2 = row->GetField(2); |
1974 |
|
tle3 = row->GetField(3); |
1975 |
|
|
1976 |
|
thistle = new cTle(tle1, tle2, tle3); |
1977 |
|
|
1978 |
|
return thistle; |
1979 |
|
} |