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; |
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++){ |
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;"; |
1174 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1175 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1176 |
|
this->GetGLTABLES()->AddQ(); |
1177 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1178 |
if(!pResult->GetRowCount())return (-53); |
if(!pResult->GetRowCount())return (-53); |
1179 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1231 |
myquery << " ;"; |
myquery << " ;"; |
1232 |
//myquery << " and VALIDATION=1;"; |
//myquery << " and VALIDATION=1;"; |
1233 |
// |
// |
1234 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1235 |
|
this->GetGLTABLES()->AddQ(); |
1236 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1237 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1238 |
// |
// |
1252 |
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; |
1253 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1254 |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
1255 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1256 |
|
this->GetGLTABLES()->AddQ(); |
1257 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1258 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1259 |
// |
// |
1296 |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
1297 |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1298 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1299 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1300 |
|
this->GetGLTABLES()->AddQ(); |
1301 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1302 |
if(!pResult->GetRowCount())return (-55);//throw -55; |
if(!pResult->GetRowCount())return (-55);//throw -55; |
1303 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1344 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1345 |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
1346 |
// |
// |
1347 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1348 |
|
this->GetGLTABLES()->AddQ(); |
1349 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1350 |
if(!pResult->GetRowCount())return (-52); |
if(!pResult->GetRowCount())return (-52); |
1351 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
1409 |
myquery << type.Data(); |
myquery << type.Data(); |
1410 |
myquery << "=" << id << ";"; |
myquery << "=" << id << ";"; |
1411 |
// |
// |
1412 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1413 |
|
this->GetGLTABLES()->AddQ(); |
1414 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1415 |
if( pResult->GetRowCount() ){ |
if( pResult->GetRowCount() ){ |
1416 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1445 |
oss.str(""); |
oss.str(""); |
1446 |
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='" |
1447 |
<< rname.str().c_str() << "';"; |
<< rname.str().c_str() << "';"; |
1448 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1449 |
|
this->GetGLTABLES()->AddQ(); |
1450 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
1451 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1452 |
// |
// |
1472 |
oss.str(""); |
oss.str(""); |
1473 |
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< " |
1474 |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
1475 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1476 |
|
this->GetGLTABLES()->AddQ(); |
1477 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
1478 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1479 |
if ( !Row ){ |
if ( !Row ){ |
1491 |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
1492 |
<< " WHERE ID_RAW = " << idraw |
<< " WHERE ID_RAW = " << idraw |
1493 |
<< ";"; |
<< ";"; |
1494 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
1495 |
|
this->GetGLTABLES()->AddQ(); |
1496 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1497 |
if ( pResult ){ |
if ( pResult ){ |
1498 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1778 |
dbc->Query("SET time_zone = '+0:00'"); |
dbc->Query("SET time_zone = '+0:00'"); |
1779 |
|
|
1780 |
// Do the query |
// Do the query |
1781 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
1782 |
|
this->GetGLTABLES()->AddQ(); |
1783 |
result = dbc->Query(myquery.Data()); |
result = dbc->Query(myquery.Data()); |
1784 |
if(! result->GetRowCount() ) { |
if(! result->GetRowCount() ) { |
1785 |
cerr << "GL_TLE: query failed: " << myquery.Data() << endl; |
cerr << "GL_TLE: query failed: " << myquery.Data() << endl; |