1#include "GaudiKernel/Kernel.h"
2#include "GaudiKernel/IInterface.h"
3#include "GaudiKernel/StatusCode.h"
4#include "GaudiKernel/SvcFactory.h"
5#include "GaudiKernel/MsgStream.h"
6#include "GaudiKernel/IIncidentSvc.h"
7#include "GaudiKernel/Incident.h"
8#include "GaudiKernel/IIncidentListener.h"
9#include "GaudiKernel/IDataProviderSvc.h"
10#include "GaudiKernel/Service.h"
11#include "GaudiKernel/SmartDataPtr.h"
27declareProperty(
"Host",m_host=
"bes3db2.ihep.ac.cn");
36 MsgStream log(messageService(), name());
37 log << MSG::INFO <<
"@initialize()" << endreq;
39 StatusCode sc = Service::initialize();
41 if ( sc.isFailure() )
return sc;
44 sc = service(
"IncidentSvc", incsvc);
47 incsvc -> addListener(
this,
"NewRun", priority);
51 sc = serviceLocator()->service(
"DatabaseSvc",m_dbsvc,
true);
52 if (sc .isFailure() ) {
53 log << MSG::ERROR <<
"Unable to find DatabaseSvc " << endreq;
58 sc = serviceLocator()->service(
"EventDataSvc", m_eventSvc,
true);
59 if (sc .isFailure() ) {
60 log << MSG::ERROR <<
"Unable to find EventDataSvc " << endreq;
69 MsgStream log(messageService(), name());
70 log << MSG::INFO <<
"@initialize()" << endreq;
72 StatusCode sc = Service::finalize();
83 return Service::queryInterface(riid, ppvIF);
86 return StatusCode::SUCCESS;
90 MsgStream log( messageService(), name() );
91 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
93 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,
"/Event/EventHeader");
94 int run = eventHeader->runNumber();
97 if ( inc.type() ==
"NewRun" ){
98 log << MSG::DEBUG <<
"New Run:" << run << endreq;
109 std::cerr <<
"ERROR in BeamEnergySvc: runNo is invalid!" << std::endl;
115 MsgStream log(messageService(), name());
116 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,
"/Event/EventHeader");
117 int run = eventHeader->runNumber();
120 log << MSG::INFO <<
"This data is the MC sample with the Run Number: " << run << endreq;
129 snprintf(stmt1, 1024,
130 "select BER_PRB, BPR_PRB "
131 "from RunParams where run_number = %d", run);
134 int row_no = m_dbsvc->
query(
"run", stmt1, res);
136 log << MSG::FATAL <<
"can not find result for BeamEnergySvc" << endreq;
146 m_beamE=(E_E+E_P)/2.0;
virtual StatusCode initialize()
BeamEnergySvc(const std::string &name, ISvcLocator *svcLoc)
virtual StatusCode finalize()
void handle(const Incident &)
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvIF)
double GetDouble(std::string key)
static const InterfaceID & interfaceID()
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0