BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
BeamEnergySvc Class Reference

#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 ()
void handle (const Incident &)
void getBeamEnergyInfo ()
bool isRunValid ()
double getbeamE ()

Friends

class CnvFactory< BeamEnergySvc >

Detailed Description

Definition at line 17 of file BeamEnergySvc.h.

Constructor & Destructor Documentation

◆ BeamEnergySvc()

BeamEnergySvc::BeamEnergySvc ( const std::string & name,
ISvcLocator * svcLoc )

Definition at line 23 of file BeamEnergySvc.cxx.

24 : base_class( name, svcloc ), m_run( -1 ), m_isRunValid( false ), m_beamE( 0 ) {
25 declareProperty( "Host", m_host = "bes3db2.ihep.ac.cn" );
26}

Referenced by BeamEnergySvc().

◆ ~BeamEnergySvc()

BeamEnergySvc::~BeamEnergySvc ( )
virtual

Definition at line 28 of file BeamEnergySvc.cxx.

28{}

Member Function Documentation

◆ finalize()

StatusCode BeamEnergySvc::finalize ( )
virtual

Definition at line 60 of file BeamEnergySvc.cxx.

60 {
61 MsgStream log( msgSvc(), name() );
62 log << MSG::INFO << "@initialize()" << endmsg;
63
64 StatusCode sc = Service::finalize();
65
66 return sc;
67}
IMessageSvc * msgSvc()

◆ getbeamE()

double BeamEnergySvc::getbeamE ( )

Definition at line 98 of file BeamEnergySvc.cxx.

98 {
99 if ( !isRunValid() )
100 { std::cerr << "ERROR in BeamEnergySvc: runNo is invalid!" << std::endl; }
101 return m_beamE;
102}

◆ getBeamEnergyInfo()

void BeamEnergySvc::getBeamEnergyInfo ( )

Definition at line 104 of file BeamEnergySvc.cxx.

104 {
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
125 DatabaseRecordVector res;
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}

Referenced by handle().

◆ handle()

void BeamEnergySvc::handle ( const Incident & inc)

Definition at line 81 of file BeamEnergySvc.cxx.

81 {
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}

◆ initialize()

StatusCode BeamEnergySvc::initialize ( )
virtual

Definition at line 30 of file BeamEnergySvc.cxx.

30 {
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}

◆ isRunValid()

bool BeamEnergySvc::isRunValid ( )

Definition at line 96 of file BeamEnergySvc.cxx.

96{ return m_isRunValid; }

Referenced by getbeamE().

◆ CnvFactory< BeamEnergySvc >

friend class CnvFactory< BeamEnergySvc >
friend

Definition at line 1 of file BeamEnergySvc.h.


The documentation for this class was generated from the following files: