BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
CheckMySQL.cxx
Go to the documentation of this file.
1#include "CheckMySQL.h"
2#include "TH1F.h"
3#include "TBufferFile.h"
4CheckMYSQL::CheckMYSQL( const std::string& name,
5 ISvcLocator* pSvcLocator )
6 : Algorithm ( name, pSvcLocator )
7{
8 // Declare properties here.
9
10}
11
12
14 StatusCode sc;
15 MsgStream log(msgSvc(), name());
16 log << MSG::INFO << "Initialize()" << endreq;
17
18
19 return StatusCode::SUCCESS;
20
21}
22
23
24StatusCode CheckMYSQL::execute( ) {
25 MsgStream log(msgSvc(), name());
26 // int i;
27 char *opt_host_name = "bes3db2.ihep.ac.cn";
28// char *opt_host_name = "koala.ihep.ac.cn";
29 char *opt_user_name = "maqm";
30 char *opt_password = "maqm_offline";
31 unsigned int opt_port_num = 3306;
32 char *opt_socket_name = NULL;
33 char *opt_db_name = "offlinedb";
34 unsigned int opt_flags = 0;
35 MYSQL *conn;
36
37
38
39// calibUtil::Metadata *meta = new calibUtil::Metadata(opt_host_name, "*",opt_db_name);
40conn = mysql_init(NULL);
41
42 mysql_real_connect(conn, opt_host_name, opt_user_name, opt_password,
43 opt_db_name, opt_port_num, opt_socket_name, opt_flags);
44 printf("connect the database ok\n");
45
46
47time_t now;
48struct tm *timenow;
49timenow = localtime(&now);
50printf("Local time is %s\n",asctime(timenow));
51
52 TFile *f = new TFile("/ihepbatch/besd12/max/bBhabha_EsTime_run6018.root");
53 cout<<"step11111111"<<endl;
54
55 TTree *Level0 = (TTree*)f-> Get("h2");
56 TBufferFile Level0_buf(TBuffer::kWrite);
57 Level0->Streamer(Level0_buf);
58
59 cout<<"step22222222"<<endl;
60
61 TTree *Level1 = (TTree*)f-> Get("calibconst");
62 TBufferFile Level1_buf(TBuffer::kWrite);
63 Level1->Streamer(Level1_buf);
64
65
66/*
67 TH1F* LayerCntMap_1 = (TH1F*)f->Get("LayerCntMap");
68// TH1F* LayerCntMap = new TH1F((TH1F)f->Get("LayerCntMap"));
69// LayerCntMap->Copy(f->Get("LayerCntMap"));
70// const double* con = LayerCntMap_1->GetBuffer();
71// int size = LayerCntMap_1->GetBufferSize();
72 std::cout<<""step5555555555"<<std::endl;
73 TAxis* xaxis = LayerCntMap_1->GetXaxis();
74 double xmin = xaxis->GetXmin();
75 double xmax = xaxis->GetXmax();
76 double xbins = xaxis->GetNbins();
77 std::cout<<""step6666666"<<std::endl;
78 std::cout<<"xbins=="<<xbins<<"xmin=="<<xmin<<"xmax=="<<xmax<<std::endl;
79 TH1F* LayerCntMap = new TH1F("LayerCntMap","LayerCntMap",xbins,xmin,xmax);
80 for(int i=0;i<size;i++){
81 LayerCntMap->Fill(con[i]);
82 }
83
84 TBuffer LayerCntMap_buf(TBuffer::kWrite);
85 LayerCntMap->Copy(*(f->Get("LayerCntMap")));
86 LayerCntMap->Streamer(LayerCntMap_buf);
87 std::cout<<"55555555555555"<<std::endl;
88 f->Close();
89 TFile* check = new TFile("check.root","recreate");
90// LayerCntMap->Write();
91 check->Write();
92*/
93/* int size = 4096;
94 int bins = 10;
95 int xmin = 0;
96 int xmax = 10;
97 TH1F* histogramU16_ = new TH1F ("histogramU16_", "U16 data", bins, xmin, xmax);
98 histogramU16_->SetBit (TH1::kCanRebin); // allow automatic rebinning
99
100 for (int i = 0; i < 10; i++) {
101 histogramU16_->Fill(i);
102 }
103
104 char buffer[1024000];
105 TBuffer LayerCntMap_buf(TBuffer::kWrite, 1024000, buffer, true);
106 std::cout<<"aaaaaaaaa"<<std::endl;
107 histogramU16_->Streamer(LayerCntMap_buf);
108
109 cout<<"step55555555555"<<endl;
110 TH1F* BoxCntMap = (TH1F*)f->Get("BoxCntMap");
111 char buffer_1[52400];
112 TBuffer BoxCntMap_buf(TBuffer::kWrite,524000,buffer_1,true);
113 BoxCntMap->Streamer(BoxCntMap_buf);
114
115 cout<<"step66666666"<<std::endl;
116 TH1F* StripCntMap = (TH1F*)f->Get("StripCntMap");
117 char buffer_2[52400];
118 TBuffer StripCntMap_buf(TBuffer::kWrite,524000,buffer_2,true);
119 StripCntMap->Streamer(StripCntMap_buf);
120 cout<<"step7777777777"<<std::endl;
121
122 TH1F* LayerProMap = (TH1F*)f->Get("LayerProMap");
123 char buffer_3[52400];
124 TBuffer LayerProMap_buf(TBuffer::kWrite,524000,buffer_3,true);
125 LayerProMap->Streamer(LayerProMap_buf);
126
127 cout<<"step88888888888888"<<std::endl;
128
129 TH1F* BoxProMap = (TH1F*)f->Get("BoxProMap");
130 char buffer_4[52400];
131 TBuffer BoxProMap_buf(TBuffer::kWrite,524000,buffer_4,true);
132 BoxProMap->Streamer(BoxProMap_buf);
133
134 cout<<"step9999999999999"<<std::endl;
135 */
136char query[5024000],buf[1024*1000],buf1[1024*1000],*p,*p1;
137unsigned int from_len,from_len1;
138
139int status;
140int id =60034;
141
142
143sprintf(query,"INSERT INTO EsTimeCalConst(SerNo,RunFrom,RunTo,EsTimeH2,EsTimeH9) VALUES(%d,'100','1000','",id);
144
145 printf("%s\n",query);
146 p= query + strlen(query);
147p += mysql_escape_string(p,Level0_buf.Buffer(),Level0_buf.BufferSize());
148
149 strcat(p,"','");
150cout<<"strlen(query)22222222222="<<strlen(query)<<endl;
151
152 p= query + strlen(query);
153 p +=mysql_escape_string(p,Level1_buf.Buffer(),Level1_buf.BufferSize());
154 strcat(p,"')");
155 status = mysql_query(conn,query);
156 printf("%d\n",status);
157
158
159
160
161//cout<<"status================"<<status<<endl;
162
163unsigned long *lengths;
164
165 MYSQL_RES *res_set;
166 MYSQL_ROW row;
167
168//char *p1;
169 char stmt1[200];//="select context from mytesttable where id = %d,";
170 int serno =1;
171// sprintf(stmt1,"select BarTofPar,EndTofPar,RunFrom,RunTo from TofCalConst where SerNo=%d",serno);
172 sprintf(stmt1,"select EsTimeH2,EsTimeH9,RunFrom,RunTo from TofCalConst where SerNo=%d",serno);
173
174// char stmt1[100]="select tree1,tree2 from TofCalConst where ser_no = 10026";
175 printf("%s\n",stmt1);
176 if(mysql_real_query(conn, stmt1, strlen(stmt1)) != 0)
177 printf("query error\n");
178 res_set = mysql_store_result (conn);
179 mysql_field_seek (res_set, 0);
180
181 row = mysql_fetch_row (res_set);
182 lengths = mysql_fetch_lengths(res_set);
183for(int i=0;i<8;i++){
184// cout<<"size of row["<<i<<"]"<<sizeof(row[i])<<endl;
185 cout<<"lengths["<<i<<"]="<<lengths[i]<<endl;
186 }
187/*
188//string ss(row[0]);
189//const char *pp = ss.c_str();
190
191 TTree* newHist= new TTree();
192 TBuffer rootBuffer2(TBuffer::kRead,lengths[0], row[0], kFALSE);
193// TBuffer rootBuffer2(TBuffer::kRead,lengths[0], void pp, kFALSE);
194 newHist->Streamer(rootBuffer2);
195 newHist->Print();
196 int nentri = newHist -> GetEntries();*/
197// double xtpar;
198// int xtkey;
199/*double atten,w3;
200 newHist -> SetBranchAddress("Atten", &atten);
201 newHist -> SetBranchAddress("W3", &w3);
202 cout<<"nentri="<<nentri<<endl;
203 for(int ii=0;ii<nentri;ii++){
204 newHist->GetEntry(ii);
205 cout<<"Atten="<<atten<<"W3="<<w3<<endl;
206 }
207 */
208/* TTree* newHist1= new TTree();
209 TBuffer rootBuffer3(TBuffer::kRead,lengths[1], row[1], kFALSE);
210 newHist1->Streamer(rootBuffer3);
211 newHist1->Print();
212 int nentri1 = newHist1 -> GetEntries();
213// double xtpar;
214// int xtkey;
215//double atten,w3;
216 double p6;
217 newHist1 -> SetBranchAddress("Atten", &atten);
218 newHist1 -> SetBranchAddress("P6", &p6);
219 cout<<"nentri1="<<nentri1<<endl;
220 for(int ii=0;ii<nentri1;ii++){
221 newHist1->GetEntry(ii);
222 cout<<"Atten="<<atten<<"P6="<<p6<<endl;
223 }
224 */
225 return StatusCode::SUCCESS;
226}
227StatusCode CheckMYSQL::finalize( ) {
228
229 MsgStream log(msgSvc(), name());
230 log << MSG::INFO
231 << " CheckMYSQL FINALIZE!! "
232 << endreq;
233
234 return StatusCode::SUCCESS;
235}
236
237
struct st_mysql_res MYSQL_RES
struct st_mysql MYSQL
IMessageSvc * msgSvc()
CheckMYSQL(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CheckMySQL.cxx:4
StatusCode initialize()
Definition: CheckMySQL.cxx:13
StatusCode finalize()
Definition: CheckMySQL.cxx:227
StatusCode execute()
Definition: CheckMySQL.cxx:24
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")