| 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 |
|
if (Row) |
| 72 |
|
delete Row; |
| 73 |
|
pResult = dbc->Query(query.Data()); |
| 74 |
|
// |
| 75 |
|
Row = pResult->Next(); |
| 76 |
|
// |
| 77 |
|
Int_t dim = pResult->GetFieldCount(); |
| 78 |
|
if ( dim < 1 || dim > 2 ){ |
| 79 |
|
printf(" Dim == %i not supported yet \n",dim); |
| 80 |
|
return NULL; |
| 81 |
|
}; |
| 82 |
|
// |
| 83 |
|
TH1D *h1 = NULL; |
| 84 |
|
TH2D *h2 = NULL; |
| 85 |
|
Double_t f1 = 0.; |
| 86 |
|
Double_t minf1 = numeric_limits<Double_t>::max(); |
| 87 |
|
Double_t maxf1 = numeric_limits<Double_t>::min(); |
| 88 |
|
Double_t f2 = 0.; |
| 89 |
|
Double_t minf2 = numeric_limits<Double_t>::max(); |
| 90 |
|
Double_t maxf2 = numeric_limits<Double_t>::min(); |
| 91 |
|
// |
| 92 |
|
while ( Row ){ |
| 93 |
|
f1 = (Double_t)atof(Row->GetField(0)); |
| 94 |
|
if ( f1 > maxf1 ) maxf1 = f1; |
| 95 |
|
if ( f1 < minf1 ) minf1 = f1; |
| 96 |
|
if ( dim == 2 ){ |
| 97 |
|
f2 = (Double_t)atof(Row->GetField(1)); |
| 98 |
|
if ( f2 > maxf2 ) maxf2 = f2; |
| 99 |
|
if ( f2 < minf2 ) minf2 = f2; |
| 100 |
|
|
| 101 |
|
}; |
| 102 |
|
if (Row) |
| 103 |
|
delete Row; |
| 104 |
|
Row = pResult->Next(); |
| 105 |
|
}; |
| 106 |
|
pResult->Delete(); |
| 107 |
|
// |
| 108 |
|
|
| 109 |
|
// |
| 110 |
|
Int_t f1bin = 70; |
| 111 |
|
Int_t f2bin = 70; |
| 112 |
|
if ( dim == 1 ){ |
| 113 |
|
f1bin = int((maxf1-minf1)/1000.); |
| 114 |
|
if ( f1bin < 70 ) f1bin = 70; |
| 115 |
|
if ( f1bin > 1000 ) f1bin = 1000; |
| 116 |
|
if ( !strcmp(hname.Data(),"q2th") ) hname += "1"; |
| 117 |
|
// h1 = dynamic_cast<TH1D*>(gDirectory->FindObject(hname.Data())); |
| 118 |
|
h1 = (TH1D*)(gDirectory->FindObject(hname.Data())); |
| 119 |
|
if ( !strcmp(hname.Data(),"q2th1") ){ |
| 120 |
|
if ( h1 ) h1->Delete(); |
| 121 |
|
}; |
| 122 |
|
if ( !h1 ) h1 = new TH1D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02); |
| 123 |
|
// h1->SetBit(TH1::kCanRebin); |
| 124 |
|
if ( verbose ) printf("\n\n Row %s \n",pResult->GetFieldName(0)); |
| 125 |
|
}; |
| 126 |
|
if ( dim == 2 ){ |
| 127 |
|
f2bin = int((maxf2-minf2)/1000.); |
| 128 |
|
if ( f2bin < 70 ) f2bin = 70; |
| 129 |
|
if ( f2bin > 1000 ) f2bin = 1000; |
| 130 |
|
if ( !strcmp(hname.Data(),"q2th") ) hname += "2"; |
| 131 |
|
// h2 = dynamic_cast<TH2D*>(gDirectory->FindObject(hname.Data())); |
| 132 |
|
h2 = (TH2D*)(gDirectory->FindObject(hname.Data())); |
| 133 |
|
if ( !strcmp(hname.Data(),"q2th2") ){ |
| 134 |
|
if ( h2 ) h2->Delete(); |
| 135 |
|
}; |
| 136 |
|
if ( !h2 ) h2 = new TH2D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02,f2bin,minf2*0.98,maxf2*1.02); |
| 137 |
|
// h2->SetBit(TH2::kCanRebin); |
| 138 |
|
if ( verbose ) printf("\n\n Row %s %s \n",pResult->GetFieldName(0),pResult->GetFieldName(1)); |
| 139 |
|
}; |
| 140 |
|
// |
| 141 |
|
pResult = dbc->Query(query.Data()); |
| 142 |
|
// |
| 143 |
|
if (Row) |
| 144 |
|
delete Row; |
| 145 |
|
Row = pResult->Next(); |
| 146 |
|
// |
| 147 |
|
Int_t r = 0; |
| 148 |
|
// |
| 149 |
|
while ( Row ){ |
| 150 |
|
f1 = (Double_t)atof(Row->GetField(0)); |
| 151 |
|
if ( dim == 1 ){ |
| 152 |
|
if ( verbose ) printf(" %i %f \n",r,f1); |
| 153 |
|
h1->Fill(f1); |
| 154 |
|
} else { |
| 155 |
|
f2 = (Double_t)atof(Row->GetField(1)); |
| 156 |
|
if ( verbose ) printf(" %i %f %f \n",r,f1,f2); |
| 157 |
|
h2->Fill(f1,f2); |
| 158 |
|
}; |
| 159 |
|
r++; |
| 160 |
|
if (Row) |
| 161 |
|
delete Row; |
| 162 |
|
Row = pResult->Next(); |
| 163 |
|
}; |
| 164 |
|
// |
| 165 |
|
TCanvas *c = NULL; |
| 166 |
|
TString cname = Form("%sc",hname.Data()); |
| 167 |
|
// c = dynamic_cast<TCanvas*>(gDirectory->FindObject(hname.Data())); |
| 168 |
|
c = (TCanvas*)(gDirectory->FindObject(cname.Data())); |
| 169 |
|
if ( !c ) c = new TCanvas(Form("%sc",cname.Data())); |
| 170 |
|
c->Clear(); |
| 171 |
|
c->cd(); |
| 172 |
|
if ( dim == 1 ) h1->Draw(); |
| 173 |
|
if ( dim == 2 ) h2->Draw(); |
| 174 |
|
// |
| 175 |
|
if (Row) |
| 176 |
|
delete Row; |
| 177 |
|
pResult->Delete(); |
| 178 |
|
if ( dim == 1 ) return h1; |
| 179 |
|
if ( dim == 2 ) return h2; |
| 180 |
|
// |
| 181 |
|
return NULL; |
| 182 |
|
}; |
| 183 |
|
|
| 184 |
GL_TABLES::GL_TABLES(){ |
GL_TABLES::GL_TABLES(){ |
| 185 |
}; |
}; |
| 186 |
|
|
| 207 |
mp = psw.Data(); |
mp = psw.Data(); |
| 208 |
}; |
}; |
| 209 |
|
|
| 210 |
Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
//Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
| 211 |
|
Bool_t GL_TABLES::IsConnected(TSQLServer *dbc){ |
| 212 |
// |
// |
| 213 |
// |
// |
| 214 |
// |
// |
| 244 |
TString host = fHost->Data(); |
TString host = fHost->Data(); |
| 245 |
TString user = fUser->Data(); |
TString user = fUser->Data(); |
| 246 |
TString psw = fPsw->Data(); |
TString psw = fPsw->Data(); |
| 247 |
dbc->Close(); |
if ( dbc ){ |
| 248 |
delete dbc; |
dbc->Close(); |
| 249 |
|
delete dbc; |
| 250 |
|
dbc = 0; |
| 251 |
|
}; |
| 252 |
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
| 253 |
// |
// |
| 254 |
myquery.str(""); |
myquery.str(""); |
| 685 |
Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ |
Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ |
| 686 |
// MySQL variables |
// MySQL variables |
| 687 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 688 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 689 |
stringstream myquery; |
stringstream myquery; |
| 690 |
// |
// |
| 691 |
if ( !IDRUN ) IDRUN = ID; |
if ( !IDRUN ) IDRUN = ID; |
| 749 |
UInt_t idl0 = 0; |
UInt_t idl0 = 0; |
| 750 |
UInt_t idl2 = 0; |
UInt_t idl2 = 0; |
| 751 |
// |
// |
| 752 |
|
if (Row) |
| 753 |
|
delete Row; |
| 754 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 755 |
if( Row != NULL ){ |
if( Row != NULL ){ |
| 756 |
idtrash = (UInt_t)atoll(Row->GetField(0)); |
idtrash = (UInt_t)atoll(Row->GetField(0)); |
| 770 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
| 771 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 772 |
// |
// |
| 773 |
|
if (Row) |
| 774 |
|
delete Row; |
| 775 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 776 |
if( Row != NULL ){ |
if( Row != NULL ){ |
| 777 |
fileL0 = (TString)Row->GetField(0); |
fileL0 = (TString)Row->GetField(0); |
| 789 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
| 790 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 791 |
// |
// |
| 792 |
|
if (Row) |
| 793 |
|
delete Row; |
| 794 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 795 |
if( Row != NULL ){ |
if( Row != NULL ){ |
| 796 |
fileL2 = (TString)Row->GetField(0); |
fileL2 = (TString)Row->GetField(0); |
| 797 |
}; |
} |
| 798 |
|
if (Row){ |
| 799 |
|
delete Row; |
| 800 |
|
Row = NULL; // This variable is not used below |
| 801 |
|
} |
| 802 |
// |
// |
| 803 |
// |
// |
| 804 |
// |
// |
| 863 |
//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; |
| 864 |
// MySQL variables |
// MySQL variables |
| 865 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 866 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 867 |
stringstream myquery; |
stringstream myquery; |
| 868 |
// |
// |
| 869 |
if ( !IDRUN ) IDRUN = ID; |
if ( !IDRUN ) IDRUN = ID; |
| 1164 |
Int_t GL_RUN::Query_GL_RUN(UInt_t run, TSQLServer *dbc){ |
Int_t GL_RUN::Query_GL_RUN(UInt_t run, TSQLServer *dbc){ |
| 1165 |
// MySQL variables |
// MySQL variables |
| 1166 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1167 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
|
int t; |
|
| 1168 |
int r; |
int r; |
| 1169 |
stringstream myquery; |
stringstream myquery; |
| 1170 |
// ---------------- |
// ---------------- |
| 1213 |
// |
// |
| 1214 |
if( !pResult->GetRowCount() ) return(-50); |
if( !pResult->GetRowCount() ) return(-50); |
| 1215 |
// |
// |
| 1216 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1217 |
|
if (Row) |
| 1218 |
|
delete Row; |
| 1219 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1220 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 1221 |
// Set_GL_RUN(Row); |
// Set_GL_RUN(Row); |
| 1222 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( int t = 0; t < pResult->GetFieldCount(); t++){ |
| 1223 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
| 1224 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
| 1225 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
| 1253 |
if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); |
if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); |
| 1254 |
if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
| 1255 |
}; |
}; |
| 1256 |
}; |
} |
| 1257 |
// delete pResult; |
|
| 1258 |
|
if (Row) |
| 1259 |
|
delete Row; |
| 1260 |
|
delete pResult; |
| 1261 |
return(0); |
return(0); |
| 1262 |
}; |
}; |
| 1263 |
|
|
| 1271 |
Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TString where, TSQLServer *dbc){ |
Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TString where, TSQLServer *dbc){ |
| 1272 |
// MySQL variables |
// MySQL variables |
| 1273 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1274 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 1275 |
int t; |
int t; |
| 1276 |
int r; |
int r; |
| 1277 |
stringstream myquery; |
stringstream myquery; |
| 1319 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1320 |
if(!pResult->GetRowCount())return(-50); |
if(!pResult->GetRowCount())return(-50); |
| 1321 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1322 |
|
if (Row) |
| 1323 |
|
delete Row; |
| 1324 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1325 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 1326 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 1357 |
if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); |
if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); |
| 1358 |
if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
| 1359 |
}; |
}; |
| 1360 |
}; |
} |
| 1361 |
// delete pResult; |
|
| 1362 |
|
if (Row) |
| 1363 |
|
delete Row; |
| 1364 |
|
delete pResult; |
| 1365 |
return(0); |
return(0); |
| 1366 |
};// **************************************************** |
};// **************************************************** |
| 1367 |
|
|
| 1374 |
Int_t GL_ROOT::Query_GL_ROOT(UInt_t id, TSQLServer *dbc){ |
Int_t GL_ROOT::Query_GL_ROOT(UInt_t id, TSQLServer *dbc){ |
| 1375 |
// MySQL variables |
// MySQL variables |
| 1376 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1377 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 1378 |
int t; |
int t; |
| 1379 |
int r; |
int r; |
| 1380 |
stringstream myquery; |
stringstream myquery; |
| 1393 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1394 |
if(!pResult->GetRowCount())return (-51); |
if(!pResult->GetRowCount())return (-51); |
| 1395 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1396 |
|
if (Row) |
| 1397 |
|
delete Row; |
| 1398 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1399 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 1400 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 1403 |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
| 1404 |
if(t==3) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/'; |
if(t==3) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/'; |
| 1405 |
if(t==4) NAME = Row->GetField(t); |
if(t==4) NAME = Row->GetField(t); |
| 1406 |
}; |
} |
| 1407 |
}; |
} |
| 1408 |
|
if (Row) |
| 1409 |
|
delete Row; |
| 1410 |
delete pResult; |
delete pResult; |
| 1411 |
return 0; |
return 0; |
| 1412 |
}; |
}; |
| 1421 |
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){ |
| 1422 |
// MySQL variables |
// MySQL variables |
| 1423 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1424 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 1425 |
int t; |
int t; |
| 1426 |
int r; |
int r; |
| 1427 |
stringstream myquery; |
stringstream myquery; |
| 1437 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1438 |
if(!pResult->GetRowCount())return (-53); |
if(!pResult->GetRowCount())return (-53); |
| 1439 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1440 |
|
if (Row) |
| 1441 |
|
delete Row; |
| 1442 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1443 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 1444 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 1459 |
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
| 1460 |
if (t==11) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==11) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
| 1461 |
}; |
}; |
| 1462 |
}; |
} |
| 1463 |
|
if (Row) |
| 1464 |
|
delete Row; |
| 1465 |
delete pResult; |
delete pResult; |
| 1466 |
// |
// |
| 1467 |
// if ( TO_TIME < time ) return(51); |
// if ( TO_TIME < time ) return(51); |
| 1481 |
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){ |
| 1482 |
// MySQL variables |
// MySQL variables |
| 1483 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1484 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 1485 |
int t; |
int t; |
| 1486 |
stringstream myquery; |
stringstream myquery; |
| 1487 |
uptime = 0; |
uptime = 0; |
| 1498 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1499 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
| 1500 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1501 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
| 1502 |
// |
// |
| 1503 |
if( !pResult->GetRowCount() ) return(-54); |
if( !pResult->GetRowCount() ) return(-54); |
| 1504 |
|
if (Row) |
| 1505 |
|
delete Row; |
| 1506 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1507 |
if( Row == NULL ) return (-54); |
if( Row == NULL ) return (-54); |
| 1508 |
// |
// |
| 1530 |
// |
// |
| 1531 |
if( !pResult->GetRowCount() ) return (-54); |
if( !pResult->GetRowCount() ) return (-54); |
| 1532 |
// |
// |
| 1533 |
|
if (Row) |
| 1534 |
|
delete Row; |
| 1535 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1536 |
// |
// |
| 1537 |
myfromtime = (UInt_t)atoll(Row->GetField(1)); |
myfromtime = (UInt_t)atoll(Row->GetField(1)); |
| 1554 |
// |
// |
| 1555 |
if( !pResult->GetRowCount() ) return (-54); |
if( !pResult->GetRowCount() ) return (-54); |
| 1556 |
// |
// |
| 1557 |
|
if (Row) |
| 1558 |
|
delete Row; |
| 1559 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1560 |
// |
// |
| 1561 |
}; |
}; |
| 1568 |
if (t==1) FROM_TIME = myfromtime; |
if (t==1) FROM_TIME = myfromtime; |
| 1569 |
if (t==2) TO_TIME = mytotime; |
if (t==2) TO_TIME = mytotime; |
| 1570 |
if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
| 1571 |
}; |
} |
| 1572 |
|
if (Row) |
| 1573 |
|
delete Row; |
| 1574 |
pResult->Delete(); |
pResult->Delete(); |
| 1575 |
return 0; |
return 0; |
| 1576 |
}; |
}; |
| 1586 |
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){ |
| 1587 |
// MySQL variables |
// MySQL variables |
| 1588 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1589 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 1590 |
int t; |
int t; |
| 1591 |
stringstream myquery; |
stringstream myquery; |
| 1592 |
// |
// |
| 1604 |
// |
// |
| 1605 |
if( !pResult ) return(-54); |
if( !pResult ) return(-54); |
| 1606 |
// |
// |
| 1607 |
|
if (Row) |
| 1608 |
|
delete Row; |
| 1609 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1610 |
// |
// |
| 1611 |
if( !Row ) return (-54); |
if( !Row ) return (-54); |
| 1618 |
if (t==1) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==1) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1619 |
if (t==2) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==2) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1620 |
if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
| 1621 |
}; |
} |
| 1622 |
|
if (Row) |
| 1623 |
|
delete Row; |
| 1624 |
pResult->Delete(); |
pResult->Delete(); |
| 1625 |
return 0; |
return 0; |
| 1626 |
}; |
}; |
| 1636 |
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){ |
| 1637 |
// MySQL variables |
// MySQL variables |
| 1638 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1639 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 1640 |
int t; |
int t; |
| 1641 |
int r; |
int r; |
| 1642 |
stringstream myquery; |
stringstream myquery; |
| 1650 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1651 |
if(!pResult->GetRowCount())return (-55);//throw -55; |
if(!pResult->GetRowCount())return (-55);//throw -55; |
| 1652 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1653 |
|
if (Row) |
| 1654 |
|
delete Row; |
| 1655 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1656 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 1657 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 1661 |
if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1662 |
if (t==4) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==4) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1663 |
}; |
}; |
| 1664 |
}; |
} |
| 1665 |
|
if (Row) |
| 1666 |
|
delete Row; |
| 1667 |
delete pResult; |
delete pResult; |
| 1668 |
// |
// |
| 1669 |
if(TO_TIME < time)return(51); |
if(TO_TIME < time)return(51); |
| 1682 |
// Bool_t debug = 1; |
// Bool_t debug = 1; |
| 1683 |
// MySQL variables |
// MySQL variables |
| 1684 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1685 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 1686 |
int t; |
int t; |
| 1687 |
int r; |
int r; |
| 1688 |
stringstream myquery; |
stringstream myquery; |
| 1700 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1701 |
if(!pResult->GetRowCount())return (-52); |
if(!pResult->GetRowCount())return (-52); |
| 1702 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1703 |
|
if (Row) |
| 1704 |
|
delete Row; |
| 1705 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1706 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 1707 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 1713 |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1714 |
if (t==6) TYPE = (UInt_t)atoll(Row->GetField(t)); |
if (t==6) TYPE = (UInt_t)atoll(Row->GetField(t)); |
| 1715 |
}; |
}; |
| 1716 |
}; |
} |
| 1717 |
|
if (Row) |
| 1718 |
|
delete Row; |
| 1719 |
delete pResult; |
delete pResult; |
| 1720 |
// |
// |
| 1721 |
if(TO_TIME==0) TO_TIME = numeric_limits<UInt_t>::max(); |
if(TO_TIME==0) TO_TIME = numeric_limits<UInt_t>::max(); |
| 1748 |
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){ |
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){ |
| 1749 |
// MySQL variables |
// MySQL variables |
| 1750 |
TFile *file = 0; |
TFile *file = 0; |
| 1751 |
UInt_t idraw = 0; |
UInt_t idtsy = 0; |
| 1752 |
// |
// |
| 1753 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1754 |
TSQLRow *Row; |
TSQLRow *Row = NULL; |
| 1755 |
stringstream myquery; |
stringstream myquery; |
| 1756 |
stringstream rname; |
stringstream rname; |
| 1757 |
// pcksList packetsNames; |
// pcksList packetsNames; |
| 1762 |
myquery.str(""); |
myquery.str(""); |
| 1763 |
myquery << "select "; |
myquery << "select "; |
| 1764 |
myquery << "PATH"; |
myquery << "PATH"; |
| 1765 |
myquery << ",NAME,ID_RAW"; |
myquery << ",NAME,ID_TIMESYNC"; |
| 1766 |
myquery << " from GL_ROOT where "; |
myquery << " from GL_ROOT where "; |
| 1767 |
myquery << type.Data(); |
myquery << type.Data(); |
| 1768 |
myquery << "=" << id << ";"; |
myquery << "=" << id << ";"; |
| 1771 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
| 1772 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1773 |
if( pResult->GetRowCount() ){ |
if( pResult->GetRowCount() ){ |
| 1774 |
|
if (Row) |
| 1775 |
|
delete Row; |
| 1776 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1777 |
if( Row ){ |
if( Row ){ |
| 1778 |
stringstream fname; |
stringstream fname; |
| 1780 |
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
| 1781 |
rname << Row->GetField(1); |
rname << Row->GetField(1); |
| 1782 |
file = new TFile(fname.str().c_str(),"READ"); |
file = new TFile(fname.str().c_str(),"READ"); |
| 1783 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
idtsy = (UInt_t)atoll(Row->GetField(2)); |
| 1784 |
}; |
}; |
| 1785 |
}; |
}; |
| 1786 |
// |
// |
| 1793 |
T->GetEntry(0); |
T->GetEntry(0); |
| 1794 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
| 1795 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
| 1796 |
obtfirst = ph->GetOrbitalTime(); |
// obtfirst = ph->GetOrbitalTime(); |
|
// |
|
|
// code = eh->GetCounter(); |
|
|
// UInt_t en = 0; |
|
|
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
|
|
// en = code->Get(GetPacketType(*Iter)); |
|
|
// if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){ |
|
|
// // |
|
|
// TTree *TC = 0; |
|
|
// TC = (TTree*)file->Get("CalibCalPed"); |
|
|
// if ( !TC || TC->IsZombie() ) return; |
|
|
// EventHeader *ehc = 0; |
|
|
// PscuHeader *phc = 0; |
|
|
// TC->SetBranchAddress("Header", &ehc); |
|
|
// TC->GetEntry(0); |
|
|
// phc = ehc->GetPscuHeader(); |
|
|
// pktfirst = phc->GetCounter(); |
|
|
// obtfirst = phc->GetOrbitalTime(); |
|
|
// // |
|
|
// }; |
|
|
// }; |
|
| 1797 |
// |
// |
| 1798 |
}; |
}; |
| 1799 |
// |
// |
| 1801 |
// |
// |
| 1802 |
T0 = 0; |
T0 = 0; |
| 1803 |
// |
// |
|
// |
|
| 1804 |
stringstream oss; |
stringstream oss; |
|
TString frn = rname.str().c_str(); |
|
|
frn = frn.ReplaceAll(".root",5,".pam",4); |
|
|
oss.str(""); |
|
|
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='" |
|
|
<< frn.Data() << "';"; |
|
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
|
|
this->GetGLTABLES()->AddQ(); |
|
|
pResult = dbc->Query(oss.str().c_str()); |
|
|
Row = pResult->Next(); |
|
| 1805 |
// |
// |
| 1806 |
TString name=rname.str().c_str(); |
TString name=rname.str().c_str(); |
| 1807 |
UInt_t dworbit = 0; |
UInt_t dworbit = 0; |
| 1808 |
Int_t nlength = name.Length(); |
// Int_t nlength = name.Length(); |
| 1809 |
|
delete pResult; |
| 1810 |
// |
// |
| 1811 |
// Is not a special file |
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
| 1812 |
// |
// |
| 1813 |
if ( !Row ){ |
oss.str(""); |
| 1814 |
delete pResult; |
oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; |
| 1815 |
// |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1816 |
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
this->GetGLTABLES()->AddQ(); |
| 1817 |
// |
pResult = dbc->Query(oss.str().c_str()); |
| 1818 |
oss.str(""); |
Bool_t fndit = false; |
| 1819 |
oss << "SELECT ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";"; |
if ( pResult ){ |
| 1820 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
if (Row) |
| 1821 |
this->GetGLTABLES()->AddQ(); |
delete Row; |
| 1822 |
pResult = dbc->Query(oss.str().c_str()); |
Row = pResult->Next(); |
| 1823 |
Bool_t fndit = false; |
if ( Row ){ |
|
if ( pResult ){ |
|
|
Row = pResult->Next(); |
|
|
if ( Row ){ |
|
|
oss.str(""); |
|
|
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=" |
|
|
<< Row->GetField(0) << ";"; |
|
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
|
|
this->GetGLTABLES()->AddQ(); |
|
|
pResult = dbc->Query(oss.str().c_str()); |
|
|
if ( pResult ){ |
|
|
Row = pResult->Next(); |
|
|
if ( Row ){ |
|
|
// printf(" GREAT! the DB structure is the new one! \n"); |
|
|
fndit = true; |
|
|
dworbit = 1; |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
}; |
|
|
if ( !fndit ){ |
|
|
delete pResult; |
|
|
// |
|
|
printf(" OK, you got an error because this is the old database\n Using backward compability code, hence you can continue safetly \n"); |
|
|
// |
|
|
// Old code, we must trust the filename |
|
| 1824 |
// |
// |
| 1825 |
if ( nlength < 5 ) return; |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
| 1826 |
TString dwo = 0; |
obtfirst = OBT0; |
| 1827 |
for (Int_t i = 0; i<5; i++){ |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
| 1828 |
dwo.Append(name[i],1); |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
|
}; |
|
|
if ( dwo.IsDigit() ){ |
|
|
dworbit = (UInt_t)dwo.Atoi(); |
|
|
} else { |
|
|
dwo=""; |
|
|
for (Int_t i = 8; i<13; i++){ |
|
|
dwo.Append(name[i],1); |
|
|
}; |
|
|
if ( dwo.IsDigit() ){ |
|
|
dworbit = (UInt_t)dwo.Atoi(); |
|
|
} else { |
|
|
dworbit = 1; |
|
|
}; |
|
|
}; |
|
| 1829 |
// |
// |
| 1830 |
oss.str(""); |
oss.str(""); |
| 1831 |
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 ID=" |
| 1832 |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
<< Row->GetField(3) << ";"; |
| 1833 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1834 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
| 1835 |
|
delete pResult; |
| 1836 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
| 1837 |
Row = pResult->Next(); |
if (pResult){ |
| 1838 |
if ( !Row ){ |
if (Row) |
| 1839 |
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
delete Row; |
| 1840 |
return; |
Row = pResult->Next(); |
| 1841 |
|
if ( Row ){ |
| 1842 |
|
// printf(" GREAT! the DB structure is the new one! \n"); |
| 1843 |
|
fndit = true; |
| 1844 |
|
dworbit = 1; |
| 1845 |
|
}; |
| 1846 |
}; |
}; |
| 1847 |
}; |
}; |
| 1848 |
}; |
}; |
| 1849 |
|
if ( !fndit ){ |
| 1850 |
|
// |
| 1851 |
|
printf(" ERROR OLD DB! \n"); |
| 1852 |
|
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
| 1853 |
|
// |
| 1854 |
|
}; |
| 1855 |
// |
// |
| 1856 |
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); |
| 1857 |
T0 = (UInt_t)tu.GetSec(); |
T0 = (UInt_t)tu.GetSec(); |
| 1858 |
// |
// |
| 1859 |
// look for the correct timesync entry |
toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; |
| 1860 |
|
// |
| 1861 |
|
// printf(" T0 %u toffset is %u \n",T0,toffset); |
| 1862 |
// |
// |
| 1863 |
|
if ( file ) file->Close(); |
| 1864 |
|
if (Row) |
| 1865 |
|
delete Row; |
| 1866 |
|
delete pResult; |
| 1867 |
|
}; |
| 1868 |
|
|
| 1869 |
|
GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc, Bool_t usel0file){ |
| 1870 |
|
// MySQL variables |
| 1871 |
|
TFile *file = 0; |
| 1872 |
|
UInt_t idtsy = 0; |
| 1873 |
|
// |
| 1874 |
|
TSQLResult *pResult; |
| 1875 |
|
TSQLRow *Row = NULL; |
| 1876 |
|
stringstream myquery; |
| 1877 |
|
stringstream rname; |
| 1878 |
|
// pcksList packetsNames; |
| 1879 |
|
// pcksList::iterator Iter; |
| 1880 |
|
// getPacketsNames(packetsNames); |
| 1881 |
|
rname.str(""); |
| 1882 |
|
// ---------------- |
| 1883 |
myquery.str(""); |
myquery.str(""); |
| 1884 |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
myquery << "select "; |
| 1885 |
<< " WHERE ID_RAW = " << idraw |
myquery << "PATH"; |
| 1886 |
<< ";"; |
myquery << ",NAME,ID_TIMESYNC"; |
| 1887 |
|
myquery << " from GL_ROOT where "; |
| 1888 |
|
myquery << type.Data(); |
| 1889 |
|
myquery << "=" << id << ";"; |
| 1890 |
|
// |
| 1891 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1892 |
this->GetGLTABLES()->AddQ(); |
this->GetGLTABLES()->AddQ(); |
| 1893 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1894 |
|
if( pResult->GetRowCount() ){ |
| 1895 |
|
if (Row) |
| 1896 |
|
delete Row; |
| 1897 |
|
Row = pResult->Next(); |
| 1898 |
|
if( Row ){ |
| 1899 |
|
stringstream fname; |
| 1900 |
|
fname.str(""); |
| 1901 |
|
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
| 1902 |
|
rname << Row->GetField(1); |
| 1903 |
|
if ( usel0file ) file = new TFile(fname.str().c_str(),"READ"); |
| 1904 |
|
idtsy = (UInt_t)atoll(Row->GetField(2)); |
| 1905 |
|
}; |
| 1906 |
|
}; |
| 1907 |
|
// |
| 1908 |
|
if ( usel0file && file && file->IsOpen() ){ |
| 1909 |
|
TTree *T=(TTree*)file->Get("Physics"); |
| 1910 |
|
pamela::EventHeader *eh = 0; |
| 1911 |
|
pamela::PscuHeader *ph = 0; |
| 1912 |
|
T->SetBranchAddress("Header", &eh); |
| 1913 |
|
// |
| 1914 |
|
T->GetEntry(0); |
| 1915 |
|
ph = eh->GetPscuHeader(); |
| 1916 |
|
pktfirst = ph->GetCounter(); |
| 1917 |
|
// obtfirst = ph->GetOrbitalTime(); |
| 1918 |
|
// |
| 1919 |
|
}; |
| 1920 |
|
if ( !usel0file ) pktfirst = 0; |
| 1921 |
|
// |
| 1922 |
|
// look for Resurs offset |
| 1923 |
|
// |
| 1924 |
|
T0 = 0; |
| 1925 |
|
// |
| 1926 |
|
stringstream oss; |
| 1927 |
|
// |
| 1928 |
|
TString name=rname.str().c_str(); |
| 1929 |
|
UInt_t dworbit = 0; |
| 1930 |
|
// Int_t nlength = name.Length(); |
| 1931 |
|
delete pResult; |
| 1932 |
|
// |
| 1933 |
|
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
| 1934 |
|
// |
| 1935 |
|
oss.str(""); |
| 1936 |
|
oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; |
| 1937 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1938 |
|
this->GetGLTABLES()->AddQ(); |
| 1939 |
|
pResult = dbc->Query(oss.str().c_str()); |
| 1940 |
|
Bool_t fndit = false; |
| 1941 |
if ( pResult ){ |
if ( pResult ){ |
| 1942 |
|
if (Row) |
| 1943 |
|
delete Row; |
| 1944 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1945 |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
if ( Row ){ |
| 1946 |
|
// |
| 1947 |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
| 1948 |
|
obtfirst = OBT0; |
| 1949 |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
| 1950 |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
TYPE = (UInt_t)atoll(Row->GetField(2)); |
| 1951 |
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; |
// |
| 1952 |
|
oss.str(""); |
| 1953 |
|
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=" |
| 1954 |
|
<< Row->GetField(3) << ";"; |
| 1955 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1956 |
|
this->GetGLTABLES()->AddQ(); |
| 1957 |
|
delete pResult; |
| 1958 |
|
pResult = dbc->Query(oss.str().c_str()); |
| 1959 |
|
if (pResult){ |
| 1960 |
|
if (Row) |
| 1961 |
|
delete Row; |
| 1962 |
|
Row = pResult->Next(); |
| 1963 |
|
if (Row){ |
| 1964 |
|
// printf(" GREAT! the DB structure is the new one! \n"); |
| 1965 |
|
fndit = true; |
| 1966 |
|
dworbit = 1; |
| 1967 |
|
}; |
| 1968 |
|
}; |
| 1969 |
}; |
}; |
| 1970 |
}; |
}; |
| 1971 |
|
if ( !fndit ){ |
| 1972 |
|
// |
| 1973 |
|
printf(" ERROR OLD DB! \n"); |
| 1974 |
|
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
| 1975 |
|
// |
| 1976 |
|
}; |
| 1977 |
|
// |
| 1978 |
|
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); |
| 1979 |
|
T0 = (UInt_t)tu.GetSec(); |
| 1980 |
|
// |
| 1981 |
|
toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; |
| 1982 |
// |
// |
| 1983 |
file->Close(); |
// printf(" T0 %u toffset is %u \n",T0,toffset); |
| 1984 |
|
// |
| 1985 |
|
if ( file ) file->Close(); |
| 1986 |
|
if (Row) |
| 1987 |
|
delete Row; |
| 1988 |
delete pResult; |
delete pResult; |
| 1989 |
}; |
}; |
| 1990 |
|
|
| 1995 |
*/ |
*/ |
| 1996 |
UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){ |
UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){ |
| 1997 |
// |
// |
| 1998 |
|
// printf(" OBT %u DBobt %llu toffset %u dbabstime %u\n",OBT,this->DBobt(OBT),toffset,((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
| 1999 |
return(((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
return(((UInt_t)(this->DBobt(OBT)/1000)+toffset)); |
| 2000 |
// |
// |
| 2001 |
}; |
}; |
| 2034 |
*/ |
*/ |
| 2035 |
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
| 2036 |
// |
// |
| 2037 |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt < ((Long64_t)obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){ |
| 2038 |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max()); |
| 2039 |
}; |
}; |
| 2040 |
// |
// |
| 2041 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( obt > ((Long64_t)obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
| 2042 |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
| 2043 |
}; |
}; |
| 2044 |
// |
// |
| 2255 |
// |
// |
| 2256 |
Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){ |
Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){ |
| 2257 |
TSQLResult *result; |
TSQLResult *result; |
| 2258 |
TSQLRow *row; |
TSQLRow *row = NULL; |
| 2259 |
|
|
| 2260 |
// Set the right time_zone (otherwise horrible things will occur! :) |
// Set the right time_zone (otherwise horrible things will occur! :) |
| 2261 |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 2274 |
tle = GiveTle(row); |
tle = GiveTle(row); |
| 2275 |
|
|
| 2276 |
tleFromTime = strtol(row->GetField(4), NULL, 10); |
tleFromTime = strtol(row->GetField(4), NULL, 10); |
| 2277 |
|
if (row) |
| 2278 |
|
delete row; |
| 2279 |
row = result->Next(); // second tle row |
row = result->Next(); // second tle row |
| 2280 |
if(row) |
if(row) |
| 2281 |
tleToTime = strtol(row->GetField(4), NULL, 10); |
tleToTime = strtol(row->GetField(4), NULL, 10); |
| 2284 |
tleToTime = UINT_MAX; |
tleToTime = UINT_MAX; |
| 2285 |
} |
} |
| 2286 |
|
|
| 2287 |
delete row; |
if (row) |
| 2288 |
|
delete row; |
| 2289 |
delete result; |
delete result; |
| 2290 |
|
|
| 2291 |
return 0; |
return 0; |