BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
test_mdc_read.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 "TROOT.h"
9#include "TFile.h"
10#include "TTree.h"
11#include "TObjArray.h"
12#include "TBufferFile.h"
13#include <fstream>
14#define TEST_SQL
15
16int main(int argc, char** argv) {
17 const char *opt_host_name = "202.122.37.69";
18 //const char *opt_host_name = "202.122.35.37";
19 const char *opt_user_name = "maqm";
20 const char *opt_socket_name = NULL;
21 const char *opt_db_name = "offlinedb";
22 const char *opt_table_name = "MdcCalConst";
23 static char query[80240000];
24 unsigned int opt_port_num = 3306;
25 unsigned int opt_flags = 0;
26 char *p;
27 int status=-1;
28
29
30 MYSQL *conn;
31 conn = mysql_init(NULL);
32
33 mysql_real_connect(conn, opt_host_name, opt_user_name, opt_password,
34 opt_db_name, opt_port_num, opt_socket_name, opt_flags);
35 //printf("connect the database ok\n");
36 if(conn!=0){
37 std::cout<<"connect the database ok\n"<<std::endl;
38 }else{
39 std::cout<<"can't connect to the db:"<<std::endl;
40 return -1;
41 }
42
43 unsigned long *lengths;
44
45 MYSQL_RES *res_set;
46 MYSQL_ROW row;
47
48 char stmt1[200];
49 sprintf(stmt1,"select NewXtTrees from MdcCalConst where serno = 414");
50
51 printf("%s\n",stmt1);
52 if(mysql_real_query(conn, stmt1, strlen(stmt1)) != 0)
53 printf("query error\n");
54 res_set = mysql_store_result (conn);
55 mysql_field_seek (res_set, 0);
56
57 row = mysql_fetch_row (res_set);
58 lengths = mysql_fetch_lengths(res_set);
59 //====================================
60 //read the calibdata from the buffer
61 //====================================
62 //TBufferFile rootBuffer2(TBufferFile::kRead,lengths[0], row[0], kFALSE);
63 TBufferFile rootBuffer2(TBufferFile::kRead,lengths[0], row[0], kFALSE);
64 gROOT->cd();
65 std::cout << "buffer length=" << lengths[0] << std::endl;
66
67 TObjArray array;
68 array.Streamer(rootBuffer2);
69 std::cout<< __FILE__ << " " << __LINE__ << " array size "<<array.GetSize()
70 <<" entry="<<array.GetEntries()<<std::endl;
71
72 //array.Print();
73
74 //std::cout<< __FILE__ << " " << __LINE__ << " name "<<array.At(0)<<std::endl;
75 int iTree = 0;
76 for(int t_layer=0; t_layer<43; t_layer++){
77 for(int t_entr=0; t_entr<18; t_entr++){
78 for(int t_lr=0; t_lr<2; t_lr++){
79 std::cout<<"trNewXt"<<t_layer<<"_"<<t_entr<<"_"<<t_lr<<" "<<iTree<<" name "<<((TTree*)array.At(iTree))->GetName()<<std::endl;
80 iTree++;
81 std::cout << ((TTree*)array.At(iTree))->GetName() << std::endl;
82 }
83 }
84 }
85
86 //TTree* t = (TTree*) (array.At(0));
87 //std::cout<< __FILE__ << " " << __LINE__ << " "<<t<<std::endl;
88 //std::cout << ((TTree*)array.At(0))->GetEntries() << std::endl;
89 //((TTree*)array.At(0))->Draw();
90 //t->Print();
91 //t->GetEntries();
92 //int nEntry = array->GetSize();
93 //std::cout<< __FILE__ << " " << __LINE__ << " "<<std::endl;
94 //TIter next(array);
95 //std::cout<< __FILE__ << " " << __LINE__ << " "<<std::endl;
96 //TTree* myTree;
97 //std::cout<< __FILE__ << " " << __LINE__ << " "<<std::endl;
98 //while( myTree=(TTree*)next()) {
99 //std::cout<< __FILE__ << " " << __LINE__ << " "<<std::endl;
100 // myTree->Print();
101 //}
102 //std::cout<<"array size ="<<nEntry<<std::endl;
103 //std::cout << ((TTree*)array->At(0))->GetName() << std::endl;
104 //for (int i=0;i<nEntry;i++){
105 // std::cout << array.At(i)->GetName() << std::endl;
106 //}
107
108 return 0;
109}
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)
int main()
Definition: test_IFile.cxx:11