--- chewbacca/YodaProfiler/src/GLTables.cpp 2008/11/28 09:10:15 1.5 +++ chewbacca/YodaProfiler/src/GLTables.cpp 2011/11/29 13:42:18 1.15 @@ -7,6 +7,7 @@ // #include #include +#include // #include #include @@ -17,6 +18,7 @@ #include #include // +ClassImp(Q2TH); ClassImp(GL_TABLES); ClassImp(GL_TRK_CALIB); ClassImp(GL_RUN); @@ -30,6 +32,155 @@ // 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(); + // + Int_t dim = pResult->GetFieldCount(); + if ( dim < 1 || dim > 2 ){ + printf(" Dim == %i not supported yet \n",dim); + return NULL; + }; + // + TH1D *h1 = NULL; + TH2D *h2 = NULL; + Double_t f1 = 0.; + Double_t minf1 = numeric_limits::max(); + Double_t maxf1 = numeric_limits::min(); + Double_t f2 = 0.; + Double_t minf2 = numeric_limits::max(); + Double_t maxf2 = numeric_limits::min(); + // + while ( Row ){ + f1 = (Double_t)atof(Row->GetField(0)); + if ( f1 > maxf1 ) maxf1 = f1; + if ( f1 < minf1 ) minf1 = f1; + if ( dim == 2 ){ + f2 = (Double_t)atof(Row->GetField(1)); + if ( f2 > maxf2 ) maxf2 = f2; + 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; + 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)); + }; + if ( dim == 2 ){ + f2bin = int((maxf2-minf2)/1000.); + if ( f2bin < 70 ) f2bin = 70; + if ( f2bin > 1000 ) f2bin = 1000; + 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; + // + while ( Row ){ + f1 = (Double_t)atof(Row->GetField(0)); + if ( dim == 1 ){ + if ( verbose ) printf(" %i %f \n",r,f1); + h1->Fill(f1); + } else { + f2 = (Double_t)atof(Row->GetField(1)); + if ( verbose ) printf(" %i %f %f \n",r,f1,f2); + h2->Fill(f1,f2); + }; + r++; + if (Row) + delete Row; + Row = pResult->Next(); + }; + // + 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; + // + return NULL; +}; + GL_TABLES::GL_TABLES(){ }; @@ -56,7 +207,8 @@ mp = psw.Data(); }; -Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ +//Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ +Bool_t GL_TABLES::IsConnected(TSQLServer *dbc){ // // // @@ -92,8 +244,11 @@ TString host = fHost->Data(); TString user = fUser->Data(); TString psw = fPsw->Data(); - dbc->Close(); - delete dbc; + if ( dbc ){ + dbc->Close(); + delete dbc; + dbc = 0; + }; dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); // myquery.str(""); @@ -530,7 +685,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; @@ -594,6 +749,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)); @@ -613,6 +770,8 @@ 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); @@ -630,10 +789,16 @@ 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); - }; + } + if (Row){ + delete Row; + Row = NULL; // This variable is not used below + } // // // @@ -698,7 +863,7 @@ //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; + TSQLRow *Row = NULL; stringstream myquery; // if ( !IDRUN ) IDRUN = ID; @@ -999,8 +1164,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; // ---------------- @@ -1049,11 +1213,13 @@ // if( !pResult->GetRowCount() ) 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)); @@ -1087,8 +1253,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); }; @@ -1102,7 +1271,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; @@ -1150,6 +1319,8 @@ pResult = dbc->Query(myquery.str().c_str()); if(!pResult->GetRowCount())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++){ @@ -1186,8 +1357,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 +1374,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; @@ -1219,6 +1393,8 @@ pResult = dbc->Query(myquery.str().c_str()); if(!pResult->GetRowCount())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++){ @@ -1227,8 +1403,10 @@ if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); if(t==3) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/'; if(t==4) NAME = Row->GetField(t); - }; - }; + } + } + if (Row) + delete Row; delete pResult; return 0; }; @@ -1243,7 +1421,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; @@ -1259,6 +1437,8 @@ pResult = dbc->Query(myquery.str().c_str()); if(!pResult->GetRowCount())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++){ @@ -1279,7 +1459,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); @@ -1299,7 +1481,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; @@ -1319,6 +1501,8 @@ // printf(" mysquery is %s\n",myquery.str().c_str()); // if( !pResult->GetRowCount() ) return(-54); + if (Row) + delete Row; Row = pResult->Next(); if( Row == NULL ) return (-54); // @@ -1346,6 +1530,8 @@ // if( !pResult->GetRowCount() ) return (-54); // + if (Row) + delete Row; Row = pResult->Next(); // myfromtime = (UInt_t)atoll(Row->GetField(1)); @@ -1368,6 +1554,8 @@ // if( !pResult->GetRowCount() ) return (-54); // + if (Row) + delete Row; Row = pResult->Next(); // }; @@ -1380,7 +1568,9 @@ if (t==1) FROM_TIME = myfromtime; if (t==2) TO_TIME = mytotime; if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); - }; + } + if (Row) + delete Row; pResult->Delete(); return 0; }; @@ -1396,7 +1586,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; // @@ -1414,6 +1604,8 @@ // if( !pResult ) return(-54); // + if (Row) + delete Row; Row = pResult->Next(); // if( !Row ) return (-54); @@ -1426,7 +1618,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; }; @@ -1442,7 +1636,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; @@ -1456,6 +1650,8 @@ pResult = dbc->Query(myquery.str().c_str()); if(!pResult->GetRowCount())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++){ @@ -1465,7 +1661,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); @@ -1484,7 +1682,7 @@ // Bool_t debug = 1; // MySQL variables TSQLResult *pResult; - TSQLRow *Row; + TSQLRow *Row = NULL; int t; int r; stringstream myquery; @@ -1502,6 +1700,8 @@ pResult = dbc->Query(myquery.str().c_str()); if(!pResult->GetRowCount())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++){ @@ -1513,7 +1713,9 @@ 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(); @@ -1549,7 +1751,7 @@ UInt_t idtsy = 0; // TSQLResult *pResult; - TSQLRow *Row = 0; + TSQLRow *Row = NULL; stringstream myquery; stringstream rname; // pcksList packetsNames; @@ -1569,6 +1771,8 @@ this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); if( pResult->GetRowCount() ){ + if (Row) + delete Row; Row = pResult->Next(); if( Row ){ stringstream fname; @@ -1589,7 +1793,7 @@ T->GetEntry(0); ph = eh->GetPscuHeader(); pktfirst = ph->GetCounter(); - obtfirst = ph->GetOrbitalTime(); + // obtfirst = ph->GetOrbitalTime(); // }; // @@ -1613,10 +1817,13 @@ pResult = dbc->Query(oss.str().c_str()); Bool_t fndit = false; if ( pResult ){ + if (Row) + delete Row; Row = pResult->Next(); if ( Row ){ // OBT0 = (UInt_t)atoll(Row->GetField(0)); + obtfirst = OBT0; TIMESYNC = (UInt_t)atoll(Row->GetField(1)); TYPE = (UInt_t)atoll(Row->GetField(2)); // @@ -1627,13 +1834,15 @@ 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; + }; }; }; }; @@ -1647,11 +1856,135 @@ 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); T0 = (UInt_t)tu.GetSec(); // - toffset = TIMESYNC - (UInt_t)(this->DBobt(OBT0/1000)) + T0; + toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; // // printf(" T0 %u toffset is %u \n",T0,toffset); // - file->Close(); + if ( file ) file->Close(); + if (Row) + delete Row; + delete pResult; +}; + +GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc, Bool_t usel0file){ + // MySQL variables + TFile *file = 0; + UInt_t idtsy = 0; + // + TSQLResult *pResult; + TSQLRow *Row = NULL; + stringstream myquery; + stringstream rname; + // pcksList packetsNames; + // pcksList::iterator Iter; + // getPacketsNames(packetsNames); + rname.str(""); + // ---------------- + myquery.str(""); + myquery << "select "; + myquery << "PATH"; + myquery << ",NAME,ID_TIMESYNC"; + myquery << " from GL_ROOT where "; + myquery << type.Data(); + myquery << "=" << id << ";"; + // + if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; + 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); + rname << Row->GetField(1); + if ( usel0file ) file = new TFile(fname.str().c_str(),"READ"); + idtsy = (UInt_t)atoll(Row->GetField(2)); + }; + }; + // + if ( usel0file && file && file->IsOpen() ){ + TTree *T=(TTree*)file->Get("Physics"); + pamela::EventHeader *eh = 0; + pamela::PscuHeader *ph = 0; + T->SetBranchAddress("Header", &eh); + // + T->GetEntry(0); + ph = eh->GetPscuHeader(); + pktfirst = ph->GetCounter(); + // obtfirst = ph->GetOrbitalTime(); + // + }; + if ( !usel0file ) pktfirst = 0; + // + // look for Resurs offset + // + T0 = 0; + // + stringstream oss; + // + TString name=rname.str().c_str(); + UInt_t dworbit = 0; + // Int_t nlength = name.Length(); + delete pResult; + // + // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset + // + oss.str(""); + oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; + if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; + this->GetGLTABLES()->AddQ(); + pResult = dbc->Query(oss.str().c_str()); + Bool_t fndit = false; + if ( pResult ){ + if (Row) + delete Row; + Row = pResult->Next(); + if ( Row ){ + // + OBT0 = (UInt_t)atoll(Row->GetField(0)); + obtfirst = OBT0; + TIMESYNC = (UInt_t)atoll(Row->GetField(1)); + TYPE = (UInt_t)atoll(Row->GetField(2)); + // + 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; + this->GetGLTABLES()->AddQ(); + delete pResult; + pResult = dbc->Query(oss.str().c_str()); + 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; + }; + }; + }; + }; + if ( !fndit ){ + // + printf(" ERROR OLD DB! \n"); + printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); + // + }; + // + 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); + T0 = (UInt_t)tu.GetSec(); + // + toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; + // + // printf(" T0 %u toffset is %u \n",T0,toffset); + // + if ( file ) file->Close(); + if (Row) + delete Row; delete pResult; }; @@ -1922,7 +2255,7 @@ // 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; @@ -1941,7 +2274,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); @@ -1950,7 +2284,8 @@ tleToTime = UINT_MAX; } - delete row; + if (row) + delete row; delete result; return 0;