| 7 |
// |
// |
| 8 |
#include <sstream> |
#include <sstream> |
| 9 |
#include <iostream> |
#include <iostream> |
| 10 |
|
#include <limits.h> |
| 11 |
// |
// |
| 12 |
#include <TFile.h> |
#include <TFile.h> |
| 13 |
#include <TTree.h> |
#include <TTree.h> |
| 18 |
#include <GLTables.h> |
#include <GLTables.h> |
| 19 |
#include <sgp4.h> |
#include <sgp4.h> |
| 20 |
// |
// |
| 21 |
|
ClassImp(Q2TH); |
| 22 |
ClassImp(GL_TABLES); |
ClassImp(GL_TABLES); |
| 23 |
ClassImp(GL_TRK_CALIB); |
ClassImp(GL_TRK_CALIB); |
| 24 |
ClassImp(GL_RUN); |
ClassImp(GL_RUN); |
| 32 |
// |
// |
| 33 |
using namespace std; |
using namespace std; |
| 34 |
|
|
| 35 |
|
Q2TH::Q2TH(TString host, TString user, TString psw){ |
| 36 |
|
this->Open(host,user,psw); |
| 37 |
|
}; |
| 38 |
|
|
| 39 |
|
void Q2TH::Open(TString host, TString user, TString psw){ |
| 40 |
|
fh = gSystem->ExpandPathName(host.Data()); |
| 41 |
|
fu = gSystem->ExpandPathName(user.Data()); |
| 42 |
|
fp = gSystem->ExpandPathName(psw.Data()); |
| 43 |
|
printf(" Connecting to DB %s \n",fh.Data()); |
| 44 |
|
dbc = TSQLServer::Connect(fh.Data(),fu.Data(),fp.Data()); |
| 45 |
|
if ( dbc && dbc->IsConnected() ){ |
| 46 |
|
printf(" connected! \n"); |
| 47 |
|
} else { |
| 48 |
|
printf(" ERROR! not connected... :( \n"); |
| 49 |
|
}; |
| 50 |
|
}; |
| 51 |
|
|
| 52 |
|
TObject *Q2TH::Draw(TString query, Bool_t verbose, TString hname){ |
| 53 |
|
// |
| 54 |
|
if ( !strcmp(query.Data(),"help") ){ |
| 55 |
|
printf(" USAGE: \n"); |
| 56 |
|
printf(" 1) start root and create Q2TH object with \n"); |
| 57 |
|
printf(" Q2TH *qt = new Q2TH() \n"); |
| 58 |
|
printf(" or \n"); |
| 59 |
|
printf(" Q2TH *qt = new Q2TH(\"mysql://srvg-g2-01.ts.infn.it/pamelaProcessing9_TS\",\"pamelaprod_ro\",\"mypassword\") \n"); |
| 60 |
|
printf(" 2) query the DB with \n"); |
| 61 |
|
printf(" qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\"); \n"); |
| 62 |
|
printf(" qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\",true); this will print numbers on screen \n"); |
| 63 |
|
printf(" qt->Draw(\"select REAL_TIME_INIT from ROOT_TABLE_MERGING;\",true,\"myhisto\"); this will print numbers on screen and create histo \"myhisto\"\n"); |
| 64 |
|
printf(" 3) to use your own THxD create it and then query the DB giving as argument the name of histo: \n"); |
| 65 |
|
printf(" TH2D *myhisto=new TH2D(\"myhisto\",\"myhisto\",5000,1140000000.,1240000000.,10000,0.,1.) \n"); |
| 66 |
|
printf(" qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\",false,\"myhisto\")\n\n\n"); |
| 67 |
|
|
| 68 |
|
return NULL; |
| 69 |
|
}; |
| 70 |
|
// |
| 71 |
|
pResult = dbc->Query(query.Data()); |
| 72 |
|
// |
| 73 |
|
Row = pResult->Next(); |
| 74 |
|
// |
| 75 |
|
Int_t dim = pResult->GetFieldCount(); |
| 76 |
|
if ( dim < 1 || dim > 2 ){ |
| 77 |
|
printf(" Dim == %i not supported yet \n",dim); |
| 78 |
|
return NULL; |
| 79 |
|
}; |
| 80 |
|
// |
| 81 |
|
TH1D *h1 = NULL; |
| 82 |
|
TH2D *h2 = NULL; |
| 83 |
|
Double_t f1 = 0.; |
| 84 |
|
Double_t minf1 = numeric_limits<Double_t>::max(); |
| 85 |
|
Double_t maxf1 = numeric_limits<Double_t>::min(); |
| 86 |
|
Double_t f2 = 0.; |
| 87 |
|
Double_t minf2 = numeric_limits<Double_t>::max(); |
| 88 |
|
Double_t maxf2 = numeric_limits<Double_t>::min(); |
| 89 |
|
// |
| 90 |
|
while ( Row ){ |
| 91 |
|
f1 = (Double_t)atof(Row->GetField(0)); |
| 92 |
|
if ( f1 > maxf1 ) maxf1 = f1; |
| 93 |
|
if ( f1 < minf1 ) minf1 = f1; |
| 94 |
|
if ( dim == 2 ){ |
| 95 |
|
f2 = (Double_t)atof(Row->GetField(1)); |
| 96 |
|
if ( f2 > maxf2 ) maxf2 = f2; |
| 97 |
|
if ( f2 < minf2 ) minf2 = f2; |
| 98 |
|
|
| 99 |
|
}; |
| 100 |
|
Row = pResult->Next(); |
| 101 |
|
}; |
| 102 |
|
pResult->Delete(); |
| 103 |
|
// |
| 104 |
|
|
| 105 |
|
// |
| 106 |
|
Int_t f1bin = 70; |
| 107 |
|
Int_t f2bin = 70; |
| 108 |
|
if ( dim == 1 ){ |
| 109 |
|
f1bin = int((maxf1-minf1)/1000.); |
| 110 |
|
if ( f1bin < 70 ) f1bin = 70; |
| 111 |
|
if ( f1bin > 1000 ) f1bin = 1000; |
| 112 |
|
if ( !strcmp(hname.Data(),"q2th") ) hname += "1"; |
| 113 |
|
// h1 = dynamic_cast<TH1D*>(gDirectory->FindObject(hname.Data())); |
| 114 |
|
h1 = (TH1D*)(gDirectory->FindObject(hname.Data())); |
| 115 |
|
if ( !strcmp(hname.Data(),"q2th1") ){ |
| 116 |
|
if ( h1 ) h1->Delete(); |
| 117 |
|
}; |
| 118 |
|
if ( !h1 ) h1 = new TH1D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02); |
| 119 |
|
// h1->SetBit(TH1::kCanRebin); |
| 120 |
|
if ( verbose ) printf("\n\n Row %s \n",pResult->GetFieldName(0)); |
| 121 |
|
}; |
| 122 |
|
if ( dim == 2 ){ |
| 123 |
|
f2bin = int((maxf2-minf2)/1000.); |
| 124 |
|
if ( f2bin < 70 ) f2bin = 70; |
| 125 |
|
if ( f2bin > 1000 ) f2bin = 1000; |
| 126 |
|
if ( !strcmp(hname.Data(),"q2th") ) hname += "2"; |
| 127 |
|
// h2 = dynamic_cast<TH2D*>(gDirectory->FindObject(hname.Data())); |
| 128 |
|
h2 = (TH2D*)(gDirectory->FindObject(hname.Data())); |
| 129 |
|
if ( !strcmp(hname.Data(),"q2th2") ){ |
| 130 |
|
if ( h2 ) h2->Delete(); |
| 131 |
|
}; |
| 132 |
|
if ( !h2 ) h2 = new TH2D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02,f2bin,minf2*0.98,maxf2*1.02); |
| 133 |
|
// h2->SetBit(TH2::kCanRebin); |
| 134 |
|
if ( verbose ) printf("\n\n Row %s %s \n",pResult->GetFieldName(0),pResult->GetFieldName(1)); |
| 135 |
|
}; |
| 136 |
|
// |
| 137 |
|
pResult = dbc->Query(query.Data()); |
| 138 |
|
// |
| 139 |
|
Row = pResult->Next(); |
| 140 |
|
// |
| 141 |
|
Int_t r = 0; |
| 142 |
|
// |
| 143 |
|
while ( Row ){ |
| 144 |
|
f1 = (Double_t)atof(Row->GetField(0)); |
| 145 |
|
if ( dim == 1 ){ |
| 146 |
|
if ( verbose ) printf(" %i %f \n",r,f1); |
| 147 |
|
h1->Fill(f1); |
| 148 |
|
} else { |
| 149 |
|
f2 = (Double_t)atof(Row->GetField(1)); |
| 150 |
|
if ( verbose ) printf(" %i %f %f \n",r,f1,f2); |
| 151 |
|
h2->Fill(f1,f2); |
| 152 |
|
}; |
| 153 |
|
r++; |
| 154 |
|
Row = pResult->Next(); |
| 155 |
|
}; |
| 156 |
|
// |
| 157 |
|
TCanvas *c = NULL; |
| 158 |
|
TString cname = Form("%sc",hname.Data()); |
| 159 |
|
// c = dynamic_cast<TCanvas*>(gDirectory->FindObject(hname.Data())); |
| 160 |
|
c = (TCanvas*)(gDirectory->FindObject(cname.Data())); |
| 161 |
|
if ( !c ) c = new TCanvas(Form("%sc",cname.Data())); |
| 162 |
|
c->Clear(); |
| 163 |
|
c->cd(); |
| 164 |
|
if ( dim == 1 ) h1->Draw(); |
| 165 |
|
if ( dim == 2 ) h2->Draw(); |
| 166 |
|
// |
| 167 |
|
pResult->Delete(); |
| 168 |
|
if ( dim == 1 ) return h1; |
| 169 |
|
if ( dim == 2 ) return h2; |
| 170 |
|
// |
| 171 |
|
return NULL; |
| 172 |
|
}; |
| 173 |
|
|
| 174 |
GL_TABLES::GL_TABLES(){ |
GL_TABLES::GL_TABLES(){ |
| 175 |
}; |
}; |
| 176 |
|
|
| 197 |
mp = psw.Data(); |
mp = psw.Data(); |
| 198 |
}; |
}; |
| 199 |
|
|
| 200 |
Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
//Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
| 201 |
|
Bool_t GL_TABLES::IsConnected(TSQLServer *dbc){ |
| 202 |
// |
// |
| 203 |
// |
// |
| 204 |
// |
// |
| 234 |
TString host = fHost->Data(); |
TString host = fHost->Data(); |
| 235 |
TString user = fUser->Data(); |
TString user = fUser->Data(); |
| 236 |
TString psw = fPsw->Data(); |
TString psw = fPsw->Data(); |
| 237 |
dbc->Close(); |
if ( dbc ){ |
| 238 |
delete dbc; |
dbc->Close(); |
| 239 |
|
delete dbc; |
| 240 |
|
}; |
| 241 |
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
| 242 |
// |
// |
| 243 |
myquery.str(""); |
myquery.str(""); |
| 674 |
Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ |
Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ |
| 675 |
// MySQL variables |
// MySQL variables |
| 676 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 677 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 678 |
stringstream myquery; |
stringstream myquery; |
| 679 |
// |
// |
| 680 |
if ( !IDRUN ) IDRUN = ID; |
if ( !IDRUN ) IDRUN = ID; |
| 738 |
UInt_t idl0 = 0; |
UInt_t idl0 = 0; |
| 739 |
UInt_t idl2 = 0; |
UInt_t idl2 = 0; |
| 740 |
// |
// |
| 741 |
|
if (Row) |
| 742 |
|
delete Row; |
| 743 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 744 |
if( Row != NULL ){ |
if( Row != NULL ){ |
| 745 |
idtrash = (UInt_t)atoll(Row->GetField(0)); |
idtrash = (UInt_t)atoll(Row->GetField(0)); |
| 759 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
| 760 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 761 |
// |
// |
| 762 |
|
if (Row) |
| 763 |
|
delete Row; |
| 764 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 765 |
if( Row != NULL ){ |
if( Row != NULL ){ |
| 766 |
fileL0 = (TString)Row->GetField(0); |
fileL0 = (TString)Row->GetField(0); |
| 778 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
| 779 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 780 |
// |
// |
| 781 |
|
if (Row) |
| 782 |
|
delete Row; |
| 783 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 784 |
if( Row != NULL ){ |
if( Row != NULL ){ |
| 785 |
fileL2 = (TString)Row->GetField(0); |
fileL2 = (TString)Row->GetField(0); |
| 786 |
}; |
} |
| 787 |
|
if (Row){ |
| 788 |
|
delete Row; |
| 789 |
|
Row = NULL; // This variable is not used below |
| 790 |
|
} |
| 791 |
// |
// |
| 792 |
// |
// |
| 793 |
// |
// |
| 852 |
//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; |
//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; |
| 853 |
// MySQL variables |
// MySQL variables |
| 854 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 855 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 856 |
stringstream myquery; |
stringstream myquery; |
| 857 |
// |
// |
| 858 |
if ( !IDRUN ) IDRUN = ID; |
if ( !IDRUN ) IDRUN = ID; |
| 1153 |
Int_t GL_RUN::Query_GL_RUN(UInt_t run, TSQLServer *dbc){ |
Int_t GL_RUN::Query_GL_RUN(UInt_t run, TSQLServer *dbc){ |
| 1154 |
// MySQL variables |
// MySQL variables |
| 1155 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1156 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
|
int t; |
|
| 1157 |
int r; |
int r; |
| 1158 |
stringstream myquery; |
stringstream myquery; |
| 1159 |
// ---------------- |
// ---------------- |
| 1202 |
// |
// |
| 1203 |
if( !pResult->GetRowCount() ) return(-50); |
if( !pResult->GetRowCount() ) return(-50); |
| 1204 |
// |
// |
| 1205 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1206 |
|
if (Row) |
| 1207 |
|
delete Row; |
| 1208 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1209 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 1210 |
// Set_GL_RUN(Row); |
// Set_GL_RUN(Row); |
| 1211 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( int t = 0; t < pResult->GetFieldCount(); t++){ |
| 1212 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
| 1213 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
| 1214 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
| 1242 |
if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); |
if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); |
| 1243 |
if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
| 1244 |
}; |
}; |
| 1245 |
}; |
} |
| 1246 |
// delete pResult; |
|
| 1247 |
|
if (Row) |
| 1248 |
|
delete Row; |
| 1249 |
|
delete pResult; |
| 1250 |
return(0); |
return(0); |
| 1251 |
}; |
}; |
| 1252 |
|
|
| 1260 |
Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TString where, TSQLServer *dbc){ |
Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TString where, TSQLServer *dbc){ |
| 1261 |
// MySQL variables |
// MySQL variables |
| 1262 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1263 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 1264 |
int t; |
int t; |
| 1265 |
int r; |
int r; |
| 1266 |
stringstream myquery; |
stringstream myquery; |
| 1308 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1309 |
if(!pResult->GetRowCount())return(-50); |
if(!pResult->GetRowCount())return(-50); |
| 1310 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1311 |
|
if (Row) |
| 1312 |
|
delete Row; |
| 1313 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1314 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 1315 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 1346 |
if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); |
if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); |
| 1347 |
if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
| 1348 |
}; |
}; |
| 1349 |
}; |
} |
| 1350 |
// delete pResult; |
|
| 1351 |
|
if (Row) |
| 1352 |
|
delete Row; |
| 1353 |
|
delete pResult; |
| 1354 |
return(0); |
return(0); |
| 1355 |
};// **************************************************** |
};// **************************************************** |
| 1356 |
|
|
| 1363 |
Int_t GL_ROOT::Query_GL_ROOT(UInt_t id, TSQLServer *dbc){ |
Int_t GL_ROOT::Query_GL_ROOT(UInt_t id, TSQLServer *dbc){ |
| 1364 |
// MySQL variables |
// MySQL variables |
| 1365 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1366 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 1367 |
int t; |
int t; |
| 1368 |
int r; |
int r; |
| 1369 |
stringstream myquery; |
stringstream myquery; |
| 1382 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1383 |
if(!pResult->GetRowCount())return (-51); |
if(!pResult->GetRowCount())return (-51); |
| 1384 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1385 |
|
if (Row) |
| 1386 |
|
delete Row; |
| 1387 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1388 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 1389 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 1392 |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
| 1393 |
if(t==3) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/'; |
if(t==3) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/'; |
| 1394 |
if(t==4) NAME = Row->GetField(t); |
if(t==4) NAME = Row->GetField(t); |
| 1395 |
}; |
} |
| 1396 |
}; |
} |
| 1397 |
|
if (Row) |
| 1398 |
|
delete Row; |
| 1399 |
delete pResult; |
delete pResult; |
| 1400 |
return 0; |
return 0; |
| 1401 |
}; |
}; |
| 1410 |
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){ |
| 1411 |
// MySQL variables |
// MySQL variables |
| 1412 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1413 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 1414 |
int t; |
int t; |
| 1415 |
int r; |
int r; |
| 1416 |
stringstream myquery; |
stringstream myquery; |
| 1426 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1427 |
if(!pResult->GetRowCount())return (-53); |
if(!pResult->GetRowCount())return (-53); |
| 1428 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1429 |
|
if (Row) |
| 1430 |
|
delete Row; |
| 1431 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1432 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 1433 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 1448 |
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
| 1449 |
if (t==11) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==11) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
| 1450 |
}; |
}; |
| 1451 |
}; |
} |
| 1452 |
|
if (Row) |
| 1453 |
|
delete Row; |
| 1454 |
delete pResult; |
delete pResult; |
| 1455 |
// |
// |
| 1456 |
// if ( TO_TIME < time ) return(51); |
// if ( TO_TIME < time ) return(51); |
| 1470 |
Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t &uptime, 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){ |
| 1471 |
// MySQL variables |
// MySQL variables |
| 1472 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1473 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 1474 |
int t; |
int t; |
| 1475 |
stringstream myquery; |
stringstream myquery; |
| 1476 |
uptime = 0; |
uptime = 0; |
| 1490 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
| 1491 |
// |
// |
| 1492 |
if( !pResult->GetRowCount() ) return(-54); |
if( !pResult->GetRowCount() ) return(-54); |
| 1493 |
|
if (Row) |
| 1494 |
|
delete Row; |
| 1495 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1496 |
if( Row == NULL ) return (-54); |
if( Row == NULL ) return (-54); |
| 1497 |
// |
// |
| 1519 |
// |
// |
| 1520 |
if( !pResult->GetRowCount() ) return (-54); |
if( !pResult->GetRowCount() ) return (-54); |
| 1521 |
// |
// |
| 1522 |
|
if (Row) |
| 1523 |
|
delete Row; |
| 1524 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1525 |
// |
// |
| 1526 |
myfromtime = (UInt_t)atoll(Row->GetField(1)); |
myfromtime = (UInt_t)atoll(Row->GetField(1)); |
| 1555 |
if (t==1) FROM_TIME = myfromtime; |
if (t==1) FROM_TIME = myfromtime; |
| 1556 |
if (t==2) TO_TIME = mytotime; |
if (t==2) TO_TIME = mytotime; |
| 1557 |
if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
| 1558 |
}; |
} |
| 1559 |
|
if (Row) |
| 1560 |
|
delete Row; |
| 1561 |
pResult->Delete(); |
pResult->Delete(); |
| 1562 |
return 0; |
return 0; |
| 1563 |
}; |
}; |
| 1573 |
Int_t GL_CALOPULSE_CALIB::Query_GL_CALOPULSE_CALIB(UInt_t time, UInt_t section, UInt_t pampli, TSQLServer *dbc){ |
Int_t GL_CALOPULSE_CALIB::Query_GL_CALOPULSE_CALIB(UInt_t time, UInt_t section, UInt_t pampli, TSQLServer *dbc){ |
| 1574 |
// MySQL variables |
// MySQL variables |
| 1575 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1576 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 1577 |
int t; |
int t; |
| 1578 |
stringstream myquery; |
stringstream myquery; |
| 1579 |
// |
// |
| 1591 |
// |
// |
| 1592 |
if( !pResult ) return(-54); |
if( !pResult ) return(-54); |
| 1593 |
// |
// |
| 1594 |
|
if (Row) |
| 1595 |
|
delete Row; |
| 1596 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1597 |
// |
// |
| 1598 |
if( !Row ) return (-54); |
if( !Row ) return (-54); |
| 1605 |
if (t==1) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==1) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1606 |
if (t==2) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==2) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1607 |
if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
| 1608 |
}; |
} |
| 1609 |
|
if (Row) |
| 1610 |
|
delete Row; |
| 1611 |
pResult->Delete(); |
pResult->Delete(); |
| 1612 |
return 0; |
return 0; |
| 1613 |
}; |
}; |
| 1623 |
Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UInt_t time, TSQLServer *dbc){ |
Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UInt_t time, TSQLServer *dbc){ |
| 1624 |
// MySQL variables |
// MySQL variables |
| 1625 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1626 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 1627 |
int t; |
int t; |
| 1628 |
int r; |
int r; |
| 1629 |
stringstream myquery; |
stringstream myquery; |
| 1637 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1638 |
if(!pResult->GetRowCount())return (-55);//throw -55; |
if(!pResult->GetRowCount())return (-55);//throw -55; |
| 1639 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1640 |
|
if (Row) |
| 1641 |
|
delete Row; |
| 1642 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1643 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 1644 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 1648 |
if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1649 |
if (t==4) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==4) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1650 |
}; |
}; |
| 1651 |
}; |
} |
| 1652 |
|
if (Row) |
| 1653 |
|
delete Row; |
| 1654 |
delete pResult; |
delete pResult; |
| 1655 |
// |
// |
| 1656 |
if(TO_TIME < time)return(51); |
if(TO_TIME < time)return(51); |
| 1669 |
// Bool_t debug = 1; |
// Bool_t debug = 1; |
| 1670 |
// MySQL variables |
// MySQL variables |
| 1671 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1672 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 1673 |
int t; |
int t; |
| 1674 |
int r; |
int r; |
| 1675 |
stringstream myquery; |
stringstream myquery; |
| 1687 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1688 |
if(!pResult->GetRowCount())return (-52); |
if(!pResult->GetRowCount())return (-52); |
| 1689 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1690 |
|
if (Row) |
| 1691 |
|
delete Row; |
| 1692 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1693 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 1694 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 1700 |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1701 |
if (t==6) TYPE = (UInt_t)atoll(Row->GetField(t)); |
if (t==6) TYPE = (UInt_t)atoll(Row->GetField(t)); |
| 1702 |
}; |
}; |
| 1703 |
}; |
} |
| 1704 |
|
if (Row) |
| 1705 |
|
delete Row; |
| 1706 |
delete pResult; |
delete pResult; |
| 1707 |
// |
// |
| 1708 |
if(TO_TIME==0) TO_TIME = numeric_limits<UInt_t>::max(); |
if(TO_TIME==0) TO_TIME = numeric_limits<UInt_t>::max(); |
| 1738 |
UInt_t idtsy = 0; |
UInt_t idtsy = 0; |
| 1739 |
// |
// |
| 1740 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1741 |
TSQLRow *Row = 0; |
TSQLRow *Row = NULL; |
| 1742 |
stringstream myquery; |
stringstream myquery; |
| 1743 |
stringstream rname; |
stringstream rname; |
| 1744 |
// pcksList packetsNames; |
// pcksList packetsNames; |
| 1758 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
| 1759 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1760 |
if( pResult->GetRowCount() ){ |
if( pResult->GetRowCount() ){ |
| 1761 |
|
if (Row) |
| 1762 |
|
delete Row; |
| 1763 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1764 |
if( Row ){ |
if( Row ){ |
| 1765 |
stringstream fname; |
stringstream fname; |
| 1780 |
T->GetEntry(0); |
T->GetEntry(0); |
| 1781 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
| 1782 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
| 1783 |
obtfirst = ph->GetOrbitalTime(); |
// obtfirst = ph->GetOrbitalTime(); |
| 1784 |
// |
// |
| 1785 |
}; |
}; |
| 1786 |
// |
// |
| 1804 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
| 1805 |
Bool_t fndit = false; |
Bool_t fndit = false; |
| 1806 |
if ( pResult ){ |
if ( pResult ){ |
| 1807 |
|
if (Row) |
| 1808 |
|
delete Row; |
| 1809 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1810 |
if ( Row ){ |
if ( Row ){ |
| 1811 |
// |
// |
| 1812 |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
| 1813 |
|
obtfirst = OBT0; |
| 1814 |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
| 1815 |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
| 1816 |
// |
// |
| 1821 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
| 1822 |
delete pResult; |
delete pResult; |
| 1823 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
| 1824 |
if ( pResult ){ |
if (pResult){ |
| 1825 |
Row = pResult->Next(); |
if (Row) |
| 1826 |
if ( Row ){ |
delete Row; |
| 1827 |
// printf(" GREAT! the DB structure is the new one! \n"); |
Row = pResult->Next(); |
| 1828 |
fndit = true; |
if ( Row ){ |
| 1829 |
dworbit = 1; |
// printf(" GREAT! the DB structure is the new one! \n"); |
| 1830 |
}; |
fndit = true; |
| 1831 |
|
dworbit = 1; |
| 1832 |
|
}; |
| 1833 |
|
}; |
| 1834 |
|
}; |
| 1835 |
|
}; |
| 1836 |
|
if ( !fndit ){ |
| 1837 |
|
// |
| 1838 |
|
printf(" ERROR OLD DB! \n"); |
| 1839 |
|
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
| 1840 |
|
// |
| 1841 |
|
}; |
| 1842 |
|
// |
| 1843 |
|
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); |
| 1844 |
|
T0 = (UInt_t)tu.GetSec(); |
| 1845 |
|
// |
| 1846 |
|
toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; |
| 1847 |
|
// |
| 1848 |
|
// printf(" T0 %u toffset is %u \n",T0,toffset); |
| 1849 |
|
// |
| 1850 |
|
if ( file ) file->Close(); |
| 1851 |
|
if (Row) |
| 1852 |
|
delete Row; |
| 1853 |
|
delete pResult; |
| 1854 |
|
}; |
| 1855 |
|
|
| 1856 |
|
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc, Bool_t usel0file){ |
| 1857 |
|
// MySQL variables |
| 1858 |
|
TFile *file = 0; |
| 1859 |
|
UInt_t idtsy = 0; |
| 1860 |
|
// |
| 1861 |
|
TSQLResult *pResult; |
| 1862 |
|
TSQLRow *Row = NULL; |
| 1863 |
|
stringstream myquery; |
| 1864 |
|
stringstream rname; |
| 1865 |
|
// pcksList packetsNames; |
| 1866 |
|
// pcksList::iterator Iter; |
| 1867 |
|
// getPacketsNames(packetsNames); |
| 1868 |
|
rname.str(""); |
| 1869 |
|
// ---------------- |
| 1870 |
|
myquery.str(""); |
| 1871 |
|
myquery << "select "; |
| 1872 |
|
myquery << "PATH"; |
| 1873 |
|
myquery << ",NAME,ID_TIMESYNC"; |
| 1874 |
|
myquery << " from GL_ROOT where "; |
| 1875 |
|
myquery << type.Data(); |
| 1876 |
|
myquery << "=" << id << ";"; |
| 1877 |
|
// |
| 1878 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1879 |
|
this->GetGLTABLES()->AddQ(); |
| 1880 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 1881 |
|
if( pResult->GetRowCount() ){ |
| 1882 |
|
if (Row) |
| 1883 |
|
delete Row; |
| 1884 |
|
Row = pResult->Next(); |
| 1885 |
|
if( Row ){ |
| 1886 |
|
stringstream fname; |
| 1887 |
|
fname.str(""); |
| 1888 |
|
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
| 1889 |
|
rname << Row->GetField(1); |
| 1890 |
|
if ( usel0file ) file = new TFile(fname.str().c_str(),"READ"); |
| 1891 |
|
idtsy = (UInt_t)atoll(Row->GetField(2)); |
| 1892 |
|
}; |
| 1893 |
|
}; |
| 1894 |
|
// |
| 1895 |
|
if ( usel0file && file && file->IsOpen() ){ |
| 1896 |
|
TTree *T=(TTree*)file->Get("Physics"); |
| 1897 |
|
pamela::EventHeader *eh = 0; |
| 1898 |
|
pamela::PscuHeader *ph = 0; |
| 1899 |
|
T->SetBranchAddress("Header", &eh); |
| 1900 |
|
// |
| 1901 |
|
T->GetEntry(0); |
| 1902 |
|
ph = eh->GetPscuHeader(); |
| 1903 |
|
pktfirst = ph->GetCounter(); |
| 1904 |
|
// obtfirst = ph->GetOrbitalTime(); |
| 1905 |
|
// |
| 1906 |
|
}; |
| 1907 |
|
if ( !usel0file ) pktfirst = 0; |
| 1908 |
|
// |
| 1909 |
|
// look for Resurs offset |
| 1910 |
|
// |
| 1911 |
|
T0 = 0; |
| 1912 |
|
// |
| 1913 |
|
stringstream oss; |
| 1914 |
|
// |
| 1915 |
|
TString name=rname.str().c_str(); |
| 1916 |
|
UInt_t dworbit = 0; |
| 1917 |
|
// Int_t nlength = name.Length(); |
| 1918 |
|
delete pResult; |
| 1919 |
|
// |
| 1920 |
|
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
| 1921 |
|
// |
| 1922 |
|
oss.str(""); |
| 1923 |
|
oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; |
| 1924 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1925 |
|
this->GetGLTABLES()->AddQ(); |
| 1926 |
|
pResult = dbc->Query(oss.str().c_str()); |
| 1927 |
|
Bool_t fndit = false; |
| 1928 |
|
if ( pResult ){ |
| 1929 |
|
if (Row) |
| 1930 |
|
delete Row; |
| 1931 |
|
Row = pResult->Next(); |
| 1932 |
|
if ( Row ){ |
| 1933 |
|
// |
| 1934 |
|
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
| 1935 |
|
obtfirst = OBT0; |
| 1936 |
|
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
| 1937 |
|
TYPE = (UInt_t)atoll(Row->GetField(2)); |
| 1938 |
|
// |
| 1939 |
|
oss.str(""); |
| 1940 |
|
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE ID=" |
| 1941 |
|
<< Row->GetField(3) << ";"; |
| 1942 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1943 |
|
this->GetGLTABLES()->AddQ(); |
| 1944 |
|
delete pResult; |
| 1945 |
|
pResult = dbc->Query(oss.str().c_str()); |
| 1946 |
|
if (pResult){ |
| 1947 |
|
if (Row) |
| 1948 |
|
delete Row; |
| 1949 |
|
Row = pResult->Next(); |
| 1950 |
|
if (Row){ |
| 1951 |
|
// printf(" GREAT! the DB structure is the new one! \n"); |
| 1952 |
|
fndit = true; |
| 1953 |
|
dworbit = 1; |
| 1954 |
|
}; |
| 1955 |
}; |
}; |
| 1956 |
}; |
}; |
| 1957 |
}; |
}; |
| 1965 |
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); |
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); |
| 1966 |
T0 = (UInt_t)tu.GetSec(); |
T0 = (UInt_t)tu.GetSec(); |
| 1967 |
// |
// |
| 1968 |
toffset = TIMESYNC - (UInt_t)(this->DBobt(OBT0/1000)) + T0; |
toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; |
| 1969 |
// |
// |
| 1970 |
// printf(" T0 %u toffset is %u \n",T0,toffset); |
// printf(" T0 %u toffset is %u \n",T0,toffset); |
| 1971 |
// |
// |
| 1972 |
file->Close(); |
if ( file ) file->Close(); |
| 1973 |
|
if (Row) |
| 1974 |
|
delete Row; |
| 1975 |
delete pResult; |
delete pResult; |
| 1976 |
}; |
}; |
| 1977 |
|
|
| 2242 |
// |
// |
| 2243 |
Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){ |
Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){ |
| 2244 |
TSQLResult *result; |
TSQLResult *result; |
| 2245 |
TSQLRow *row; |
TSQLRow *row = NULL; |
| 2246 |
|
|
| 2247 |
// Set the right time_zone (otherwise horrible things will occur! :) |
// Set the right time_zone (otherwise horrible things will occur! :) |
| 2248 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 2261 |
tle = GiveTle(row); |
tle = GiveTle(row); |
| 2262 |
|
|
| 2263 |
tleFromTime = strtol(row->GetField(4), NULL, 10); |
tleFromTime = strtol(row->GetField(4), NULL, 10); |
| 2264 |
|
if (row) |
| 2265 |
|
delete row; |
| 2266 |
row = result->Next(); // second tle row |
row = result->Next(); // second tle row |
| 2267 |
if(row) |
if(row) |
| 2268 |
tleToTime = strtol(row->GetField(4), NULL, 10); |
tleToTime = strtol(row->GetField(4), NULL, 10); |
| 2271 |
tleToTime = UINT_MAX; |
tleToTime = UINT_MAX; |
| 2272 |
} |
} |
| 2273 |
|
|
| 2274 |
delete row; |
if (row) |
| 2275 |
|
delete row; |
| 2276 |
delete result; |
delete result; |
| 2277 |
|
|
| 2278 |
return 0; |
return 0; |