17 |
#include <GLTables.h> |
#include <GLTables.h> |
18 |
#include <sgp4.h> |
#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); |
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 |
|
dbc->Query(myquery.str().c_str()); |
68 |
|
fNquery++; |
69 |
|
// |
70 |
|
if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ |
71 |
|
// is connected |
72 |
|
return true; |
73 |
|
} else { |
74 |
|
// |
75 |
|
printf(" WARNING: Lost connection to DB! try to recover... \n"); |
76 |
|
// |
77 |
|
TString host = fHost->Data(); |
78 |
|
TString user = fUser->Data(); |
79 |
|
TString psw = fPsw->Data(); |
80 |
|
delete dbc; |
81 |
|
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
82 |
|
// |
83 |
|
myquery.str(""); |
84 |
|
myquery << "show databases;"; |
85 |
|
dbc->Query(myquery.str().c_str()); |
86 |
|
fNquery++; |
87 |
|
// |
88 |
|
if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ |
89 |
|
// |
90 |
|
printf(" ...connection recovered, I can continue! \n"); |
91 |
|
// |
92 |
|
myquery.str(""); |
93 |
|
myquery << "SET time_zone='+0:00'"; |
94 |
|
dbc->Query(myquery.str().c_str()); |
95 |
|
fNquery++; |
96 |
|
myquery.str(""); |
97 |
|
myquery << "SET wait_timeout=173000;"; |
98 |
|
dbc->Query(myquery.str().c_str()); |
99 |
|
fNquery++; |
100 |
|
return true; |
101 |
|
}; |
102 |
|
}; |
103 |
|
// |
104 |
|
printf(" GLTABLES: connection is gone away, query will fail\n"); |
105 |
|
// |
106 |
|
return false; |
107 |
|
// |
108 |
|
}; |
109 |
|
|
110 |
|
void GL_TABLES::ResetCounters(){ |
111 |
|
fNquery = 0; |
112 |
|
}; |
113 |
|
|
114 |
|
void GL_TABLES::AddQ(){ |
115 |
|
if ( fSet ) fNquery++; |
116 |
|
}; |
117 |
|
|
118 |
|
UInt_t GL_TABLES::GetNqueries(){ |
119 |
|
UInt_t rn = 0; |
120 |
|
rn += (UInt_t&)fNquery; |
121 |
|
return(rn); |
122 |
|
}; |
123 |
|
|
124 |
GL_RUN::GL_RUN() { |
GL_RUN::GL_RUN() { |
125 |
ID = 0; |
ID = 0; |
126 |
ID_RUN_FRAG = 0; |
ID_RUN_FRAG = 0; |
254 |
TYPE = 0; |
TYPE = 0; |
255 |
} |
} |
256 |
|
|
|
GL_TLE::GL_TLE(){ |
|
|
} |
|
|
|
|
257 |
// **************************************************** |
// **************************************************** |
258 |
|
|
259 |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
518 |
// |
// |
519 |
// printf("1myquery is %s \n",myquery.str().c_str()); |
// printf("1myquery is %s \n",myquery.str().c_str()); |
520 |
// |
// |
521 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
522 |
|
this->GetGLTABLES()->AddQ(); |
523 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
524 |
// |
// |
525 |
// retrieve this ID_TRASH |
// retrieve this ID_TRASH |
526 |
// |
// |
527 |
myquery.str(""); |
myquery.str(""); |
528 |
myquery << " SELECT ID_TRASH,ID_ROOT_L0,ID_ROOT_L2 FROM GL_RUN_TRASH ORDER BY ID_TRASH DESC LIMIT 1"; |
myquery << " SELECT ID_TRASH,ID_ROOT_L0,ID_ROOT_L2 FROM GL_RUN_TRASH ORDER BY ID_TRASH DESC LIMIT 1"; |
529 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
530 |
|
this->GetGLTABLES()->AddQ(); |
531 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
532 |
// |
// |
533 |
UInt_t idtrash = 0; |
UInt_t idtrash = 0; |
549 |
// |
// |
550 |
// printf("2myquery is %s \n",myquery.str().c_str()); |
// printf("2myquery is %s \n",myquery.str().c_str()); |
551 |
// |
// |
552 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
553 |
|
this->GetGLTABLES()->AddQ(); |
554 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
555 |
// |
// |
556 |
Row = pResult->Next(); |
Row = pResult->Next(); |
566 |
// |
// |
567 |
// printf("3myquery is %s \n",myquery.str().c_str()); |
// printf("3myquery is %s \n",myquery.str().c_str()); |
568 |
// |
// |
569 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
570 |
|
this->GetGLTABLES()->AddQ(); |
571 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
572 |
// |
// |
573 |
Row = pResult->Next(); |
Row = pResult->Next(); |
584 |
// |
// |
585 |
// printf("4myquery is %s \n",myquery.str().c_str()); |
// printf("4myquery is %s \n",myquery.str().c_str()); |
586 |
// |
// |
587 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
588 |
|
this->GetGLTABLES()->AddQ(); |
589 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
590 |
// |
// |
591 |
myquery.str(""); |
myquery.str(""); |
595 |
// |
// |
596 |
// printf("4myquery is %s \n",myquery.str().c_str()); |
// printf("4myquery is %s \n",myquery.str().c_str()); |
597 |
// |
// |
598 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
599 |
|
this->GetGLTABLES()->AddQ(); |
600 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
601 |
// |
// |
602 |
myquery.str(""); |
myquery.str(""); |
607 |
// printf("4myquery is %s \n",myquery.str().c_str()); |
// printf("4myquery is %s \n",myquery.str().c_str()); |
608 |
// |
// |
609 |
// |
// |
610 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
611 |
|
this->GetGLTABLES()->AddQ(); |
612 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
613 |
// |
// |
614 |
myquery.str(""); |
myquery.str(""); |
619 |
// printf("5myquery is %s \n",myquery.str().c_str()); |
// printf("5myquery 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()); |
dbc->Query(myquery.str().c_str()); |
625 |
// |
// |
626 |
return 0; |
return 0; |
652 |
// |
// |
653 |
printf(" qui? myquery is %s \n",myquery.str().c_str()); |
printf(" qui? myquery is %s \n",myquery.str().c_str()); |
654 |
// |
// |
655 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
656 |
|
this->GetGLTABLES()->AddQ(); |
657 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
658 |
// |
// |
659 |
Row = pResult->Next(); |
Row = pResult->Next(); |
737 |
// |
// |
738 |
// printf("5myquery is %s \n",myquery.str().c_str()); |
// printf("5myquery is %s \n",myquery.str().c_str()); |
739 |
// |
// |
740 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
741 |
|
this->GetGLTABLES()->AddQ(); |
742 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
743 |
// |
// |
744 |
// |
// |
746 |
myquery << " DELETE FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
myquery << " DELETE FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
747 |
myquery << IDRUN << ";"; |
myquery << IDRUN << ";"; |
748 |
// |
// |
749 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
750 |
|
this->GetGLTABLES()->AddQ(); |
751 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
752 |
// |
// |
753 |
return 0; |
return 0; |
830 |
// |
// |
831 |
// printf("myquery is %s \n",myquery.str().c_str()); |
// printf("myquery is %s \n",myquery.str().c_str()); |
832 |
// |
// |
833 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
834 |
|
this->GetGLTABLES()->AddQ(); |
835 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
836 |
// |
// |
837 |
return 0; |
return 0; |
908 |
// |
// |
909 |
// printf("myquery is %s \n",myquery.str().c_str()); |
// printf("myquery is %s \n",myquery.str().c_str()); |
910 |
// |
// |
911 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
912 |
|
this->GetGLTABLES()->AddQ(); |
913 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
914 |
// |
// |
915 |
return 0; |
return 0; |
967 |
myquery << " from GL_RUN where ID=" << run << ";"; |
myquery << " from GL_RUN where ID=" << run << ";"; |
968 |
// |
// |
969 |
// printf(" myquery is %s \n",myquery.str().c_str()); |
// printf(" myquery is %s \n",myquery.str().c_str()); |
970 |
|
if ( !this->IsConnected(dbc) ) return -57; |
971 |
|
this->AddQ(); |
972 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
973 |
// |
// |
974 |
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
1067 |
// |
// |
1068 |
// printf(" query is %s \n",myquery.str().c_str()); |
// printf(" query is %s \n",myquery.str().c_str()); |
1069 |
// |
// |
1070 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1071 |
|
this->GetGLTABLES()->AddQ(); |
1072 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1073 |
if(!pResult->GetRowCount())return(-50); |
if(!pResult->GetRowCount())return(-50); |
1074 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1134 |
myquery << ",NAME"; |
myquery << ",NAME"; |
1135 |
myquery << " from GL_ROOT where ID=" << id << ";"; |
myquery << " from GL_ROOT where ID=" << id << ";"; |
1136 |
// |
// |
1137 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1138 |
|
this->GetGLTABLES()->AddQ(); |
1139 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1140 |
if(!pResult->GetRowCount())return (-51); |
if(!pResult->GetRowCount())return (-51); |
1141 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1145 |
if(t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if(t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1146 |
if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t)); |
if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t)); |
1147 |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
1148 |
if(t==3) PATH = Row->GetField(t); |
if(t==3) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/'; |
1149 |
if(t==4) NAME = Row->GetField(t); |
if(t==4) NAME = Row->GetField(t); |
1150 |
}; |
}; |
1151 |
}; |
}; |
1170 |
// ---------------- |
// ---------------- |
1171 |
myquery.str(""); |
myquery.str(""); |
1172 |
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; |
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; |
1173 |
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!!! |
1174 |
|
myquery << " and EV_ROOT_CALIBTRK1>=0 and and EV_ROOT_CALIBTRK2>=0"; // EM! SE MANCA UN PACCHETTO DEI DUE IL PROCESSAMENTO CRASHA... DA RIVEDERE LA VALIDAZIONE |
1175 |
|
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1176 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1177 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1178 |
|
this->GetGLTABLES()->AddQ(); |
1179 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1180 |
if(!pResult->GetRowCount())return (-53); |
if(!pResult->GetRowCount())return (-53); |
1181 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1233 |
myquery << " ;"; |
myquery << " ;"; |
1234 |
//myquery << " and VALIDATION=1;"; |
//myquery << " and VALIDATION=1;"; |
1235 |
// |
// |
1236 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1237 |
|
this->GetGLTABLES()->AddQ(); |
1238 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1239 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1240 |
// |
// |
1254 |
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; |
1255 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1256 |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
1257 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1258 |
|
this->GetGLTABLES()->AddQ(); |
1259 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1260 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1261 |
// |
// |
1298 |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
1299 |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1300 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1301 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1302 |
|
this->GetGLTABLES()->AddQ(); |
1303 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1304 |
if(!pResult->GetRowCount())return (-55);//throw -55; |
if(!pResult->GetRowCount())return (-55);//throw -55; |
1305 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1340 |
// ---------------- |
// ---------------- |
1341 |
myquery.str(""); |
myquery.str(""); |
1342 |
myquery << " select "; |
myquery << " select "; |
1343 |
myquery << " ID, PATH, NAME, DESCR, TYPE, FROM_TIME,TO_TIME "; |
myquery << " ID, PATH, NAME, DESCR, FROM_TIME,TO_TIME, TYPE "; |
1344 |
myquery << " from GL_PARAM "; |
myquery << " from GL_PARAM "; |
1345 |
myquery << " where TYPE = '"<<type<<"' "; |
myquery << " where TYPE = '"<<type<<"' "; |
1346 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1347 |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
1348 |
// |
// |
1349 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1350 |
|
this->GetGLTABLES()->AddQ(); |
1351 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1352 |
if(!pResult->GetRowCount())return (-52); |
if(!pResult->GetRowCount())return (-52); |
1353 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1355 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
1356 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1357 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1358 |
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 |
1359 |
if (t==2) NAME = Row->GetField(t); |
if (t==2) NAME = Row->GetField(t); |
1360 |
if (t==3) DESCR = Row->GetField(t); |
if (t==3) DESCR = Row->GetField(t); |
1361 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1401 |
TSQLRow *Row; |
TSQLRow *Row; |
1402 |
stringstream myquery; |
stringstream myquery; |
1403 |
stringstream rname; |
stringstream rname; |
1404 |
|
// pcksList packetsNames; |
1405 |
|
// pcksList::iterator Iter; |
1406 |
|
// getPacketsNames(packetsNames); |
1407 |
rname.str(""); |
rname.str(""); |
1408 |
// ---------------- |
// ---------------- |
1409 |
myquery.str(""); |
myquery.str(""); |
1414 |
myquery << type.Data(); |
myquery << type.Data(); |
1415 |
myquery << "=" << id << ";"; |
myquery << "=" << id << ";"; |
1416 |
// |
// |
1417 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1418 |
|
this->GetGLTABLES()->AddQ(); |
1419 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1420 |
if( pResult->GetRowCount() ){ |
if( pResult->GetRowCount() ){ |
1421 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1422 |
if( Row ){ |
if( Row ){ |
1423 |
stringstream fname; |
stringstream fname; |
1424 |
fname.str(""); |
fname.str(""); |
1425 |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
1426 |
rname << Row->GetField(1); |
rname << Row->GetField(1); |
1427 |
file = new TFile(fname.str().c_str(),"READ"); |
file = new TFile(fname.str().c_str(),"READ"); |
1428 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
idraw = (UInt_t)atoll(Row->GetField(2)); |
1439 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
1440 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
1441 |
obtfirst = ph->GetOrbitalTime(); |
obtfirst = ph->GetOrbitalTime(); |
1442 |
|
// |
1443 |
|
// code = eh->GetCounter(); |
1444 |
|
// UInt_t en = 0; |
1445 |
|
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
1446 |
|
// en = code->Get(GetPacketType(*Iter)); |
1447 |
|
// if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){ |
1448 |
|
// // |
1449 |
|
// TTree *TC = 0; |
1450 |
|
// TC = (TTree*)file->Get("CalibCalPed"); |
1451 |
|
// if ( !TC || TC->IsZombie() ) return; |
1452 |
|
// EventHeader *ehc = 0; |
1453 |
|
// PscuHeader *phc = 0; |
1454 |
|
// TC->SetBranchAddress("Header", &ehc); |
1455 |
|
// TC->GetEntry(0); |
1456 |
|
// phc = ehc->GetPscuHeader(); |
1457 |
|
// pktfirst = phc->GetCounter(); |
1458 |
|
// obtfirst = phc->GetOrbitalTime(); |
1459 |
|
// // |
1460 |
|
// }; |
1461 |
|
// }; |
1462 |
|
// |
1463 |
}; |
}; |
1464 |
// |
// |
1465 |
// look for Resurs offset |
// look for Resurs offset |
1468 |
// |
// |
1469 |
// |
// |
1470 |
stringstream oss; |
stringstream oss; |
1471 |
|
TString frn = rname.str().c_str(); |
1472 |
|
frn = frn.ReplaceAll(".root",5,".pam",4); |
1473 |
oss.str(""); |
oss.str(""); |
1474 |
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='" |
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='" |
1475 |
<< rname.str().c_str() << "';"; |
<< frn.Data() << "';"; |
1476 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1477 |
|
this->GetGLTABLES()->AddQ(); |
1478 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
1479 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1480 |
// |
// |
1493 |
for (Int_t i = 8; i<13; i++){ |
for (Int_t i = 8; i<13; i++){ |
1494 |
dwo.Append(name[i],1); |
dwo.Append(name[i],1); |
1495 |
}; |
}; |
1496 |
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
if ( dwo.IsDigit() ){ |
1497 |
|
dworbit = (UInt_t)dwo.Atoi(); |
1498 |
|
} else { |
1499 |
|
dworbit = 1; |
1500 |
|
}; |
1501 |
}; |
}; |
1502 |
// |
// |
1503 |
|
// |
1504 |
if ( !Row ){ |
if ( !Row ){ |
1505 |
oss.str(""); |
oss.str(""); |
1506 |
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< " |
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< " |
1507 |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
1508 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1509 |
|
this->GetGLTABLES()->AddQ(); |
1510 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
1511 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1512 |
if ( !Row ){ |
if ( !Row ){ |
1524 |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
1525 |
<< " WHERE ID_RAW = " << idraw |
<< " WHERE ID_RAW = " << idraw |
1526 |
<< ";"; |
<< ";"; |
1527 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1528 |
|
this->GetGLTABLES()->AddQ(); |
1529 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1530 |
if ( pResult ){ |
if ( pResult ){ |
1531 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1559 |
*/ |
*/ |
1560 |
UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){ |
UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){ |
1561 |
// |
// |
1562 |
return(((UInt_t)((this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC)); |
return(((UInt_t)((Int_t)(this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC)); |
1563 |
// |
// |
1564 |
}; |
}; |
1565 |
|
|
1566 |
|
|
1567 |
ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
/** |
1568 |
|
* Return the correct packet number if we went back to zero |
1569 |
|
*/ |
1570 |
|
Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
1571 |
// |
// |
1572 |
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) ){ |
1573 |
|
return((Long64_t)pkt_num+16777215LL); |
1574 |
|
}; |
1575 |
// |
// |
1576 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
1577 |
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())); |
|
|
}; |
|
1578 |
}; |
}; |
1579 |
// |
// |
1580 |
return((ULong64_t)obt); |
return((Long64_t)pkt_num); |
1581 |
// |
// |
1582 |
}; |
}; |
1583 |
|
|
1584 |
UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
/** |
1585 |
|
* Return the correct On Board Time if we went back to zero |
1586 |
|
*/ |
1587 |
|
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1588 |
// |
// |
1589 |
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())); |
1590 |
// |
// |
1591 |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1592 |
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)); |
|
|
}; |
|
1593 |
}; |
}; |
1594 |
// |
// |
1595 |
return(pkt_num); |
return((Long64_t)obt); |
|
// |
|
1596 |
}; |
}; |
1597 |
|
|
1598 |
|
|
1599 |
|
|
1600 |
|
// ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1601 |
|
// // |
1602 |
|
// if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
1603 |
|
// // |
1604 |
|
// if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1605 |
|
// if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
1606 |
|
// return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
1607 |
|
// } else { |
1608 |
|
// return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
1609 |
|
// }; |
1610 |
|
// }; |
1611 |
|
// // |
1612 |
|
// return((ULong64_t)obt); |
1613 |
|
// // |
1614 |
|
// }; |
1615 |
|
|
1616 |
|
// UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
1617 |
|
// // |
1618 |
|
// if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
1619 |
|
// // |
1620 |
|
// if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
1621 |
|
// if ( (pkt_num-16777215) < 0 ){ |
1622 |
|
// return((16777215-pkt_num)); |
1623 |
|
// } else { |
1624 |
|
// return((pkt_num-16777215)); |
1625 |
|
// }; |
1626 |
|
// }; |
1627 |
|
// // |
1628 |
|
// return(pkt_num); |
1629 |
|
// // |
1630 |
|
// }; |
1631 |
|
|
1632 |
/* |
/* |
1633 |
* |
* |
1634 |
* Convert the time in the DB from UInt_t to a string |
* Convert the time in the DB from UInt_t to a string |
1746 |
} |
} |
1747 |
|
|
1748 |
|
|
1749 |
// **************************************************** |
// |
1750 |
/** |
// Build a query and call DoQuery. |
1751 |
* Function to query the GL_TLE table of the DB. |
// |
1752 |
* |
// date it's an SQL datetime date and dbc is the connection to be |
1753 |
* time is the unix time for which a good tle is requested. |
// used. It will query for the tle with the nearest but previous date |
1754 |
* |
// and the immediatly next one. |
1755 |
* Return the pointer to a cTle object that has the closest and |
// |
1756 |
* previous date compared with time. |
Int_t GL_TLE::Query(TString date, TSQLServer *dbc){ |
|
* |
|
|
* If errors occurs it returns NULL. |
|
|
*/ |
|
|
cTle* GL_TLE::Query_GL_TLE(UInt_t time, TSQLServer *dbc){ |
|
1757 |
stringstream myquery; |
stringstream myquery; |
1758 |
myquery.str(""); |
myquery.str(""); |
1759 |
|
|
1760 |
myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE " |
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1761 |
<< "WHERE FROM_TIME < FROM_UNIXTIME(" << time << ") ORDER BY FROM_TIME DESC LIMIT 1;"; |
<< "WHERE FROM_TIME <= '" << date.Data() |
1762 |
|
<< "' ORDER BY FROM_TIME DESC LIMIT 1) " |
1763 |
|
<< "UNION " |
1764 |
|
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1765 |
|
<< "WHERE FROM_TIME > '" << date.Data() |
1766 |
|
<< "' ORDER BY FROM_TIME ASC LIMIT 1)"; |
1767 |
|
|
1768 |
return Query_GL_TLE_go(myquery.str(), dbc); |
return DoQuery(myquery.str().c_str(), dbc); |
1769 |
} |
} |
1770 |
|
|
1771 |
|
|
1772 |
// **************************************************** |
// |
1773 |
/** |
// Build a query and call DoQuery. |
1774 |
* Function to query the GL_TLE table of the DB. |
// |
1775 |
* |
// time is the UTC date in unix time (UTC) and dbc is the connection |
1776 |
* date is a datetime format YYYY-MM-DD hh:mm:ss for which a good tle |
// to be used. It will query for the tle with the nearest but |
1777 |
* is requested. |
// previous date and the immediatly next one. |
1778 |
* |
// |
1779 |
* Return the pointer to a cTle object that has the closest and |
// Returns the value returned by DoQuery(). |
1780 |
* previous date compared with time. |
// |
1781 |
* |
Int_t GL_TLE::Query(UInt_t time, TSQLServer *dbc){ |
|
* If errors occurs it returns NULL. |
|
|
*/ |
|
|
cTle* GL_TLE::Query_GL_TLE(TString date, TSQLServer *dbc){ |
|
1782 |
stringstream myquery; |
stringstream myquery; |
1783 |
myquery.str(""); |
myquery.str(""); |
1784 |
|
|
1785 |
myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE " |
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1786 |
<< "WHERE FROM_TIME < '" << date.Data() << "' ORDER BY FROM_TIME DESC LIMIT 1;"; |
<< "WHERE FROM_TIME <= FROM_UNIXTIME('" << time |
1787 |
|
<< "') ORDER BY FROM_TIME DESC LIMIT 1) " |
1788 |
|
<< "UNION " |
1789 |
|
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1790 |
|
<< "WHERE FROM_TIME > FROM_UNIXTIME('" << time |
1791 |
|
<< "') ORDER BY FROM_TIME ASC LIMIT 1)"; |
1792 |
|
|
1793 |
return Query_GL_TLE_go(myquery.str(), dbc); |
return DoQuery(myquery.str().c_str(), dbc); |
1794 |
} |
} |
1795 |
|
|
1796 |
|
|
1797 |
// **************************************************** |
// |
1798 |
/** |
// Do the query myquery on the connectio dbc. Initialize tle, |
1799 |
* Private function used by Query_GL_TLE methods. |
// tleFromTime and tleToTime. |
1800 |
* |
// |
1801 |
* myquery is the query string. |
// We should have two rows (unless the table is old). From the last |
1802 |
* |
// one we only take tleToTime. |
1803 |
* Return the pointer to a cTle object that has the closest and |
// |
1804 |
* previous date compared with time. |
// Returns 0 for success, 1 for failure. |
1805 |
* |
// |
1806 |
* If errors occurs it returns NULL. |
Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){ |
|
*/ |
|
|
cTle* GL_TLE::Query_GL_TLE_go(TString myquery, TSQLServer *dbc){ |
|
|
cTle *tle; |
|
|
string tle1, tle2, tle3; |
|
|
|
|
|
// MySQL variables |
|
1807 |
TSQLResult *result; |
TSQLResult *result; |
1808 |
TSQLRow *row; |
TSQLRow *row; |
1809 |
|
|
1810 |
|
// Set the right time_zone (otherwise horrible things will occur! :) |
1811 |
|
dbc->Query("SET time_zone = '+0:00'"); |
1812 |
|
|
1813 |
|
// Do the query |
1814 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1815 |
|
this->GetGLTABLES()->AddQ(); |
1816 |
result = dbc->Query(myquery.Data()); |
result = dbc->Query(myquery.Data()); |
1817 |
if(! result->GetRowCount() ) return NULL; |
if(! result->GetRowCount() ) { |
1818 |
|
cerr << "GL_TLE: query failed: " << myquery.Data() << endl; |
1819 |
|
return 1; |
1820 |
|
} |
1821 |
|
|
1822 |
|
// Get results |
1823 |
|
row = result->Next(); // first tle row |
1824 |
|
tle = GiveTle(row); |
1825 |
|
|
1826 |
|
tleFromTime = strtol(row->GetField(4), NULL, 10); |
1827 |
|
|
1828 |
|
row = result->Next(); // second tle row |
1829 |
|
if(row) |
1830 |
|
tleToTime = strtol(row->GetField(4), NULL, 10); |
1831 |
|
else { |
1832 |
|
cerr << "GL_TLE: Warning: using last avaible TLE. Please update GL_TLE table!\n"; |
1833 |
|
tleToTime = UINT_MAX; |
1834 |
|
} |
1835 |
|
|
1836 |
row = result->Next(); |
delete row; |
1837 |
tle1 = row->GetField(0); |
delete result; |
|
tle2 = row->GetField(1); |
|
|
tle3 = row->GetField(2); |
|
1838 |
|
|
1839 |
tle = new cTle(tle1, tle2, tle3); |
return 0; |
1840 |
|
} |
1841 |
|
|
|
delete result; |
|
|
delete row; |
|
1842 |
|
|
1843 |
return tle; |
// |
1844 |
|
// Build a cTle object from the GL_TLE row. |
1845 |
|
// |
1846 |
|
cTle* GL_TLE::GiveTle(TSQLRow *row) { |
1847 |
|
cTle *thistle = NULL; |
1848 |
|
string tle1, tle2, tle3; |
1849 |
|
|
1850 |
|
// Build cTle object |
1851 |
|
tle1 = row->GetField(1); |
1852 |
|
tle2 = row->GetField(2); |
1853 |
|
tle3 = row->GetField(3); |
1854 |
|
|
1855 |
|
thistle = new cTle(tle1, tle2, tle3); |
1856 |
|
|
1857 |
|
return thistle; |
1858 |
} |
} |