DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4EventAction.cpp
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 // Framework include files
15 #include <DD4hep/InstanceCount.h>
16 #include <DDG4/Geant4EventAction.h>
17 
18 // Geant4 headers
19 #include <G4Threading.hh>
20 #include <G4AutoLock.hh>
21 
22 using namespace dd4hep::sim;
23 
24 namespace {
25  G4Mutex event_action_mutex=G4MUTEX_INITIALIZER;
26 }
27 
30  : Geant4Action(ctxt, nam)
31 {
33 }
34 
38 }
39 
41 void Geant4EventAction::begin(const G4Event* ) {
42 }
43 
45 void Geant4EventAction::end(const G4Event* ) {
46 }
47 
50  : Geant4EventAction(ctxt, nam)
51 {
53 }
54 
57  detail::releasePtr(m_action);
59 }
60 
63  m_action->configureFiber(thread_context);
64 }
65 
68  if (action) {
69  action->addRef();
70  m_properties.adopt(action->properties());
71  m_action = action;
72  return;
73  }
74  except("Geant4SharedEventAction: Attempt to use invalid actor!");
75 }
76 
78 void Geant4SharedEventAction::begin(const G4Event* event) {
79  if ( m_action ) {
80  G4AutoLock protection_lock(&event_action_mutex); {
82  m_action->begin(event);
83  }
84  }
85 }
86 
88 void Geant4SharedEventAction::end(const G4Event* event) {
89  if ( m_action ) {
90  G4AutoLock protection_lock(&event_action_mutex); {
92  m_action->end(event);
93  }
94  }
95 }
96 
99  : Geant4Action(ctxt, nam) {
100  m_needsControl = true;
102 }
103 
107  m_actors.clear();
108  m_begin.clear();
109  m_end.clear();
110  m_final.clear();
112 }
113 
116  m_context = ctxt;
117  m_actors.updateContext(ctxt);
118 }
119 
122  m_actors(&Geant4Action::configureFiber, thread_context);
123 }
124 
126 Geant4EventAction* Geant4EventActionSequence::get(const std::string& nam) const {
127  return m_actors.get(FindByName(TypeName::split(nam).second));
128 }
129 
132  if (action) {
133  G4AutoLock protection_lock(&event_action_mutex);
134  action->addRef();
135  m_actors.add(action);
136  return;
137  }
138  except("Geant4EventActionSequence: Attempt to add invalid actor!");
139 }
140 
142 void Geant4EventActionSequence::begin(const G4Event* event) {
144  m_begin(event);
145 }
146 
148 void Geant4EventActionSequence::end(const G4Event* event) {
149  m_end(event);
151  m_final(event);
152 }
dd4hep::sim::Geant4EventActionSequence::begin
virtual void begin(const G4Event *event)
Begin-of-event callback.
Definition: Geant4EventAction.cpp:142
dd4hep::sim::Geant4Action::m_needsControl
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:123
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:62
dd4hep::sim::Geant4Action::configureFiber
virtual void configureFiber(Geant4Context *thread_context)
Set or update client for the use in a new thread fiber.
Definition: Geant4Action.cpp:140
dd4hep::sim::Geant4EventActionSequence::Geant4EventActionSequence
Geant4EventActionSequence(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4EventAction.cpp:98
dd4hep::sim::Geant4EventActionSequence::updateContext
virtual void updateContext(Geant4Context *ctxt) override
Set or update client context.
Definition: Geant4EventAction.cpp:115
dd4hep::sim::Geant4Action::FindByName
Functor to access elements by name.
Definition: Geant4Action.h:157
dd4hep::sim::Geant4Action::m_context
Geant4Context * m_context
Reference to the Geant4 context.
Definition: Geant4Action.h:116
Geant4EventAction.h
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4SharedEventAction::m_action
Geant4EventAction * m_action
Reference to the shared action.
Definition: Geant4EventAction.h:88
dd4hep::sim::Geant4Action::ContextSwap
Functor to update the context of a Geant4Action object.
Definition: Geant4Action.h:138
dd4hep::sim::Geant4Action::m_properties
PropertyManager m_properties
Property pool.
Definition: Geant4Action.h:127
dd4hep::sim::Geant4EventActionSequence::m_actors
Actors< Geant4EventAction > m_actors
The list of action objects to be called.
Definition: Geant4EventAction.h:133
dd4hep::sim::Geant4Action::except
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
Definition: Geant4Action.cpp:256
dd4hep::sim::Geant4EventAction
Concrete basic implementation of the Geant4 event action.
Definition: Geant4EventAction.h:53
dd4hep::sim::Geant4EventAction::Geant4EventAction
Geant4EventAction(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4EventAction.cpp:29
dd4hep::sim::Geant4SharedEventAction::use
virtual void use(Geant4EventAction *action)
Underlying object to be used during the execution of this thread.
Definition: Geant4EventAction.cpp:67
dd4hep::PropertyManager::adopt
void adopt(const PropertyManager &copy)
Import properties of another instance.
Definition: ComponentProperties.cpp:97
dd4hep::sim::Geant4EventActionSequence::m_begin
CallbackSequence m_begin
Callback sequence for event initialization action.
Definition: Geant4EventAction.h:127
dd4hep::sim::Geant4EventAction::begin
virtual void begin(const G4Event *event)
Begin-of-event callback.
Definition: Geant4EventAction.cpp:41
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4EventActionSequence::m_end
CallbackSequence m_end
Callback sequence for event finalization action.
Definition: Geant4EventAction.h:129
dd4hep::sim::Geant4Action
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:113
dd4hep::sim::Geant4Action::release
long release()
Decrease reference count. Implicit destruction.
Definition: Geant4Action.cpp:76
dd4hep::CallbackSequence::clear
void clear()
Clear the sequence and remove all callbacks.
Definition: Callback.h:363
dd4hep::sim::TypeName::split
static TypeName split(const std::string &type_name)
Split string pair according to default delimiter ('/')
Definition: Geant4Action.cpp:40
dd4hep::sim::Geant4EventAction::~Geant4EventAction
virtual ~Geant4EventAction()
Default destructor.
Definition: Geant4EventAction.cpp:36
dd4hep::sim::Geant4Action::properties
PropertyManager & properties()
Access to the properties of the object.
Definition: Geant4Action.h:292
dd4hep::sim::Geant4SharedEventAction::~Geant4SharedEventAction
virtual ~Geant4SharedEventAction()
Default destructor.
Definition: Geant4EventAction.cpp:56
dd4hep::sim::Geant4EventActionSequence::end
virtual void end(const G4Event *event)
End-of-event callback.
Definition: Geant4EventAction.cpp:148
dd4hep::sim::Geant4Action::addRef
long addRef()
Increase reference count.
Definition: Geant4Action.cpp:71
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4SharedEventAction::begin
virtual void begin(const G4Event *event) override
Begin-of-event callback.
Definition: Geant4EventAction.cpp:78
dd4hep::sim::Geant4EventActionSequence::get
Geant4EventAction * get(const std::string &name) const
Get an action by name.
Definition: Geant4EventAction.cpp:126
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:121
dd4hep::sim::Geant4EventActionSequence::m_final
CallbackSequence m_final
Callback sequence for event finalization action.
Definition: Geant4EventAction.h:131
dd4hep::sim::Geant4EventAction::end
virtual void end(const G4Event *event)
End-of-event callback.
Definition: Geant4EventAction.cpp:45
dd4hep::sim::Geant4SharedEventAction::Geant4SharedEventAction
Geant4SharedEventAction(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4EventAction.cpp:49
InstanceCount.h
dd4hep::sim::Geant4EventActionSequence::~Geant4EventActionSequence
virtual ~Geant4EventActionSequence()
Default destructor.
Definition: Geant4EventAction.cpp:105
dd4hep::sim::Geant4SharedEventAction::end
virtual void end(const G4Event *event) override
End-of-event callback.
Definition: Geant4EventAction.cpp:88
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:131