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
12#include "GaudiKernel/ServiceHandle.h"
13#include <GaudiKernel/StatusCode.h>
14#include "GaudiKernel/ToolHandle.h"
15#include "GaudiKernel/IChronoStatSvc.h"
18
20
21// ISF includes
24#include "ISF_Event/SimSvcID.h"
25
26namespace ISF {
27
28 class IParticleBroker;
29 class ITruthSvc;
30
40 class BaseSimulationSvc : public extends<AthService, ISimulationSvc> {
41 public:
42
43 //** Constructor with parameters */
44 BaseSimulationSvc( const std::string& name, ISvcLocator* pSvcLocator):
45 base_class(name,pSvcLocator) {};
46
48 virtual ~BaseSimulationSvc() {};
49
51 virtual StatusCode sysInitialize() override
52 {
53 if ( AthService::sysInitialize().isFailure() ) {
54 ATH_MSG_FATAL( m_screenOutputPrefix << " Cannot initialize AthService! Abort.");
55 return StatusCode::FAILURE;
56 }
57 if ( m_chrono.retrieve().isFailure()){
58 ATH_MSG_FATAL( m_screenOutputPrefix << " Cannot retrieve ChronoStatSvc! Abort.");
59 return StatusCode::FAILURE;
60 }
61
62 return StatusCode::SUCCESS;
63 }
64
66 const std::string& simSvcDescriptor() override { return m_simDescr.value(); }
67
69 virtual StatusCode setupEvent() override
70 { return StatusCode::SUCCESS; }
71
73 virtual StatusCode releaseEvent() override
74 { return StatusCode::SUCCESS; }
75
77 virtual StatusCode setParticleBroker( IParticleBroker *broker) override {
78 m_particleBroker = broker;
79 return StatusCode::SUCCESS;
80 }
81
83 virtual StatusCode simulateVector(const ISFParticleVector& particles, McEventCollection* mcEventCollection, McEventCollection *) override {
84 // this implementation is a wrapper in case the simulator does
85 // implement particle-vector input
86 StatusCode sc = StatusCode::SUCCESS;
87 // simulate each particle individually
88 for (ISF::ISFParticle* part : particles) {
89 ATH_MSG_VERBOSE( m_screenOutputPrefix << "Starting simulation of particle: " << part );
90 if ( this->simulate(*part, mcEventCollection).isFailure()) {
91 ATH_MSG_WARNING("Simulation of particle failed!" << endmsg <<
92 " -> simulator: " << this->simSvcDescriptor() <<
93 " -> particle : " << *part );
94 sc = StatusCode::FAILURE;
95 }
96 }
97 return sc;
98 }
99
101 virtual StatusCode simulate(ISFParticle& isp, McEventCollection* mcEventCollection) override;
102
104 const ChronoEntity* chronoStart(const IChronoSvc::ChronoTag& tag ) {
105 if (m_chrono) return m_chrono->chronoStart( tag);
106 return nullptr;
107 }
108
110 const ChronoEntity* chronoStop(const IChronoSvc::ChronoTag& tag ) {
111 if (m_chrono) return m_chrono->chronoStop( tag);
112 return nullptr;
113 }
114
120
126
128 template <class T> StatusCode retrieveTool(ToolHandle<T>& thandle){
129 if (!thandle.empty() && thandle.retrieve().isFailure()){
130 ATH_MSG_FATAL( m_screenOutputPrefix << "Cannot retrieve " << thandle << ". Abort.");
131 return StatusCode::FAILURE;
132 } else
133 ATH_MSG_DEBUG(m_screenOutputPrefix << "Successfully retrieved " << thandle);
134 return StatusCode::SUCCESS;
135 }
136
138 template <class T>
139 StatusCode retrieveTools(ToolHandleArray<T>& thandleArray){
140 if (!thandleArray.empty() && thandleArray.retrieve().isFailure()){
141 ATH_MSG_FATAL( m_screenOutputPrefix << "Cannot retrieve " << thandleArray << ". Abort.");
142 return StatusCode::FAILURE;
143 } else
144 ATH_MSG_DEBUG(m_screenOutputPrefix << "Successfully retrieved " << thandleArray);
145 return StatusCode::SUCCESS;
146 }
147
149 template<class T>
150 StatusCode recordCollection( T*& coll, const std::string& collName) const{
151 // create if necessary
152 coll = coll ? coll : new T;
153 // record
154 if (evtStore()->record( coll, collName).isFailure()){
155 ATH_MSG_FATAL( m_screenOutputPrefix << "Cannot record collection " << collName << ". Abort." );
156 return StatusCode::FAILURE;
157 } else
158 ATH_MSG_DEBUG(m_screenOutputPrefix << "Successfully recorded collection " << collName);
159 return StatusCode::SUCCESS;
160 }
161
163 template<class T>
164 StatusCode retrieveCollection(T*& coll, const std::string& collName, bool forceBreak=true) const {
165 // check for existence in the soft case
166 if (!forceBreak && !evtStore()->contains<T>(collName)) {
167 coll = 0;
168 ATH_MSG_DEBUG(m_screenOutputPrefix << "Collection does not exists (not required). Ignore.");
169 return StatusCode::SUCCESS;
170 }
171 if ( evtStore()->retrieve(coll, collName).isFailure()){
172 ATH_MSG_FATAL( m_screenOutputPrefix << "Cannot retireve collection " << collName << ". Abort." );
173 return StatusCode::FAILURE;
174 } else
175 ATH_MSG_DEBUG(m_screenOutputPrefix << "Successfully retrieved collection " << collName);
176 return StatusCode::SUCCESS;
177 }
178
179 private:
182
184 ServiceHandle<StoreGateSvc> m_evtStore{this, "EvtStore", "StoreGateSvc/StoreGateSvc",
185 "Handle to a StoreGateSvc instance: it will be used to retrieve data during the course of the job"};
186
188 ServiceHandle<StoreGateSvc> m_detStore{this, "DetStore", "StoreGateSvc/DetectorStore",
189 "Handle to a StoreGateSvc/DetectorStore instance: it will be used to retrieve data during the course of the job"};
190
191
192 protected:
194 Gaudi::Property<std::string> m_simDescr{this, "Identifier", {},
195 "A unique string to identify the simulator."};
196
198 Gaudi::Property<std::string> m_screenOutputPrefix{this, "ScreenOutputPrefix", "isf >> ",
199 "Prefix for log output"};
200
202 ServiceHandle<IChronoStatSvc> m_chrono{this, "ChronoStatService", "ChronoStatSvc"};
203
206
207 };
208
209
212 {
213 return StatusCode::SUCCESS;
214 }
215}
216
217
218#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)
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.