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 |
|
}; |
42 |
|
|
43 |
|
|
44 |
|
void GL_TABLES::Set(TString host, TString user, TString psw){ |
45 |
|
fHost = new TString(host.Data()); |
46 |
|
fUser = new TString(user.Data()); |
47 |
|
fPsw = new TString(psw.Data()); |
48 |
|
fSet = true; |
49 |
|
fNquery = 0; |
50 |
|
}; |
51 |
|
|
52 |
|
Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
53 |
|
// |
54 |
|
// |
55 |
|
// |
56 |
|
if ( !fSet ){ |
57 |
|
return true; |
58 |
|
}; |
59 |
|
// |
60 |
|
// |
61 |
|
// |
62 |
|
// printf(" host is %s \n",fHost->Data()); |
63 |
|
// |
64 |
|
stringstream myquery; |
65 |
|
myquery.str(""); |
66 |
|
myquery << "show databases;"; |
67 |
|
if ( dbc ){ |
68 |
|
if ( dbc->IsConnected() ){ |
69 |
|
dbc->Query(myquery.str().c_str()); |
70 |
|
fNquery++; |
71 |
|
if ( !(dbc->GetErrorCode()) ){ |
72 |
|
// printf("ok\n"); |
73 |
|
// |
74 |
|
// if ( (dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006) ){ |
75 |
|
// if ( !(dbc->GetErrorCode()) ){ |
76 |
|
// is connected |
77 |
|
return true; |
78 |
|
// }; |
79 |
|
}; |
80 |
|
}; |
81 |
|
}; |
82 |
|
// printf("porca di quella \n"); |
83 |
|
if ( true ) { |
84 |
|
// |
85 |
|
printf(" WARNING: Lost connection to DB! try to recover... \n"); |
86 |
|
// |
87 |
|
TString host = fHost->Data(); |
88 |
|
TString user = fUser->Data(); |
89 |
|
TString psw = fPsw->Data(); |
90 |
|
delete dbc; |
91 |
|
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
92 |
|
// |
93 |
|
myquery.str(""); |
94 |
|
myquery << "show databases;"; |
95 |
|
dbc->Query(myquery.str().c_str()); |
96 |
|
fNquery++; |
97 |
|
// printf(" e riporca di quella \n"); |
98 |
|
// |
99 |
|
// if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ |
100 |
|
if ( !(dbc->GetErrorCode()) ){ |
101 |
|
// |
102 |
|
printf(" ...connection recovered, I can continue! \n"); |
103 |
|
// |
104 |
|
myquery.str(""); |
105 |
|
myquery << "SET time_zone='+0:00'"; |
106 |
|
dbc->Query(myquery.str().c_str()); |
107 |
|
fNquery++; |
108 |
|
myquery.str(""); |
109 |
|
myquery << "SET wait_timeout=173000;"; |
110 |
|
dbc->Query(myquery.str().c_str()); |
111 |
|
fNquery++; |
112 |
|
return true; |
113 |
|
}; |
114 |
|
}; |
115 |
|
// |
116 |
|
printf(" GLTABLES: connection is gone away, query will fail\n"); |
117 |
|
// |
118 |
|
return false; |
119 |
|
// |
120 |
|
}; |
121 |
|
|
122 |
|
void GL_TABLES::ResetCounters(){ |
123 |
|
fNquery = 0; |
124 |
|
}; |
125 |
|
|
126 |
|
void GL_TABLES::AddQ(){ |
127 |
|
if ( fSet ) fNquery++; |
128 |
|
}; |
129 |
|
|
130 |
|
UInt_t GL_TABLES::GetNqueries(){ |
131 |
|
UInt_t rn = 0; |
132 |
|
rn += (UInt_t&)fNquery; |
133 |
|
return(rn); |
134 |
|
}; |
135 |
|
|
136 |
GL_RUN::GL_RUN() { |
GL_RUN::GL_RUN() { |
137 |
ID = 0; |
ID = 0; |
138 |
ID_RUN_FRAG = 0; |
ID_RUN_FRAG = 0; |
167 |
VALIDATION = 0; |
VALIDATION = 0; |
168 |
} |
} |
169 |
|
|
170 |
|
|
171 |
void GL_RUN::Clear() { |
void GL_RUN::Clear() { |
172 |
ID = 0; |
ID = 0; |
173 |
ID_RUN_FRAG = 0; |
ID_RUN_FRAG = 0; |
232 |
OBT2 = 0; |
OBT2 = 0; |
233 |
PKT1 = 0; |
PKT1 = 0; |
234 |
PKT2 = 0; |
PKT2 = 0; |
235 |
|
BOOT_NUMBER = 0; |
236 |
|
VALIDATION = 0; |
237 |
} |
} |
238 |
|
|
239 |
GL_CALO_CALIB::GL_CALO_CALIB(){ |
GL_CALO_CALIB::GL_CALO_CALIB(){ |
259 |
obtfirst = 0; |
obtfirst = 0; |
260 |
pktfirst = 0; |
pktfirst = 0; |
261 |
toffset = 0; |
toffset = 0; |
262 |
ID = 0; |
// ID = 0; |
263 |
ID_RAW = 0; |
// ID_RAW = 0; |
264 |
OBT0 = 0; |
OBT0 = 0; |
265 |
TIMESYNC = 0; |
TIMESYNC = 0; |
266 |
TYPE = 0; |
TYPE = 0; |
267 |
}// **************************************************** |
} |
268 |
|
|
269 |
|
// **************************************************** |
270 |
|
|
271 |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
272 |
EV_FROM = evfrom; |
EV_FROM = evfrom; |
440 |
CAL_DSP_MASK = 0; |
CAL_DSP_MASK = 0; |
441 |
}; |
}; |
442 |
|
|
443 |
|
void GL_RUN::Set_GL_RUN(TSQLRow *Row){ |
444 |
|
for( Int_t t = 0; t < 30; t++){ |
445 |
|
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
446 |
|
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
447 |
|
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
448 |
|
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
449 |
|
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
450 |
|
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
451 |
|
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
452 |
|
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
453 |
|
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
454 |
|
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
455 |
|
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
456 |
|
if (t==11) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
457 |
|
if (t==12) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
458 |
|
if (t==13) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
459 |
|
if (t==14) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
460 |
|
if (t==15) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
461 |
|
if (t==16) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
462 |
|
if (t==17) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
463 |
|
if (t==18) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
464 |
|
if (t==19) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
465 |
|
if (t==20) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
466 |
|
if (t==21) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
467 |
|
if (t==22) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
468 |
|
if (t==23) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
469 |
|
if (t==24) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
470 |
|
if (t==25) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
471 |
|
if (t==26) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
472 |
|
if (t==27) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
473 |
|
if (t==28) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
474 |
|
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
475 |
|
}; |
476 |
|
|
477 |
|
} |
478 |
|
|
479 |
|
/** |
480 |
|
* This method delete the run from the "FromTable" table and store it in the GL_RUN_TRASH table |
481 |
|
* If IDRUN is 0 "this->ID" run is used. |
482 |
|
* |
483 |
|
**/ |
484 |
|
Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ |
485 |
|
// MySQL variables |
486 |
|
TSQLResult *pResult; |
487 |
|
TSQLRow *Row; |
488 |
|
stringstream myquery; |
489 |
|
// |
490 |
|
if ( !IDRUN ) IDRUN = ID; |
491 |
|
if ( !IDRUN ) return 1; |
492 |
|
// ---------------- |
493 |
|
myquery.str(""); |
494 |
|
myquery << " INSERT INTO GL_RUN_TRASH ("; |
495 |
|
myquery << "ID"; |
496 |
|
myquery << ",ID_RUN_FRAG"; |
497 |
|
myquery << ",ID_ROOT_L0"; |
498 |
|
myquery << ",ID_ROOT_L2"; |
499 |
|
myquery << ",RUNHEADER_TIME"; |
500 |
|
myquery << ",RUNTRAILER_TIME"; |
501 |
|
myquery << ",RUNHEADER_OBT"; |
502 |
|
myquery << ",RUNTRAILER_OBT"; |
503 |
|
myquery << ",RUNHEADER_PKT"; |
504 |
|
myquery << ",RUNTRAILER_PKT"; |
505 |
|
myquery << ",BOOT_NUMBER"; |
506 |
|
myquery << ",EV_FROM"; |
507 |
|
myquery << ",EV_TO"; |
508 |
|
myquery << ",NEVENTS"; |
509 |
|
myquery << ",PKT_COUNTER"; |
510 |
|
myquery << ",PKT_READY_COUNTER"; |
511 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
512 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
513 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
514 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
515 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
516 |
|
myquery << ",ACQ_BUILD_INFO"; |
517 |
|
myquery << ",ACQ_VAR_INFO"; |
518 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
519 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
520 |
|
myquery << ",TRK_CALIB_USED"; |
521 |
|
myquery << ",CAL_DSP_MASK"; |
522 |
|
myquery << ",LAST_TIMESYNC"; |
523 |
|
myquery << ",OBT_TIMESYNC"; |
524 |
|
myquery << ",VALIDATION"; |
525 |
|
myquery << ",INSERT_TIME"; |
526 |
|
myquery << ") SELECT * FROM "; |
527 |
|
myquery << FromTable.Data(); |
528 |
|
myquery << " WHERE ID="; |
529 |
|
myquery << (UInt_t)IDRUN << ";"; |
530 |
|
// |
531 |
|
// printf("1myquery is %s \n",myquery.str().c_str()); |
532 |
|
// |
533 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
534 |
|
this->GetGLTABLES()->AddQ(); |
535 |
|
dbc->Query(myquery.str().c_str()); |
536 |
|
// |
537 |
|
// retrieve this ID_TRASH |
538 |
|
// |
539 |
|
myquery.str(""); |
540 |
|
myquery << " SELECT ID_TRASH,ID_ROOT_L0,ID_ROOT_L2 FROM GL_RUN_TRASH ORDER BY ID_TRASH DESC LIMIT 1"; |
541 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
542 |
|
this->GetGLTABLES()->AddQ(); |
543 |
|
pResult = dbc->Query(myquery.str().c_str()); |
544 |
|
// |
545 |
|
UInt_t idtrash = 0; |
546 |
|
UInt_t idl0 = 0; |
547 |
|
UInt_t idl2 = 0; |
548 |
|
// |
549 |
|
Row = pResult->Next(); |
550 |
|
if( Row != NULL ){ |
551 |
|
idtrash = (UInt_t)atoll(Row->GetField(0)); |
552 |
|
idl0 = (UInt_t)atoll(Row->GetField(1)); |
553 |
|
idl2 = (UInt_t)atoll(Row->GetField(2)); |
554 |
|
}; |
555 |
|
// |
556 |
|
TString fileL0 = ""; |
557 |
|
TString fileL2 = ""; |
558 |
|
myquery.str(""); |
559 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
560 |
|
myquery << idl0 << ";"; |
561 |
|
// |
562 |
|
// printf("2myquery is %s \n",myquery.str().c_str()); |
563 |
|
// |
564 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
565 |
|
this->GetGLTABLES()->AddQ(); |
566 |
|
pResult = dbc->Query(myquery.str().c_str()); |
567 |
|
// |
568 |
|
Row = pResult->Next(); |
569 |
|
if( Row != NULL ){ |
570 |
|
fileL0 = (TString)Row->GetField(0); |
571 |
|
}; |
572 |
|
// |
573 |
|
// |
574 |
|
// |
575 |
|
myquery.str(""); |
576 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
577 |
|
myquery << idl2 << ";"; |
578 |
|
// |
579 |
|
// printf("3myquery is %s \n",myquery.str().c_str()); |
580 |
|
// |
581 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
582 |
|
this->GetGLTABLES()->AddQ(); |
583 |
|
pResult = dbc->Query(myquery.str().c_str()); |
584 |
|
// |
585 |
|
Row = pResult->Next(); |
586 |
|
if( Row != NULL ){ |
587 |
|
fileL2 = (TString)Row->GetField(0); |
588 |
|
}; |
589 |
|
// |
590 |
|
// |
591 |
|
// |
592 |
|
myquery.str(""); |
593 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL0='"; |
594 |
|
myquery << fileL0.Data() << "' where ID_TRASH="; |
595 |
|
myquery << idtrash << ";"; |
596 |
|
// |
597 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
598 |
|
// |
599 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
600 |
|
this->GetGLTABLES()->AddQ(); |
601 |
|
dbc->Query(myquery.str().c_str()); |
602 |
|
// |
603 |
|
myquery.str(""); |
604 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='"; |
605 |
|
myquery << fileL2.Data() << "' where ID_TRASH="; |
606 |
|
myquery << idtrash << ";"; |
607 |
|
// |
608 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
609 |
|
// |
610 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
611 |
|
this->GetGLTABLES()->AddQ(); |
612 |
|
dbc->Query(myquery.str().c_str()); |
613 |
|
// |
614 |
|
myquery.str(""); |
615 |
|
myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='"; |
616 |
|
myquery << FromTable.Data() << "' where ID_TRASH="; |
617 |
|
myquery << idtrash << ";"; |
618 |
|
// |
619 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
620 |
|
// |
621 |
|
// |
622 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
623 |
|
this->GetGLTABLES()->AddQ(); |
624 |
|
dbc->Query(myquery.str().c_str()); |
625 |
|
// |
626 |
|
myquery.str(""); |
627 |
|
myquery << " DELETE FROM "; |
628 |
|
myquery << FromTable.Data() << " where ID="; |
629 |
|
myquery << IDRUN << ";"; |
630 |
|
// |
631 |
|
// printf("5myquery is %s \n",myquery.str().c_str()); |
632 |
|
// |
633 |
|
// |
634 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
635 |
|
this->GetGLTABLES()->AddQ(); |
636 |
|
dbc->Query(myquery.str().c_str()); |
637 |
|
// |
638 |
|
return 0; |
639 |
|
}; |
640 |
|
|
641 |
|
|
642 |
|
|
643 |
|
/** |
644 |
|
* This method restore a run from the GL_RUN_TRASH table. |
645 |
|
* If ID is 0 "this->ID" is used; if "ToTable" is empty BELONG_TO field of GL_RUN_TRASH is used. |
646 |
|
* |
647 |
|
**/ |
648 |
|
Int_t GL_RUN::RestoreRun(TSQLServer *dbc,UInt_t IDRUN,TString ToTable){ |
649 |
|
// insert into GL_RUN_FRAGMENTS select * FROM GL_RUN where ID=11; |
650 |
|
//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; |
651 |
|
// MySQL variables |
652 |
|
TSQLResult *pResult; |
653 |
|
TSQLRow *Row; |
654 |
|
stringstream myquery; |
655 |
|
// |
656 |
|
if ( !IDRUN ) IDRUN = ID; |
657 |
|
if ( !IDRUN ) return 1; |
658 |
|
// |
659 |
|
if ( !strcmp(ToTable.Data(),"") ){ |
660 |
|
// |
661 |
|
myquery.str(""); |
662 |
|
myquery << " SELECT BELONGED_TO FROM GL_RUN_TRASH WHERE ID="; |
663 |
|
myquery << (UInt_t)IDRUN << ";"; |
664 |
|
// |
665 |
|
printf(" qui? myquery is %s \n",myquery.str().c_str()); |
666 |
|
// |
667 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
668 |
|
this->GetGLTABLES()->AddQ(); |
669 |
|
pResult = dbc->Query(myquery.str().c_str()); |
670 |
|
// |
671 |
|
Row = pResult->Next(); |
672 |
|
if( Row != NULL ){ |
673 |
|
ToTable = (TString)Row->GetField(0); |
674 |
|
} else { |
675 |
|
return 1; |
676 |
|
}; |
677 |
|
}; |
678 |
|
// ---------------- |
679 |
|
myquery.str(""); |
680 |
|
myquery << " INSERT INTO "; |
681 |
|
myquery << ToTable.Data(); |
682 |
|
myquery << " ("; |
683 |
|
myquery << "ID"; |
684 |
|
myquery << ",ID_RUN_FRAG"; |
685 |
|
myquery << ",ID_ROOT_L0"; |
686 |
|
myquery << ",ID_ROOT_L2"; |
687 |
|
myquery << ",RUNHEADER_TIME"; |
688 |
|
myquery << ",RUNTRAILER_TIME"; |
689 |
|
myquery << ",RUNHEADER_OBT"; |
690 |
|
myquery << ",RUNTRAILER_OBT"; |
691 |
|
myquery << ",RUNHEADER_PKT"; |
692 |
|
myquery << ",RUNTRAILER_PKT"; |
693 |
|
myquery << ",BOOT_NUMBER"; |
694 |
|
myquery << ",EV_FROM"; |
695 |
|
myquery << ",EV_TO"; |
696 |
|
myquery << ",NEVENTS"; |
697 |
|
myquery << ",PKT_COUNTER"; |
698 |
|
myquery << ",PKT_READY_COUNTER"; |
699 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
700 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
701 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
702 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
703 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
704 |
|
myquery << ",ACQ_BUILD_INFO"; |
705 |
|
myquery << ",ACQ_VAR_INFO"; |
706 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
707 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
708 |
|
myquery << ",TRK_CALIB_USED"; |
709 |
|
myquery << ",CAL_DSP_MASK"; |
710 |
|
myquery << ",LAST_TIMESYNC"; |
711 |
|
myquery << ",OBT_TIMESYNC"; |
712 |
|
myquery << ",VALIDATION"; |
713 |
|
myquery << ",INSERT_TIME"; |
714 |
|
myquery << ") SELECT "; |
715 |
|
myquery << "ID"; |
716 |
|
myquery << ",ID_RUN_FRAG"; |
717 |
|
myquery << ",ID_ROOT_L0"; |
718 |
|
myquery << ",ID_ROOT_L2"; |
719 |
|
myquery << ",RUNHEADER_TIME"; |
720 |
|
myquery << ",RUNTRAILER_TIME"; |
721 |
|
myquery << ",RUNHEADER_OBT"; |
722 |
|
myquery << ",RUNTRAILER_OBT"; |
723 |
|
myquery << ",RUNHEADER_PKT"; |
724 |
|
myquery << ",RUNTRAILER_PKT"; |
725 |
|
myquery << ",BOOT_NUMBER"; |
726 |
|
myquery << ",EV_FROM"; |
727 |
|
myquery << ",EV_TO"; |
728 |
|
myquery << ",NEVENTS"; |
729 |
|
myquery << ",PKT_COUNTER"; |
730 |
|
myquery << ",PKT_READY_COUNTER"; |
731 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
732 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
733 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
734 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
735 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
736 |
|
myquery << ",ACQ_BUILD_INFO"; |
737 |
|
myquery << ",ACQ_VAR_INFO"; |
738 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
739 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
740 |
|
myquery << ",TRK_CALIB_USED"; |
741 |
|
myquery << ",CAL_DSP_MASK"; |
742 |
|
myquery << ",LAST_TIMESYNC"; |
743 |
|
myquery << ",OBT_TIMESYNC"; |
744 |
|
myquery << ",VALIDATION"; |
745 |
|
myquery << ",INSERT_TIME"; |
746 |
|
myquery << " FROM GL_RUN_TRASH "; |
747 |
|
myquery << " WHERE BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
748 |
|
myquery << (UInt_t)IDRUN << ";"; |
749 |
|
// |
750 |
|
// printf("5myquery is %s \n",myquery.str().c_str()); |
751 |
|
// |
752 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
753 |
|
this->GetGLTABLES()->AddQ(); |
754 |
|
dbc->Query(myquery.str().c_str()); |
755 |
|
// |
756 |
|
// |
757 |
|
myquery.str(""); |
758 |
|
myquery << " DELETE FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
759 |
|
myquery << IDRUN << ";"; |
760 |
|
// |
761 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
762 |
|
this->GetGLTABLES()->AddQ(); |
763 |
|
dbc->Query(myquery.str().c_str()); |
764 |
|
// |
765 |
|
return 0; |
766 |
|
}; |
767 |
|
|
768 |
/** |
/** |
769 |
* Function to fill the GL_RUN table of the DB. |
* Function to fill the GL_RUN table of the DB. |
842 |
// |
// |
843 |
// printf("myquery is %s \n",myquery.str().c_str()); |
// printf("myquery is %s \n",myquery.str().c_str()); |
844 |
// |
// |
845 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
846 |
|
this->GetGLTABLES()->AddQ(); |
847 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
848 |
// |
// |
849 |
return 0; |
return 0; |
920 |
// |
// |
921 |
// printf("myquery is %s \n",myquery.str().c_str()); |
// printf("myquery is %s \n",myquery.str().c_str()); |
922 |
// |
// |
923 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
924 |
|
this->GetGLTABLES()->AddQ(); |
925 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
926 |
// |
// |
927 |
return 0; |
return 0; |
978 |
myquery << ",VALIDATION"; |
myquery << ",VALIDATION"; |
979 |
myquery << " from GL_RUN where ID=" << run << ";"; |
myquery << " from GL_RUN where ID=" << run << ";"; |
980 |
// |
// |
981 |
|
// printf(" myquery is %s \n",myquery.str().c_str()); |
982 |
|
if ( !this->IsConnected(dbc) ) return -57; |
983 |
|
this->AddQ(); |
984 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
985 |
if(!pResult->GetRowCount())return(-50); |
// |
986 |
|
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
987 |
|
// |
988 |
|
if( !pResult->GetRowCount() ) return(-50); |
989 |
|
// |
990 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
991 |
Row = pResult->Next(); |
Row = pResult->Next(); |
992 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
993 |
|
// Set_GL_RUN(Row); |
994 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
995 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
996 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
997 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
998 |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
999 |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
1000 |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
1001 |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
1002 |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
1003 |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
1004 |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
1005 |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
1006 |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
1007 |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
1008 |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1009 |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1010 |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
1011 |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
1012 |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
1013 |
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)); |
1014 |
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)); |
1015 |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
1016 |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
1017 |
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)); |
1018 |
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)); |
1019 |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
1020 |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
1021 |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
1022 |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
1023 |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
1024 |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
|
|
|
|
|
|
1025 |
}; |
}; |
1026 |
}; |
}; |
1027 |
delete pResult; |
// delete pResult; |
1028 |
|
return(0); |
|
return 0; |
|
|
|
|
1029 |
}; |
}; |
1030 |
|
|
1031 |
/** |
/** |
1079 |
// |
// |
1080 |
// printf(" query is %s \n",myquery.str().c_str()); |
// printf(" query is %s \n",myquery.str().c_str()); |
1081 |
// |
// |
1082 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1083 |
|
this->GetGLTABLES()->AddQ(); |
1084 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1085 |
if(!pResult->GetRowCount())return(-50); |
if(!pResult->GetRowCount())return(-50); |
1086 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1146 |
myquery << ",NAME"; |
myquery << ",NAME"; |
1147 |
myquery << " from GL_ROOT where ID=" << id << ";"; |
myquery << " from GL_ROOT where ID=" << id << ";"; |
1148 |
// |
// |
1149 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1150 |
|
this->GetGLTABLES()->AddQ(); |
1151 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1152 |
if(!pResult->GetRowCount())return (-51); |
if(!pResult->GetRowCount())return (-51); |
1153 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1157 |
if(t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if(t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1158 |
if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t)); |
if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t)); |
1159 |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1160 |
if(t==3) PATH = Row->GetField(t); |
if(t==3) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/'; |
1161 |
if(t==4) NAME = Row->GetField(t); |
if(t==4) NAME = Row->GetField(t); |
1162 |
}; |
}; |
1163 |
}; |
}; |
1169 |
* Function to query the GL_TRK_CALIB table of the DB. |
* Function to query the GL_TRK_CALIB table of the DB. |
1170 |
* |
* |
1171 |
* \param run starting time |
* \param run starting time |
1172 |
|
* \param dbc DB server |
1173 |
* \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 |
1174 |
*/ |
*/ |
1175 |
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){ |
1181 |
stringstream myquery; |
stringstream myquery; |
1182 |
// ---------------- |
// ---------------- |
1183 |
myquery.str(""); |
myquery.str(""); |
1184 |
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; |
1185 |
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!!! |
1186 |
|
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 |
1187 |
|
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1188 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1189 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1190 |
|
this->GetGLTABLES()->AddQ(); |
1191 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1192 |
if(!pResult->GetRowCount())return (-53); |
if(!pResult->GetRowCount())return (-53); |
1193 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1197 |
stringstream row; |
stringstream row; |
1198 |
row.str(""); |
row.str(""); |
1199 |
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 |
1200 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1201 |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1202 |
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()); |
1203 |
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()); |
1204 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1205 |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
1206 |
// |
// |
1207 |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
1208 |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
1209 |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
1210 |
if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t)); |
if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t)); |
1211 |
}; |
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
1212 |
|
if (t==11) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
1213 |
|
}; |
1214 |
}; |
}; |
1215 |
delete pResult; |
delete pResult; |
1216 |
|
// |
1217 |
|
// if ( TO_TIME < time ) return(51); |
1218 |
// |
// |
|
if(TO_TIME < time)return(51); |
|
1219 |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
1220 |
// |
// |
1221 |
return 0; |
return 0; |
1228 |
* \param run starting time |
* \param run starting time |
1229 |
* \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 |
1230 |
*/ |
*/ |
1231 |
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){ |
1232 |
// MySQL variables |
// MySQL variables |
1233 |
TSQLResult *pResult; |
TSQLResult *pResult; |
1234 |
TSQLRow *Row; |
TSQLRow *Row; |
1235 |
int t; |
int t; |
1236 |
stringstream myquery; |
stringstream myquery; |
1237 |
|
uptime = 0; |
1238 |
// |
// |
1239 |
// select the correct calibration |
// select the correct calibration |
1240 |
// |
// |
1242 |
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; |
1243 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1244 |
myquery << " and TO_TIME > " << time; |
myquery << " and TO_TIME > " << time; |
1245 |
myquery << " and VALIDATION=1;"; |
myquery << " ;"; |
1246 |
|
//myquery << " and VALIDATION=1;"; |
1247 |
// |
// |
1248 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1249 |
|
this->GetGLTABLES()->AddQ(); |
1250 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1251 |
|
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1252 |
|
// |
1253 |
|
if( !pResult->GetRowCount() ) return(-54); |
1254 |
|
Row = pResult->Next(); |
1255 |
|
if( Row == NULL ) return (-54); |
1256 |
|
// |
1257 |
|
uptime = (UInt_t)atoll(Row->GetField(2)); |
1258 |
// |
// |
1259 |
// 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... |
1260 |
// |
// |
1261 |
if( !pResult->GetRowCount() ){ |
if( atoi(Row->GetField(4)) == 0 ){ // if validation = 0 |
|
// pResult->Delete(); |
|
1262 |
// |
// |
1263 |
// 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 |
1264 |
// |
// |
1266 |
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; |
1267 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1268 |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
1269 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1270 |
|
this->GetGLTABLES()->AddQ(); |
1271 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1272 |
|
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1273 |
// |
// |
1274 |
// if no results yet quit with error |
// if no results yet quit with error |
1275 |
// |
// |
1276 |
if( !pResult->GetRowCount() ) return (-54); |
if( !pResult->GetRowCount() ) return (-54); |
1277 |
|
// |
1278 |
|
Row = pResult->Next(); |
1279 |
|
// |
1280 |
}; |
}; |
1281 |
// |
// |
1282 |
// store infos and exit |
// store infos and exit |
1283 |
// |
// |
|
Row = pResult->Next(); |
|
1284 |
if( Row == NULL ) return (-54); |
if( Row == NULL ) return (-54); |
1285 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1286 |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1308 |
// ---------------- |
// ---------------- |
1309 |
myquery.str(""); |
myquery.str(""); |
1310 |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
1311 |
myquery << " AND VALIDATION = 1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1312 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1313 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1314 |
|
this->GetGLTABLES()->AddQ(); |
1315 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1316 |
if(!pResult->GetRowCount())return (-55);//throw -55; |
if(!pResult->GetRowCount())return (-55);//throw -55; |
1317 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1352 |
// ---------------- |
// ---------------- |
1353 |
myquery.str(""); |
myquery.str(""); |
1354 |
myquery << " select "; |
myquery << " select "; |
1355 |
myquery << " ID, PATH, NAME, DESCR, TYPE, FROM_TIME,TO_TIME "; |
myquery << " ID, PATH, NAME, DESCR, FROM_TIME,TO_TIME, TYPE "; |
1356 |
myquery << " from GL_PARAM "; |
myquery << " from GL_PARAM "; |
1357 |
myquery << " where TYPE = '"<<type<<"' "; |
myquery << " where TYPE = '"<<type<<"' "; |
1358 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1359 |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
1360 |
// |
// |
1361 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1362 |
|
this->GetGLTABLES()->AddQ(); |
1363 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1364 |
if(!pResult->GetRowCount())return (-52); |
if(!pResult->GetRowCount())return (-52); |
1365 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1367 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
1368 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1369 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1370 |
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 |
1371 |
if (t==2) NAME = Row->GetField(t); |
if (t==2) NAME = Row->GetField(t); |
1372 |
if (t==3) DESCR = Row->GetField(t); |
if (t==3) DESCR = Row->GetField(t); |
1373 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1412 |
TSQLResult *pResult; |
TSQLResult *pResult; |
1413 |
TSQLRow *Row; |
TSQLRow *Row; |
1414 |
stringstream myquery; |
stringstream myquery; |
1415 |
|
stringstream rname; |
1416 |
|
// pcksList packetsNames; |
1417 |
|
// pcksList::iterator Iter; |
1418 |
|
// getPacketsNames(packetsNames); |
1419 |
|
rname.str(""); |
1420 |
// ---------------- |
// ---------------- |
1421 |
myquery.str(""); |
myquery.str(""); |
1422 |
myquery << "select "; |
myquery << "select "; |
1426 |
myquery << type.Data(); |
myquery << type.Data(); |
1427 |
myquery << "=" << id << ";"; |
myquery << "=" << id << ";"; |
1428 |
// |
// |
1429 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1430 |
|
this->GetGLTABLES()->AddQ(); |
1431 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1432 |
if( pResult->GetRowCount() ){ |
if( pResult->GetRowCount() ){ |
1433 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1434 |
if( Row ){ |
if( Row ){ |
1435 |
stringstream fname; |
stringstream fname; |
1436 |
fname.str(""); |
fname.str(""); |
1437 |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
1438 |
|
rname << Row->GetField(1); |
1439 |
file = new TFile(fname.str().c_str(),"READ"); |
file = new TFile(fname.str().c_str(),"READ"); |
1440 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
idraw = (UInt_t)atoll(Row->GetField(2)); |
1441 |
}; |
}; |
1451 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
1452 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
1453 |
obtfirst = ph->GetOrbitalTime(); |
obtfirst = ph->GetOrbitalTime(); |
1454 |
|
// |
1455 |
|
// code = eh->GetCounter(); |
1456 |
|
// UInt_t en = 0; |
1457 |
|
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
1458 |
|
// en = code->Get(GetPacketType(*Iter)); |
1459 |
|
// if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){ |
1460 |
|
// // |
1461 |
|
// TTree *TC = 0; |
1462 |
|
// TC = (TTree*)file->Get("CalibCalPed"); |
1463 |
|
// if ( !TC || TC->IsZombie() ) return; |
1464 |
|
// EventHeader *ehc = 0; |
1465 |
|
// PscuHeader *phc = 0; |
1466 |
|
// TC->SetBranchAddress("Header", &ehc); |
1467 |
|
// TC->GetEntry(0); |
1468 |
|
// phc = ehc->GetPscuHeader(); |
1469 |
|
// pktfirst = phc->GetCounter(); |
1470 |
|
// obtfirst = phc->GetOrbitalTime(); |
1471 |
|
// // |
1472 |
|
// }; |
1473 |
|
// }; |
1474 |
|
// |
1475 |
}; |
}; |
1476 |
// |
// |
1477 |
// look for Resurs offset |
// look for Resurs offset |
1478 |
// |
// |
1479 |
UInt_t t0 = 0; |
T0 = 0; |
1480 |
// |
// |
1481 |
myquery.str(""); |
// |
1482 |
myquery << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= " |
stringstream oss; |
1483 |
<< idraw << " AND TO_ID_RAW >= " |
TString frn = rname.str().c_str(); |
1484 |
<< idraw << ";"; |
frn = frn.ReplaceAll(".root",5,".pam",4); |
1485 |
pResult = dbc->Query(myquery.str().c_str()); |
oss.str(""); |
1486 |
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='" |
1487 |
|
<< frn.Data() << "';"; |
1488 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1489 |
|
this->GetGLTABLES()->AddQ(); |
1490 |
|
pResult = dbc->Query(oss.str().c_str()); |
1491 |
|
Row = pResult->Next(); |
1492 |
|
// |
1493 |
|
TString name=rname.str().c_str(); |
1494 |
|
UInt_t dworbit = 0; |
1495 |
|
Int_t nlength = name.Length(); |
1496 |
|
if ( nlength < 5 ) return; |
1497 |
|
TString dwo = 0; |
1498 |
|
for (Int_t i = 0; i<5; i++){ |
1499 |
|
dwo.Append(name[i],1); |
1500 |
|
}; |
1501 |
|
if ( dwo.IsDigit() ){ |
1502 |
|
dworbit = (UInt_t)dwo.Atoi(); |
1503 |
|
} else { |
1504 |
|
dwo=""; |
1505 |
|
for (Int_t i = 8; i<13; i++){ |
1506 |
|
dwo.Append(name[i],1); |
1507 |
|
}; |
1508 |
|
if ( dwo.IsDigit() ){ |
1509 |
|
dworbit = (UInt_t)dwo.Atoi(); |
1510 |
|
} else { |
1511 |
|
dworbit = 1; |
1512 |
|
}; |
1513 |
|
}; |
1514 |
|
// |
1515 |
|
// |
1516 |
|
if ( !Row ){ |
1517 |
|
oss.str(""); |
1518 |
|
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< " |
1519 |
|
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
1520 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1521 |
|
this->GetGLTABLES()->AddQ(); |
1522 |
|
pResult = dbc->Query(oss.str().c_str()); |
1523 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1524 |
if ( Row ){ |
if ( !Row ){ |
1525 |
// |
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
1526 |
t0 = (UInt_t)TDatime(Row->GetField(0)).Convert(); |
return; |
|
// |
|
1527 |
}; |
}; |
1528 |
}; |
}; |
1529 |
// |
// |
1530 |
|
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); |
1531 |
|
T0 = (UInt_t)tu.GetSec(); |
1532 |
// |
// |
1533 |
// look for the correct timesync entry |
// look for the correct timesync entry |
1534 |
// |
// |
1535 |
myquery.str(""); |
myquery.str(""); |
1536 |
myquery << " SELECT OBT0,TIMESYNC FROM GL_TIMESYNC " |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
1537 |
<< " WHERE ID_RAW = " << idraw |
<< " WHERE ID_RAW = " << idraw |
1538 |
<< ";"; |
<< ";"; |
1539 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1540 |
|
this->GetGLTABLES()->AddQ(); |
1541 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1542 |
if ( pResult ){ |
if ( pResult ){ |
1543 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1544 |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
1545 |
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)); |
1546 |
|
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
1547 |
|
TYPE = (UInt_t)atoll(Row->GetField(2)); |
1548 |
|
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; |
1549 |
}; |
}; |
1550 |
}; |
}; |
1551 |
// |
// |
1564 |
// |
// |
1565 |
}; |
}; |
1566 |
|
|
1567 |
|
/** |
1568 |
|
* |
1569 |
|
* Returns the Resurs time given the OBT needed to process inclination and orbital infos |
1570 |
|
* |
1571 |
|
*/ |
1572 |
|
UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){ |
1573 |
|
// |
1574 |
|
return(((UInt_t)((Int_t)(this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC)); |
1575 |
|
// |
1576 |
|
}; |
1577 |
|
|
1578 |
|
|
1579 |
ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
/** |
1580 |
|
* Return the correct packet number if we went back to zero |
1581 |
|
*/ |
1582 |
|
Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
1583 |
// |
// |
1584 |
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) ){ |
1585 |
|
return((Long64_t)pkt_num+16777215LL); |
1586 |
|
}; |
1587 |
// |
// |
1588 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
1589 |
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())); |
|
|
}; |
|
1590 |
}; |
}; |
1591 |
// |
// |
1592 |
return((ULong64_t)obt); |
return((Long64_t)pkt_num); |
1593 |
// |
// |
1594 |
}; |
}; |
1595 |
|
|
1596 |
UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
/** |
1597 |
|
* Return the correct On Board Time if we went back to zero |
1598 |
|
*/ |
1599 |
|
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1600 |
// |
// |
1601 |
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())); |
1602 |
// |
// |
1603 |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1604 |
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)); |
|
|
}; |
|
1605 |
}; |
}; |
1606 |
// |
// |
1607 |
return(pkt_num); |
return((Long64_t)obt); |
|
// |
|
1608 |
}; |
}; |
1609 |
|
|
1610 |
|
|
1611 |
|
|
1612 |
|
// ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1613 |
|
// // |
1614 |
|
// if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
1615 |
|
// // |
1616 |
|
// if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1617 |
|
// if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
1618 |
|
// return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
1619 |
|
// } else { |
1620 |
|
// return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
1621 |
|
// }; |
1622 |
|
// }; |
1623 |
|
// // |
1624 |
|
// return((ULong64_t)obt); |
1625 |
|
// // |
1626 |
|
// }; |
1627 |
|
|
1628 |
|
// UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
1629 |
|
// // |
1630 |
|
// if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
1631 |
|
// // |
1632 |
|
// if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
1633 |
|
// if ( (pkt_num-16777215) < 0 ){ |
1634 |
|
// return((16777215-pkt_num)); |
1635 |
|
// } else { |
1636 |
|
// return((pkt_num-16777215)); |
1637 |
|
// }; |
1638 |
|
// }; |
1639 |
|
// // |
1640 |
|
// return(pkt_num); |
1641 |
|
// // |
1642 |
|
// }; |
1643 |
|
|
1644 |
|
/* |
1645 |
|
* |
1646 |
|
* Convert the time in the DB from UInt_t to a string |
1647 |
|
* |
1648 |
|
* @param dbt time in the DB |
1649 |
|
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
1650 |
|
* |
1651 |
|
*/ |
1652 |
|
TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){ |
1653 |
|
// |
1654 |
|
Int_t offset = 0; |
1655 |
|
TString rtime; |
1656 |
|
Bool_t found = false; |
1657 |
|
// |
1658 |
|
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
1659 |
|
// |
1660 |
|
offset = 60*60*3; // UTC (Coordinated Universal Time) + 3hs = Moscow Winter Time |
1661 |
|
found = true; |
1662 |
|
// |
1663 |
|
}; |
1664 |
|
// |
1665 |
|
if ( !strcmp(tzone.Data(),"CET") ){ |
1666 |
|
// |
1667 |
|
offset = 60*60*1; // CET (Central European Time) = UTC + 1 hs |
1668 |
|
found = true; |
1669 |
|
// |
1670 |
|
}; |
1671 |
|
// |
1672 |
|
if ( !strcmp(tzone.Data(),"CEST") ){ |
1673 |
|
// |
1674 |
|
offset = 60*60*2; // CEST (Central European Summer Time) = UTC + 2 h |
1675 |
|
found = true; |
1676 |
|
// |
1677 |
|
}; |
1678 |
|
// |
1679 |
|
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){ |
1680 |
|
// |
1681 |
|
offset = 60*60*4; // MSD (Moscow Summer Time) = UTC + 4 h |
1682 |
|
found = true; |
1683 |
|
// |
1684 |
|
}; |
1685 |
|
// |
1686 |
|
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
1687 |
|
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
1688 |
|
tzone = "UTC"; |
1689 |
|
}; |
1690 |
|
// |
1691 |
|
dbt += offset; |
1692 |
|
// |
1693 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
1694 |
|
// |
1695 |
|
rtime = time->AsString("s"); |
1696 |
|
// |
1697 |
|
delete time; |
1698 |
|
// |
1699 |
|
return(rtime); |
1700 |
|
} |
1701 |
|
|
1702 |
|
/* |
1703 |
|
* |
1704 |
|
* Convert the time from TZONE to UTC |
1705 |
|
* |
1706 |
|
* @param dbt time in the DB |
1707 |
|
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
1708 |
|
* |
1709 |
|
*/ |
1710 |
|
TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){ |
1711 |
|
// |
1712 |
|
Int_t offset = 0; |
1713 |
|
TString rtime; |
1714 |
|
// |
1715 |
|
Bool_t found = false; |
1716 |
|
// |
1717 |
|
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
1718 |
|
// |
1719 |
|
offset = -60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3hs |
1720 |
|
found = true; |
1721 |
|
// |
1722 |
|
}; |
1723 |
|
// |
1724 |
|
if ( !strcmp(tzone.Data(),"CET") ){ |
1725 |
|
// |
1726 |
|
offset = -60*60*1; // CET (Central European Time) - 1 hs = UTC |
1727 |
|
found = true; |
1728 |
|
// |
1729 |
|
}; |
1730 |
|
// |
1731 |
|
if ( !strcmp(tzone.Data(),"CEST") ){ |
1732 |
|
// |
1733 |
|
offset = -60*60*2; // CEST (Central European Summer Time) - 2 h = UTC |
1734 |
|
found = true; |
1735 |
|
// |
1736 |
|
}; |
1737 |
|
// |
1738 |
|
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){ |
1739 |
|
// |
1740 |
|
offset = -60*60*4; // MSD (Moscow Summer Time) - 4 h = UTC |
1741 |
|
found = true; |
1742 |
|
// |
1743 |
|
}; |
1744 |
|
// |
1745 |
|
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
1746 |
|
// |
1747 |
|
offset = 0; |
1748 |
|
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
1749 |
|
tzone = "UTC"; |
1750 |
|
}; |
1751 |
|
// |
1752 |
|
dbt += offset; |
1753 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
1754 |
|
// |
1755 |
|
rtime = time->AsString("s"); |
1756 |
|
// |
1757 |
|
return(rtime); |
1758 |
|
} |
1759 |
|
|
1760 |
|
|
1761 |
|
// |
1762 |
|
// Build a query and call DoQuery. |
1763 |
|
// |
1764 |
|
// date it's an SQL datetime date and dbc is the connection to be |
1765 |
|
// used. It will query for the tle with the nearest but previous date |
1766 |
|
// and the immediatly next one. |
1767 |
|
// |
1768 |
|
Int_t GL_TLE::Query(TString date, TSQLServer *dbc){ |
1769 |
|
stringstream myquery; |
1770 |
|
myquery.str(""); |
1771 |
|
|
1772 |
|
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1773 |
|
<< "WHERE FROM_TIME <= '" << date.Data() |
1774 |
|
<< "' ORDER BY FROM_TIME DESC LIMIT 1) " |
1775 |
|
<< "UNION " |
1776 |
|
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1777 |
|
<< "WHERE FROM_TIME > '" << date.Data() |
1778 |
|
<< "' ORDER BY FROM_TIME ASC LIMIT 1)"; |
1779 |
|
|
1780 |
|
return DoQuery(myquery.str().c_str(), dbc); |
1781 |
|
} |
1782 |
|
|
1783 |
|
|
1784 |
|
// |
1785 |
|
// Build a query and call DoQuery. |
1786 |
|
// |
1787 |
|
// time is the UTC date in unix time (UTC) and dbc is the connection |
1788 |
|
// to be used. It will query for the tle with the nearest but |
1789 |
|
// previous date and the immediatly next one. |
1790 |
|
// |
1791 |
|
// Returns the value returned by DoQuery(). |
1792 |
|
// |
1793 |
|
Int_t GL_TLE::Query(UInt_t time, TSQLServer *dbc){ |
1794 |
|
stringstream myquery; |
1795 |
|
myquery.str(""); |
1796 |
|
|
1797 |
|
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1798 |
|
<< "WHERE FROM_TIME <= FROM_UNIXTIME('" << time |
1799 |
|
<< "') ORDER BY FROM_TIME DESC LIMIT 1) " |
1800 |
|
<< "UNION " |
1801 |
|
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1802 |
|
<< "WHERE FROM_TIME > FROM_UNIXTIME('" << time |
1803 |
|
<< "') ORDER BY FROM_TIME ASC LIMIT 1)"; |
1804 |
|
|
1805 |
|
return DoQuery(myquery.str().c_str(), dbc); |
1806 |
|
} |
1807 |
|
|
1808 |
|
|
1809 |
|
// |
1810 |
|
// Do the query myquery on the connectio dbc. Initialize tle, |
1811 |
|
// tleFromTime and tleToTime. |
1812 |
|
// |
1813 |
|
// We should have two rows (unless the table is old). From the last |
1814 |
|
// one we only take tleToTime. |
1815 |
|
// |
1816 |
|
// Returns 0 for success, 1 for failure. |
1817 |
|
// |
1818 |
|
Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){ |
1819 |
|
TSQLResult *result; |
1820 |
|
TSQLRow *row; |
1821 |
|
|
1822 |
|
// Set the right time_zone (otherwise horrible things will occur! :) |
1823 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1824 |
|
dbc->Query("SET time_zone = '+0:00'"); |
1825 |
|
|
1826 |
|
// Do the query |
1827 |
|
this->GetGLTABLES()->AddQ(); |
1828 |
|
result = dbc->Query(myquery.Data()); |
1829 |
|
if(! result->GetRowCount() ) { |
1830 |
|
cerr << "GL_TLE: query failed: " << myquery.Data() << endl; |
1831 |
|
return 1; |
1832 |
|
} |
1833 |
|
|
1834 |
|
// Get results |
1835 |
|
row = result->Next(); // first tle row |
1836 |
|
tle = GiveTle(row); |
1837 |
|
|
1838 |
|
tleFromTime = strtol(row->GetField(4), NULL, 10); |
1839 |
|
|
1840 |
|
row = result->Next(); // second tle row |
1841 |
|
if(row) |
1842 |
|
tleToTime = strtol(row->GetField(4), NULL, 10); |
1843 |
|
else { |
1844 |
|
cerr << "GL_TLE: Warning: using last avaible TLE. Please update GL_TLE table!\n"; |
1845 |
|
tleToTime = UINT_MAX; |
1846 |
|
} |
1847 |
|
|
1848 |
|
delete row; |
1849 |
|
delete result; |
1850 |
|
|
1851 |
|
return 0; |
1852 |
|
} |
1853 |
|
|
1854 |
|
|
1855 |
|
// |
1856 |
|
// Build a cTle object from the GL_TLE row. |
1857 |
|
// |
1858 |
|
cTle* GL_TLE::GiveTle(TSQLRow *row) { |
1859 |
|
cTle *thistle = NULL; |
1860 |
|
string tle1, tle2, tle3; |
1861 |
|
|
1862 |
|
// Build cTle object |
1863 |
|
tle1 = row->GetField(1); |
1864 |
|
tle2 = row->GetField(2); |
1865 |
|
tle3 = row->GetField(3); |
1866 |
|
|
1867 |
|
thistle = new cTle(tle1, tle2, tle3); |
1868 |
|
|
1869 |
|
return thistle; |
1870 |
|
} |