BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
test_mdc_write.cxx File Reference
#include <iostream>
#include <string>
#include <cstdlib>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <mysql/mysql.h>
#include "TFile.h"
#include "TTree.h"
#include "TObjArray.h"
#include "TBufferFile.h"
#include <fstream>

Go to the source code of this file.

Macros

#define TEST_SQL
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ TEST_SQL

#define TEST_SQL

Definition at line 13 of file test_mdc_write.cxx.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 15 of file test_mdc_write.cxx.

15 {
16 if(argc<3){
17 printf("mdc.exe rootFile calConstId\n ../x86_64-slc5-gcc43-opt/mdc_write.exe /panfs/panfs.ihep.ac.cn/home/data/zhangyao/trackingStudy/calib/const2db/MdcCalibConst_newXtFun.root 414\n");
18 return -1;
19 }
20 const char *opt_host_name = "202.122.37.69";
21 //const char *opt_host_name = "202.122.35.37";
22 const char *opt_user_name = "maqm";
23 const char *opt_socket_name = NULL;
24 const char *opt_db_name = "offlinedb";
25 const char *opt_table_name = "MdcCalConst";
26 static char query[80240000];
27 unsigned int opt_port_num = 3306;
28 unsigned int opt_flags = 0;
29 char *opt_id = argv[2];
30 TFile *f= new TFile(argv[1]);
31 char *p;
32 int status=-1;
33
34 char query_check[1024];
35 sprintf(query_check,"select RunFrom,RunTo,CalParVer,SftVer from %s where SerNo=%s",opt_table_name,opt_id);
36 //new xttree---------------------------------------------------------------
37 TObjArray newxttrees_1;
38
39 TBufferFile newxttrees_buf(TBuffer::kWrite);
40
41 int nTree=0;
42 for(int t_layer=0; t_layer<43; t_layer++){
43 for(int t_bin=0; t_bin<18; t_bin++){
44 for(int t_lr=0; t_lr<2; t_lr++){
45 char newXtTreeName[20];
46 sprintf(newXtTreeName,"trNewXt%02d_%02d_%d",t_layer,t_bin,t_lr);
47 TTree *newXttree = ((TTree*)f->Get(newXtTreeName))->CloneTree();
48 newxttrees_1.Add(newXttree);
49 nTree++;
50 }
51 }
52 }
53 newxttrees_1.Streamer(newxttrees_buf);
54
55 //std::ofstream of("output.bin", std::ios::binary);
56 //of.write(newxttrees_buf.Buffer(), newxttrees_buf.BufferSize());
57 //of.close();
58 //return 0;
59
60 printf("newxttrees_1.size=%d\n",newxttrees_1.GetSize());
61 printf("nTree=%d\n entry=%d\n",nTree,newxttrees_1.GetEntries());
62 sprintf(query,"UPDATE %s SET NewXtTrees='",opt_table_name);
63 p= query + strlen(query);
64 p += mysql_escape_string(p,newxttrees_buf.Buffer(),newxttrees_buf.BufferSize());
65 strcat(p,"' WHERE SerNo = ");
66 p= query + strlen(query);
67 strcat(p,opt_id);
68
69 MYSQL *conn;
70 conn = mysql_init(NULL);
71 mysql_real_connect(conn, opt_host_name, opt_user_name, opt_password,
72 opt_db_name, opt_port_num, opt_socket_name, opt_flags);
73 status = mysql_query(conn,query_check);
74 MYSQL_RES* result = mysql_store_result(conn);
75 MYSQL_ROW row = mysql_fetch_row(result);
76
77 char query_jc[400];
78 char query_jc1[400];
79
80 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]);
81 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]);
82
83 mysql_free_result(result);
84 status = mysql_query(conn,query_jc);
85 result = mysql_store_result(conn);
86 int num_fields = mysql_num_rows(result);
87 if(num_fields>1) return -1;
88 mysql_free_result(result);
89 status = mysql_query(conn,query_jc1);
90 result = mysql_store_result(conn);
91 num_fields = mysql_num_rows(result);
92 if(num_fields>1) return -1;
93 mysql_free_result(result);
94 status = mysql_query(conn,query);
95 printf("status=%d\n",status);
96 int kkkk=mysql_errno(conn);
97 printf("err=%d\n",kkkk);
98 return 0;
99}
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")