ATLAS Offline Software
Loading...
Searching...
No Matches
BaseSimulationSvc.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef ISF_BASESIMULATIONSVC_H
6#define ISF_BASESIMULATIONSVC_H 1
7
8// STL includes
9#include <string>
10
11// FrameWork includes
13#include "GaudiKernel/ServiceHandle.h"
14#include <GaudiKernel/StatusCode.h>
15#include "GaudiKernel/ToolHandle.h"
16#include "GaudiKernel/IChronoStatSvc.h"
19
21
22// ISF includes
25#include "ISF_Event/SimSvcID.h"
26
27namespace ISF {
28
29 class IParticleBroker;
30 class ITruthSvc;
31
41 class BaseSimulationSvc : public extends<AthService, ISimulationSvc> {
42 public:
43
44 //** Constructor with parameters */
45 BaseSimulationSvc( const std::string& name, ISvcLocator* pSvcLocator):
46 base_class(name,pSvcLocator) {};
47
49 virtual ~BaseSimulationSvc() {};
50
52 virtual StatusCode sysInitialize() override
53 {
54 if ( AthService::sysInitialize().isFailure() ) {
55 ATH_MSG_FATAL( m_screenOutputPrefix << " Cannot initialize AthService! Abort.");
56 return StatusCode::FAILURE;
57 }
58 if ( m_chrono.retrieve().isFailure()){
59 ATH_MSG_FATAL( m_screenOutputPrefix << " Cannot retrieve ChronoStatSvc! Abort.");
60 return StatusCode::FAILURE;
61 }
62
63 return StatusCode::SUCCESS;
64 }
65
67 const std::string& simSvcDescriptor() override { return m_simDescr.value(); }
68
70 virtual StatusCode setupEvent() override
71 { return StatusCode::SUCCESS; }
72
74 virtual StatusCode releaseEvent() override
75 { return StatusCode::SUCCESS; }
76
78 virtual StatusCode setParticleBroker( IParticleBroker *broker) override {
79 m_particleBroker = broker;
80 return StatusCode::SUCCESS;
81 }
82
84 virtual StatusCode simulateVector(const ISFParticleVector& particles, McEventCollection* mcEventCollection, McEventCollection *) override {
85 // this implementation is a wrapper in case the simulator does
86 // implement particle-vector input
87 StatusCode sc = StatusCode::SUCCESS;
88 // simulate each particle individually
89 for (ISF::ISFParticle* part : particles) {
90 ATH_MSG_VERBOSE( m_screenOutputPrefix << "Starting simulation of particle: " << part );
91 if ( this->simulate(*part, mcEventCollection).isFailure()) {
92 ATH_MSG_WARNING("Simulation of particle failed!" << endmsg <<
93 " -> simulator: " << this->simSvcDescriptor() <<
94 " -> particle : " << *part );
95 sc = StatusCode::FAILURE;
96 }
97 }
98 return sc;
99 }
100
102 virtual StatusCode simulate(ISFParticle& isp, McEventCollection* mcEventCollection) override;
103
105 const ChronoEntity* chronoStart(const IChronoSvc::ChronoTag& tag ) {
106 if (m_chrono) return m_chrono->chronoStart( tag);
107 return nullptr;
108 }
109
111 const ChronoEntity* chronoStop(const IChronoSvc::ChronoTag& tag ) {
112 if (m_chrono) return m_chrono->chronoStop( tag);
113 return nullptr;
114 }
115
121
127
129 template <class T> StatusCode retrieveTool(ToolHandle<T>& thandle){
130 if (!thandle.empty() && thandle.retrieve().isFailure()){
131 ATH_MSG_FATAL( m_screenOutputPrefix << "Cannot retrieve " << thandle << ". Abort.");
132 return StatusCode::FAILURE;
133 } else
134 ATH_MSG_DEBUG(m_screenOutputPrefix << "Successfully retrieved " << thandle);
135 return StatusCode::SUCCESS;
136 }
137
139 template <class T>
140 StatusCode retrieveTools(ToolHandleArray<T>& thandleArray){
141 if (!thandleArray.empty() && thandleArray.retrieve().isFailure()){
142 ATH_MSG_FATAL( m_screenOutputPrefix << "Cannot retrieve " << thandleArray << ". Abort.");
143 return StatusCode::FAILURE;
144 } else
145 ATH_MSG_DEBUG(m_screenOutputPrefix << "Successfully retrieved " << thandleArray);
146 return StatusCode::SUCCESS;
147 }
148
150 template<class T>
151 StatusCode recordCollection( T*& coll, const std::string& collName) const{
152 // create if necessary
153 coll = coll ? coll : new T;
154 // record
155 if (evtStore()->record( coll, collName).isFailure()){
156 ATH_MSG_FATAL( m_screenOutputPrefix << "Cannot record collection " << collName << ". Abort." );
157 return StatusCode::FAILURE;
158 } else
159 ATH_MSG_DEBUG(m_screenOutputPrefix << "Successfully recorded collection " << collName);
160 return StatusCode::SUCCESS;
161 }
162
164 template<class T>
165 StatusCode retrieveCollection(T*& coll, const std::string& collName, bool forceBreak=true) const {
166 // check for existence in the soft case
167 if (!forceBreak && !evtStore()->contains<T>(collName)) {
168 coll = 0;
169 ATH_MSG_DEBUG(m_screenOutputPrefix << "Collection does not exists (not required). Ignore.");
170 return StatusCode::SUCCESS;
171 }
172 if ( evtStore()->retrieve(coll, collName).isFailure()){
173 ATH_MSG_FATAL( m_screenOutputPrefix << "Cannot retireve collection " << collName << ". Abort." );
174 return StatusCode::FAILURE;
175 } else
176 ATH_MSG_DEBUG(m_screenOutputPrefix << "Successfully retrieved collection " << collName);
177 return StatusCode::SUCCESS;
178 }
179
180 private:
183
185 ServiceHandle<StoreGateSvc> m_evtStore{this, "EvtStore", "StoreGateSvc/StoreGateSvc",
186 "Handle to a StoreGateSvc instance: it will be used to retrieve data during the course of the job"};
187
189 ServiceHandle<StoreGateSvc> m_detStore{this, "DetStore", "StoreGateSvc/DetectorStore",
190 "Handle to a StoreGateSvc/DetectorStore instance: it will be used to retrieve data during the course of the job"};
191
192
193 protected:
195 Gaudi::Property<std::string> m_simDescr{this, "Identifier", {},
196 "A unique string to identify the simulator."};
197
199 Gaudi::Property<std::string> m_screenOutputPrefix{this, "ScreenOutputPrefix", "isf >> ",
200 "Prefix for log output"};
201
203 ServiceHandle<IChronoStatSvc> m_chrono{this, "ChronoStatService", "ChronoStatSvc"};
204
207
208 };
209
210
213 {
214 return StatusCode::SUCCESS;
215 }
216}
217
218
219#endif //> !ISF_BASESIMULATIONSVC_H
#define endmsg
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
defines and typedefs for IOVSvc
static Double_t sc
virtual StatusCode sysInitialize() override
Gaudi sysInitialize() methods.
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
IParticleBroker * m_particleBroker
The particle service used to push particles into the simulation.
virtual StatusCode setupEvent() override
Setup Event chain - in case of a begin-of event action is needed.
ServiceHandle< StoreGateSvc > m_evtStore
Handle to StoreGate (event store by default)
StatusCode retrieveCollection(T *&coll, const std::string &collName, bool forceBreak=true) const
templated retrieve collection method, boolean steers that force break
Gaudi::Property< std::string > m_screenOutputPrefix
Screen output refinement.
virtual StatusCode simulateVector(const ISFParticleVector &particles, McEventCollection *mcEventCollection, McEventCollection *) override
Simulation call for vectors of particles.
StatusCode retrieveTools(ToolHandleArray< T > &thandleArray)
templated Tool retrieval - gives unique handling & look and feel
StatusCode retrieveTool(ToolHandle< T > &thandle)
templated Tool retrieval - gives unique handling & look and feel
const ChronoEntity * chronoStop(const IChronoSvc::ChronoTag &tag)
wrapper call to stop chrono with given tag
ServiceHandle< StoreGateSvc > & evtStore()
Gaudi::Property< std::string > m_simDescr
The simulator service descriptor.
const ChronoEntity * chronoStart(const IChronoSvc::ChronoTag &tag)
wrapper call to start chrono with given tag
ServiceHandle< StoreGateSvc > m_detStore
Handle to StoreGate (detector store by default)
StatusCode recordCollection(T *&coll, const std::string &collName) const
templated record collection method, will create a new one if not existing
ServiceHandle< StoreGateSvc > & detStore()
virtual ~BaseSimulationSvc()
Destructor.
virtual StatusCode releaseEvent() override
Release Event chain - in case of an end-of event action is needed.
virtual StatusCode simulate(ISFParticle &isp, McEventCollection *mcEventCollection) override
Simulation call for individual particles.
BaseSimulationSvc()
Default constructor.
const ServiceHandle< StoreGateSvc > & evtStore() const
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
BaseSimulationSvc(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode setParticleBroker(IParticleBroker *broker) override
Inform the SimulationSvc about the ParticleBroker svc.
const std::string & simSvcDescriptor() override
Return the simulation service descriptor.
ServiceHandle< IChronoStatSvc > m_chrono
The timing service for general usage.
@ class IParticleBroker
The generic ISF particle definition,.
Definition ISFParticle.h:42
@ class ITruthSvc
Definition ITruthSvc.h:29
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
ISFParticleOrderedQueue.
std::vector< ISF::ISFParticle * > ISFParticleVector
ISFParticle vector.