DD4hep  1.38.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 
27  : Geant4Action(ctxt, nam)
28 {
30 }
31 
35 }
36 
38 void Geant4EventAction::begin(const G4Event* ) {
39 }
40 
42 void Geant4EventAction::end(const G4Event* ) {
43 }
44 
47  : Geant4EventAction(ctxt, nam)
48 {
50 }
51 
54  detail::releasePtr(m_action);
56 }
57 
60  m_action->configureFiber(thread_context);
61 }
62 
65  if (action) {
66  action->addRef();
67  m_properties.adopt(action->properties());
68  m_action = action;
69  return;
70  }
71  except("Geant4SharedEventAction: Attempt to use invalid actor!");
72 }
73 
75 void Geant4SharedEventAction::begin(const G4Event* event) {
76  if ( m_action ) {
77  G4AutoLock protection_lock(m_action->mutex()); {
79  m_action->begin(event);
80  }
81  }
82 }
83 
85 void Geant4SharedEventAction::end(const G4Event* event) {
86  if ( m_action ) {
87  G4AutoLock protection_lock(m_action->mutex()); {
89  m_action->end(event);
90  }
91  }
92 }
93 
96  : Geant4Action(ctxt, nam) {
97  m_needsControl = true;
99 }
100 
104  m_actors.clear();
105  m_begin.clear();
106  m_end.clear();
107  m_final.clear();
109 }
110 
113  m_context = ctxt;
114  m_actors.updateContext(ctxt);
115 }
116 
119  m_actors(&Geant4Action::configureFiber, thread_context);
120 }
121 
123 Geant4EventAction* Geant4EventActionSequence::get(const std::string& nam) const {
124  return m_actors.get(FindByName(TypeName::split(nam).second));
125 }
126 
129  if (action) {
130  {
131  G4AutoLock actionLock(action->mutex());
132  action->addRef();
133  }
134  G4AutoLock protection_lock(mutex());
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:59
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: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::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:98
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::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::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:57
dd4hep::sim::Geant4EventAction::Geant4EventAction
Geant4EventAction(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4EventAction.cpp:26
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::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:137
dd4hep::sim::Geant4EventAction::begin
virtual void begin(const G4Event *event)
Begin-of-event callback.
Definition: Geant4EventAction.cpp:38
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:139
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:362
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:33
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:53
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: EDM4hepFileReader.cpp:46
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::Geant4EventAction::end
virtual void end(const G4Event *event)
End-of-event callback.
Definition: Geant4EventAction.cpp:42
dd4hep::sim::Geant4SharedEventAction::Geant4SharedEventAction
Geant4SharedEventAction(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4EventAction.cpp:46
InstanceCount.h
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
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