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