1#include "GaudiKernel/MsgStream.h"
5: Service(name, svcLoc),
11 declareProperty(
"Host" , m_host = std::string(
"bes3db2.ihep.ac.cn"));
12 declareProperty(
"DbName" , m_dbName = std::string(
"run"));
13 declareProperty(
"UserName" , m_userName = std::string(
"guest"));
14 declareProperty(
"Password" , m_password = std::string(
"guestpass"));
15 declareProperty(
"PortNum" , m_port_num = 3306);
24 MsgStream log(messageService(), name());
25 log << MSG::INFO <<
"@initialize()" << endreq;
27 StatusCode sc = Service::initialize();
34 MsgStream log(messageService(), name());
35 log << MSG::INFO <<
"@initialize()" << endreq;
37 StatusCode sc = Service::finalize();
48 return Service::queryInterface(riid, ppvIF);
51 return StatusCode::SUCCESS;
54MYSQL* BeamEnergySvc::OpenDb()
const {
56 const char* host = m_host.c_str() ;
57 const char* user = m_userName.c_str() ;
58 const char* passwd = m_password.c_str() ;
59 const char* db = m_dbName.c_str() ;
60 unsigned int port_num = m_port_num;
62 MYSQL* mysql = mysql_init(NULL);
63 mysql = mysql_real_connect(mysql, host, user, passwd, db, port_num,
68 fprintf(stderr,
"can not open database: offlinedb\n");
75void BeamEnergySvc::CloseDb(
MYSQL* mysql)
const {
80void BeamEnergySvc::ReadDb(
int run ){
81 MsgStream log(messageService(), name());
84 log << MSG::INFO <<
"This data is the MC sample with the Run Number: " << run << endreq;
90 MYSQL* mysql=OpenDb();
94 "select BER_PRB, BPR_PRB "
95 "from RunParams where run_number = %d", run);
96 if (mysql_real_query(mysql, stmt, strlen(stmt))) {
97 fprintf(stderr,
"query error\n");
102 MYSQL_RES* result_set = mysql_store_result(mysql);
103 MYSQL_ROW row = mysql_fetch_row(result_set);
105 fprintf(stderr,
"cannot find data for RunNo %d\n", run);
112 sscanf(row[0],
"%lf", &E_E);
113 sscanf(row[1],
"%lf", &E_P);
115 m_beamE=(E_E+E_P)/2.0;
118 mysql_free_result(result_set);
133 std::cerr <<
"ERROR in BeamEnergySvc: runNo is invalid!" << std::endl;
struct st_mysql_res MYSQL_RES
virtual StatusCode initialize()
BeamEnergySvc(const std::string &name, ISvcLocator *svcLoc)
virtual StatusCode finalize()
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvIF)
static const InterfaceID & interfaceID()