BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
DedxSimSvc.cxx
Go to the documentation of this file.
2#include "GaudiKernel/Kernel.h"
3#include "GaudiKernel/IInterface.h"
4#include "GaudiKernel/StatusCode.h"
5#include "GaudiKernel/SvcFactory.h"
6#include "GaudiKernel/MsgStream.h"
7#include "GaudiKernel/SmartDataPtr.h"
8#include "GaudiKernel/DataSvc.h"
9
10#include "GaudiKernel/IIncidentSvc.h"
11#include "GaudiKernel/Incident.h"
12#include "GaudiKernel/IIncidentListener.h"
13
15#include "CLHEP/Vector/ThreeVector.h"
18#include <math.h>
19#include <vector>
20#include <iostream>
21#include <fstream>
22#include <string>
24#include "TH1F.h"
27
28using namespace std;
29using CLHEP::Hep3Vector;
30
31DECLARE_COMPONENT(DedxSimSvc)
32
33DedxSimSvc::DedxSimSvc( const std::string& name, ISvcLocator* svcloc ) : base_class(name, svcloc) {
34 }
35
37}
38/*
39StatusCode DedxSimSvc::queryInterface(const InterfaceID& riid, void** ppvInterface){
40 if( IID_IDedxSimSvc.versionMatch(riid) ){
41 *ppvInterface = static_cast<IDedxSimSvc*> (this);
42 } else{
43 return Service::queryInterface(riid, ppvInterface);
44 }
45 return StatusCode::SUCCESS;
46}
47*/
48
50 MsgStream log(messageService(), name());
51 log << MSG::INFO << name() << "DedxSimSvc::initialize()" << endreq;
52
53 StatusCode sc = Service::initialize();
54 if( sc.isFailure() ) return sc;
55
56 IIncidentSvc* incsvc;
57 sc = service("IncidentSvc", incsvc);
58 int priority = 100;
59 if( sc.isSuccess() ){
60 incsvc -> addListener(this, "NewRun", priority);
61 }
62 sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
63 if (sc .isFailure() ) {
64 log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
65 return sc;
66 }
67
68 m_runfrom = -999999;
69 m_runto = -999999;
70 m_version = -1;
71 m_numDedxHists = 0;
72 m_numBg = 0;
73 m_numTheta = 0;
74 m_dedx_hists = nullptr;
75 m_bgRange = nullptr;
76 return StatusCode::SUCCESS;
77}
78
80 MsgStream log(messageService(), name());
81 log << MSG::INFO << name() << "DedxSimSvc::finalize()" << endreq;
82 return StatusCode::SUCCESS;
83}
84
85void DedxSimSvc::handle(const Incident& inc){
86 MsgStream log( messageService(), name() );
87 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
88
89 if ( inc.type() == "NewRun" ){
90 log << MSG::DEBUG << "New Run" << endreq;
91 SmartDataPtr<Event::EventHeader> evt(m_eventSvc,"/Event/EventHeader");
92 int runNo;
93 if( evt ){
94 runNo = evt -> runNumber();
95 log << MSG::DEBUG <<"The runNumber of current event is "<<runNo<<endreq;
96 }
97 else{
98 log << MSG::ERROR << "ERROR accessing Event" <<endreq;
99 }
100 if(runNo<m_runfrom || runNo>m_runto){
101 update_param_svc();
102 }
103 }
104}
105
106
107void
108DedxSimSvc::update_param_svc() {
109 MsgStream log(messageService(), name());
110 IDataProviderSvc* pCalibDataSvc;
111 StatusCode sc = service("CalibDataSvc", pCalibDataSvc, true);
112 if ( !sc.isSuccess() ) {
113 log << MSG::ERROR
114 << "Could not get IDataProviderSvc interface of CalibXmlCnvSvc"
115 << endreq;
116 return ;
117 } else {
118 log << MSG::DEBUG
119 << "Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"
120 << endreq;
121 }
122
123 std::string fullPath = "/Calib/DedxSim";
124 CalibDataSvc* m_calibDataSvc;
125 m_calibDataSvc = dynamic_cast<CalibDataSvc*>(pCalibDataSvc);
126 SmartDataPtr<CalibData::DedxSimData> pDedxSimData(m_calibDataSvc, fullPath);
127 m_runfrom = pDedxSimData->getrunfrm();
128 m_runto = pDedxSimData->getrunto();
129 m_version = pDedxSimData->getVersion();
130 m_numDedxHists = pDedxSimData->gethistNo();
131 m_numBg = pDedxSimData->getRangeNo();
132 if (m_version == 0) m_numTheta = 10;
133 else m_numTheta = pDedxSimData->getThetaNo();
134 m_dedx_hists = pDedxSimData->getHist();
135 m_bgRange = pDedxSimData->getRange();
136 log << MSG::DEBUG << "DedxSimSvc::update_param_svc() finish" << endreq;
137}
int runNo
Definition: DQA_TO_DB.cxx:12
virtual StatusCode finalize()
Definition: DedxSimSvc.cxx:79
virtual StatusCode initialize()
Definition: DedxSimSvc.cxx:49
void handle(const Incident &)
Definition: DedxSimSvc.cxx:85