BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
test_Tof.cxx
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/rdbModel/src/test/test_build.cxx,v 1.1.1.1 2005/10/17 06:10:53 maqm Exp $
2// Test program for rdbModel primitive buiding blocks
3
4#include <iostream>
5#include <string>
6#include <cstdlib>
7#include <time.h>
8#include <stdio.h>
9#include <string.h>
10#include <mysql/mysql.h>
11#include <fstream>
12#define TEST_SQL
13
14#include "TFile.h"
15#include "TTree.h"
16#include "TBufferFile.h"
17#include <fstream>
18
19int main(int argc, char** argv) {
20 char *opt_host_name = "bes3db1.ihep.ac.cn";
21 char *opt_user_name = "maqm";
22 unsigned int opt_port_num = 3306;
23 char *opt_socket_name = NULL;
24 char *opt_db_name = "offlinedb";
25 unsigned int opt_flags = 0;
26 MYSQL *conn;
27
28
29
30 conn = mysql_init(NULL);
31
32 mysql_real_connect(conn, opt_host_name, opt_user_name, opt_password,
33 opt_db_name, opt_port_num, opt_socket_name, opt_flags);
34 //printf("connect the database ok\n");
35 if(conn!=0){
36 std::cout<<"connect the database ok\n"<<std::endl;
37 }else{
38 std::cout<<"can't connect to the db:"<<std::endl;
39 return -1;
40 }
41
42unsigned long *lengths;
43
44 MYSQL_RES *res_set;
45 MYSQL_ROW row;
46
47 char stmt1[200];//="select context from mytesttable where id = %d,";
48 sprintf(stmt1,"select TofConPar from TofCalConst where serno = 2564");
49
50 printf("%s\n",stmt1);
51
52 int status = mysql_real_query(conn, stmt1, strlen(stmt1));
53 if(status)
54 {
55 std::cout << "Query is:" <<stmt1<< " failed: " << mysql_error(conn) << std::endl;
56 return -1;}
57 res_set = mysql_store_result (conn);
58 mysql_field_seek (res_set, 0);
59
60 //int lengths = 0;
61 row = mysql_fetch_row (res_set);
62 lengths = mysql_fetch_lengths(res_set);
63 std::cout<<"lengths[0]: " << lengths[0] <<std::endl;
64
65//====================================
66////read the calibdata from the buffer
67////====================================
68 TTree* newHist= new TTree();
69 TBufferFile rootBuffer2(TBufferFile::kRead,lengths[0], row[0], kFALSE);
70 newHist->Streamer(rootBuffer2);
71 newHist->Print();
72 int nentri = newHist -> GetEntries();
73 std::cout<<"nentri is:"<<nentri<<std::endl;
74int runno;
75double rungain;
76/*newHist->SetBranchAddress("runno", &runno);
77newHist->SetBranchAddress("rungain", &rungain);
78 for ( int i = 0; i < 10; ++i ) {
79 newHist->GetEntry(i);
80 std::cout << "runno: " << runno << " rungain: " << rungain << std::endl;
81}*/
82
83 mysql_free_result(res_set);
84
85 mysql_close(conn);
86
87
88
89 return 0;
90}
91
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