--- chewbacca/YodaProfiler/src/GLTables.cpp 2009/08/05 18:48:44 1.10 +++ chewbacca/YodaProfiler/src/GLTables.cpp 2009/12/15 09:58:25 1.12 @@ -18,6 +18,7 @@ #include #include // +ClassImp(Q2TH); ClassImp(GL_TABLES); ClassImp(GL_TRK_CALIB); ClassImp(GL_RUN); @@ -31,6 +32,135 @@ // using namespace std; +Q2TH::Q2TH(TString host, TString user, TString psw){ + fh = gSystem->ExpandPathName(host.Data()); + fu = gSystem->ExpandPathName(user.Data()); + fp = gSystem->ExpandPathName(psw.Data()); + dbc = TSQLServer::Connect(fh.Data(),fu.Data(),fp.Data()); +}; + +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; + }; + // + 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; + + }; + 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()); + // + 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++; + 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(); + // + pResult->Delete(); + if ( dim == 1 ) return h1; + if ( dim == 2 ) return h2; + // + return NULL; +}; + GL_TABLES::GL_TABLES(){ };