--- chewbacca/YodaProfiler/src/GLTables.cpp 2009/12/14 16:53:43 1.11 +++ chewbacca/YodaProfiler/src/GLTables.cpp 2015/01/19 12:34:16 1.20 @@ -33,14 +33,43 @@ using namespace std; Q2TH::Q2TH(TString host, TString user, TString psw){ + this->Open(host,user,psw); +}; + +void Q2TH::Open(TString host, TString user, TString psw){ fh = gSystem->ExpandPathName(host.Data()); fu = gSystem->ExpandPathName(user.Data()); fp = gSystem->ExpandPathName(psw.Data()); + printf(" Connecting to DB %s \n",fh.Data()); dbc = TSQLServer::Connect(fh.Data(),fu.Data(),fp.Data()); + if ( dbc && dbc->IsConnected() ){ + printf(" connected! \n"); + } else { + printf(" ERROR! not connected... :( \n"); + }; }; TObject *Q2TH::Draw(TString query, Bool_t verbose, TString hname){ // + if ( !strcmp(query.Data(),"help") ){ + printf(" USAGE: \n"); + printf(" 1) start root and create Q2TH object with \n"); + printf(" Q2TH *qt = new Q2TH() \n"); + printf(" or \n"); + printf(" Q2TH *qt = new Q2TH(\"mysql://srvg-g2-01.ts.infn.it/pamelaProcessing9_TS\",\"pamelaprod_ro\",\"mypassword\") \n"); + printf(" 2) query the DB with \n"); + printf(" qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\"); \n"); + printf(" qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\",true); this will print numbers on screen \n"); + printf(" qt->Draw(\"select REAL_TIME_INIT from ROOT_TABLE_MERGING;\",true,\"myhisto\"); this will print numbers on screen and create histo \"myhisto\"\n"); + printf(" 3) to use your own THxD create it and then query the DB giving as argument the name of histo: \n"); + printf(" TH2D *myhisto=new TH2D(\"myhisto\",\"myhisto\",5000,1140000000.,1240000000.,10000,0.,1.) \n"); + printf(" qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\",false,\"myhisto\")\n\n\n"); + + return NULL; + }; + // + if (Row) + delete Row; pResult = dbc->Query(query.Data()); // Row = pResult->Next(); @@ -70,17 +99,27 @@ if ( f2 < minf2 ) minf2 = f2; }; + if (Row) + delete Row; Row = pResult->Next(); }; pResult->Delete(); // + + // Int_t f1bin = 70; Int_t f2bin = 70; if ( dim == 1 ){ f1bin = int((maxf1-minf1)/1000.); if ( f1bin < 70 ) f1bin = 70; if ( f1bin > 1000 ) f1bin = 1000; - h1 = new TH1D(Form("%s1",hname.Data()),Form("%s1",hname.Data()),f1bin,minf1*0.98,maxf1*1.02); + if ( !strcmp(hname.Data(),"q2th") ) hname += "1"; + // h1 = dynamic_cast(gDirectory->FindObject(hname.Data())); + h1 = (TH1D*)(gDirectory->FindObject(hname.Data())); + if ( !strcmp(hname.Data(),"q2th1") ){ + if ( h1 ) h1->Delete(); + }; + if ( !h1 ) h1 = new TH1D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02); // h1->SetBit(TH1::kCanRebin); if ( verbose ) printf("\n\n Row %s \n",pResult->GetFieldName(0)); }; @@ -88,13 +127,21 @@ f2bin = int((maxf2-minf2)/1000.); if ( f2bin < 70 ) f2bin = 70; if ( f2bin > 1000 ) f2bin = 1000; - h2 = new TH2D(Form("%s2",hname.Data()),Form("%s2",hname.Data()),f1bin,minf1*0.98,maxf1*1.02,f2bin,minf2*0.98,maxf2*1.02); + if ( !strcmp(hname.Data(),"q2th") ) hname += "2"; + // h2 = dynamic_cast(gDirectory->FindObject(hname.Data())); + h2 = (TH2D*)(gDirectory->FindObject(hname.Data())); + if ( !strcmp(hname.Data(),"q2th2") ){ + if ( h2 ) h2->Delete(); + }; + if ( !h2 ) h2 = new TH2D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02,f2bin,minf2*0.98,maxf2*1.02); // h2->SetBit(TH2::kCanRebin); if ( verbose ) printf("\n\n Row %s %s \n",pResult->GetFieldName(0),pResult->GetFieldName(1)); }; // pResult = dbc->Query(query.Data()); // + if (Row) + delete Row; Row = pResult->Next(); // Int_t r = 0; @@ -102,22 +149,31 @@ while ( Row ){ f1 = (Double_t)atof(Row->GetField(0)); if ( dim == 1 ){ - if ( verbose ) printf(" %f \n",r,f1); + if ( verbose ) printf(" %i %f \n",r,f1); h1->Fill(f1); } else { f2 = (Double_t)atof(Row->GetField(1)); - if ( verbose ) printf(" %f %f \n",r,f1,f2); + if ( verbose ) printf(" %i %f %f \n",r,f1,f2); h2->Fill(f1,f2); }; r++; + if (Row) + delete Row; Row = pResult->Next(); }; // - TCanvas *c = new TCanvas(Form("%sc",hname.Data())); + TCanvas *c = NULL; + TString cname = Form("%sc",hname.Data()); + // c = dynamic_cast(gDirectory->FindObject(hname.Data())); + c = (TCanvas*)(gDirectory->FindObject(cname.Data())); + if ( !c ) c = new TCanvas(Form("%sc",cname.Data())); + c->Clear(); c->cd(); if ( dim == 1 ) h1->Draw(); if ( dim == 2 ) h2->Draw(); // + if (Row) + delete Row; pResult->Delete(); if ( dim == 1 ) return h1; if ( dim == 2 ) return h2; @@ -167,7 +223,7 @@ myquery << "show databases;"; if ( dbc ){ if ( dbc->IsConnected() ){ - dbc->Query(myquery.str().c_str()); + delete dbc->Query(myquery.str().c_str()); fNquery++; if ( !(dbc->GetErrorCode()) ){ // printf("ok\n"); @@ -191,12 +247,13 @@ if ( dbc ){ dbc->Close(); delete dbc; + dbc = 0; }; dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); // myquery.str(""); myquery << "show databases;"; - dbc->Query(myquery.str().c_str()); + delete dbc->Query(myquery.str().c_str()); fNquery++; // if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ if ( !(dbc->GetErrorCode()) ){ @@ -204,12 +261,16 @@ printf(" ...connection recovered, I can continue! \n"); // myquery.str(""); - myquery << "SET time_zone='+0:00'"; - dbc->Query(myquery.str().c_str()); + myquery << "SET time_zone='+0:00';"; + delete dbc->Query(myquery.str().c_str()); + fNquery++; + myquery.str(""); + myquery << "SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';"; + delete dbc->Query(myquery.str().c_str()); fNquery++; myquery.str(""); myquery << "SET wait_timeout=173000;"; - dbc->Query(myquery.str().c_str()); + delete dbc->Query(myquery.str().c_str()); fNquery++; return true; }; @@ -628,7 +689,7 @@ Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ // MySQL variables TSQLResult *pResult; - TSQLRow *Row; + TSQLRow *Row = NULL; stringstream myquery; // if ( !IDRUN ) IDRUN = ID; @@ -678,7 +739,7 @@ // if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); - dbc->Query(myquery.str().c_str()); + delete dbc->Query(myquery.str().c_str()); // // retrieve this ID_TRASH // @@ -692,6 +753,8 @@ UInt_t idl0 = 0; UInt_t idl2 = 0; // + if (Row) + delete Row; Row = pResult->Next(); if( Row != NULL ){ idtrash = (UInt_t)atoll(Row->GetField(0)); @@ -707,10 +770,18 @@ // // printf("2myquery is %s \n",myquery.str().c_str()); // - if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; + if ( !this->GetGLTABLES()->IsConnected(dbc) ){ + if (pResult) + delete pResult; + if (Row) + delete Row; + return -57; + } this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); // + if (Row) + delete Row; Row = pResult->Next(); if( Row != NULL ){ fileL0 = (TString)Row->GetField(0); @@ -724,14 +795,28 @@ // // printf("3myquery is %s \n",myquery.str().c_str()); // - if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; + if ( !this->GetGLTABLES()->IsConnected(dbc) ){ + if (pResult) + delete pResult; + if (Row) + delete Row; + return -57; + } this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); // + if (Row) + delete Row; Row = pResult->Next(); if( Row != NULL ){ fileL2 = (TString)Row->GetField(0); - }; + } + delete pResult; + pResult = NULL; + if (Row){ + delete Row; + Row = NULL; // This variable is not used below + } // // // @@ -744,7 +829,7 @@ // if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); - dbc->Query(myquery.str().c_str()); + delete dbc->Query(myquery.str().c_str()); // myquery.str(""); myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='"; @@ -755,7 +840,7 @@ // if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); - dbc->Query(myquery.str().c_str()); + delete dbc->Query(myquery.str().c_str()); // myquery.str(""); myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='"; @@ -767,7 +852,7 @@ // if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); - dbc->Query(myquery.str().c_str()); + delete dbc->Query(myquery.str().c_str()); // myquery.str(""); myquery << " DELETE FROM "; @@ -779,7 +864,7 @@ // if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); - dbc->Query(myquery.str().c_str()); + delete dbc->Query(myquery.str().c_str()); // return 0; }; @@ -795,8 +880,8 @@ // insert into GL_RUN_FRAGMENTS 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; // MySQL variables - TSQLResult *pResult; - TSQLRow *Row; + TSQLResult *pResult = NULL; + TSQLRow *Row = NULL; stringstream myquery; // if ( !IDRUN ) IDRUN = ID; @@ -818,9 +903,15 @@ if( Row != NULL ){ ToTable = (TString)Row->GetField(0); } else { + delete pResult; return 1; }; }; + + if (pResult) + delete pResult; + if (Row) + delete Row; // ---------------- myquery.str(""); myquery << " INSERT INTO "; @@ -901,7 +992,7 @@ // if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); - dbc->Query(myquery.str().c_str()); + delete dbc->Query(myquery.str().c_str()); // // myquery.str(""); @@ -910,7 +1001,7 @@ // if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); - dbc->Query(myquery.str().c_str()); + delete dbc->Query(myquery.str().c_str()); // return 0; }; @@ -998,7 +1089,7 @@ // if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); - dbc->Query(myquery.str().c_str()); + delete dbc->Query(myquery.str().c_str()); // return 0; @@ -1080,7 +1171,7 @@ // if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); - dbc->Query(myquery.str().c_str()); + delete dbc->Query(myquery.str().c_str()); // return 0; @@ -1097,8 +1188,7 @@ Int_t GL_RUN::Query_GL_RUN(UInt_t run, TSQLServer *dbc){ // MySQL variables TSQLResult *pResult; - TSQLRow *Row; - int t; + TSQLRow *Row = NULL; int r; stringstream myquery; // ---------------- @@ -1145,13 +1235,20 @@ // // printf(" getrowcount %i \n",pResult->GetRowCount()); // - if( !pResult->GetRowCount() ) return(-50); + if( !pResult->GetRowCount() ){ + delete pResult; + if (Row) + delete Row; + return(-50); + } // - for( r=0; r < 1000; r++){ + for( r=0; r < 1000; r++){ + if (Row) + delete Row; Row = pResult->Next(); if( Row == NULL ) break; // Set_GL_RUN(Row); - for( t = 0; t < pResult->GetFieldCount(); t++){ + for( int t = 0; t < pResult->GetFieldCount(); t++){ if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); @@ -1185,8 +1282,11 @@ if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); }; - }; - // delete pResult; + } + + if (Row) + delete Row; + delete pResult; return(0); }; @@ -1200,7 +1300,7 @@ Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TString where, TSQLServer *dbc){ // MySQL variables TSQLResult *pResult; - TSQLRow *Row; + TSQLRow *Row = NULL; int t; int r; stringstream myquery; @@ -1246,8 +1346,15 @@ if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); - if(!pResult->GetRowCount())return(-50); + if(!pResult->GetRowCount()){ + delete pResult; + if (Row) + delete Row; + return(-50); + } for( r=0; r < 1000; r++){ + if (Row) + delete Row; Row = pResult->Next(); if( Row == NULL ) break; for( t = 0; t < pResult->GetFieldCount(); t++){ @@ -1284,8 +1391,11 @@ if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); }; - }; - // delete pResult; + } + + if (Row) + delete Row; + delete pResult; return(0); };// **************************************************** @@ -1298,7 +1408,7 @@ Int_t GL_ROOT::Query_GL_ROOT(UInt_t id, TSQLServer *dbc){ // MySQL variables TSQLResult *pResult; - TSQLRow *Row; + TSQLRow *Row = NULL; int t; int r; stringstream myquery; @@ -1315,18 +1425,30 @@ if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); - if(!pResult->GetRowCount())return (-51); + if(!pResult->GetRowCount()){ + delete pResult; + if (Row) + delete Row; + return (-51); + } for( r=0; r < 1000; r++){ + if (Row) + delete Row; Row = pResult->Next(); if( Row == NULL ) break; for( t = 0; t < pResult->GetFieldCount(); t++){ if(t==0) ID = (UInt_t)atoll(Row->GetField(t)); if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t)); if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); - if(t==3) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/'; + if(t==3){ + PATH = TString(Row->GetField(t)) + '/'; + gSystem->ExpandPathName(PATH); + } if(t==4) NAME = Row->GetField(t); - }; - }; + } + } + if (Row) + delete Row; delete pResult; return 0; }; @@ -1341,7 +1463,7 @@ Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(UInt_t time, TSQLServer *dbc){ // MySQL variables TSQLResult *pResult; - TSQLRow *Row; + TSQLRow *Row = NULL; int t; int r; stringstream myquery; @@ -1355,8 +1477,13 @@ if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); - if(!pResult->GetRowCount())return (-53); + if(!pResult->GetRowCount()){ + delete pResult; + return (-53); + } for( r=0; r < 1000; r++){ + if (Row) + delete Row; Row = pResult->Next(); if( Row == NULL ) break; for( t = 0; t < pResult->GetFieldCount(); t++){ @@ -1377,7 +1504,9 @@ if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); if (t==11) VALIDATION = (UInt_t)atoll(Row->GetField(t)); }; - }; + } + if (Row) + delete Row; delete pResult; // // if ( TO_TIME < time ) return(51); @@ -1397,7 +1526,7 @@ Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t &uptime, UInt_t section, TSQLServer *dbc){ // MySQL variables TSQLResult *pResult; - TSQLRow *Row; + TSQLRow *Row = NULL; int t; stringstream myquery; uptime = 0; @@ -1416,9 +1545,17 @@ pResult = dbc->Query(myquery.str().c_str()); // printf(" mysquery is %s\n",myquery.str().c_str()); // - if( !pResult->GetRowCount() ) return(-54); + if (Row) + delete Row; + if( !pResult->GetRowCount() ){ + delete pResult; + return(-54); + } Row = pResult->Next(); - if( Row == NULL ) return (-54); + if( Row == NULL ){ + delete pResult; + return (-54); + } // uptime = (UInt_t)atoll(Row->GetField(2)); // @@ -1435,15 +1572,28 @@ myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section; myquery << " and FROM_TIME <= " << time; myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; - if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; + if ( !this->GetGLTABLES()->IsConnected(dbc) ){ + if(pResult) + delete pResult; + if(Row) + delete Row; + return -57; + } this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); // printf(" mysquery is %s\n",myquery.str().c_str()); // // if no results yet quit with error // - if( !pResult->GetRowCount() ) return (-54); + if( !pResult->GetRowCount() ){ + delete pResult; + if(Row) + delete Row; + return (-54); + } // + if (Row) + delete Row; Row = pResult->Next(); // myfromtime = (UInt_t)atoll(Row->GetField(1)); @@ -1457,29 +1607,47 @@ myquery.str(""); myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALO_CALIB where SECTION=" << section; myquery << " and VALIDATION=1 ORDER BY ABS(" << time << "-FROM_TIME) asc limit 1;"; - if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; + if ( !this->GetGLTABLES()->IsConnected(dbc) ){ + if(pResult) + delete pResult; + if(Row) + delete Row; + return -57; + } this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); // printf(" mysquery is %s\n",myquery.str().c_str()); // // if no results yet quit with error // - if( !pResult->GetRowCount() ) return (-54); + if( !pResult->GetRowCount() ){ + if (Row) + delete Row; + delete pResult; + return (-54); + } // + if (Row) + delete Row; Row = pResult->Next(); // }; // // store infos and exit // - if( Row == NULL ) return (-54); + if( Row == NULL ){ + delete pResult; + return (-54); + } for( t = 0; t < pResult->GetFieldCount(); t++){ if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); if (t==1) FROM_TIME = myfromtime; if (t==2) TO_TIME = mytotime; if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); - }; - pResult->Delete(); + } + if (Row) + delete Row; + delete pResult; return 0; }; @@ -1494,7 +1662,7 @@ Int_t GL_CALOPULSE_CALIB::Query_GL_CALOPULSE_CALIB(UInt_t time, UInt_t section, UInt_t pampli, TSQLServer *dbc){ // MySQL variables TSQLResult *pResult; - TSQLRow *Row; + TSQLRow *Row = NULL; int t; stringstream myquery; // @@ -1512,9 +1680,14 @@ // if( !pResult ) return(-54); // + if (Row) + delete Row; Row = pResult->Next(); // - if( !Row ) return (-54); + if( !Row ){ + delete pResult; + return (-54); + } // // store infos and exit // @@ -1524,7 +1697,9 @@ if (t==1) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); if (t==2) TO_TIME = (UInt_t)atoll(Row->GetField(t)); if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); - }; + } + if (Row) + delete Row; pResult->Delete(); return 0; }; @@ -1540,7 +1715,7 @@ Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UInt_t time, TSQLServer *dbc){ // MySQL variables TSQLResult *pResult; - TSQLRow *Row; + TSQLRow *Row = NULL; int t; int r; stringstream myquery; @@ -1552,8 +1727,13 @@ if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); - if(!pResult->GetRowCount())return (-55);//throw -55; + if(!pResult->GetRowCount()){ + delete pResult; + return (-55);//throw -55; + } for( r=0; r < 1000; r++){ + if (Row) + delete Row; Row = pResult->Next(); if( Row == NULL ) break; for( t = 0; t < pResult->GetFieldCount(); t++){ @@ -1563,7 +1743,9 @@ if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); if (t==4) TO_TIME = (UInt_t)atoll(Row->GetField(t)); }; - }; + } + if (Row) + delete Row; delete pResult; // if(TO_TIME < time)return(51); @@ -1582,7 +1764,7 @@ // Bool_t debug = 1; // MySQL variables TSQLResult *pResult; - TSQLRow *Row; + TSQLRow *Row = NULL; int t; int r; stringstream myquery; @@ -1598,20 +1780,30 @@ if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); - if(!pResult->GetRowCount())return (-52); + if(!pResult->GetRowCount()){ + delete pResult; + return (-52); + } for( r=0; r < 1000; r++){ + if (Row) + delete Row; Row = pResult->Next(); if( Row == NULL ) break; for( t = 0; t < pResult->GetFieldCount(); t++){ - if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); - if (t==1) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/';// put in fpath the path to that file - if (t==2) NAME = Row->GetField(t); - if (t==3) DESCR = Row->GetField(t); - if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); - if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); - if (t==6) TYPE = (UInt_t)atoll(Row->GetField(t)); + if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); + if (t==1) { + PATH = TString(Row->GetField(t)) + "/";// put in fpath the path to that file + gSystem->ExpandPathName(PATH); + } + if (t==2) NAME = Row->GetField(t); + if (t==3) DESCR = Row->GetField(t); + if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); + if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); + if (t==6) TYPE = (UInt_t)atoll(Row->GetField(t)); }; - }; + } + if (Row) + delete Row; delete pResult; // if(TO_TIME==0) TO_TIME = numeric_limits::max(); @@ -1647,7 +1839,7 @@ UInt_t idtsy = 0; // TSQLResult *pResult; - TSQLRow *Row = 0; + TSQLRow *Row = NULL; stringstream myquery; stringstream rname; // pcksList packetsNames; @@ -1667,11 +1859,15 @@ this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); if( pResult->GetRowCount() ){ + if (Row) + delete Row; Row = pResult->Next(); if( Row ){ stringstream fname; fname.str(""); - fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); + TString auxStr(Row->GetField(0)); + gSystem->ExpandPathName(auxStr); + fname << auxStr << "/" << Row->GetField(1); rname << Row->GetField(1); file = new TFile(fname.str().c_str(),"READ"); idtsy = (UInt_t)atoll(Row->GetField(2)); @@ -1687,6 +1883,10 @@ T->GetEntry(0); ph = eh->GetPscuHeader(); pktfirst = ph->GetCounter(); + if ( eh ){ + delete eh; + eh = 0; + } // obtfirst = ph->GetOrbitalTime(); // }; @@ -1698,9 +1898,13 @@ stringstream oss; // TString name=rname.str().c_str(); - UInt_t dworbit = 0; + // UInt_t dworbit = 0; // Int_t nlength = name.Length(); - delete pResult; + delete pResult; + if (Row){ + delete Row; + Row = NULL; + } // // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset // @@ -1711,6 +1915,8 @@ pResult = dbc->Query(oss.str().c_str()); Bool_t fndit = false; if ( pResult ){ + if (Row) + delete Row; Row = pResult->Next(); if ( Row ){ // @@ -1722,17 +1928,23 @@ 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(3) << ";"; - if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; + if ( !this->GetGLTABLES()->IsConnected(dbc) ){ + delete pResult; + delete Row; + return; + } this->GetGLTABLES()->AddQ(); delete pResult; 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 (pResult){ + if (Row) + delete Row; + Row = pResult->Next(); + if ( Row ){ + // printf(" GREAT! the DB structure is the new one! \n"); + fndit = true; + // dworbit = 1; + }; }; }; }; @@ -1751,6 +1963,8 @@ // printf(" T0 %u toffset is %u \n",T0,toffset); // if ( file ) file->Close(); + if (Row) + delete Row; delete pResult; }; @@ -1760,7 +1974,7 @@ UInt_t idtsy = 0; // TSQLResult *pResult; - TSQLRow *Row = 0; + TSQLRow *Row = NULL; stringstream myquery; stringstream rname; // pcksList packetsNames; @@ -1780,11 +1994,15 @@ this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); if( pResult->GetRowCount() ){ + if (Row) + delete Row; Row = pResult->Next(); if( Row ){ stringstream fname; fname.str(""); - fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); + TString auxString(Row->GetField(0)); + gSystem->ExpandPathName(auxString); + fname << auxString << "/" << Row->GetField(1); rname << Row->GetField(1); if ( usel0file ) file = new TFile(fname.str().c_str(),"READ"); idtsy = (UInt_t)atoll(Row->GetField(2)); @@ -1800,6 +2018,10 @@ T->GetEntry(0); ph = eh->GetPscuHeader(); pktfirst = ph->GetCounter(); + if ( eh ){ + delete eh; + eh = 0; + } // obtfirst = ph->GetOrbitalTime(); // }; @@ -1812,9 +2034,13 @@ stringstream oss; // TString name=rname.str().c_str(); - UInt_t dworbit = 0; + // UInt_t dworbit = 0; // Int_t nlength = name.Length(); - delete pResult; + delete pResult; + if (Row){ + delete Row; + Row = NULL; + } // // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset // @@ -1825,6 +2051,8 @@ pResult = dbc->Query(oss.str().c_str()); Bool_t fndit = false; if ( pResult ){ + if (Row) + delete Row; Row = pResult->Next(); if ( Row ){ // @@ -1836,17 +2064,23 @@ 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(3) << ";"; - if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; + if ( !this->GetGLTABLES()->IsConnected(dbc) ){ + delete pResult; + delete Row; + return; + } this->GetGLTABLES()->AddQ(); delete pResult; 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 (pResult){ + if (Row) + delete Row; + Row = pResult->Next(); + if (Row){ + // printf(" GREAT! the DB structure is the new one! \n"); + fndit = true; + // dworbit = 1; + }; }; }; }; @@ -1865,6 +2099,8 @@ // printf(" T0 %u toffset is %u \n",T0,toffset); // if ( file ) file->Close(); + if (Row) + delete Row; delete pResult; }; @@ -2135,17 +2371,19 @@ // Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){ TSQLResult *result; - TSQLRow *row; + TSQLRow *row = NULL; // Set the right time_zone (otherwise horrible things will occur! :) if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; - dbc->Query("SET time_zone = '+0:00'"); + delete dbc->Query("SET time_zone = '+0:00';"); + delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';"); // Do the query this->GetGLTABLES()->AddQ(); result = dbc->Query(myquery.Data()); if(! result->GetRowCount() ) { cerr << "GL_TLE: query failed: " << myquery.Data() << endl; + delete result; return 1; } @@ -2154,7 +2392,8 @@ tle = GiveTle(row); tleFromTime = strtol(row->GetField(4), NULL, 10); - + if (row) + delete row; row = result->Next(); // second tle row if(row) tleToTime = strtol(row->GetField(4), NULL, 10); @@ -2163,7 +2402,8 @@ tleToTime = UINT_MAX; } - delete row; + if (row) + delete row; delete result; return 0;