BOSS 7.0.7
BESIII Offline Software System
Loading...
Searching...
No Matches
BeamEnergySvc.cxx
Go to the documentation of this file.
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"
13#include "EventModel/Event.h"
16
17#include <math.h>
18
19using namespace std;
20
21
22BeamEnergySvc::BeamEnergySvc( const std::string& name, ISvcLocator* svcloc ) : Service(name, svcloc),
23 m_run(-1),
24 m_isRunValid(false),
25 m_beamE(0)
26{
27declareProperty("Host",m_host="bes3db2.ihep.ac.cn");
28}
29
31{
32}
33
35{
36 MsgStream log(messageService(), name());
37 log << MSG::INFO << "@initialize()" << endreq;
38
39 StatusCode sc = Service::initialize();
40
41 if ( sc.isFailure() ) return sc;
42
43 IIncidentSvc* incsvc;
44 sc = service("IncidentSvc", incsvc);
45 int priority = 100;
46 if( sc.isSuccess() ){
47 incsvc -> addListener(this, "NewRun", priority);
48 }
49
50
51 sc = serviceLocator()->service("DatabaseSvc",m_dbsvc,true);
52 if (sc .isFailure() ) {
53 log << MSG::ERROR << "Unable to find DatabaseSvc " << endreq;
54 return sc;
55 }
56
57
58 sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
59 if (sc .isFailure() ) {
60 log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
61 return sc;
62 }
63 m_run=0;
64 return sc;
65}
66
68{
69 MsgStream log(messageService(), name());
70 log << MSG::INFO << "@initialize()" << endreq;
71
72 StatusCode sc = Service::finalize();
73
74 return sc;
75}
76
77StatusCode BeamEnergySvc::queryInterface(const InterfaceID& riid, void** ppvIF)
78{
79 if ( IBeamEnergySvc::interfaceID().versionMatch(riid) ) {
80 *ppvIF = dynamic_cast<IBeamEnergySvc*>(this);
81 }
82 else {
83 return Service::queryInterface(riid, ppvIF);
84 }
85 addRef();
86 return StatusCode::SUCCESS;
87}
88
89void BeamEnergySvc::handle(const Incident& inc){
90 MsgStream log( messageService(), name() );
91 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
92
93 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
94 int run = eventHeader->runNumber();
95 // if( run<0 || run>11000 ) return;
96
97 if ( inc.type() == "NewRun" ){
98 log << MSG::DEBUG << "New Run:" << run << endreq;
100 }
101}
102
104 return m_isRunValid;
105}
106
108 if (!isRunValid()){
109 std::cerr << "ERROR in BeamEnergySvc: runNo is invalid!" << std::endl;
110 }
111 return m_beamE;
112}
113
115 MsgStream log(messageService(), name());
116 SmartDataPtr<Event::EventHeader> eventHeader(m_eventSvc,"/Event/EventHeader");
117 int run = eventHeader->runNumber();
118
119 if(run<0){
120 log << MSG::INFO << "This data is the MC sample with the Run Number: " << run << endreq;
121 m_isRunValid = true;
122 m_beamE = 1.8865;
123 return ;
124 //run=-run;
125 }
126 m_run = run;
127 char stmt1[400];
128
129 snprintf(stmt1, 1024,
130 "select BER_PRB, BPR_PRB "
131 "from RunParams where run_number = %d", run);
132
134 int row_no = m_dbsvc->query("run", stmt1, res);
135 if(row_no==0){
136 log << MSG::FATAL << "can not find result for BeamEnergySvc" << endreq;
137 exit(1);
138 }
139
140 m_isRunValid = true;
141
142 DatabaseRecord* records = res[0];
143 double E_E=0, E_P=0;
144 E_E = records->GetDouble("BER_PRB");
145 E_P = records->GetDouble("BPR_PRB");
146 m_beamE=(E_E+E_P)/2.0;
147
148 return;
149}
void getBeamEnergyInfo()
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)
virtual ~BeamEnergySvc()
double GetDouble(std::string key)
static const InterfaceID & interfaceID()
virtual int query(const std::string &dbName, const std::string &sql, DatabaseRecordVector &res)=0