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 |
|
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; |
266 |
TYPE = 0; |
TYPE = 0; |
267 |
} |
} |
268 |
|
|
|
GL_TLE::GL_TLE(){ |
|
|
} |
|
|
|
|
269 |
// **************************************************** |
// **************************************************** |
270 |
|
|
271 |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
530 |
// |
// |
531 |
// printf("1myquery is %s \n",myquery.str().c_str()); |
// 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()); |
dbc->Query(myquery.str().c_str()); |
536 |
// |
// |
537 |
// retrieve this ID_TRASH |
// retrieve this ID_TRASH |
538 |
// |
// |
539 |
myquery.str(""); |
myquery.str(""); |
540 |
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"; |
541 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
542 |
|
this->GetGLTABLES()->AddQ(); |
543 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
544 |
// |
// |
545 |
UInt_t idtrash = 0; |
UInt_t idtrash = 0; |
561 |
// |
// |
562 |
// printf("2myquery is %s \n",myquery.str().c_str()); |
// 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()); |
pResult = dbc->Query(myquery.str().c_str()); |
567 |
// |
// |
568 |
Row = pResult->Next(); |
Row = pResult->Next(); |
578 |
// |
// |
579 |
// printf("3myquery is %s \n",myquery.str().c_str()); |
// 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()); |
pResult = dbc->Query(myquery.str().c_str()); |
584 |
// |
// |
585 |
Row = pResult->Next(); |
Row = pResult->Next(); |
596 |
// |
// |
597 |
// printf("4myquery is %s \n",myquery.str().c_str()); |
// 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()); |
dbc->Query(myquery.str().c_str()); |
602 |
// |
// |
603 |
myquery.str(""); |
myquery.str(""); |
607 |
// |
// |
608 |
// printf("4myquery is %s \n",myquery.str().c_str()); |
// 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()); |
dbc->Query(myquery.str().c_str()); |
613 |
// |
// |
614 |
myquery.str(""); |
myquery.str(""); |
619 |
// printf("4myquery is %s \n",myquery.str().c_str()); |
// 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()); |
dbc->Query(myquery.str().c_str()); |
625 |
// |
// |
626 |
myquery.str(""); |
myquery.str(""); |
631 |
// printf("5myquery is %s \n",myquery.str().c_str()); |
// 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()); |
dbc->Query(myquery.str().c_str()); |
637 |
// |
// |
638 |
return 0; |
return 0; |
664 |
// |
// |
665 |
printf(" qui? myquery is %s \n",myquery.str().c_str()); |
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()); |
pResult = dbc->Query(myquery.str().c_str()); |
670 |
// |
// |
671 |
Row = pResult->Next(); |
Row = pResult->Next(); |
749 |
// |
// |
750 |
// printf("5myquery is %s \n",myquery.str().c_str()); |
// 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()); |
dbc->Query(myquery.str().c_str()); |
755 |
// |
// |
756 |
// |
// |
758 |
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="; |
759 |
myquery << IDRUN << ";"; |
myquery << IDRUN << ";"; |
760 |
// |
// |
761 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
762 |
|
this->GetGLTABLES()->AddQ(); |
763 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
764 |
// |
// |
765 |
return 0; |
return 0; |
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; |
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()); |
// 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 |
// |
// |
986 |
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
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 |
}; |
}; |
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,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; |
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++){ |
1245 |
myquery << " ;"; |
myquery << " ;"; |
1246 |
//myquery << " and VALIDATION=1;"; |
//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()); |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1252 |
// |
// |
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()); |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1273 |
// |
// |
1310 |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
1311 |
myquery << " 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)); |
1413 |
TSQLRow *Row; |
TSQLRow *Row; |
1414 |
stringstream myquery; |
stringstream myquery; |
1415 |
stringstream rname; |
stringstream rname; |
1416 |
|
// pcksList packetsNames; |
1417 |
|
// pcksList::iterator Iter; |
1418 |
|
// getPacketsNames(packetsNames); |
1419 |
rname.str(""); |
rname.str(""); |
1420 |
// ---------------- |
// ---------------- |
1421 |
myquery.str(""); |
myquery.str(""); |
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); |
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)); |
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 |
1480 |
// |
// |
1481 |
// |
// |
1482 |
stringstream oss; |
stringstream oss; |
1483 |
|
TString frn = rname.str().c_str(); |
1484 |
|
frn = frn.ReplaceAll(".root",5,".pam",4); |
1485 |
oss.str(""); |
oss.str(""); |
1486 |
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='" |
1487 |
<< rname.str().c_str() << "';"; |
<< frn.Data() << "';"; |
1488 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1489 |
|
this->GetGLTABLES()->AddQ(); |
1490 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
1491 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1492 |
// |
// |
1505 |
for (Int_t i = 8; i<13; i++){ |
for (Int_t i = 8; i<13; i++){ |
1506 |
dwo.Append(name[i],1); |
dwo.Append(name[i],1); |
1507 |
}; |
}; |
1508 |
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
if ( dwo.IsDigit() ){ |
1509 |
|
dworbit = (UInt_t)dwo.Atoi(); |
1510 |
|
} else { |
1511 |
|
dworbit = 1; |
1512 |
|
}; |
1513 |
}; |
}; |
1514 |
// |
// |
1515 |
|
// |
1516 |
if ( !Row ){ |
if ( !Row ){ |
1517 |
oss.str(""); |
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< " |
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;"; |
<< 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()); |
pResult = dbc->Query(oss.str().c_str()); |
1523 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1524 |
if ( !Row ){ |
if ( !Row ){ |
1536 |
myquery << " SELECT OBT0,TIMESYNC,TYPE 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(); |
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 |
* Convert the time in the DB from UInt_t to a string |
1758 |
} |
} |
1759 |
|
|
1760 |
|
|
1761 |
// **************************************************** |
// |
1762 |
/** |
// Build a query and call DoQuery. |
1763 |
* Function to query the GL_TLE table of the DB. |
// |
1764 |
* |
// date it's an SQL datetime date and dbc is the connection to be |
1765 |
* 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 |
1766 |
* |
// and the immediatly next one. |
1767 |
* Return the pointer to a cTle object that has the closest and |
// |
1768 |
* 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){ |
|
1769 |
stringstream myquery; |
stringstream myquery; |
1770 |
myquery.str(""); |
myquery.str(""); |
1771 |
|
|
1772 |
myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE " |
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1773 |
<< "WHERE FROM_TIME < FROM_UNIXTIME(" << time << ") ORDER BY FROM_TIME DESC LIMIT 1;"; |
<< "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 Query_GL_TLE_go(myquery.str(), dbc); |
return DoQuery(myquery.str().c_str(), dbc); |
1781 |
} |
} |
1782 |
|
|
1783 |
|
|
1784 |
// **************************************************** |
// |
1785 |
/** |
// Build a query and call DoQuery. |
1786 |
* Function to query the GL_TLE table of the DB. |
// |
1787 |
* |
// time is the UTC date in unix time (UTC) and dbc is the connection |
1788 |
* 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 |
1789 |
* is requested. |
// previous date and the immediatly next one. |
1790 |
* |
// |
1791 |
* Return the pointer to a cTle object that has the closest and |
// Returns the value returned by DoQuery(). |
1792 |
* previous date compared with time. |
// |
1793 |
* |
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){ |
|
1794 |
stringstream myquery; |
stringstream myquery; |
1795 |
myquery.str(""); |
myquery.str(""); |
1796 |
|
|
1797 |
myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE " |
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
1798 |
<< "WHERE FROM_TIME < '" << date.Data() << "' ORDER BY FROM_TIME DESC LIMIT 1;"; |
<< "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 Query_GL_TLE_go(myquery.str(), dbc); |
return DoQuery(myquery.str().c_str(), dbc); |
1806 |
} |
} |
1807 |
|
|
1808 |
|
|
1809 |
// **************************************************** |
// |
1810 |
/** |
// Do the query myquery on the connectio dbc. Initialize tle, |
1811 |
* Private function used by Query_GL_TLE methods. |
// tleFromTime and tleToTime. |
1812 |
* |
// |
1813 |
* myquery is the query string. |
// We should have two rows (unless the table is old). From the last |
1814 |
* |
// one we only take tleToTime. |
1815 |
* Return the pointer to a cTle object that has the closest and |
// |
1816 |
* previous date compared with time. |
// Returns 0 for success, 1 for failure. |
1817 |
* |
// |
1818 |
* 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 |
|
1819 |
TSQLResult *result; |
TSQLResult *result; |
1820 |
TSQLRow *row; |
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()); |
result = dbc->Query(myquery.Data()); |
1829 |
if(! result->GetRowCount() ) return NULL; |
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 |
row = result->Next(); |
delete row; |
1849 |
tle1 = row->GetField(0); |
delete result; |
|
tle2 = row->GetField(1); |
|
|
tle3 = row->GetField(2); |
|
1850 |
|
|
1851 |
tle = new cTle(tle1, tle2, tle3); |
return 0; |
1852 |
|
} |
1853 |
|
|
|
delete result; |
|
|
delete row; |
|
1854 |
|
|
1855 |
return tle; |
// |
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 |
} |
} |