17 {
18 char *opt_host_name = "202.122.37.69";
19 char *opt_user_name = "maqm";
20 unsigned int opt_port_num = 3306;
21 char *opt_socket_name = NULL;
22 char *opt_db_name = "offlinedb";
23
24 unsigned int opt_flags = 0;
26
27
28
29conn = mysql_init(NULL);
30
31 mysql_real_connect(conn, opt_host_name, opt_user_name, opt_password,
32 opt_db_name, opt_port_num, opt_socket_name, opt_flags);
33 printf("connect the database ok\n");
34
35unsigned long *lengths;
36
38 MYSQL_ROW row;
39
40
41
42
43
44 char stmt1[200];
45 sprintf(stmt1,
"select RunGain from DedxCalConst where serno = 687");
46
47 printf("%s\n",stmt1);
48 if(mysql_real_query(conn, stmt1, strlen(stmt1)) != 0)
49 printf("query error\n");
50 res_set = mysql_store_result (conn);
51 mysql_field_seek (res_set, 0);
52
53 row = mysql_fetch_row (res_set);
54 lengths = mysql_fetch_lengths(res_set);
55
56
57
58
59
60
61
62 TTree* newHist= new TTree();
63 TBufferFile rootBuffer2(TBufferFile::kRead,lengths[0], row[0], kFALSE);
64std::cout << "zzz: " << lengths[0] << std::endl;
65
66
67
68 newHist->Streamer(rootBuffer2);
69 newHist->Print();
70 int nentri = newHist -> GetEntries();
71 std::cout<<"nentri is:"<<nentri<<std::endl;
72
73int runno;
74double rungain;
75newHist->SetBranchAddress("runno", &runno);
76newHist->SetBranchAddress("rungain", &rungain);
77 for ( int i = 0; i < 10; ++i ) {
78 newHist->GetEntry(i);
79 std::cout << "runno: " << runno << " rungain: " << rungain << std::endl;
80}
81
82
83
84
85
86
87
88
89
90
91
92
93 return 0;
94}
struct st_mysql_res MYSQL_RES
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)