BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
test_dedx.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 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;
25 MYSQL *conn;
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
37 MYSQL_RES *res_set;
38 MYSQL_ROW row;
39
40
41 //====================================
42 //search in the MYSQL
43 //=====================================
44 char stmt1[200];//="select context from mytesttable where id = %d,";
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/*for(int i=0;i<5;i++){
56 std::cout<<"lengths["<<i<<"]="<<lengths[i]<<std::endl;
57 }
58*/
59//====================================
60//read the calibdata from the buffer
61//====================================
62 TTree* newHist= new TTree();
63 TBufferFile rootBuffer2(TBufferFile::kRead,lengths[0], row[0], kFALSE);
64std::cout << "zzz: " << lengths[0] << std::endl;
65// ofstream ofs("out.bin", std::ios::binary);
66//ofs.write(row[0], lengths[0]);
67//return 0;
68 newHist->Streamer(rootBuffer2);
69 newHist->Print();
70 int nentri = newHist -> GetEntries();
71 std::cout<<"nentri is:"<<nentri<<std::endl;
72//*runcalib
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//print values of wiregain
83/* double gwire[6796];
84 newHist->SetBranchAddress("wireg", &gwire);
85 newHist->GetEntry(0);
86 for(int i=0;i<200;i++)
87 std::cout<<"gwire: ["<<i<<"] = "<<gwire[i]<<std::endl;
88*/
89/* double gwire[7000];
90 gwire=newHist->GetEntry(0);
91 for(int i=0;i<200;i++)
92 std::cout<<"gwire: ["<<i<<"] = "<<gwire[i]<<std::endl;*/
93 return 0;
94}
95
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