BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
test_emc.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 "TFile.h"
12#include "TTree.h"
13#include "TBufferFile.h"
14#include <fstream>
15#define TEST_SQL
16
17int main(int argc, char** argv) {
18 char *opt_host_name = "202.122.37.69";
19 char *opt_user_name = "maqm";
20 char *opt_password = "";
21 unsigned int opt_port_num = 3306;
22 char *opt_socket_name = NULL;
23 char *opt_db_name = "offlinedb";
24 /*char *opt_host_name=argv[1];
25 unsigned int opt_port_num = 3306;
26 //sscanf(agv[2],"%d",opt_port_name);
27 char *opt_socket_name = NULL;
28 char *opt_db_name = argv[3];
29 char *opt_user_name = argv[4];
30 char *opt_password = argv[5];
31
32 char *opt_table_name = argv[7];
33 */
34 unsigned int opt_flags = 0;
35 MYSQL *conn;
36
37
38
39 conn = mysql_init(NULL);
40
41 mysql_real_connect(conn, opt_host_name, opt_user_name, opt_password,
42 opt_db_name, opt_port_num, opt_socket_name, opt_flags);
43 //printf("connect the database ok\n");
44 if(conn!=0){
45 std::cout<<"connect the database ok\n"<<std::endl;
46 }else{
47 std::cout<<"can't connect to the db:"<<std::endl;
48 return -1;
49 }
50
51unsigned long *lengths;
52
53 MYSQL_RES *res_set;
54 MYSQL_ROW row;
55
56 char stmt1[200];//="select context from mytesttable where id = %d,";
57 sprintf(stmt1,"select DigiCalibConst from EmcCalConst where serno = 456");
58
59 printf("%s\n",stmt1);
60 if(mysql_real_query(conn, stmt1, strlen(stmt1)) != 0)
61 printf("query error\n");
62 res_set = mysql_store_result (conn);
63 mysql_field_seek (res_set, 0);
64
65 row = mysql_fetch_row (res_set);
66 lengths = mysql_fetch_lengths(res_set);
67/*for(int i=0;i<5;i++){
68 std::cout<<"lengths["<<i<<"]="<<lengths[i]<<std::endl;
69 }
70*/
71//====================================
72//read the calibdata from the buffer
73//====================================
74 TTree* newHist= new TTree();
75 TBufferFile rootBuffer2(TBufferFile::kRead,lengths[0], row[0], kFALSE);
76std::cout << "zzz: " << lengths[0] << std::endl;
77// ofstream ofs("out.bin", std::ios::binary);
78//ofs.write(row[0], lengths[0]);
79//return 0;
80 newHist->Streamer(rootBuffer2);
81 newHist->Print();
82 int nentri = newHist -> GetEntries();
83 std::cout<<"nentri is:"<<nentri<<std::endl;
84double rungain[7000];
85newHist->SetBranchAddress("DigiCalibConst", rungain);
86 for ( int i = 0; i < 6240; ++i ) {
87 newHist->GetEntry(i);
88 std::cout << " rungain: " << rungain[i] << std::endl;
89}
90
91 return 0;
92}
93
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