BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
CalConstSqlHelper.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <string>
3#include <cstdlib>
4#include <time.h>
5#include <stdio.h>
6#include <string.h>
7#include <mysql/mysql.h>
8#include "TFile.h"
9#include "TTree.h"
10#include "TROOT.h"
11#include "TH1F.h"
12#include "TAxis.h"
13#include "TH1.h"
14#include "TBufferFile.h"
15#include <fstream>
16#define CALCONSTSQLHELPER
17
18using namespace std;
19
20int main(int argc, char** argv) {
21
22 if(argc!=10) {
23 printf("error, wrong argument number!\n");
24 return 0;
25 }
26 char *opt_host_name=argv[1];
27 unsigned int opt_port_num = 3306;
28 char *opt_socket_name = NULL;
29 char *opt_db_name = argv[3];
30 char *opt_user_name = argv[4];
31 char *opt_password = argv[5];
32 TFile *f= new TFile(argv[6]);
33 char *opt_table_name = argv[7];
34 char *opt_type = argv[8];
35 char *opt_id = argv[9];
36 unsigned int opt_flags = 0;
37
38 static char query[80240000];
39 char *p;
40 char query_check[1024];
41
42 int status=-1;
43
44 if(f->IsZombie()) return 0;
45
46
47 gROOT->cd();
48 if(strcmp(opt_type,"MDC")==0){
49 sprintf(query_check,"select RunFrom,RunTo,CalParVer,SftVer from %s where SerNo=%s",opt_table_name,opt_id);
50 /*
51 Int_t key;
52 Double_t xtpar,delt0,t0,qtpar0,qtpar1,sdpar;
53
54 //xttree-------------------------------------------------------------------
55 TTree *xttree_1 = new TTree("XtTree", "XtTree");
56 xttree_1->SetDirectory(0);
57 xttree_1 -> Branch("xtkey", &key, "key/I");
58 xttree_1 -> Branch("xtpar", &xtpar, "xtpar/D");
59
60 //new xttree---------------------------------------------------------------
61 TObjArray newxttrees_1;
62
63 //t0tree-------------------------------------------------------------------
64 TTree *t0tree_1 = new TTree("T0Tree", "T0Tree");
65 t0tree_1->SetDirectory(0);
66 t0tree_1 -> Branch("t0", &t0, "t0/D");
67 t0tree_1 -> Branch("delt0", &delt0, "delt0/D");
68
69 //qttree-------------------------------------------------------------------
70 TTree *qttree_1 = new TTree("QtTree", "QtTree");
71 qttree_1->SetDirectory(0);
72 qttree_1 -> Branch("qtpar0", &qtpar0, "qtpar0/D");
73 qttree_1 -> Branch("qtpar1", &qtpar1, "qtpar1/D");
74
75 //sdtree-------------------------------------------------------------------
76 TTree *sdtree_1 = new TTree("SdTree", "SdTree");
77 sdtree_1->SetDirectory(0);
78 sdtree_1 -> Branch("sdkey", &key, "key/I");
79 sdtree_1 -> Branch("sdpar", &sdpar, "sdpar/D");
80
81 TBufferFile qttree_buf(TBufferFile::kWrite);
82
83 TBufferFile t0tree_buf(TBufferFile::kWrite);
84
85 TBufferFile xttree_buf(TBufferFile::kWrite);
86
87 TBufferFile sdtree_buf(TBufferFile::kWrite);
88
89 TFile *f= new TFile(argv[6]);
90 TTree *qttree = (TTree*)f-> Get("QtTree");
91 qttree -> SetBranchAddress("qtpar0", &qtpar0);
92 qttree -> SetBranchAddress("qtpar1", &qtpar1);
93 Int_t nentries = qttree -> GetEntries();
94 Int_t i=0;
95 for(i=0; i<nentries; i++){
96 qttree -> GetEntry(i);
97 qttree_1->Fill();
98 }
99
100 TTree *sdtree = (TTree*)f-> Get("SdTree");
101 sdtree -> SetBranchAddress("sdpar", &sdpar);
102 sdtree -> SetBranchAddress("sdkey", &key);
103 nentries = sdtree -> GetEntries();
104 for(i=0; i<nentries; i++){
105 sdtree -> GetEntry(i);
106 sdtree_1->Fill();
107 }
108
109
110 TTree *t0tree = (TTree*)f-> Get("T0Tree");
111 t0tree -> SetBranchAddress("t0", &t0);
112 t0tree -> SetBranchAddress("delt0", &delt0);
113 nentries = t0tree -> GetEntries();
114 for(i=0; i<nentries; i++){
115 t0tree -> GetEntry(i);
116 t0tree_1->Fill();
117 }
118
119
120 TTree *xttree = (TTree*)f-> Get("XtTree");
121 xttree -> SetBranchAddress("xtpar", &xtpar);
122 xttree -> SetBranchAddress("xtkey", &key);
123 nentries = xttree -> GetEntries();
124 for(i=0; i<nentries; i++){
125 xttree -> GetEntry(i);
126 xttree_1->Fill();
127 }
128
129
130 qttree_1->Streamer(qttree_buf);
131 t0tree_1->Streamer(t0tree_buf);
132 xttree_1->Streamer(xttree_buf);
133 sdtree_1->Streamer(sdtree_buf);
134 */
135
136 //new xttree---------------------------------------------------------------
137 bool foundNewXtTree = false;
138 TObjArray newxttrees;
139 TBufferFile newxttree_buf(TBufferFile::kWrite);
140 int nNewXtTree = 0;
141 const int maxNewXtTreeNum = 43*18*2;
142 for(int t_layer=0; t_layer<43; t_layer++){
143 for(int t_bin=0; t_bin<18; t_bin++){
144 for(int t_lr=0; t_lr<2; t_lr++){
145 char newXtTreeName[20];
146 sprintf(newXtTreeName,"trNewXt%02d_%02d_%d",t_layer,t_bin,t_lr);
147 if(!f->Get(newXtTreeName)) break;
148 TTree *newXttree = ((TTree*)f->Get(newXtTreeName))->CloneTree();
149 newxttrees.Add(newXttree);
150 nNewXtTree++;
151 }
152 }
153 }
154 if(nNewXtTree==maxNewXtTreeNum) {
155 foundNewXtTree = true;
156 newxttrees.Streamer(newxttree_buf);
157 }
158
159 //r2ttrees
160 TObjArray r2ttrees;
161 TBufferFile r2ttree_buf(TBufferFile::kWrite);
162 int nR2tTree = 0;
163 const int maxR2tTreeNum = 43;
164 for(int t_layer=0; t_layer<43; t_layer++){
165 char r2tTreeName[20];
166 sprintf(r2tTreeName,"r2t%02d",t_layer);
167 if(!f->Get(r2tTreeName)) break;
168 TTree *r2ttree = ((TTree*)f->Get(r2tTreeName))->CloneTree();
169 r2ttrees.Add(r2ttree);
170 nR2tTree++;
171 }
172 if(nR2tTree!=maxR2tTreeNum){
173 printf("r2t tree error\n");
174 }else{
175 r2ttrees.Streamer(r2ttree_buf);
176 }
177
178 //cout<<"r2t buffer size "<<r2ttree_buf.BufferSize()<<endl;
179
180
181 //xttree-------------------------------------------------------------------
182 bool foundOldXtTree = false;
183 TTree *xttree = (TTree*)f-> Get("XtTree");
184 if(xttree){ foundOldXtTree = true; }
185 TTree *xttree_copy = xttree->CloneTree();
186 TBufferFile xttree_buf(TBufferFile::kWrite);
187 if(xttree) xttree_copy->Streamer(xttree_buf);
188 //std::cout<< __FILE__ << " " << __LINE__ << " xttree buf size "<<xttree_buf.BufferSize()<<std::endl;
189
190 //test xttree
191 if(!foundOldXtTree && !foundNewXtTree) {
192 printf("no Xt Tree\n");
193 return 0;
194 }
195
196
197 //t0tree
198 TTree *t0tree = (TTree*)f-> Get("T0Tree");
199 TTree *t0tree_copy = t0tree->CloneTree();
200 TBufferFile t0tree_buf(TBufferFile::kWrite);
201 t0tree_copy->Streamer(t0tree_buf);
202
203 //qttree
204 TTree *qttree = (TTree*)f-> Get("QtTree");
205 TTree *qttree_copy = qttree->CloneTree();
206 TBufferFile qttree_buf(TBufferFile::kWrite);
207 qttree_copy->Streamer(qttree_buf);
208
209 //sdtree
210 TTree *sdtree = (TTree*)f-> Get("SdTree");
211 TTree *sdtree_copy = sdtree->CloneTree();
212 TBufferFile sdtree_buf(TBufferFile::kWrite);
213 sdtree_copy->Streamer(sdtree_buf);
214
215 //cout<<"r2t nTree "<<r2ttrees.GetEntries()<<endl;
216 //cout<<"new xt buffer size "<<newxttree_buf.BufferSize()<<endl;
217 //cout<<"new xt nTree "<<newxttrees.GetEntries()<<endl;
218
219 //-- create sql --
220 sprintf(query,"UPDATE %s SET QtTree='",opt_table_name);
221 p= query + strlen(query);
222 p += mysql_escape_string(p,qttree_buf.Buffer(),qttree_buf.BufferSize());
223
224 if(xttree){
225 strcat(p,"',XtTree='");
226 p= query + strlen(query);
227 p +=mysql_escape_string(p,xttree_buf.Buffer(),xttree_buf.BufferSize());
228 }
229
230 if(nNewXtTree == maxNewXtTreeNum){
231 strcat(p,"',NewXtTrees='");
232 p= query + strlen(query);
233 p +=mysql_escape_string(p,newxttree_buf.Buffer(),newxttree_buf.BufferSize());
234 }
235
236 strcat(p,"',T0Tree='");
237 p= query + strlen(query);
238 p +=mysql_escape_string(p,t0tree_buf.Buffer(),t0tree_buf.BufferSize());
239
240 strcat(p,"',SdTree='");
241 p= query + strlen(query);
242 p +=mysql_escape_string(p,sdtree_buf.Buffer(),sdtree_buf.BufferSize());
243
244 strcat(p,"',R2tTrees='");
245 p= query + strlen(query);
246 p +=mysql_escape_string(p,r2ttree_buf.Buffer(),r2ttree_buf.BufferSize());
247
248 strcat(p,"' WHERE SerNo = ");
249 p= query + strlen(query);
250 strcat(p,opt_id);
251
252
253 } else if(strcmp(opt_type,"EMC")==0){
254 sprintf(query_check,"select RunFrom,RunTo,CalParVer,SftVer from %s where SerNo=%s",opt_table_name,opt_id);
255
256 TTree *DigiCalibConst = (TTree*)f-> Get("DigiCalibConst");
257 TTree *DigiCalibConst_copy = DigiCalibConst->CloneTree();
258 TBufferFile DigiCalibConst_buf(TBufferFile::kWrite);
259 DigiCalibConst_copy->Streamer(DigiCalibConst_buf);
260 /* double gwire[7000];
261 DigiCalibConst -> SetBranchAddress("DigiCalibConst", gwire);
262 DigiCalibConst->GetEntry(0);
263 for(int i=0;i<200;i++)
264 std::cout<<"gwire: ["<<i<<"] = "<<gwire[i]<<std::endl;
265 */
266
267 sprintf(query,"UPDATE %s SET DigiCalibConst='",opt_table_name);
268 p= query + strlen(query);
269 p += mysql_escape_string(p,DigiCalibConst_buf.Buffer(),DigiCalibConst_buf.BufferSize());
270 strcat(p,"' WHERE SerNo = ");
271 strcat(p,opt_id);
272
273 } else if(strcmp(opt_type,"TOF")==0){
274 sprintf(query_check,"select RunFrom,RunTo,CalParVer,SftVer from %s where SerNo=%s",opt_table_name,opt_id);
275
276 TTree *xttree = (TTree*)f-> Get("BarTofPar");
277 TTree *xttree_copy = xttree->CloneTree();
278 TBufferFile rootBuffer(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
279 xttree_copy->Streamer(rootBuffer);
280
281 TTree *xttree1 = (TTree*)f-> Get("EndTofPar");
282 TTree *xttree1_copy = xttree1->CloneTree();
283 TBufferFile rootBuffer1(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
284 xttree1_copy->Streamer(rootBuffer1);
285
286 TTree *xttree2 = (TTree*)f-> Get("BarTofParCommon");
287 TTree *xttree2_copy = xttree2->CloneTree();
288 TBufferFile rootBuffer2(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
289 xttree2_copy->Streamer(rootBuffer2);
290
291 TTree *xttree3 = (TTree*)f-> Get("CalibInfo");
292 TTree *xttree3_copy = xttree3->CloneTree();
293 TBufferFile rootBuffer3(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
294 xttree3_copy->Streamer(rootBuffer3);
295
296 //int flag=0;
297 //maqm add for more tree:EtfTofPar
298 TTree *xttree4 = (TTree*)f-> Get("EtfTofPar");
299 TBufferFile rootBuffer4(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
300 if (xttree4) {
301 TTree *xttree4_copy = xttree4->CloneTree();
302 xttree4_copy->Streamer(rootBuffer4);
303 }
304 //maqm add for more tree:EtfTofBunch
305 TTree *xttree5 = (TTree*)f-> Get("EtfTofBunch");
306 TBufferFile rootBuffer5(TBufferFile::kWrite);
307 if (xttree5) {
308 TTree *xttree5_copy = xttree5->CloneTree();
309 xttree5_copy->Streamer(rootBuffer5);
310 }
311
312
313 sprintf(query,"UPDATE %s SET BarTofPar='",opt_table_name);
314 p= query + strlen(query);
315 p += mysql_escape_string(p,rootBuffer.Buffer(),rootBuffer.BufferSize());
316 strcat(p,"',EndTofPar='");
317 p= query + strlen(query);
318 p +=mysql_escape_string(p,rootBuffer1.Buffer(),rootBuffer1.BufferSize());
319 strcat(p,"',TofConPar='");
320 p= query + strlen(query);
321 p +=mysql_escape_string(p,rootBuffer2.Buffer(),rootBuffer2.BufferSize());
322 strcat(p,"',BarTof='");
323 p= query + strlen(query);
324 //maqm add for adding tree:CalibInfo
325 p +=mysql_escape_string(p,rootBuffer3.Buffer(),rootBuffer3.BufferSize());
326 if (xttree4) {
327 strcat(p,"',EtfTofPar='");
328 p= query + strlen(query);
329 p +=mysql_escape_string(p,rootBuffer4.Buffer(),rootBuffer4.BufferSize());
330 }
331 if (xttree5) {
332 strcat(p,"',EtfTofBunch='");
333 p= query + strlen(query);
334 p +=mysql_escape_string(p,rootBuffer5.Buffer(),rootBuffer5.BufferSize());
335 }
336
337 strcat(p,"' WHERE SerNo = ");
338 strcat(p,opt_id);
339
340 } else if(strcmp(opt_type,"MUC")==0){
341 sprintf(query_check,"select RunFrom,RunTo,CalParVer,SftVer from %s where SerNo=%s",opt_table_name,opt_id);
342
343 TTree *xttree = (TTree*)f-> Get("LayConst");
344 TTree *xttree_copy = xttree->CloneTree();
345 TBufferFile rootBuffer(TBufferFile::kWrite);
346 xttree_copy->Streamer(rootBuffer);
347
348 TTree *xttree1 = (TTree*)f-> Get("BoxConst");
349 TTree *xttree1_copy = xttree1->CloneTree();
350 TBufferFile rootBuffer1(TBufferFile::kWrite);
351 xttree1_copy->Streamer(rootBuffer1);
352
353 TTree *xttree2 = (TTree*)f-> Get("StrConst");
354 TTree *xttree2_copy =xttree2->CloneTree();
355 TBufferFile rootBuffer2(TBufferFile::kWrite);
356 xttree2_copy->Streamer(rootBuffer2);
357
358
359 sprintf(query,"UPDATE %s SET LayTree='",opt_table_name);
360 p= query + strlen(query);
361 p += mysql_escape_string(p,rootBuffer.Buffer(),rootBuffer.BufferSize());
362 strcat(p,"',BoxTree='");
363 p= query + strlen(query);
364 p += mysql_escape_string(p,rootBuffer1.Buffer(),rootBuffer1.BufferSize());
365 strcat(p,"',StrTree='");
366 p= query + strlen(query);
367 p += mysql_escape_string(p,rootBuffer2.Buffer(),rootBuffer2.BufferSize());
368 strcat(p,"' WHERE SerNo = ");
369 strcat(p,opt_id);
370 }
371 else if(strcmp(opt_type,"DEDX")==0){
372 sprintf(query_check,"select RunFrom,RunTo,CalParVer,SftVer from %s where SerNo=%s",opt_table_name,opt_id);
373 /* TTree *ww1=new TTree("wiregcalib","wiregcalib");
374 Double_t gwire[6796];
375 ww1 -> Branch("wireg", &gwire, "wireg[6796]/D");
376 */
377
378 TTree *ddgcalib = (TTree*)f-> Get("ddgcalib");
379 TTree *ddgcalib_copy = ddgcalib->CloneTree();
380 TBufferFile ddgcalib_buf(TBufferFile::kWrite);
381 ddgcalib_copy->Streamer(ddgcalib_buf);
382
383 TTree *entracalib = (TTree*)f-> Get("entracalib");
384 TTree *entracalib_copy = entracalib->CloneTree();
385 TBufferFile entracalib_buf(TBufferFile::kWrite);
386 entracalib_copy->Streamer(entracalib_buf);
387
388 TTree *gaincalib = (TTree*)f-> Get("gaincalib");
389 TTree *gaincalib_copy = gaincalib->CloneTree();
390 TBufferFile gaincalib_buf(TBufferFile::kWrite);
391 gaincalib_copy->Streamer(gaincalib_buf);
392
393 TTree *ggscalib = (TTree*)f-> Get("ggscalib");
394 TTree *ggscalib_copy = ggscalib->CloneTree();
395 TBufferFile ggscalib_buf(TBufferFile::kWrite);
396 ggscalib_copy->Streamer(ggscalib_buf);
397
398 TTree *layergcalib = (TTree*)f-> Get("layergcalib");
399 TTree *layergcalib_copy = layergcalib->CloneTree();
400 TBufferFile layergcalib_buf(TBufferFile::kWrite);
401 layergcalib_copy->Streamer(layergcalib_buf);
402
403 TTree *resolcalib = (TTree*)f-> Get("resolcalib");
404 TTree *resolcalib_copy =resolcalib->CloneTree();
405 TBufferFile resolcalib_buf(TBufferFile::kWrite);
406 resolcalib_copy->Streamer(resolcalib_buf);
407
408 TTree *wiregcalib = (TTree*)f-> Get("wiregcalib");
409 TTree *wiregcalib_copy = wiregcalib->CloneTree();
410 /*double gwire[7000];
411 wiregcalib -> SetBranchAddress("wireg", gwire);
412 wiregcalib->GetEntry(0);
413 for(int i=0;i<200;i++)
414 std::cout<<"gwire: ["<<i<<"] = "<<gwire[i]<<std::endl; */
415 TBufferFile wiregcalib_buf(TBufferFile::kWrite);
416 wiregcalib_copy->Streamer(wiregcalib_buf);
417
418
419 TTree *zdepcalib = (TTree*)f-> Get("zdepcalib");
420 TTree *zdepcalib_copy = zdepcalib->CloneTree();
421 TBufferFile zdepcalib_buf(TBufferFile::kWrite);
422 zdepcalib_copy->Streamer(zdepcalib_buf);
423
424 TTree *runcalib = (TTree*)f-> Get("runcalib");
425 TTree *runcalib_copy = runcalib->CloneTree();
426 TBufferFile runcalib_buf(TBufferFile::kWrite);
427 runcalib_copy->Streamer(runcalib_buf);
428 /*TTree *docasin = (TTree*)f-> Get("docasin");
429 TBufferFile docasin_buf(TBufferFile::kWrite);
430 docasin->Streamer(docasin_buf);
431 TTree *spacecharge = (TTree*)f-> Get("spacecharge");
432 TBufferFile spacecharge_buf(TBufferFile::kWrite);
433 spacecharge->Streamer(spacecharge_buf);*/
434
435 sprintf(query,"UPDATE %s SET WireGain='",opt_table_name);
436 // sprintf(query,"UPDATE %s SET Resolution ='",opt_table_name);
437 p= query + strlen(query);
438 //std::cout<<"sql is: "<<query.str().c_str()<<std::endl;
439 p += mysql_escape_string(p,wiregcalib_buf.Buffer(),wiregcalib_buf.BufferSize());
440 //std::cout<<"sql is:"<<wiregcalib_buf.Buffer()<<std::endl;
441 strcat(p,"',Resolution = '");
442 p= query + strlen(query);
443 p += mysql_escape_string(p,resolcalib_buf.Buffer(),resolcalib_buf.BufferSize());
444 strcat(p,"',MeanGain = '");
445 p= query + strlen(query);
446 p += mysql_escape_string(p,gaincalib_buf.Buffer(),gaincalib_buf.BufferSize());
447 strcat(p,"',GasGain = '");
448 p= query + strlen(query);
449 p += mysql_escape_string(p,ggscalib_buf.Buffer(),ggscalib_buf.BufferSize());
450 strcat(p,"',LayerGain = '");
451 p= query + strlen(query);
452 p += mysql_escape_string(p,layergcalib_buf.Buffer(),layergcalib_buf.BufferSize());
453 strcat(p,"',ZDep = '");
454 p= query + strlen(query);
455 p += mysql_escape_string(p,zdepcalib_buf.Buffer(),zdepcalib_buf.BufferSize());
456 strcat(p,"',EntranceAng = '");
457 p= query + strlen(query);
458 p += mysql_escape_string(p,entracalib_buf.Buffer(),entracalib_buf.BufferSize());
459 strcat(p,"',RunGain = '");
460 p= query + strlen(query);
461 //p += mysql_escape_string(p,runcalib_buf.Buffer(),runcalib_buf.BufferSize());
462 p += mysql_escape_string(p,runcalib_buf.Buffer(),runcalib_buf.Length());
463 //std::cout << "zzz: " << runcalib_buf.BufferSize() << " " << runcalib_buf.Length() << std::endl;
464
465 /*strcat(p,"',DocaSin = '");
466 p= query + strlen(query);
467 p += mysql_escape_string(p,docasin_buf.Buffer(),docasin_buf.BufferSize());
468 strcat(p,"',SpaceCharge = '");
469 p= query + strlen(query);
470 p += mysql_escape_string(p,spacecharge_buf.Buffer(),spacecharge_buf.BufferSize());*/
471
472 strcat(p,"',DriftDist = '");
473 p= query + strlen(query);
474 p += mysql_escape_string(p,ddgcalib_buf.Buffer(),ddgcalib_buf.BufferSize());
475 strcat(p,"' WHERE SerNo = ");
476 strcat(p,opt_id);
477 //std::cout<<"sql is:"<<p<<std::endl;
478 } else if(strcmp(opt_type,"ESTIME")==0){
479 sprintf(query_check,"select RunFrom,RunTo,CalParVer,SftVer from %s where SerNo=%s",opt_table_name,opt_id);
480
481 TTree *xttree = (TTree*)f-> Get("h2");
482 TTree *xttree_copy = xttree->CloneTree();
483 TBufferFile rootBuffer(TBufferFile::kWrite);
484 xttree_copy->Streamer(rootBuffer);
485
486 TTree *xttree1 = (TTree*)f-> Get("calibconst");
487 TTree *xttree1_copy = xttree1->CloneTree();
488 TBufferFile rootBuffer1(TBufferFile::kWrite);
489 xttree1_copy->Streamer(rootBuffer1);
490
491 TTree *xttree2 = (TTree*)f-> Get("calibconst");
492 Int_t bunchtime;
493 Double_t t0offset;
494 xttree2->SetBranchAddress("bunchtime",&bunchtime);
495 xttree2->SetBranchAddress("t0offset",&t0offset);
496 for(Int_t i = 0 ; i < (Int_t)xttree2->GetEntries() ; i++){
497 xttree2->GetEntry(i);
498 }
499 //printf("bunchtime=%d",bunchtime);
500 //printf("t0offset=%f",t0offset);
501 sprintf(query,"UPDATE %s SET EsTimeH2='",opt_table_name);
502 p= query + strlen(query);
503 p += mysql_escape_string(p,rootBuffer.Buffer(),rootBuffer.BufferSize());
504 strcat(p,"',EsTimeH9='");
505 p= query + strlen(query);
506 p += mysql_escape_string(p,rootBuffer1.Buffer(),rootBuffer1.BufferSize());
507 char c[64];
508 sprintf(c, "%d",bunchtime);
509 strcat(p,"', Bunchtime=");
510 strcat(p,c);
511 strcat(p,", T0offset=");
512 sprintf(c, "%f", t0offset);
513 strcat(p,c);
514 strcat(p," WHERE SerNo = ");
515 strcat(p,opt_id);
516 } else if(strcmp(opt_type,"ESTTOF")==0){
517 sprintf(query_check,"select RunFrom,RunTo,CalParVer,SftVer from %s where SerNo=%s",opt_table_name,opt_id);
518
519 TTree *xttree = (TTree*)f-> Get("BarTofPar");
520 TTree *xttree_copy = xttree->CloneTree();
521 TBufferFile rootBuffer(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
522 xttree_copy->Streamer(rootBuffer);
523
524 TTree *xttree1 = (TTree*)f-> Get("EndTofPar");
525 TTree *xttree1_copy = xttree1->CloneTree();
526 TBufferFile rootBuffer1(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
527 xttree1_copy->Streamer(rootBuffer1);
528
529 TTree *xttree2 = (TTree*)f-> Get("BarTofParCommon");
530 TTree *xttree2_copy = xttree2->CloneTree();
531 TBufferFile rootBuffer2(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
532 xttree2_copy->Streamer(rootBuffer2);
533
534 TTree *xttree3 = (TTree*)f-> Get("CalibInfo");
535 TTree *xttree3_copy = xttree3->CloneTree();
536 TBufferFile rootBuffer3(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
537 xttree3_copy->Streamer(rootBuffer3);
538
539 //int flag=0;
540 //maqm add for more tree:EtfTofPar
541 TTree *xttree4 = (TTree*)f-> Get("EtfTofPar");
542 TBufferFile rootBuffer4(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
543 if (xttree4) {
544 TTree *xttree4_copy = xttree4->CloneTree();
545 xttree4_copy->Streamer(rootBuffer4);
546 }
547 //maqm add for more tree:EtfTofBunch
548 TTree *xttree5 = (TTree*)f-> Get("EtfTofBunch");
549 TBufferFile rootBuffer5(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
550 if (xttree5) {
551 TTree *xttree5_copy = xttree5->CloneTree();
552 xttree5_copy->Streamer(rootBuffer5);
553 }
554
555
556
557
558 sprintf(query,"UPDATE %s SET BarTofPar='",opt_table_name);
559 p= query + strlen(query);
560 p += mysql_escape_string(p,rootBuffer.Buffer(),rootBuffer.BufferSize());
561 strcat(p,"',EndTofPar='");
562 p= query + strlen(query);
563 p +=mysql_escape_string(p,rootBuffer1.Buffer(),rootBuffer1.BufferSize());
564 strcat(p,"',TofConPar='");
565 p= query + strlen(query);
566 p +=mysql_escape_string(p,rootBuffer2.Buffer(),rootBuffer2.BufferSize());
567 strcat(p,"',BarTof='");
568 p= query + strlen(query);
569 p +=mysql_escape_string(p,rootBuffer3.Buffer(),rootBuffer3.BufferSize());
570 if (xttree4) {
571 strcat(p,"',EtfTofPar='");
572 p= query + strlen(query);
573 p +=mysql_escape_string(p,rootBuffer4.Buffer(),rootBuffer4.BufferSize());
574 }
575 if (xttree5) {
576 strcat(p,"',EtfTofBunch='");
577 p= query + strlen(query);
578 p +=mysql_escape_string(p,rootBuffer5.Buffer(),rootBuffer5.BufferSize());
579 }
580 strcat(p,"' WHERE SerNo = ");
581 strcat(p,opt_id);
582 } else if(strcmp(opt_type,"TOFQELEC")==0){
583 sprintf(query_check,"select RunFrom,RunTo,CalParVer,SftVer from %s where TofQELecSerNo=%s",opt_table_name,opt_id);
584
585 TTree *xttree = (TTree*)f-> Get("BarBoardNum");
586 TTree *xttree_copy = xttree->CloneTree();
587 TBufferFile rootBuffer(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
588 xttree_copy->Streamer(rootBuffer);
589
590 TTree *xttree1 = (TTree*)f-> Get("EndBoardNum");
591 TTree *xttree1_copy = xttree1->CloneTree();
592 TBufferFile rootBuffer1(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
593 xttree1_copy->Streamer(rootBuffer1);
594
595 TTree *xttree2 = (TTree*)f-> Get("QElecBarParEast");//yzhang? FIXME
596 TTree *xttree2_copy = xttree2->CloneTree();
597 TBufferFile rootBuffer2(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
598 xttree2_copy->Streamer(rootBuffer2);
599
600 TTree *xttree3 = (TTree*)f-> Get("QElecBarParWest");
601 TTree *xttree3_copy = xttree3->CloneTree();
602 TBufferFile rootBuffer3(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
603 xttree3_copy->Streamer(rootBuffer3);
604
605 TTree *xttree4 = (TTree*)f-> Get("QElecEndPar");
606 TTree *xttree4_copy = xttree4->CloneTree();
607 TBufferFile rootBuffer4(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
608 xttree4_copy->Streamer(rootBuffer4);
609
610 TTree *xttree5 = (TTree*)f-> Get("SimQElecBarParEast");
611 TTree *xttree5_copy = xttree5->CloneTree();
612 TBufferFile rootBuffer5(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
613 xttree5_copy->Streamer(rootBuffer5);
614
615 TTree *xttree6 = (TTree*)f-> Get("SimQElecBarParWest");
616 TTree *xttree6_copy = xttree6->CloneTree();
617 TBufferFile rootBuffer6(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
618 xttree6_copy->Streamer(rootBuffer6);
619
620 TTree *xttree7 = (TTree*)f-> Get("SimQElecEndPar");
621 TTree *xttree7_copy = xttree7->CloneTree();
622 TBufferFile rootBuffer7(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
623 xttree7_copy->Streamer(rootBuffer7);
624
625 sprintf(query,"UPDATE %s SET BarBoardNum='",opt_table_name);
626 p= query + strlen(query);
627 p += mysql_escape_string(p,rootBuffer.Buffer(),rootBuffer.BufferSize());
628 strcat(p,"',EndBoardNum='");
629 p= query + strlen(query);
630 p +=mysql_escape_string(p,rootBuffer1.Buffer(),rootBuffer1.BufferSize());
631 strcat(p,"',QElecBarParEast='");
632 p= query + strlen(query);
633 p +=mysql_escape_string(p,rootBuffer2.Buffer(),rootBuffer2.BufferSize());
634 strcat(p,"',QElecBarParWest='");
635 p= query + strlen(query);
636 p +=mysql_escape_string(p,rootBuffer3.Buffer(),rootBuffer3.BufferSize());
637 strcat(p,"',QElecEndPar='");
638 p= query + strlen(query);
639 p +=mysql_escape_string(p,rootBuffer4.Buffer(),rootBuffer4.BufferSize());
640 strcat(p,"',SimQElecBarParEast='");
641 p= query + strlen(query);
642 p +=mysql_escape_string(p,rootBuffer5.Buffer(),rootBuffer5.BufferSize());
643 strcat(p,"',SimQElecBarParWest='");
644 p= query + strlen(query);
645 p +=mysql_escape_string(p,rootBuffer6.Buffer(),rootBuffer6.BufferSize());
646 strcat(p,"',SimQElecEndPar='");
647 p= query + strlen(query);
648 p +=mysql_escape_string(p,rootBuffer7.Buffer(),rootBuffer7.BufferSize());
649
650 strcat(p,"' WHERE TofQELecSerNo = ");
651 strcat(p,opt_id);
652 } else if(strcmp(opt_type,"DEDXCURVE")==0){
653 sprintf(query_check,"select RunFrom,RunTo,DedxCurveParVer,SftVer from %s where DedxCurveParSerNo=%s",opt_table_name,opt_id);
654
655 TTree *xttree = (TTree*)f-> Get("curve");
656 TTree *xttree_copy = xttree->CloneTree();
657 TBufferFile rootBuffer(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
658 xttree_copy->Streamer(rootBuffer);
659
660 TTree *xttree1 = (TTree*)f-> Get("sigma");
661 TTree *xttree1_copy = xttree1->CloneTree();
662 TBufferFile rootBuffer1(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
663 xttree1_copy->Streamer(rootBuffer1);
664
665 sprintf(query,"UPDATE %s SET DedxCurvePar='",opt_table_name);
666 p= query + strlen(query);
667 p += mysql_escape_string(p,rootBuffer.Buffer(),rootBuffer.BufferSize());
668 strcat(p,"',DedxSigmaPar='");
669 p= query + strlen(query);
670 p +=mysql_escape_string(p,rootBuffer1.Buffer(),rootBuffer1.BufferSize());
671 strcat(p,"' WHERE DedxCurveParSerNo = ");
672 strcat(p,opt_id);
673
674 } else if(strcmp(opt_type,"TOFSIM")==0){
675 sprintf(query_check,"select RunFrom,RunTo,TofSimParVer,SftVer from %s where TofSimSvcSerNo=%s",opt_table_name,opt_id);
676
677 TTree *xttree = (TTree*)f-> Get("BTofSim");
678 TTree *xttree_copy = xttree->CloneTree();
679 TBufferFile rootBuffer(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
680 xttree_copy->Streamer(rootBuffer);
681
682 TTree *xttree1 = (TTree*)f-> Get("ETofSim");
683 TTree *xttree1_copy = xttree1->CloneTree();
684 TBufferFile rootBuffer1(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
685 xttree1_copy->Streamer(rootBuffer1);
686
687 TTree *xttree2 = (TTree*)f-> Get("SimConstants");
688 TTree *xttree2_copy = xttree2->CloneTree();
689 TBufferFile rootBuffer2(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
690 xttree2_copy->Streamer(rootBuffer2);
691
692 sprintf(query,"UPDATE %s SET BTofSim='",opt_table_name);
693 p= query + strlen(query);
694 p += mysql_escape_string(p,rootBuffer.Buffer(),rootBuffer.BufferSize());
695
696 strcat(p,"',ETofSim='");
697 p= query + strlen(query);
698 p +=mysql_escape_string(p,rootBuffer1.Buffer(),rootBuffer1.BufferSize());
699
700 strcat(p,"',SimConstants='");
701 p= query + strlen(query);
702 p +=mysql_escape_string(p,rootBuffer2.Buffer(),rootBuffer2.BufferSize());
703
704 strcat(p,"' WHERE TofSimSvcSerNo = ");
705 strcat(p,opt_id);
706
707 } else if(strcmp(opt_type,"DEDXSIM")==0){
708 sprintf(query_check,"select RunFrom,RunTo,CalParVer,SftVer from %s where SerNo=%s",opt_table_name,opt_id);
709
710 TTree *xttree = (TTree*)f-> Get("TH1F_Col");
711 gROOT->cd();
712 TTree *xttree_copy = xttree->CloneTree();
713 TBufferFile rootBuffer(TBufferFile::kWrite);//, 46216, buffer, kTRUE);
714 //rootBuffer.WriteObject(xttree);
715 xttree_copy->Streamer(rootBuffer);
716 cout<<"rootBuffer.BufferSize()"<<rootBuffer.BufferSize()<<endl;
717
718 TTree *xttree1 = (TTree*)f-> Get("bin");
719 TTree *xttree1_copy = xttree1->CloneTree();
720 TBufferFile rootBuffer1(TBufferFile::kWrite);
721 xttree1_copy->Streamer(rootBuffer1);
722
723 sprintf(query,"UPDATE %s SET TH1F_Col='",opt_table_name);
724 p= query + strlen(query);
725 p += mysql_escape_string(p,rootBuffer.Buffer(),rootBuffer.BufferSize());
726 strcat(p,"',bin='");
727 p= query + strlen(query);
728 p +=mysql_escape_string(p,rootBuffer1.Buffer(),rootBuffer1.BufferSize());
729 strcat(p,"' WHERE SerNo = ");
730 strcat(p,opt_id);
731 }
732 else if(strcmp(opt_type,"INJSIGINTERVAL")==0){
733 printf(query_check,"select RunFrom,RunTo,CalParVer,SftVer from %s where SerNo=%s",opt_table_name,opt_id);
734
735 TTree *Interval = (TTree*)f-> Get("interval");
736 TTree *Interval_copy = Interval->CloneTree();
737 TBufferFile Interval_buf(TBufferFile::kWrite);
738 Interval_copy->Streamer(Interval_buf);
739
740 sprintf(query,"UPDATE %s SET interval='",opt_table_name);
741 p= query + strlen(query);
742 p += mysql_escape_string(p,Interval_buf.Buffer(),Interval_buf.BufferSize());
743 strcat(p,"' WHERE SerNo = ");
744 strcat(p,opt_id);
745 }
746 else if(strcmp(opt_type,"INJSIGTIME")==0){
747 printf(query_check,"select Runfrom,RunTo,CalParVer,SftVer from %s where SerNo=%s",opt_table_name,opt_id);
748
749 TTree *Ist = (TTree*)f-> Get("ist");
750 TTree *Ist_copy = Ist->CloneTree();
751 TBufferFile Ist_buf(TBufferFile::kWrite);
752 Ist_copy->Streamer(Ist_buf);
753
754 sprintf(query,"UPDATE %s SET ist='",opt_table_name);
755 p= query + strlen(query);
756 p += mysql_escape_string(p,Ist_buf.Buffer(),Ist_buf.BufferSize());
757 strcat(p,"' WHERE SerNo = ");
758 strcat(p,opt_id);
759 }
760 else if(strcmp(opt_type,"OFFEVTFILTER")==0){
761 printf(query_check,"select RunFrom,RunTo,CalParVer,SftVer from %s where SerNo=%s",opt_table_name,opt_id);
762
763 TTree *Data = (TTree*)f-> Get("data");
764 TTree *Data_copy = Data->CloneTree();
765 TBufferFile Data_buf(TBufferFile::kWrite);
766 Data_copy->Streamer(Data_buf);
767
768 TTree *Oef = (TTree*)f-> Get("oef");
769 TTree *Oef_copy = Oef->CloneTree();
770 TBufferFile Oef_buf(TBufferFile::kWrite);
771 Oef_copy->Streamer(Oef_buf);
772
773 sprintf(query,"UPDATE %s SET data='",opt_table_name);
774 p= query + strlen(query);
775 p += mysql_escape_string(p,Data_buf.Buffer(),Data_buf.BufferSize());
776 strcat(p,"',oef='");
777 p= query + strlen(query);
778 p +=mysql_escape_string(p,Oef_buf.Buffer(),Oef_buf.BufferSize());
779 strcat(p,"' WHERE SerNo = ");
780 strcat(p,opt_id);
781 }
782
783 else {
784 printf("error, wrong type");
785 return 0;
786 }
787
788
789 MYSQL *conn;
790 conn = mysql_init(NULL);
791 mysql_real_connect(conn, opt_host_name, opt_user_name, opt_password,
792 opt_db_name, opt_port_num, opt_socket_name, opt_flags);
793
794 //std::cout<< "query_check " << query_check<< " "<<std::endl;
795 status = mysql_query(conn,query_check);
796 MYSQL_RES* result = mysql_store_result(conn);
797
798 /* MYSQL_ROW row = mysql_fetch_row(result);
799 char query_jc[400];
800 char query_jc1[400];
801
802 if(strcmp(opt_type,"DEDXCURVE")==0){
803 sprintf(query_jc,"select * from %s where (RunFrom between %s and %s or RunTo between %s and %s) and DedxCurveParVer='%s' and SftVer='%s'",opt_table_name,row[0],row[1],row[0],row[1],row[2],row[3]);
804 sprintf(query_jc1,"select * from %s where RunFrom<=%s and RunTo>=%s and DedxCurveParVer='%s' and SftVer='%s'",opt_table_name,row[0],row[1],row[2],row[3]);
805 }
806 else if (strcmp(opt_type,"TOFSIM")==0){
807 sprintf(query_jc,"select * from %s where (RunFrom between %s and %s or RunTo between %s and %s) and TofSimParVer='%s' and SftVer='%s'",opt_table_name,row[0],row[1],row[0],row[1],row[2],row[3]);
808 sprintf(query_jc1,"select * from %s where RunFrom<=%s and RunTo>=%s and TofSimParVer='%s' and SftVer='%s'",opt_table_name,row[0],row[1],row[2],row[3]);
809 }
810 else{
811 sprintf(query_jc,"select * from %s where (RunFrom between %s and %s or RunTo between %s and %s) and CalParVer='%s' and SftVer='%s'",opt_table_name,row[0],row[1],row[0],row[1],row[2],row[3]);
812 sprintf(query_jc1,"select * from %s where RunFrom<=%s and RunTo>=%s and CalParVer='%s' and SftVer='%s'",opt_table_name,row[0],row[1],row[2],row[3]);
813 }
814 mysql_free_result(result);
815 status = mysql_query(conn,query_jc);
816 result = mysql_store_result(conn);
817 int num_fields = mysql_num_rows(result);
818 if(num_fields>1) return -1;
819 mysql_free_result(result);
820 status = mysql_query(conn,query_jc1);
821 result = mysql_store_result(conn);
822 num_fields = mysql_num_rows(result);
823 if(num_fields>1) return -1;
824 mysql_free_result(result);*/
825 status = mysql_query(conn,query);
826 printf("status=%d\n",status);
827 int kkkk=mysql_errno(conn);
828 printf("err=%d\n",kkkk);
829
830 f->Close();
831 return 0;
832}
struct st_mysql_res MYSQL_RES
struct st_mysql MYSQL
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")
int main()
Definition: test_IFile.cxx:11