--- chewbacca/YodaProfiler/src/GLTables.cpp 2008/09/23 07:20:33 1.1 +++ chewbacca/YodaProfiler/src/GLTables.cpp 2012/02/12 11:41:00 1.16 @@ -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){ // // // @@ -71,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"); @@ -92,13 +244,16 @@ 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(""); 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()) ){ @@ -107,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; }; @@ -168,6 +323,8 @@ TRK_CALIB_USED = 0; CAL_DSP_MASK = 0; BOOT_NUMBER = 0; + PHYSENDRUN_MASK_S3S2S12 = 0; + PHYSENDRUN_MASK_S11CRC = 0; VALIDATION = 0; } @@ -203,6 +360,8 @@ TRK_CALIB_USED = 0; CAL_DSP_MASK = 0; BOOT_NUMBER = 0; + PHYSENDRUN_MASK_S3S2S12 = 0; + PHYSENDRUN_MASK_S11CRC = 0; VALIDATION = 0; } @@ -214,6 +373,13 @@ NAME = ""; } +GL_RAW::GL_RAW(){ + ID = 0; + PATH = ""; + NAME = ""; + BOOT_NUMBER = 0; +} + GL_PARAM::GL_PARAM(){ ID = 0; PATH = ""; @@ -368,6 +534,15 @@ COMPILATIONTIMESTAMP = value; }; +void GL_RUN:: SetPHYSENDRUN_MASK_S3S2S12(UInt_t value){ + PHYSENDRUN_MASK_S3S2S12 = value; +}; + +void GL_RUN:: SetPHYSENDRUN_MASK_S11CRC(UInt_t value){ + PHYSENDRUN_MASK_S11CRC = value; +}; + + void GL_RUN:: SetFAV_WRK_SCHEDULE(UInt_t value){ FAV_WRK_SCHEDULE = value; }; @@ -435,7 +610,7 @@ RM_ACQ_AFTER_CALIB = runh->RM_ACQ_AFTER_CALIB; RM_ACQ_SETTING_MODE = runh->RM_ACQ_SETTING_MODE; TRK_CALIB_USED = runh->TRK_CALIB_USED; - CAL_DSP_MASK = runh->CAL_DSP_MASK; + CAL_DSP_MASK = runh->CAL_DSP_MASK; }; void GL_RUN::Set_GL_RUNT0(){ @@ -465,7 +640,7 @@ }; void GL_RUN::Set_GL_RUN(TSQLRow *Row){ - for( Int_t t = 0; t < 30; t++){ + for( Int_t t = 0; t < 32; 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)); @@ -495,7 +670,9 @@ if (t==26) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); if (t==27) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); if (t==28) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); - if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); + if (t==29) PHYSENDRUN_MASK_S3S2S12 = (UInt_t)atoll(Row->GetField(t)); + if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); + if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); }; } @@ -508,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; @@ -545,6 +722,8 @@ myquery << ",CAL_DSP_MASK"; myquery << ",LAST_TIMESYNC"; myquery << ",OBT_TIMESYNC"; + myquery << ",PHYSENDRUN_MASK_S3S2S12"; + myquery << ",PHYSENDRUN_MASK_S11CRC"; myquery << ",VALIDATION"; myquery << ",INSERT_TIME"; myquery << ") SELECT * FROM "; @@ -556,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 // @@ -570,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)); @@ -585,10 +766,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); @@ -602,14 +791,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 + } // // // @@ -622,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='"; @@ -633,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='"; @@ -645,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 "; @@ -657,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; }; @@ -673,8 +876,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; @@ -696,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 "; @@ -733,6 +942,8 @@ myquery << ",CAL_DSP_MASK"; myquery << ",LAST_TIMESYNC"; myquery << ",OBT_TIMESYNC"; + myquery << ",PHYSENDRUN_MASK_S3S2S12"; + myquery << ",PHYSENDRUN_MASK_S11CRC"; myquery << ",VALIDATION"; myquery << ",INSERT_TIME"; myquery << ") SELECT "; @@ -765,6 +976,8 @@ myquery << ",CAL_DSP_MASK"; myquery << ",LAST_TIMESYNC"; myquery << ",OBT_TIMESYNC"; + myquery << ",PHYSENDRUN_MASK_S3S2S12"; + myquery << ",PHYSENDRUN_MASK_S11CRC"; myquery << ",VALIDATION"; myquery << ",INSERT_TIME"; myquery << " FROM GL_RUN_TRASH "; @@ -775,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(""); @@ -784,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; }; @@ -830,6 +1043,8 @@ myquery << ",TRK_CALIB_USED"; myquery << ",CAL_DSP_MASK"; myquery << ",BOOT_NUMBER"; + myquery << ",PHYSENDRUN_MASK_S3S2S12"; + myquery << ",PHYSENDRUN_MASK_S11CRC"; myquery << ",VALIDATION"; myquery << ") VALUES ('"; @@ -862,13 +1077,15 @@ myquery << (UInt_t)TRK_CALIB_USED << "','"; myquery << (UInt_t)CAL_DSP_MASK << "','"; myquery << (UInt_t)BOOT_NUMBER << "','"; + myquery << (UInt_t)PHYSENDRUN_MASK_S3S2S12 << "','"; + myquery << (UInt_t)PHYSENDRUN_MASK_S11CRC << "','"; myquery << (UInt_t)VALIDATION << "');"; // // printf("myquery is %s \n",myquery.str().c_str()); // 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; @@ -913,6 +1130,8 @@ myquery << ",TRK_CALIB_USED"; myquery << ",CAL_DSP_MASK"; myquery << ",BOOT_NUMBER"; + myquery << ",PHYSENDRUN_MASK_S3S2S12"; + myquery << ",PHYSENDRUN_MASK_S11CRC"; myquery << ") VALUES ('"; myquery << (UInt_t)ID << "','"; myquery << (UInt_t)ID_ROOT_L0 << "','"; @@ -940,13 +1159,15 @@ myquery << (UInt_t)PKT_READY_COUNTER << "','"; myquery << (UInt_t)TRK_CALIB_USED << "','"; myquery << (UInt_t)CAL_DSP_MASK << "','"; - myquery << (UInt_t)BOOT_NUMBER << "');"; + myquery << (UInt_t)BOOT_NUMBER << "','"; + myquery << (UInt_t)PHYSENDRUN_MASK_S3S2S12 << "','"; + myquery << (UInt_t)PHYSENDRUN_MASK_S11CRC << "');"; // // printf("myquery is %s \n",myquery.str().c_str()); // 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; @@ -963,8 +1184,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; // ---------------- @@ -999,6 +1219,8 @@ myquery << ",TRK_CALIB_USED"; myquery << ",CAL_DSP_MASK"; myquery << ",BOOT_NUMBER"; + myquery << ",PHYSENDRUN_MASK_S3S2S12"; + myquery << ",PHYSENDRUN_MASK_S11CRC"; myquery << ",VALIDATION"; myquery << " from GL_RUN where ID=" << run << ";"; // @@ -1009,13 +1231,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)); @@ -1045,10 +1274,15 @@ if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); - if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); + if (t==29) PHYSENDRUN_MASK_S3S2S12 = (UInt_t)atoll(Row->GetField(t)); + 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); }; @@ -1062,7 +1296,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; @@ -1098,6 +1332,8 @@ myquery << ",TRK_CALIB_USED"; myquery << ",CAL_DSP_MASK"; myquery << ",BOOT_NUMBER"; + myquery << ",PHYSENDRUN_MASK_S3S2S12"; + myquery << ",PHYSENDRUN_MASK_S11CRC"; myquery << ",VALIDATION"; myquery << " from GL_RUN_FRAGMENTS where " << where.Data() << ";"; // @@ -1106,8 +1342,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++){ @@ -1140,10 +1383,15 @@ if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); - if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); + if (t==29) PHYSENDRUN_MASK_S3S2S12 = (UInt_t)atoll(Row->GetField(t)); + 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); };// **************************************************** @@ -1156,7 +1404,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; @@ -1173,18 +1421,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; }; @@ -1199,7 +1459,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; @@ -1213,8 +1473,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++){ @@ -1235,7 +1500,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); @@ -1255,7 +1522,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; @@ -1272,11 +1539,19 @@ if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); - // printf(" mysquery is %s\n",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)); // @@ -1293,15 +1568,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)); @@ -1310,34 +1598,52 @@ // // if the selected calibration is too old (more than 5 orbits old) try to take the closest not corrupted one // - if ( (time-myfromtime)>28500 ){ + if ( (time-myfromtime)>28500 && myfromtime > 0 ){ // 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; }; @@ -1352,7 +1658,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; // @@ -1370,9 +1676,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 // @@ -1382,7 +1693,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; }; @@ -1398,7 +1711,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; @@ -1410,8 +1723,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++){ @@ -1421,7 +1739,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); @@ -1440,7 +1760,7 @@ // Bool_t debug = 1; // MySQL variables TSQLResult *pResult; - TSQLRow *Row; + TSQLRow *Row = NULL; int t; int r; stringstream myquery; @@ -1456,20 +1776,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(); @@ -1502,10 +1832,10 @@ GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){ // MySQL variables TFile *file = 0; - UInt_t idraw = 0; + UInt_t idtsy = 0; // TSQLResult *pResult; - TSQLRow *Row; + TSQLRow *Row = NULL; stringstream myquery; stringstream rname; // pcksList packetsNames; @@ -1516,7 +1846,7 @@ myquery.str(""); myquery << "select "; myquery << "PATH"; - myquery << ",NAME,ID_RAW"; + myquery << ",NAME,ID_TIMESYNC"; myquery << " from GL_ROOT where "; myquery << type.Data(); myquery << "=" << id << ";"; @@ -1525,14 +1855,18 @@ 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"); - idraw = (UInt_t)atoll(Row->GetField(2)); + idtsy = (UInt_t)atoll(Row->GetField(2)); }; }; // @@ -1545,27 +1879,7 @@ T->GetEntry(0); ph = eh->GetPscuHeader(); pktfirst = ph->GetCounter(); - 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(); -// // -// }; -// }; + // obtfirst = ph->GetOrbitalTime(); // }; // @@ -1573,117 +1887,208 @@ // T0 = 0; // - // 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(); // TString name=rname.str().c_str(); UInt_t dworbit = 0; - Int_t nlength = name.Length(); + // Int_t nlength = name.Length(); + delete pResult; + if (Row){ + delete Row; + Row = NULL; + } // - // 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 // - if ( !Row ){ - 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 ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";"; - if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; - this->GetGLTABLES()->AddQ(); - pResult = dbc->Query(oss.str().c_str()); - Bool_t fndit = false; - 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 + 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 ){ // - if ( nlength < 5 ) return; - TString dwo = 0; - for (Int_t i = 0; i<5; i++){ - dwo.Append(name[i],1); - }; - 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; - }; - }; + 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 FROM_ORBIT< " - << dworbit << " order by FROM_ORBIT desc limit 1;"; - if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; + 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) ){ + delete pResult; + delete Row; + return; + } this->GetGLTABLES()->AddQ(); + delete pResult; pResult = dbc->Query(oss.str().c_str()); - Row = pResult->Next(); - if ( !Row ){ - printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); - return; + 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(); // - // look for the correct timesync entry + 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; +}; + +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 OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " - << " WHERE ID_RAW = " << idraw - << ";"; + 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(""); + 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)); + }; + }; + // + 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; + 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 + // + 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 != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ + 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)); - toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; + 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) ){ + delete pResult; + delete Row; + 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"); + // + }; // - file->Close(); + 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; }; @@ -1694,6 +2099,7 @@ */ UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){ // + // printf(" OBT %u DBobt %llu toffset %u dbabstime %u\n",OBT,this->DBobt(OBT),toffset,((UInt_t)(this->DBobt(OBT)/1000)+toffset)); return(((UInt_t)(this->DBobt(OBT)/1000)+toffset)); // }; @@ -1732,11 +2138,11 @@ */ Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ // - if ( obt < (obtfirst/2) && obtfirst > (numeric_limits::max()/2) ){ + if ( obt < ((Long64_t)obtfirst/2) && obtfirst > (numeric_limits::max()/2) ){ return((Long64_t)obt+(Long64_t)numeric_limits::max()); }; // - if ( obt > (obtfirst*2) && obt > (numeric_limits::max()/2) ){ + if ( obt > ((Long64_t)obtfirst*2) && obt > (numeric_limits::max()/2) ){ return((Long64_t)obt-(Long64_t)numeric_limits::max()); }; // @@ -1953,17 +2359,18 @@ // 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'"); // 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; } @@ -1972,7 +2379,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); @@ -1981,7 +2389,8 @@ tleToTime = UINT_MAX; } - delete row; + if (row) + delete row; delete result; return 0;