BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
test_sql.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 "TBufferFile.h"

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 14 of file test_sql.cxx.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 16 of file test_sql.cxx.

16 {
17 // char *opt_host_name = "202.122.33.53";
18 //char *opt_user_name = "maqm";
19 //unsigned int opt_port_num = 3306;
20 //char *opt_socket_name = NULL;
21 //char *opt_db_name = "offlinedb";
22 char *opt_host_name=argv[1];
23 unsigned int opt_port_num = 3306;
24 //sscanf(agv[2],"%d",opt_port_name);
25 char *opt_socket_name = NULL;
26 char *opt_db_name = argv[3];
27 char *opt_user_name = argv[4];
28 char *opt_password = argv[5];
29
30 char *opt_table_name = argv[7];
31
32 unsigned int opt_flags = 0;
33 MYSQL *conn;
34
35
36
37conn = mysql_init(NULL);
38
39 mysql_real_connect(conn, opt_host_name, opt_user_name, opt_password,
40 opt_db_name, opt_port_num, opt_socket_name, opt_flags);
41 printf("connect the database ok\n");
42
43time_t now;
44struct tm *timenow;
45timenow = localtime(&now);
46printf("Local time is %s\n",asctime(timenow));
47
48//=================================
49//read the TFile of MDC calibData
50//=================================
51
52
53 std::cout<<"host="<<argv[1]<<std::endl;
54 std::cout<<"path ="<<argv[6]<<std::endl;
55// if(argv[1]=='mdc'){
56 std::cout<<"11111111"<<std::endl;
57 TFile *f= new TFile(argv[6]);
58 TTree *qttree = (TTree*)f-> Get("QtTree");
59 TBufferFile qttree_buf(TBufferFile::kWrite);
60 qttree->Streamer(qttree_buf);
61
62 TTree *sdtree = (TTree*)f-> Get("SdTree");
63 TBufferFile sdtree_buf(TBufferFile::kWrite);
64 sdtree->Streamer(sdtree_buf);
65
66 TTree *t0tree = (TTree*)f-> Get("T0Tree");
67 TBufferFile t0tree_buf(TBufferFile::kWrite);
68 t0tree->Streamer(t0tree_buf);
69
70 TTree *xttree = (TTree*)f-> Get("XtTree");
71 TBufferFile xttree_buf(TBufferFile::kWrite);
72 xttree->Streamer(xttree_buf);
73
74
75char query[5024000],buf[1024*1000],buf1[1024*1000],*p,*p1;
76char query1[5024];
77unsigned int from_len,from_len1;
78
79int status=-1;
80int id =10;
81std::cout<<"qttreesize"<<qttree_buf.BufferSize()<<std::endl;
82std::cout<<"sdtree====="<<sdtree_buf.BufferSize()<<std::endl;
83std::cout<<"t0tree====="<<t0tree_buf.BufferSize()<<std::endl;
84std::cout<<"xttree====="<<xttree_buf.BufferSize()<<std::endl;
85
86//============================
87//insert the data the MYSQL
88//===========================
89//sprintf(query,"INSERT INTO MdcCalConst(serNo,QtTree,XtTree,T0Tree,SdTree) VALUES(%d,'",id);
90
91//sprintf(query,"UPDATE MdcCalConst SET RunFrom =100,QtTree='");
92 sprintf(query,"UPDATE %s SET QtTree='",opt_table_name);
93
94 printf("%s\n",query);
95 p= query + strlen(query);
96p += mysql_escape_string(p,qttree_buf.Buffer(),qttree_buf.BufferSize());
97
98 strcat(p,"',XtTree='");
99//cout<<"strlen(query)22222222222="<<strlen(query)<<endl;
100
101 p= query + strlen(query);
102 p +=mysql_escape_string(p,xttree_buf.Buffer(),xttree_buf.BufferSize());
103 strcat(p,"',T0Tree='");
104
105 p= query + strlen(query);
106 p +=mysql_escape_string(p,t0tree_buf.Buffer(),t0tree_buf.BufferSize());
107 strcat(p,"',SdTree='");
108
109 p= query + strlen(query);
110 p +=mysql_escape_string(p,sdtree_buf.Buffer(),sdtree_buf.BufferSize());
111 strcat(p,"' WHERE SerNo = ");
112 p= query + strlen(query);
113 sprintf(query1,"%d",id);
114 strcat(p,query1);
115// p+=id;
116//printf("%s\n",query);
117 status = mysql_query(conn,query);
118 printf("status==%d\n",status);
119// }
120
121
122
123/*
124 std::cout<<"status================"<<status<<std::endl;
125
126unsigned long *lengths;
127
128 MYSQL_RES *res_set;
129 MYSQL_ROW row;
130
131
132 //====================================
133 //search in the MYSQL
134 //=====================================
135 char stmt1[200];//="select context from mytesttable where id = %d,";
136 sprintf(stmt1,"select XtTree,QtTree,T0Tree,SdTree from MdcCalConst where ser_no = %d",id);
137
138 printf("%s\n",stmt1);
139 if(mysql_real_query(conn, stmt1, strlen(stmt1)) != 0)
140 printf("query error\n");
141 res_set = mysql_store_result (conn);
142 mysql_field_seek (res_set, 0);
143
144 row = mysql_fetch_row (res_set);
145 lengths = mysql_fetch_lengths(res_set);
146for(int i=0;i<5;i++){
147 std::cout<<"lengths["<<i<<"]="<<lengths[i]<<std::endl;
148 }
149
150//====================================
151//read the calibdata from the buffer
152//====================================
153 TTree* newHist= new TTree();
154 TBufferFile rootBuffer2(TBufferFile::kRead,lengths[0], row[0], kFALSE);
155 newHist->Streamer(rootBuffer2);
156 newHist->Print();
157 int nentri = newHist -> GetEntries();
158*/
159 return 0;
160}
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")