#include <BeamEnergySvc.h>
Inheritance diagram for BeamEnergySvc:
Public Member Functions | |
BeamEnergySvc (const std::string &name, ISvcLocator *svcLoc) | |
virtual | ~BeamEnergySvc () |
virtual StatusCode | initialize () |
virtual StatusCode | finalize () |
virtual StatusCode | queryInterface (const InterfaceID &riid, void **ppvIF) |
void | handle (const Incident &) |
void | getBeamEnergyInfo () |
bool | isRunValid () |
double | getbeamE () |
Static Public Member Functions | |
static const InterfaceID & | interfaceID () |
Private Attributes | |
std::string | m_host |
IDataProviderSvc * | m_eventSvc |
IDatabaseSvc * | m_dbsvc |
int | m_run |
bool | m_isRunValid |
double | m_beamE |
Friends | |
class | CnvFactory< BeamEnergySvc > |
Definition at line 17 of file BeamEnergySvc.h.
BeamEnergySvc::BeamEnergySvc | ( | const std::string & | name, | |
ISvcLocator * | svcLoc | |||
) |
Definition at line 22 of file BeamEnergySvc.cxx.
References m_host.
00022 : Service(name, svcloc), 00023 m_run(-1), 00024 m_isRunValid(false), 00025 m_beamE(0) 00026 { 00027 declareProperty("Host",m_host="bes3db2.ihep.ac.cn"); 00028 }
BeamEnergySvc::~BeamEnergySvc | ( | ) | [virtual] |
StatusCode BeamEnergySvc::finalize | ( | ) | [virtual] |
Definition at line 67 of file BeamEnergySvc.cxx.
References Bes_Common::INFO.
00068 { 00069 MsgStream log(messageService(), name()); 00070 log << MSG::INFO << "@initialize()" << endreq; 00071 00072 StatusCode sc = Service::finalize(); 00073 00074 return sc; 00075 }
double BeamEnergySvc::getbeamE | ( | ) | [virtual] |
Implements IBeamEnergySvc.
Definition at line 107 of file BeamEnergySvc.cxx.
References isRunValid(), and m_beamE.
00107 { 00108 if (!isRunValid()){ 00109 std::cerr << "ERROR in BeamEnergySvc: runNo is invalid!" << std::endl; 00110 } 00111 return m_beamE; 00112 }
void BeamEnergySvc::getBeamEnergyInfo | ( | ) | [virtual] |
Implements IBeamEnergySvc.
Definition at line 114 of file BeamEnergySvc.cxx.
References Bes_Common::FATAL, DatabaseRecord::GetDouble(), Bes_Common::INFO, m_beamE, m_dbsvc, m_eventSvc, m_isRunValid, m_run, and IDatabaseSvc::query().
Referenced by handle().
00114 { 00115 MsgStream log(messageService(), name()); 00116 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader"); 00117 int run = eventHeader->runNumber(); 00118 00119 if(run<0){ 00120 log << MSG::INFO << "This data is the MC sample with the Run Number: " << run << endreq; 00121 m_isRunValid = true; 00122 m_beamE = 1.8865; 00123 return ; 00124 //run=-run; 00125 } 00126 m_run = run; 00127 char stmt1[400]; 00128 00129 snprintf(stmt1, 1024, 00130 "select BER_PRB, BPR_PRB " 00131 "from RunParams where run_number = %d", run); 00132 00133 DatabaseRecordVector res; 00134 int row_no = m_dbsvc->query("run", stmt1, res); 00135 if(row_no==0){ 00136 log << MSG::FATAL << "can not find result for BeamEnergySvc" << endreq; 00137 exit(1); 00138 } 00139 00140 m_isRunValid = true; 00141 00142 DatabaseRecord* records = res[0]; 00143 double E_E=0, E_P=0; 00144 E_E = records->GetDouble("BER_PRB"); 00145 E_P = records->GetDouble("BPR_PRB"); 00146 m_beamE=(E_E+E_P)/2.0; 00147 00148 return; 00149 }
void BeamEnergySvc::handle | ( | const Incident & | ) |
Definition at line 89 of file BeamEnergySvc.cxx.
References Bes_Common::DEBUG, getBeamEnergyInfo(), and m_eventSvc.
00089 { 00090 MsgStream log( messageService(), name() ); 00091 log << MSG::DEBUG << "handle: " << inc.type() << endreq; 00092 00093 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader"); 00094 int run = eventHeader->runNumber(); 00095 // if( run<0 || run>11000 ) return; 00096 00097 if ( inc.type() == "NewRun" ){ 00098 log << MSG::DEBUG << "New Run:" << run << endreq; 00099 getBeamEnergyInfo(); 00100 } 00101 }
StatusCode BeamEnergySvc::initialize | ( | ) | [virtual] |
Definition at line 34 of file BeamEnergySvc.cxx.
References calibUtil::ERROR, Bes_Common::INFO, m_dbsvc, m_eventSvc, and m_run.
00035 { 00036 MsgStream log(messageService(), name()); 00037 log << MSG::INFO << "@initialize()" << endreq; 00038 00039 StatusCode sc = Service::initialize(); 00040 00041 if ( sc.isFailure() ) return sc; 00042 00043 IIncidentSvc* incsvc; 00044 sc = service("IncidentSvc", incsvc); 00045 int priority = 100; 00046 if( sc.isSuccess() ){ 00047 incsvc -> addListener(this, "NewRun", priority); 00048 } 00049 00050 00051 sc = serviceLocator()->service("DatabaseSvc",m_dbsvc,true); 00052 if (sc .isFailure() ) { 00053 log << MSG::ERROR << "Unable to find DatabaseSvc " << endreq; 00054 return sc; 00055 } 00056 00057 00058 sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true); 00059 if (sc .isFailure() ) { 00060 log << MSG::ERROR << "Unable to find EventDataSvc " << endreq; 00061 return sc; 00062 } 00063 m_run=0; 00064 return sc; 00065 }
static const InterfaceID& IBeamEnergySvc::interfaceID | ( | ) | [inline, static, inherited] |
Definition at line 16 of file IBeamEnergySvc.h.
References IID_IBeamEnergySvc().
Referenced by queryInterface().
00016 { return IID_IBeamEnergySvc; }
bool BeamEnergySvc::isRunValid | ( | ) | [virtual] |
Implements IBeamEnergySvc.
Definition at line 103 of file BeamEnergySvc.cxx.
References m_isRunValid.
Referenced by getbeamE().
00103 { 00104 return m_isRunValid; 00105 }
StatusCode BeamEnergySvc::queryInterface | ( | const InterfaceID & | riid, | |
void ** | ppvIF | |||
) | [virtual] |
Definition at line 77 of file BeamEnergySvc.cxx.
References IBeamEnergySvc::interfaceID().
00078 { 00079 if ( IBeamEnergySvc::interfaceID().versionMatch(riid) ) { 00080 *ppvIF = dynamic_cast<IBeamEnergySvc*>(this); 00081 } 00082 else { 00083 return Service::queryInterface(riid, ppvIF); 00084 } 00085 addRef(); 00086 return StatusCode::SUCCESS; 00087 }
friend class CnvFactory< BeamEnergySvc > [friend] |
Definition at line 19 of file BeamEnergySvc.h.
double BeamEnergySvc::m_beamE [private] |
IDatabaseSvc* BeamEnergySvc::m_dbsvc [private] |
IDataProviderSvc* BeamEnergySvc::m_eventSvc [private] |
Definition at line 37 of file BeamEnergySvc.h.
Referenced by getBeamEnergyInfo(), handle(), and initialize().
std::string BeamEnergySvc::m_host [private] |
bool BeamEnergySvc::m_isRunValid [private] |
int BeamEnergySvc::m_run [private] |