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
Geant4RunAction.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/Geant4RunAction.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 action_mutex=G4MUTEX_INITIALIZER;
29  G4Mutex sequence_mutex=G4MUTEX_INITIALIZER;
30 }
31 
33 Geant4RunAction::Geant4RunAction(Geant4Context* ctxt, const string& nam)
34  : Geant4Action(ctxt, nam) {
36 }
37 
41 }
42 
44 void Geant4RunAction::begin(const G4Run*) {
45 }
46 
48 void Geant4RunAction::end(const G4Run*) {
49 }
50 
53  : Geant4RunAction(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("Geant4SharedRunAction: Attempt to use invalid actor!");
78 }
79 
81 void Geant4SharedRunAction::begin(const G4Run* run) {
82  if ( m_action ) {
83  G4AutoLock protection_lock(&action_mutex); {
85  m_action->begin(run);
86  }
87  }
88 }
89 
91 void Geant4SharedRunAction::end(const G4Run* run) {
92  if ( m_action ) {
93  G4AutoLock protection_lock(&action_mutex); {
95  m_action->end(run);
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();
114 }
115 
118  m_context = ctxt;
119  m_actors.updateContext(ctxt);
120 }
121 
124  m_actors(&Geant4Action::configureFiber, thread_context);
125 }
126 
129  return m_actors.get(FindByName(TypeName::split(nam).second));
130 }
131 
134  if (action) {
135  G4AutoLock protection_lock(&action_mutex);
136  action->addRef();
137  m_actors.add(action);
138  return;
139  }
140  throw runtime_error("Geant4RunActionSequence: Attempt to add invalid actor!");
141 }
142 
144 void Geant4RunActionSequence::begin(const G4Run* run) {
145  G4AutoLock protection_lock(&sequence_mutex);
147  m_begin(run);
148 }
149 
151 void Geant4RunActionSequence::end(const G4Run* run) {
152  G4AutoLock protection_lock(&sequence_mutex);
153  m_end(run);
155 }
Functor to access elements by name.
Definition: Geant4Action.h:135
long release()
Decrease reference count. Implicit destruction.
virtual ~Geant4SharedRunAction()
Default destructor.
Geant4SharedRunAction()=default
Inhibit default constructor.
virtual void end(const G4Run *run)
End-of-run callback.
virtual void configureFiber(Geant4Context *thread_context)
Set or update client for the use in a new thread fiber.
static void decrement(T *)
Decrement count according to type information.
void adopt(const PropertyManager &copy)
Export properties of another instance.
Geant4RunAction * get(const std::string &name) const
Get an action by name.
Concrete basic implementation of the Geant4 run action base class.
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:261
virtual void begin(const G4Run *run)
Begin-of-run callback.
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
virtual void updateContext(Geant4Context *ctxt)
Set or update client context.
virtual void configureFiber(Geant4Context *thread_context)
Set or update client for the use in a new thread fiber.
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.
CallbackSequence m_begin
Callback sequence for begin-run action.
long addRef()
Increase reference count.
void clear()
Clear the sequence and remove all callbacks.
Definition: Callback.h:358
virtual ~Geant4RunAction()
Default destructor.
virtual void use(Geant4RunAction *action)
Underlying object to be used during the execution of this thread.
virtual ~Geant4RunActionSequence()
Default destructor.
Actors< Geant4RunAction > m_actors
The list of action objects to be called.
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:101
virtual void end(const G4Run *run)
End-of-run callback.
CallbackSequence m_end
Callback sequence for end-run action.
Geant4RunAction * m_action
Reference to the shared action.
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
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 ('/')
virtual void end(const G4Run *run)
End-of-run callback.
Generic context to extend user, run and event information.
void adopt(Geant4RunAction *action)
Add an actor responding to all callbacks. Sequence takes ownership.
PropertyManager m_properties
Property pool.
Definition: Geant4Action.h:105
static const double second
Definition: DD4hepUnits.h:112
Geant4RunActionSequence()=default
Inhibit default constructor.
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:91
virtual void begin(const G4Run *run)
Begin-of-run callback.
virtual void begin(const G4Run *run)
Begin-of-run callback.