10#include <mysql/mysql.h>
13#include "TBufferFile.h"
17int main(
int argc,
char** argv) {
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";
24 unsigned int opt_flags = 0;
29conn = mysql_init(NULL);
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");
35unsigned long *lengths;
45 sprintf(stmt1,
"select RunGain from DedxCalConst where serno = 687");
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);
53 row = mysql_fetch_row (res_set);
54 lengths = mysql_fetch_lengths(res_set);
62 TTree* newHist=
new TTree();
63 TBufferFile rootBuffer2(TBufferFile::kRead,lengths[0], row[0], kFALSE);
64std::cout <<
"zzz: " << lengths[0] << std::endl;
68 newHist->Streamer(rootBuffer2);
70 int nentri = newHist -> GetEntries();
71 std::cout<<
"nentri is:"<<nentri<<std::endl;
75newHist->SetBranchAddress(
"runno", &runno);
76newHist->SetBranchAddress(
"rungain", &rungain);
77 for (
int i = 0; i < 10; ++i ) {
79 std::cout <<
"runno: " << runno <<
" rungain: " << rungain << std::endl;
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)