--- chewbacca/YodaProfiler/src/GLTables.cpp 2011/11/29 13:42:18 1.15 +++ chewbacca/YodaProfiler/src/GLTables.cpp 2012/02/12 11:41:00 1.16 @@ -223,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"); @@ -253,7 +253,7 @@ // 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()) ){ @@ -262,11 +262,11 @@ // myquery.str(""); myquery << "SET time_zone='+0:00'"; - dbc->Query(myquery.str().c_str()); + 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; }; @@ -735,7 +735,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 // @@ -766,7 +766,13 @@ // // 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()); // @@ -785,7 +791,13 @@ // // 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()); // @@ -795,6 +807,8 @@ if( Row != NULL ){ fileL2 = (TString)Row->GetField(0); } + delete pResult; + pResult = NULL; if (Row){ delete Row; Row = NULL; // This variable is not used below @@ -811,7 +825,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='"; @@ -822,7 +836,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='"; @@ -834,7 +848,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 "; @@ -846,7 +860,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; }; @@ -862,7 +876,7 @@ // 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; + TSQLResult *pResult = NULL; TSQLRow *Row = NULL; stringstream myquery; // @@ -885,9 +899,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 "; @@ -968,7 +988,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(""); @@ -977,7 +997,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; }; @@ -1065,7 +1085,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; @@ -1147,7 +1167,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; @@ -1211,7 +1231,12 @@ // // 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++){ if (Row) @@ -1317,7 +1342,12 @@ 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; @@ -1391,7 +1421,12 @@ 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; @@ -1401,7 +1436,10 @@ 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); } } @@ -1435,7 +1473,10 @@ 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; @@ -1500,11 +1541,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)); // @@ -1521,14 +1568,25 @@ 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; @@ -1545,14 +1603,25 @@ 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; @@ -1562,7 +1631,10 @@ // // 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; @@ -1571,7 +1643,7 @@ } if (Row) delete Row; - pResult->Delete(); + delete pResult; return 0; }; @@ -1608,7 +1680,10 @@ delete Row; Row = pResult->Next(); // - if( !Row ) return (-54); + if( !Row ){ + delete pResult; + return (-54); + } // // store infos and exit // @@ -1648,7 +1723,10 @@ 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; @@ -1698,20 +1776,26 @@ 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) @@ -1777,7 +1861,9 @@ 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)); @@ -1806,7 +1892,11 @@ TString name=rname.str().c_str(); 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 // @@ -1830,7 +1920,11 @@ 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()); @@ -1898,7 +1992,9 @@ 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)); @@ -1928,7 +2024,11 @@ TString name=rname.str().c_str(); 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 // @@ -1952,7 +2052,11 @@ 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()); @@ -2259,13 +2363,14 @@ // 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'"); // 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; }