| 7 |
// |
// |
| 8 |
#include <sstream> |
#include <sstream> |
| 9 |
#include <iostream> |
#include <iostream> |
| 10 |
|
#include <limits.h> |
| 11 |
// |
// |
| 12 |
#include <TFile.h> |
#include <TFile.h> |
| 13 |
#include <TTree.h> |
#include <TTree.h> |
| 18 |
#include <GLTables.h> |
#include <GLTables.h> |
| 19 |
#include <sgp4.h> |
#include <sgp4.h> |
| 20 |
// |
// |
| 21 |
|
ClassImp(Q2TH); |
| 22 |
ClassImp(GL_TABLES); |
ClassImp(GL_TABLES); |
| 23 |
ClassImp(GL_TRK_CALIB); |
ClassImp(GL_TRK_CALIB); |
| 24 |
ClassImp(GL_RUN); |
ClassImp(GL_RUN); |
| 32 |
// |
// |
| 33 |
using namespace std; |
using namespace std; |
| 34 |
|
|
| 35 |
|
Q2TH::Q2TH(TString host, TString user, TString psw){ |
| 36 |
|
fh = gSystem->ExpandPathName(host.Data()); |
| 37 |
|
fu = gSystem->ExpandPathName(user.Data()); |
| 38 |
|
fp = gSystem->ExpandPathName(psw.Data()); |
| 39 |
|
dbc = TSQLServer::Connect(fh.Data(),fu.Data(),fp.Data()); |
| 40 |
|
}; |
| 41 |
|
|
| 42 |
|
TObject *Q2TH::Draw(TString query, Bool_t verbose, TString hname){ |
| 43 |
|
// |
| 44 |
|
if ( !strcmp(query.Data(),"help") ){ |
| 45 |
|
printf(" USAGE: \n"); |
| 46 |
|
printf(" 1) start root and create Q2TH object with \n"); |
| 47 |
|
printf(" Q2TH *qt = new Q2TH() \n"); |
| 48 |
|
printf(" or \n"); |
| 49 |
|
printf(" Q2TH *qt = new Q2TH(\"mysql://srvg-g2-01.ts.infn.it/pamelaProcessing9_TS\",\"pamelaprod_ro\",\"mypassword\") \n"); |
| 50 |
|
printf(" 2) query the DB with \n"); |
| 51 |
|
printf(" qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\"); \n"); |
| 52 |
|
printf(" qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\",true); this will print numbers on screen \n"); |
| 53 |
|
printf(" qt->Draw(\"select REAL_TIME_INIT from ROOT_TABLE_MERGING;\",true,\"myhisto\"); this will print numbers on screen and create histo \"myhisto\"\n"); |
| 54 |
|
printf(" 3) to use your own THxD create it and then query the DB giving as argument the name of histo: \n"); |
| 55 |
|
printf(" TH2D *myhisto=new TH2D(\"myhisto\",\"myhisto\",5000,1140000000.,1240000000.,10000,0.,1.) \n"); |
| 56 |
|
printf(" qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\",false,\"myhisto\")\n\n\n"); |
| 57 |
|
|
| 58 |
|
return NULL; |
| 59 |
|
}; |
| 60 |
|
// |
| 61 |
|
pResult = dbc->Query(query.Data()); |
| 62 |
|
// |
| 63 |
|
Row = pResult->Next(); |
| 64 |
|
// |
| 65 |
|
Int_t dim = pResult->GetFieldCount(); |
| 66 |
|
if ( dim < 1 || dim > 2 ){ |
| 67 |
|
printf(" Dim == %i not supported yet \n",dim); |
| 68 |
|
return NULL; |
| 69 |
|
}; |
| 70 |
|
// |
| 71 |
|
TH1D *h1 = NULL; |
| 72 |
|
TH2D *h2 = NULL; |
| 73 |
|
Double_t f1 = 0.; |
| 74 |
|
Double_t minf1 = numeric_limits<Double_t>::max(); |
| 75 |
|
Double_t maxf1 = numeric_limits<Double_t>::min(); |
| 76 |
|
Double_t f2 = 0.; |
| 77 |
|
Double_t minf2 = numeric_limits<Double_t>::max(); |
| 78 |
|
Double_t maxf2 = numeric_limits<Double_t>::min(); |
| 79 |
|
// |
| 80 |
|
while ( Row ){ |
| 81 |
|
f1 = (Double_t)atof(Row->GetField(0)); |
| 82 |
|
if ( f1 > maxf1 ) maxf1 = f1; |
| 83 |
|
if ( f1 < minf1 ) minf1 = f1; |
| 84 |
|
if ( dim == 2 ){ |
| 85 |
|
f2 = (Double_t)atof(Row->GetField(1)); |
| 86 |
|
if ( f2 > maxf2 ) maxf2 = f2; |
| 87 |
|
if ( f2 < minf2 ) minf2 = f2; |
| 88 |
|
|
| 89 |
|
}; |
| 90 |
|
Row = pResult->Next(); |
| 91 |
|
}; |
| 92 |
|
pResult->Delete(); |
| 93 |
|
// |
| 94 |
|
|
| 95 |
|
// |
| 96 |
|
Int_t f1bin = 70; |
| 97 |
|
Int_t f2bin = 70; |
| 98 |
|
if ( dim == 1 ){ |
| 99 |
|
f1bin = int((maxf1-minf1)/1000.); |
| 100 |
|
if ( f1bin < 70 ) f1bin = 70; |
| 101 |
|
if ( f1bin > 1000 ) f1bin = 1000; |
| 102 |
|
if ( !strcmp(hname.Data(),"q2th") ) hname += "1"; |
| 103 |
|
// h1 = dynamic_cast<TH1D*>(gDirectory->FindObject(hname.Data())); |
| 104 |
|
h1 = (TH1D*)(gDirectory->FindObject(hname.Data())); |
| 105 |
|
if ( !strcmp(hname.Data(),"q2th1") ){ |
| 106 |
|
if ( h1 ) h1->Delete(); |
| 107 |
|
}; |
| 108 |
|
if ( !h1 ) h1 = new TH1D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02); |
| 109 |
|
// h1->SetBit(TH1::kCanRebin); |
| 110 |
|
if ( verbose ) printf("\n\n Row %s \n",pResult->GetFieldName(0)); |
| 111 |
|
}; |
| 112 |
|
if ( dim == 2 ){ |
| 113 |
|
f2bin = int((maxf2-minf2)/1000.); |
| 114 |
|
if ( f2bin < 70 ) f2bin = 70; |
| 115 |
|
if ( f2bin > 1000 ) f2bin = 1000; |
| 116 |
|
if ( !strcmp(hname.Data(),"q2th") ) hname += "2"; |
| 117 |
|
// h2 = dynamic_cast<TH2D*>(gDirectory->FindObject(hname.Data())); |
| 118 |
|
h2 = (TH2D*)(gDirectory->FindObject(hname.Data())); |
| 119 |
|
if ( !strcmp(hname.Data(),"q2th2") ){ |
| 120 |
|
if ( h2 ) h2->Delete(); |
| 121 |
|
}; |
| 122 |
|
if ( !h2 ) h2 = new TH2D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02,f2bin,minf2*0.98,maxf2*1.02); |
| 123 |
|
// h2->SetBit(TH2::kCanRebin); |
| 124 |
|
if ( verbose ) printf("\n\n Row %s %s \n",pResult->GetFieldName(0),pResult->GetFieldName(1)); |
| 125 |
|
}; |
| 126 |
|
// |
| 127 |
|
pResult = dbc->Query(query.Data()); |
| 128 |
|
// |
| 129 |
|
Row = pResult->Next(); |
| 130 |
|
// |
| 131 |
|
Int_t r = 0; |
| 132 |
|
// |
| 133 |
|
while ( Row ){ |
| 134 |
|
f1 = (Double_t)atof(Row->GetField(0)); |
| 135 |
|
if ( dim == 1 ){ |
| 136 |
|
if ( verbose ) printf(" %i %f \n",r,f1); |
| 137 |
|
h1->Fill(f1); |
| 138 |
|
} else { |
| 139 |
|
f2 = (Double_t)atof(Row->GetField(1)); |
| 140 |
|
if ( verbose ) printf(" %i %f %f \n",r,f1,f2); |
| 141 |
|
h2->Fill(f1,f2); |
| 142 |
|
}; |
| 143 |
|
r++; |
| 144 |
|
Row = pResult->Next(); |
| 145 |
|
}; |
| 146 |
|
// |
| 147 |
|
TCanvas *c = NULL; |
| 148 |
|
TString cname = Form("%sc",hname.Data()); |
| 149 |
|
// c = dynamic_cast<TCanvas*>(gDirectory->FindObject(hname.Data())); |
| 150 |
|
c = (TCanvas*)(gDirectory->FindObject(cname.Data())); |
| 151 |
|
if ( !c ) c = new TCanvas(Form("%sc",cname.Data())); |
| 152 |
|
c->Clear(); |
| 153 |
|
c->cd(); |
| 154 |
|
if ( dim == 1 ) h1->Draw(); |
| 155 |
|
if ( dim == 2 ) h2->Draw(); |
| 156 |
|
// |
| 157 |
|
pResult->Delete(); |
| 158 |
|
if ( dim == 1 ) return h1; |
| 159 |
|
if ( dim == 2 ) return h2; |
| 160 |
|
// |
| 161 |
|
return NULL; |
| 162 |
|
}; |
| 163 |
|
|
| 164 |
GL_TABLES::GL_TABLES(){ |
GL_TABLES::GL_TABLES(){ |
| 165 |
}; |
}; |
| 166 |
|
|