From 569312c73b53c56d8cefe0077f21a4e0201ea8a9 Mon Sep 17 00:00:00 2001 From: Ete Remi <remi.ete@gmail.com> Date: Tue, 27 Feb 2018 15:37:24 +0100 Subject: [PATCH] Geant4InputAction and Geant4EventReader: register input action into event reader enabling the event reader to access the Geant4 context --- DDG4/include/DDG4/Geant4InputAction.h | 9 +++++++++ DDG4/src/Geant4InputAction.cpp | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/DDG4/include/DDG4/Geant4InputAction.h b/DDG4/include/DDG4/Geant4InputAction.h index 8cc138366..823491335 100644 --- a/DDG4/include/DDG4/Geant4InputAction.h +++ b/DDG4/include/DDG4/Geant4InputAction.h @@ -32,6 +32,8 @@ namespace dd4hep { /// Namespace for the Geant4 based simulation part of the AIDA detector description toolkit namespace sim { + + class Geant4InputAction; /// Basic geant4 event reader class. This interface/base-class must be implemented by concrete readers. /** @@ -39,6 +41,7 @@ namespace dd4hep { * * \author P.Kostka (main author) * \author M.Frank (code reshuffeling into new DDG4 scheme) + * \author R.Ete (added context from input action) * \version 1.0 * \ingroup DD4HEP_SIMULATION */ @@ -66,6 +69,8 @@ namespace dd4hep { bool m_directAccess; /// Current event number int m_currEvent; + /// The input action context + Geant4InputAction *m_inputAction; /// transform the string parameter value into the type of parameter /** @@ -89,6 +94,10 @@ namespace dd4hep { Geant4EventReader(const std::string& nam); /// Default destructor virtual ~Geant4EventReader(); + /// Get the context (from the input action) + Geant4Context* context() const; + /// Set the input action + void setInputAction(Geant4InputAction* action); /// File name const std::string& name() const { return m_name; } /// Flag if direct event access (by event sequence number) is supported (Default: false) diff --git a/DDG4/src/Geant4InputAction.cpp b/DDG4/src/Geant4InputAction.cpp index f07a39010..6dcf9044a 100644 --- a/DDG4/src/Geant4InputAction.cpp +++ b/DDG4/src/Geant4InputAction.cpp @@ -29,7 +29,7 @@ typedef Geant4InputAction::Vertices Vertices ; /// Initializing constructor Geant4EventReader::Geant4EventReader(const std::string& nam) - : m_name(nam), m_directAccess(false), m_currEvent(0) + : m_name(nam), m_directAccess(false), m_currEvent(0), m_inputAction(0) { } @@ -37,6 +37,20 @@ Geant4EventReader::Geant4EventReader(const std::string& nam) Geant4EventReader::~Geant4EventReader() { } +/// Get the context (from the input action) +Geant4Context* Geant4EventReader::context() const { + if( 0 == m_inputAction ) { + printout(FATAL,"Geant4EventReader: %s", "No input action registered!"); + throw std::runtime_error("Geant4EventReader: No input action registered!"); + } + return m_inputAction->context(); +} + +/// Set the input action +void Geant4EventReader::setInputAction(Geant4InputAction* action) { + m_inputAction = action; +} + /// Skip event. To be implemented for sequential sources Geant4EventReader::EventReaderStatus Geant4EventReader::skipEvent() { if ( hasDirectAccess() ) { @@ -148,6 +162,7 @@ int Geant4InputAction::readParticles(int evt_number, } m_reader->setParameters( m_parameters ); m_reader->checkParameters( m_parameters ); + m_reader->setInputAction( this ); } catch(const exception& e) { err = e.what(); -- GitLab