DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4RunAction.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/Geant4RunAction.h>
17 
18 // Geant4 headers
19 #include <G4Threading.hh>
20 #include <G4AutoLock.hh>
21 
22 using namespace dd4hep::sim;
23 
24 namespace {
25  G4Mutex action_mutex=G4MUTEX_INITIALIZER;
26  G4Mutex sequence_mutex=G4MUTEX_INITIALIZER;
27 }
28 
30 Geant4RunAction::Geant4RunAction(Geant4Context* ctxt, const std::string& nam)
31  : Geant4Action(ctxt, nam) {
33 }
34 
38 }
39 
41 void Geant4RunAction::begin(const G4Run*) {
42 }
43 
45 void Geant4RunAction::end(const G4Run*) {
46 }
47 
50  : Geant4RunAction(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("Geant4SharedRunAction: Attempt to use invalid actor!");
75 }
76 
78 void Geant4SharedRunAction::begin(const G4Run* run) {
79  if ( m_action ) {
80  G4AutoLock protection_lock(&action_mutex); {
82  m_action->begin(run);
83  }
84  }
85 }
86 
88 void Geant4SharedRunAction::end(const G4Run* run) {
89  if ( m_action ) {
90  G4AutoLock protection_lock(&action_mutex); {
92  m_action->end(run);
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();
111 }
112 
115  m_context = ctxt;
116  m_actors.updateContext(ctxt);
117 }
118 
121  m_actors(&Geant4Action::configureFiber, thread_context);
122 }
123 
125 Geant4RunAction* Geant4RunActionSequence::get(const std::string& nam) const {
126  return m_actors.get(FindByName(TypeName::split(nam).second));
127 }
128 
131  if (action) {
132  G4AutoLock protection_lock(&action_mutex);
133  action->addRef();
134  m_actors.add(action);
135  return;
136  }
137  except("Geant4RunActionSequence: Attempt to add invalid actor!");
138 }
139 
141 void Geant4RunActionSequence::begin(const G4Run* run) {
142  G4AutoLock protection_lock(&sequence_mutex);
144  m_begin(run);
145 }
146 
148 void Geant4RunActionSequence::end(const G4Run* run) {
149  G4AutoLock protection_lock(&sequence_mutex);
150  m_end(run);
152 }
dd4hep::sim::Geant4RunActionSequence::adopt
void adopt(Geant4RunAction *action)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4RunAction.cpp:130
dd4hep::sim::Geant4RunActionSequence::updateContext
virtual void updateContext(Geant4Context *ctxt) override
Set or update client context.
Definition: Geant4RunAction.cpp:114
dd4hep::sim::Geant4Action::m_needsControl
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:123
dd4hep::sim::Geant4SharedRunAction::~Geant4SharedRunAction
virtual ~Geant4SharedRunAction()
Default destructor.
Definition: Geant4RunAction.cpp:56
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::Geant4Action::FindByName
Functor to access elements by name.
Definition: Geant4Action.h:157
dd4hep::sim::Geant4RunActionSequence::m_actors
Actors< Geant4RunAction > m_actors
The list of action objects to be called.
Definition: Geant4RunAction.h:125
dd4hep::sim::Geant4RunActionSequence::end
virtual void end(const G4Run *run)
End-of-run callback.
Definition: Geant4RunAction.cpp:148
dd4hep::sim::Geant4Action::m_context
Geant4Context * m_context
Reference to the Geant4 context.
Definition: Geant4Action.h:116
Geant4RunAction.h
dd4hep::sim::Geant4RunActionSequence::Geant4RunActionSequence
Geant4RunActionSequence(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4RunAction.cpp:98
dd4hep::sim::Geant4SharedRunAction::end
virtual void end(const G4Run *run) override
End-of-run callback.
Definition: Geant4RunAction.cpp:88
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4RunAction::begin
virtual void begin(const G4Run *run)
Begin-of-run callback.
Definition: Geant4RunAction.cpp:41
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::Geant4Action::except
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
Definition: Geant4Action.cpp:256
dd4hep::sim::Geant4RunActionSequence::~Geant4RunActionSequence
virtual ~Geant4RunActionSequence()
Default destructor.
Definition: Geant4RunAction.cpp:105
dd4hep::sim::Geant4SharedRunAction::begin
virtual void begin(const G4Run *run) override
Begin-of-run callback.
Definition: Geant4RunAction.cpp:78
dd4hep::PropertyManager::adopt
void adopt(const PropertyManager &copy)
Import properties of another instance.
Definition: ComponentProperties.cpp:97
dd4hep::sim::Geant4RunAction::end
virtual void end(const G4Run *run)
End-of-run callback.
Definition: Geant4RunAction.cpp:45
dd4hep::sim::Geant4SharedRunAction::Geant4SharedRunAction
Geant4SharedRunAction(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4RunAction.cpp:49
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
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::Geant4Action::properties
PropertyManager & properties()
Access to the properties of the object.
Definition: Geant4Action.h:292
dd4hep::sim::Geant4SharedRunAction::configureFiber
virtual void configureFiber(Geant4Context *thread_context) override
Set or update client for the use in a new thread fiber.
Definition: Geant4RunAction.cpp:62
dd4hep::sim::Geant4RunActionSequence::begin
virtual void begin(const G4Run *run)
Begin-of-run callback.
Definition: Geant4RunAction.cpp:141
dd4hep::sim::Geant4SharedRunAction::m_action
Geant4RunAction * m_action
Reference to the shared action.
Definition: Geant4RunAction.h:80
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::Geant4SharedRunAction::use
virtual void use(Geant4RunAction *action)
Underlying object to be used during the execution of this thread.
Definition: Geant4RunAction.cpp:67
dd4hep::sim::Geant4RunActionSequence::m_begin
CallbackSequence m_begin
Callback sequence for begin-run action.
Definition: Geant4RunAction.h:121
dd4hep::sim::Geant4RunActionSequence::get
Geant4RunAction * get(const std::string &name) const
Get an action by name.
Definition: Geant4RunAction.cpp:125
dd4hep::sim::Geant4RunAction
Concrete basic implementation of the Geant4 run action base class.
Definition: Geant4RunAction.h:45
dd4hep::sim::Geant4RunAction::~Geant4RunAction
virtual ~Geant4RunAction()
Default destructor.
Definition: Geant4RunAction.cpp:36
dd4hep::sim::Geant4RunActionSequence::m_end
CallbackSequence m_end
Callback sequence for end-run action.
Definition: Geant4RunAction.h:123
dd4hep::sim::Geant4RunActionSequence::configureFiber
virtual void configureFiber(Geant4Context *thread_context) override
Set or update client for the use in a new thread fiber.
Definition: Geant4RunAction.cpp:120
InstanceCount.h
dd4hep::sim::Geant4RunAction::Geant4RunAction
Geant4RunAction(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4RunAction.cpp:30
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