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