DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4EventAction.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 // Framework include files
16 #include "DD4hep/InstanceCount.h"
17 #include "DDG4/Geant4EventAction.h"
18 // Geant4 headers
19 #include "G4Threading.hh"
20 #include "G4AutoLock.hh"
21 // C/C++ include files
22 #include <stdexcept>
23 
24 using namespace std;
25 using namespace DD4hep::Simulation;
26 
27 namespace {
28  G4Mutex event_action_mutex=G4MUTEX_INITIALIZER;
29 }
30 
32 Geant4EventAction::Geant4EventAction(Geant4Context* ctxt, const string& nam)
33  : Geant4Action(ctxt, nam)
34 {
36 }
37 
41 }
42 
44 void Geant4EventAction::begin(const G4Event* ) {
45 }
46 
48 void Geant4EventAction::end(const G4Event* ) {
49 }
50 
53  : Geant4EventAction(ctxt, nam)
54 {
56 }
57 
62 }
63 
66  m_action->configureFiber(thread_context);
67 }
68 
71  if (action) {
72  action->addRef();
73  m_properties.adopt(action->properties());
74  m_action = action;
75  return;
76  }
77  throw runtime_error("Geant4SharedEventAction: Attempt to use invalid actor!");
78 }
79 
81 void Geant4SharedEventAction::begin(const G4Event* event) {
82  if ( m_action ) {
83  G4AutoLock protection_lock(&event_action_mutex); {
85  m_action->begin(event);
86  }
87  }
88 }
89 
91 void Geant4SharedEventAction::end(const G4Event* event) {
92  if ( m_action ) {
93  G4AutoLock protection_lock(&event_action_mutex); {
95  m_action->end(event);
96  }
97  }
98 }
99 
102  : Geant4Action(ctxt, nam) {
103  m_needsControl = true;
105 }
106 
110  m_actors.clear();
111  m_begin.clear();
112  m_end.clear();
113  m_final.clear();
115 }
116 
119  m_context = ctxt;
120  m_actors.updateContext(ctxt);
121 }
122 
125  m_actors(&Geant4Action::configureFiber, thread_context);
126 }
127 
130  return m_actors.get(FindByName(TypeName::split(nam).second));
131 }
132 
135  if (action) {
136  G4AutoLock protection_lock(&event_action_mutex);
137  action->addRef();
138  m_actors.add(action);
139  return;
140  }
141  throw runtime_error("Geant4EventActionSequence: Attempt to add invalid actor!");
142 }
143 
145 void Geant4EventActionSequence::begin(const G4Event* event) {
147  m_begin(event);
148 }
149 
151 void Geant4EventActionSequence::end(const G4Event* event) {
152  m_end(event);
154  m_final(event);
155 }
Functor to access elements by name.
Definition: Geant4Action.h:135
virtual void configureFiber(Geant4Context *thread_context)
Set or update client for the use in a new thread fiber.
long release()
Decrease reference count. Implicit destruction.
Geant4SharedEventAction()=default
Inhibit copy constructor.
virtual ~Geant4EventActionSequence()
Default destructor.
virtual void end(const G4Event *event)
End-of-event callback.
Geant4EventActionSequence()=default
Inhibit copy constructor.
static void decrement(T *)
Decrement count according to type information.
void adopt(const PropertyManager &copy)
Export properties of another instance.
virtual void end(const G4Event *event)
End-of-event callback.
virtual ~Geant4SharedEventAction()
Default destructor.
virtual void updateContext(Geant4Context *ctxt)
Set or update client context.
Concrete basic implementation of the Geant4 event action.
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:261
Geant4Context * m_context
Reference to the Geant4 context.
Definition: Geant4Action.h:94
void releasePtr(T &p)
Helper to delete objects from heap and reset the pointer. Saves many many lines of code...
Definition: Primitives.h:316
CallbackSequence m_end
Callback sequence for event finalization action.
void adopt(Geant4EventAction *action)
Add an actor responding to all callbacks. Sequence takes ownership.
PropertyManager & properties()
Access to the properties of the object.
Definition: Geant4Action.h:283
virtual void configureFiber(Geant4Context *thread_context)
Set or update client for the use in a new thread fiber.
Geant4EventAction * m_action
Reference to the shared action.
long addRef()
Increase reference count.
void clear()
Clear the sequence and remove all callbacks.
Definition: Callback.h:358
CallbackSequence m_begin
Callback sequence for event initialization action.
virtual void end(const G4Event *event)
End-of-event callback.
Geant4EventAction * get(const std::string &name) const
Get an action by name.
virtual void begin(const G4Event *event)
Begin-of-event callback.
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:101
virtual void configureFiber(Geant4Context *thread_context)
Set or update client for the use in a new thread fiber.
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
virtual ~Geant4EventAction()
Default destructor.
Functor to update the context of a Geant4Action object.
Definition: Geant4Action.h:116
static TypeName split(const std::string &type_name)
Split string pair according to default delimiter ('/')
Generic context to extend user, run and event information.
PropertyManager m_properties
Property pool.
Definition: Geant4Action.h:105
static const double second
Definition: DD4hepUnits.h:112
virtual void use(Geant4EventAction *action)
Underlying object to be used during the execution of this thread.
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:91
CallbackSequence m_final
Callback sequence for event finalization action.
virtual void begin(const G4Event *event)
Begin-of-event callback.
virtual void begin(const G4Event *event)
Begin-of-event callback.
Actors< Geant4EventAction > m_actors
The list of action objects to be called.