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 |
|
this->Open(host,user,psw); |
37 |
|
}; |
38 |
|
|
39 |
|
void Q2TH::Open(TString host, TString user, TString psw){ |
40 |
|
fh = gSystem->ExpandPathName(host.Data()); |
41 |
|
fu = gSystem->ExpandPathName(user.Data()); |
42 |
|
fp = gSystem->ExpandPathName(psw.Data()); |
43 |
|
printf(" Connecting to DB %s \n",fh.Data()); |
44 |
|
dbc = TSQLServer::Connect(fh.Data(),fu.Data(),fp.Data()); |
45 |
|
if ( dbc && dbc->IsConnected() ){ |
46 |
|
printf(" connected! \n"); |
47 |
|
} else { |
48 |
|
printf(" ERROR! not connected... :( \n"); |
49 |
|
}; |
50 |
|
}; |
51 |
|
|
52 |
|
TObject *Q2TH::Draw(TString query, Bool_t verbose, TString hname){ |
53 |
|
// |
54 |
|
if ( !strcmp(query.Data(),"help") ){ |
55 |
|
printf(" USAGE: \n"); |
56 |
|
printf(" 1) start root and create Q2TH object with \n"); |
57 |
|
printf(" Q2TH *qt = new Q2TH() \n"); |
58 |
|
printf(" or \n"); |
59 |
|
printf(" Q2TH *qt = new Q2TH(\"mysql://srvg-g2-01.ts.infn.it/pamelaProcessing9_TS\",\"pamelaprod_ro\",\"mypassword\") \n"); |
60 |
|
printf(" 2) query the DB with \n"); |
61 |
|
printf(" qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\"); \n"); |
62 |
|
printf(" qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\",true); this will print numbers on screen \n"); |
63 |
|
printf(" qt->Draw(\"select REAL_TIME_INIT from ROOT_TABLE_MERGING;\",true,\"myhisto\"); this will print numbers on screen and create histo \"myhisto\"\n"); |
64 |
|
printf(" 3) to use your own THxD create it and then query the DB giving as argument the name of histo: \n"); |
65 |
|
printf(" TH2D *myhisto=new TH2D(\"myhisto\",\"myhisto\",5000,1140000000.,1240000000.,10000,0.,1.) \n"); |
66 |
|
printf(" qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\",false,\"myhisto\")\n\n\n"); |
67 |
|
|
68 |
|
return NULL; |
69 |
|
}; |
70 |
|
// |
71 |
|
pResult = dbc->Query(query.Data()); |
72 |
|
// |
73 |
|
Row = pResult->Next(); |
74 |
|
// |
75 |
|
Int_t dim = pResult->GetFieldCount(); |
76 |
|
if ( dim < 1 || dim > 2 ){ |
77 |
|
printf(" Dim == %i not supported yet \n",dim); |
78 |
|
return NULL; |
79 |
|
}; |
80 |
|
// |
81 |
|
TH1D *h1 = NULL; |
82 |
|
TH2D *h2 = NULL; |
83 |
|
Double_t f1 = 0.; |
84 |
|
Double_t minf1 = numeric_limits<Double_t>::max(); |
85 |
|
Double_t maxf1 = numeric_limits<Double_t>::min(); |
86 |
|
Double_t f2 = 0.; |
87 |
|
Double_t minf2 = numeric_limits<Double_t>::max(); |
88 |
|
Double_t maxf2 = numeric_limits<Double_t>::min(); |
89 |
|
// |
90 |
|
while ( Row ){ |
91 |
|
f1 = (Double_t)atof(Row->GetField(0)); |
92 |
|
if ( f1 > maxf1 ) maxf1 = f1; |
93 |
|
if ( f1 < minf1 ) minf1 = f1; |
94 |
|
if ( dim == 2 ){ |
95 |
|
f2 = (Double_t)atof(Row->GetField(1)); |
96 |
|
if ( f2 > maxf2 ) maxf2 = f2; |
97 |
|
if ( f2 < minf2 ) minf2 = f2; |
98 |
|
|
99 |
|
}; |
100 |
|
Row = pResult->Next(); |
101 |
|
}; |
102 |
|
pResult->Delete(); |
103 |
|
// |
104 |
|
|
105 |
|
// |
106 |
|
Int_t f1bin = 70; |
107 |
|
Int_t f2bin = 70; |
108 |
|
if ( dim == 1 ){ |
109 |
|
f1bin = int((maxf1-minf1)/1000.); |
110 |
|
if ( f1bin < 70 ) f1bin = 70; |
111 |
|
if ( f1bin > 1000 ) f1bin = 1000; |
112 |
|
if ( !strcmp(hname.Data(),"q2th") ) hname += "1"; |
113 |
|
// h1 = dynamic_cast<TH1D*>(gDirectory->FindObject(hname.Data())); |
114 |
|
h1 = (TH1D*)(gDirectory->FindObject(hname.Data())); |
115 |
|
if ( !strcmp(hname.Data(),"q2th1") ){ |
116 |
|
if ( h1 ) h1->Delete(); |
117 |
|
}; |
118 |
|
if ( !h1 ) h1 = new TH1D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02); |
119 |
|
// h1->SetBit(TH1::kCanRebin); |
120 |
|
if ( verbose ) printf("\n\n Row %s \n",pResult->GetFieldName(0)); |
121 |
|
}; |
122 |
|
if ( dim == 2 ){ |
123 |
|
f2bin = int((maxf2-minf2)/1000.); |
124 |
|
if ( f2bin < 70 ) f2bin = 70; |
125 |
|
if ( f2bin > 1000 ) f2bin = 1000; |
126 |
|
if ( !strcmp(hname.Data(),"q2th") ) hname += "2"; |
127 |
|
// h2 = dynamic_cast<TH2D*>(gDirectory->FindObject(hname.Data())); |
128 |
|
h2 = (TH2D*)(gDirectory->FindObject(hname.Data())); |
129 |
|
if ( !strcmp(hname.Data(),"q2th2") ){ |
130 |
|
if ( h2 ) h2->Delete(); |
131 |
|
}; |
132 |
|
if ( !h2 ) h2 = new TH2D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02,f2bin,minf2*0.98,maxf2*1.02); |
133 |
|
// h2->SetBit(TH2::kCanRebin); |
134 |
|
if ( verbose ) printf("\n\n Row %s %s \n",pResult->GetFieldName(0),pResult->GetFieldName(1)); |
135 |
|
}; |
136 |
|
// |
137 |
|
pResult = dbc->Query(query.Data()); |
138 |
|
// |
139 |
|
Row = pResult->Next(); |
140 |
|
// |
141 |
|
Int_t r = 0; |
142 |
|
// |
143 |
|
while ( Row ){ |
144 |
|
f1 = (Double_t)atof(Row->GetField(0)); |
145 |
|
if ( dim == 1 ){ |
146 |
|
if ( verbose ) printf(" %i %f \n",r,f1); |
147 |
|
h1->Fill(f1); |
148 |
|
} else { |
149 |
|
f2 = (Double_t)atof(Row->GetField(1)); |
150 |
|
if ( verbose ) printf(" %i %f %f \n",r,f1,f2); |
151 |
|
h2->Fill(f1,f2); |
152 |
|
}; |
153 |
|
r++; |
154 |
|
Row = pResult->Next(); |
155 |
|
}; |
156 |
|
// |
157 |
|
TCanvas *c = NULL; |
158 |
|
TString cname = Form("%sc",hname.Data()); |
159 |
|
// c = dynamic_cast<TCanvas*>(gDirectory->FindObject(hname.Data())); |
160 |
|
c = (TCanvas*)(gDirectory->FindObject(cname.Data())); |
161 |
|
if ( !c ) c = new TCanvas(Form("%sc",cname.Data())); |
162 |
|
c->Clear(); |
163 |
|
c->cd(); |
164 |
|
if ( dim == 1 ) h1->Draw(); |
165 |
|
if ( dim == 2 ) h2->Draw(); |
166 |
|
// |
167 |
|
pResult->Delete(); |
168 |
|
if ( dim == 1 ) return h1; |
169 |
|
if ( dim == 2 ) return h2; |
170 |
|
// |
171 |
|
return NULL; |
172 |
|
}; |
173 |
|
|
174 |
GL_TABLES::GL_TABLES(){ |
GL_TABLES::GL_TABLES(){ |
175 |
}; |
}; |
176 |
|
|
197 |
mp = psw.Data(); |
mp = psw.Data(); |
198 |
}; |
}; |
199 |
|
|
200 |
Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
//Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
201 |
|
Bool_t GL_TABLES::IsConnected(TSQLServer *dbc){ |
202 |
// |
// |
203 |
// |
// |
204 |
// |
// |
234 |
TString host = fHost->Data(); |
TString host = fHost->Data(); |
235 |
TString user = fUser->Data(); |
TString user = fUser->Data(); |
236 |
TString psw = fPsw->Data(); |
TString psw = fPsw->Data(); |
237 |
dbc->Close(); |
if ( dbc ){ |
238 |
delete dbc; |
dbc->Close(); |
239 |
|
delete dbc; |
240 |
|
}; |
241 |
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
242 |
// |
// |
243 |
myquery.str(""); |
myquery.str(""); |