--- chewbacca/YodaProfiler/src/GLTables.cpp 2011/11/29 13:42:18 1.15 +++ chewbacca/YodaProfiler/src/GLTables.cpp 2014/10/14 13:19:31 1.19 @@ -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()) ){ @@ -261,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; }; @@ -735,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 // @@ -766,7 +770,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 +795,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 +811,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 +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='"; @@ -822,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='"; @@ -834,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 "; @@ -846,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; }; @@ -862,7 +880,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 +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 "; @@ -968,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(""); @@ -977,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; }; @@ -1065,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; @@ -1147,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; @@ -1211,7 +1235,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 +1346,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 +1425,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 +1440,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 +1477,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 +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)); // @@ -1521,14 +1572,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 +1607,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 +1635,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 +1647,7 @@ } if (Row) delete Row; - pResult->Delete(); + delete pResult; return 0; }; @@ -1608,7 +1684,10 @@ delete Row; Row = pResult->Next(); // - if( !Row ) return (-54); + if( !Row ){ + delete pResult; + return (-54); + } // // store infos and exit // @@ -1648,7 +1727,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 +1780,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 +1865,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)); @@ -1804,9 +1894,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 // @@ -1830,7 +1924,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()); @@ -1841,7 +1939,7 @@ if ( Row ){ // printf(" GREAT! the DB structure is the new one! \n"); fndit = true; - dworbit = 1; + // dworbit = 1; }; }; }; @@ -1898,7 +1996,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)); @@ -1926,9 +2026,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 // @@ -1952,7 +2056,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()); @@ -1963,7 +2071,7 @@ if (Row){ // printf(" GREAT! the DB structure is the new one! \n"); fndit = true; - dworbit = 1; + // dworbit = 1; }; }; }; @@ -2259,13 +2367,15 @@ // 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; }