16#include "TofEnergyCalibSvc/TofEnergyCalibSvc.h"
17#include "GaudiKernel/Kernel.h"
18#include "GaudiKernel/IInterface.h"
19#include "GaudiKernel/StatusCode.h"
20#include "GaudiKernel/SvcFactory.h"
21#include "GaudiKernel/MsgStream.h"
22#include "GaudiKernel/ISvcLocator.h"
23#include "GaudiKernel/SmartDataPtr.h"
24#include "GaudiKernel/IDataProviderSvc.h"
25#include "GaudiKernel/PropertyMgr.h"
28#include "GaudiKernel/IIncidentSvc.h"
29#include "GaudiKernel/Incident.h"
30#include "GaudiKernel/IIncidentListener.h"
32#include "GaudiKernel/ISvcLocator.h"
33#include "GaudiKernel/Bootstrap.h"
34#include "EventModel/EventModel.h"
35#include "EventModel/Event.h"
36#include "EventModel/EventHeader.h"
44 Service (name, svcloc){
46 declareProperty(
"Host" , host = std::string(
"bes3db2.ihep.ac.cn"));
47 declareProperty(
"DbName" , dbName = std::string(
"offlinedb"));
48 declareProperty(
"UserName" , userName = std::string(
"guest"));
49 declareProperty(
"Password" , password = std::string(
"guestpass"));
50 declareProperty(
"IsData" , m_IsData = std::string(
"default"));
51 declareProperty(
"BossRelease",m_bossRelease = std::string(
"default"));
59 if( IID_ITofEnergyCalibSvc.versionMatch(riid) ){
62 return Service::queryInterface(riid, ppvInterface);
64 return StatusCode::SUCCESS;
68 MsgStream log(messageService(), name());
69 log << MSG::INFO <<
"TofEnergyCalibSvc::initialize()" << endreq;
71 StatusCode sc = Service::initialize();
72 if( sc.isFailure() )
return sc;
76 sc = service(
"IncidentSvc", incsvc);
79 incsvc -> addListener(
this,
"NewRun", priority);
82 sc = serviceLocator()->service(
"DatabaseSvc",
m_dbsvc,
true);
83 if (sc .isFailure() ) {
84 log << MSG::ERROR <<
"Unable to find DatabaseSvc " << endreq;
88 sc = serviceLocator()->service(
"EventDataSvc", m_eventSvc,
true);
89 if (sc .isFailure() ) {
90 log << MSG::ERROR <<
"Unable to find EventDataSvc " << endreq;
94 return StatusCode::SUCCESS;
98 MsgStream log(messageService(), name());
99 log << MSG::INFO <<
"TofEnergyCalibSvc::finalize()" << endreq;
101 return StatusCode::SUCCESS;
105 MsgStream log( messageService(), name() );
106 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
108 if ( inc.type() ==
"NewRun" ){
109 log << MSG::DEBUG <<
"NewRun" << endreq;
111 log << MSG::ERROR <<
"can not initilize Tof energy Calib Constants" << endreq;
118 MsgStream log(messageService(), name());
119 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,
"/Event/EventHeader");
120 int run = eventHeader->runNumber();
121 cout<<
"Run in getTofEnergyCalibSvcInfo() is: "<<run<<endl;
125 cout <<
"This data is the MC sample with the Run Number: " << run << endl;
129 if(m_bossRelease==
"default") m_bossRelease = getenv(
"BES_RELEASE");
130 sprintf(stmt1,
"select CalibConst,Para1,Para2,Para3,Para4,Para5 from TofEnergyCalib where BossVer = '%s' and RunFrom <= %d and RunTo >= %d and IsData = '%s'", m_bossRelease.c_str(), run, run, m_IsData.c_str());
131 cout<<
"stmt is:"<<stmt1<<endl;
136 m_CalibConst = dbrec.
GetDouble(
"CalibConst");
142 cout<<
"m_CalibConst is:"<<m_CalibConst<<endl;
143 cout <<
"Successfully fetch TofEnergyCalibSvc information for run: "
146 }
else if( row_no<=0 ) {
147 cout <<
" TofEnergyCalibSvc:: can not found TofEnergyCalibSvc information of run:"
148 << run <<
", boss version " << m_bossRelease << endl;
double GetDouble(std::string key)
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0
virtual StatusCode initialize()
bool getTofEnergyCalibSvcInfo()
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
TofEnergyCalibSvc(const std::string &name, ISvcLocator *svcloc)
virtual StatusCode finalize()
void handle(const Incident &)