BOSS 7.0.9
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
31
32DedxSimSvc::DedxSimSvc( const string& name, ISvcLocator* svcloc) :
33 Service (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
49 MsgStream log(messageService(), name());
50 log << MSG::INFO << name() << "DedxSimSvc::initialize()" << endreq;
51
52 StatusCode sc = Service::initialize();
53 if( sc.isFailure() ) return sc;
54
55 IIncidentSvc* incsvc;
56 sc = service("IncidentSvc", incsvc);
57 int priority = 100;
58 if( sc.isSuccess() ){
59 incsvc -> addListener(this, "NewRun", priority);
60 }
61 sc = serviceLocator()->service("EventDataSvc", m_eventSvc, true);
62 if (sc .isFailure() ) {
63 log << MSG::ERROR << "Unable to find EventDataSvc " << endreq;
64 return sc;
65 }
66
67 m_runfrom = -999999;
68 m_runto = -999999;
69 m_version = -1;
70 m_numDedxHists = 0;
71 m_numBg = 0;
72 m_numTheta = 0;
73 m_dedx_hists = nullptr;
74 m_bgRange = nullptr;
75 return StatusCode::SUCCESS;
76}
77
79 MsgStream log(messageService(), name());
80 log << MSG::INFO << name() << "DedxSimSvc::finalize()" << endreq;
81 return StatusCode::SUCCESS;
82}
83
84void DedxSimSvc::handle(const Incident& inc){
85 MsgStream log( messageService(), name() );
86 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
87
88 if ( inc.type() == "NewRun" ){
89 log << MSG::DEBUG << "New Run" << endreq;
90 SmartDataPtr<Event::EventHeader> evt(m_eventSvc,"/Event/EventHeader");
91 int runNo;
92 if( evt ){
93 runNo = evt -> runNumber();
94 log << MSG::DEBUG <<"The runNumber of current event is "<<runNo<<endreq;
95 }
96 else{
97 log << MSG::ERROR << "ERROR accessing Event" <<endreq;
98 }
99 if(runNo<m_runfrom || runNo>m_runto){
100 update_param_svc();
101 }
102 }
103}
104
105
106void
107DedxSimSvc::update_param_svc() {
108 MsgStream log(messageService(), name());
109 IDataProviderSvc* pCalibDataSvc;
110 StatusCode sc = service("CalibDataSvc", pCalibDataSvc, true);
111 if ( !sc.isSuccess() ) {
112 log << MSG::ERROR
113 << "Could not get IDataProviderSvc interface of CalibXmlCnvSvc"
114 << endreq;
115 return ;
116 } else {
117 log << MSG::DEBUG
118 << "Retrieved IDataProviderSvc interface of CalibXmlCnvSvc"
119 << endreq;
120 }
121
122 std::string fullPath = "/Calib/DedxSim";
123 CalibDataSvc* m_calibDataSvc;
124 m_calibDataSvc = dynamic_cast<CalibDataSvc*>(pCalibDataSvc);
125 SmartDataPtr<CalibData::DedxSimData> pDedxSimData(m_calibDataSvc, fullPath);
126 m_runfrom = pDedxSimData->getrunfrm();
127 m_runto = pDedxSimData->getrunto();
128 m_version = pDedxSimData->getVersion();
129 m_numDedxHists = pDedxSimData->gethistNo();
130 m_numBg = pDedxSimData->getRangeNo();
131 if (m_version == 0) m_numTheta = 10;
132 else m_numTheta = pDedxSimData->getThetaNo();
133 m_dedx_hists = pDedxSimData->getHist();
134 m_bgRange = pDedxSimData->getRange();
135 log << MSG::DEBUG << "DedxSimSvc::update_param_svc() finish" << endreq;
136}
int runNo
Definition: DQA_TO_DB.cxx:12
virtual StatusCode finalize()
Definition: DedxSimSvc.cxx:78
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
Definition: DedxSimSvc.cxx:39
DedxSimSvc(const std::string &name, ISvcLocator *svcloc)
Definition: DedxSimSvc.cxx:32
virtual StatusCode initialize()
Definition: DedxSimSvc.cxx:48
void handle(const Incident &)
Definition: DedxSimSvc.cxx:84