DD4hep  1.38.0
Detector Description Toolkit for High Energy Physics
Geant4EventAction.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 #ifndef DDG4_GEANT4EVENTACTION_H
15 #define DDG4_GEANT4EVENTACTION_H
16 
17 // Framework include files
18 #include <DDG4/Geant4Action.h>
19 
20 // Geant4 headers
21 #include <G4Types.hh>
22 #include <G4AutoLock.hh>
23 
24 // Forward declarations
25 class G4Event;
26 
28 namespace dd4hep {
29 
31  namespace sim {
32 
33  // Forward declarations
34  class Geant4EventAction;
35  class Geant4SharedEventAction;
36  class Geant4EventActionSequence;
37 
39 
58  public:
60 
61  protected:
65  mutable G4Mutex m_mutex = G4MUTEX_INITIALIZER;
66 
67  public:
69  Geant4EventAction(Geant4Context* context, const std::string& nam);
71  virtual ~Geant4EventAction();
73  virtual void begin(const G4Event* event);
75  virtual void end(const G4Event* event);
77  G4Mutex& mutex() const {
78  return m_mutex;
79  }
80  };
81 
83 
96  protected:
99 
100  protected:
103 
104  public:
106  Geant4SharedEventAction(Geant4Context* context, const std::string& nam);
108  virtual ~Geant4SharedEventAction();
110  virtual void configureFiber(Geant4Context* thread_context) override;
112  virtual void use(Geant4EventAction* action);
114  virtual void begin(const G4Event* event) override;
116  virtual void end(const G4Event* event) override;
117  };
118 
120 
135  protected:
145  mutable G4Mutex m_mutex = G4MUTEX_INITIALIZER;
146 
147  protected:
150 
151  public:
153  Geant4EventActionSequence(Geant4Context* context, const std::string& nam);
155  virtual ~Geant4EventActionSequence();
157  virtual void updateContext(Geant4Context* ctxt) override;
159  virtual void configureFiber(Geant4Context* thread_context) override;
161  Geant4EventAction* get(const std::string& name) const;
163  template <typename Q, typename T>
164  void callAtBegin(Q* p, void (T::*f)(const G4Event*)) {
165  m_begin.add(p, f);
166  }
168  template <typename Q, typename T>
169  void callAtEnd(Q* p, void (T::*f)(const G4Event*)) {
170  m_end.add(p, f);
171  }
173  template <typename Q, typename T>
174  void callAtFinal(Q* p, void (T::*f)(const G4Event*)) {
175  m_final.add(p, f);
176  }
178  void adopt(Geant4EventAction* action);
180  virtual void begin(const G4Event* event);
182  virtual void end(const G4Event* event);
184  G4Mutex& mutex() const {
185  return m_mutex;
186  }
187  };
188 
189  } // End namespace sim
190 } // End namespace dd4hep
191 #endif // DDG4_GEANT4EVENTACTION_H
dd4hep::sim::Geant4EventActionSequence::begin
virtual void begin(const G4Event *event)
Begin-of-event callback.
Definition: Geant4EventAction.cpp:142
dd4hep::sim::Geant4EventAction::DDG4_DEFINE_ACTION_CONSTRUCTORS
DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4EventAction)
Define standard assignments and constructors.
dd4hep::sim::Geant4SharedEventAction::configureFiber
virtual void configureFiber(Geant4Context *thread_context) override
Set or update client for the use in a new thread fiber.
Definition: Geant4EventAction.cpp:59
dd4hep::sim::Geant4EventActionSequence::Geant4EventActionSequence
Geant4EventActionSequence(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4EventAction.cpp:95
dd4hep::sim::Geant4EventActionSequence::mutex
G4Mutex & mutex() const
access to mutex for this action sequence
Definition: Geant4EventAction.h:184
dd4hep::sim::Geant4EventActionSequence::updateContext
virtual void updateContext(Geant4Context *ctxt) override
Set or update client context.
Definition: Geant4EventAction.cpp:112
dd4hep::sim::Geant4EventActionSequence::m_mutex
G4Mutex m_mutex
Synchronisation lock.
Definition: Geant4EventAction.h:145
dd4hep::CallbackSequence::add
void add(const Callback &cb, Location where)
Generically Add a new callback to the sequence depending on the location arguments.
Definition: Callback.h:366
dd4hep::sim::Geant4SharedEventAction::m_action
Geant4EventAction * m_action
Reference to the shared action.
Definition: Geant4EventAction.h:98
dd4hep::sim::Geant4SharedEventAction::DDG4_DEFINE_ACTION_CONSTRUCTORS
DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4SharedEventAction)
Define standard assignments and constructors.
dd4hep::sim::Geant4EventActionSequence::callAtEnd
void callAtEnd(Q *p, void(T::*f)(const G4Event *))
Register end-of-event callback.
Definition: Geant4EventAction.h:169
dd4hep::sim::Geant4EventAction::mutex
G4Mutex & mutex() const
access to mutex for this action
Definition: Geant4EventAction.h:77
dd4hep::sim::Geant4EventActionSequence::m_actors
Actors< Geant4EventAction > m_actors
The list of action objects to be called.
Definition: Geant4EventAction.h:143
dd4hep::sim::Geant4SharedEventAction
Implementation of the Geant4 shared event action.
Definition: Geant4EventAction.h:95
dd4hep::sim::Geant4EventAction
Concrete basic implementation of the Geant4 event action.
Definition: Geant4EventAction.h:57
dd4hep::CallbackSequence
Definition of an actor on sequences of callbacks.
Definition: Callback.h:338
dd4hep::sim::Geant4EventAction::Geant4EventAction
Geant4EventAction(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4EventAction.cpp:26
dd4hep::sim::Geant4EventActionSequence::callAtBegin
void callAtBegin(Q *p, void(T::*f)(const G4Event *))
Register begin-of-event callback.
Definition: Geant4EventAction.h:164
dd4hep::sim::Geant4SharedEventAction::use
virtual void use(Geant4EventAction *action)
Underlying object to be used during the execution of this thread.
Definition: Geant4EventAction.cpp:64
dd4hep::sim::Geant4EventActionSequence::m_begin
CallbackSequence m_begin
Callback sequence for event initialization action.
Definition: Geant4EventAction.h:137
dd4hep::sim::Geant4EventAction::begin
virtual void begin(const G4Event *event)
Begin-of-event callback.
Definition: Geant4EventAction.cpp:38
dd4hep::sim::Geant4EventActionSequence::callAtFinal
void callAtFinal(Q *p, void(T::*f)(const G4Event *))
Register event-cleanup callback (after end-of-event callback – unordered)
Definition: Geant4EventAction.h:174
dd4hep::sim::Geant4EventActionSequence::DDG4_DEFINE_ACTION_CONSTRUCTORS
DDG4_DEFINE_ACTION_CONSTRUCTORS(Geant4EventActionSequence)
Define standard assignments and constructors.
dd4hep::sim::Geant4EventAction::shared_type
Geant4SharedEventAction shared_type
Definition: Geant4EventAction.h:59
dd4hep::sim::Geant4EventActionSequence::m_end
CallbackSequence m_end
Callback sequence for event finalization action.
Definition: Geant4EventAction.h:139
dd4hep::sim::Geant4Action
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:113
dd4hep::sim::Geant4Action::name
const std::string & name() const
Access name of the action.
Definition: Geant4Action.h:280
dd4hep::sim::Geant4EventAction::~Geant4EventAction
virtual ~Geant4EventAction()
Default destructor.
Definition: Geant4EventAction.cpp:33
dd4hep::sim::Geant4SharedEventAction::~Geant4SharedEventAction
virtual ~Geant4SharedEventAction()
Default destructor.
Definition: Geant4EventAction.cpp:53
dd4hep::sim::Geant4EventActionSequence::end
virtual void end(const G4Event *event)
End-of-event callback.
Definition: Geant4EventAction.cpp:148
dd4hep::sim::Geant4EventAction::m_mutex
G4Mutex m_mutex
Synchronisation lock.
Definition: Geant4EventAction.h:65
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4SharedEventAction::begin
virtual void begin(const G4Event *event) override
Begin-of-event callback.
Definition: Geant4EventAction.cpp:75
dd4hep::sim::Geant4EventActionSequence::get
Geant4EventAction * get(const std::string &name) const
Get an action by name.
Definition: Geant4EventAction.cpp:123
dd4hep::sim::Geant4EventActionSequence::configureFiber
virtual void configureFiber(Geant4Context *thread_context) override
Set or update client for the use in a new thread fiber.
Definition: Geant4EventAction.cpp:118
dd4hep::sim::Geant4EventActionSequence::m_final
CallbackSequence m_final
Callback sequence for event finalization action.
Definition: Geant4EventAction.h:141
dd4hep::sim::Geant4Action::Actors
Actor class to manipulate action groups.
Definition: Geant4Action.h:168
dd4hep::sim::Geant4EventAction::end
virtual void end(const G4Event *event)
End-of-event callback.
Definition: Geant4EventAction.cpp:42
dd4hep::sim::Geant4EventActionSequence
Concrete implementation of the Geant4 event action sequence.
Definition: Geant4EventAction.h:134
dd4hep::sim::Geant4SharedEventAction::Geant4SharedEventAction
Geant4SharedEventAction(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4EventAction.cpp:46
dd4hep::sim::Geant4EventActionSequence::~Geant4EventActionSequence
virtual ~Geant4EventActionSequence()
Default destructor.
Definition: Geant4EventAction.cpp:102
dd4hep::sim::Geant4SharedEventAction::end
virtual void end(const G4Event *event) override
End-of-event callback.
Definition: Geant4EventAction.cpp:85
Geant4Action.h
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270
dd4hep::sim::Geant4EventActionSequence::adopt
void adopt(Geant4EventAction *action)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4EventAction.cpp:128