DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4SteppingAction.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>
17 
18 // Geant4 headers
19 #include <G4Threading.hh>
20 #include <G4AutoLock.hh>
21 
22 using namespace dd4hep::sim;
23 namespace {
24  G4Mutex action_mutex=G4MUTEX_INITIALIZER;
25 }
26 
29 : Geant4Action(ctxt, nam) {
31 }
32 
36 }
37 
39 void Geant4SteppingAction::operator()(const G4Step*, G4SteppingManager*) {
40 }
41 
44  : Geant4SteppingAction(ctxt, nam), m_action(0)
45 {
47 }
48 
51  detail::releasePtr(m_action);
53 }
54 
57  if (action) {
58  action->addRef();
59  m_properties.adopt(action->properties());
60  m_action = action;
61  return;
62  }
63  except("Attempt to use invalid actor!");
64 }
65 
68  m_action->configureFiber(thread_context);
69 }
70 
72 void Geant4SharedSteppingAction::operator()(const G4Step* s, G4SteppingManager* m) {
73  if ( m_action ) {
74  G4AutoLock protection_lock(&action_mutex); {
76  (*m_action)(s,m);
77  }
78  }
79 }
80 
83 : Geant4Action(ctxt, nam) {
84  m_needsControl = true;
86 }
87 
91  m_actors.clear();
92  m_calls.clear();
94 }
95 
98  m_actors(&Geant4Action::configureFiber, thread_context);
99 }
100 
103  m_context = ctxt;
104  m_actors.updateContext(ctxt);
105 }
106 
109  return m_actors.get(FindByName(TypeName::split(nam).second));
110 }
111 
113 void Geant4SteppingActionSequence::operator()(const G4Step* step, G4SteppingManager* mgr) {
114  m_actors(&Geant4SteppingAction::operator(), step, mgr);
115  m_calls(step, mgr);
116 }
117 
120  if (action) {
121  G4AutoLock protection_lock(&action_mutex);
122  action->addRef();
123  m_actors.add(action);
124  return;
125  }
126  except("Attempt to add invalid actor!");
127 }
dd4hep::sim::Geant4Action::m_needsControl
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:123
dd4hep::sim::Geant4SteppingAction
Concrete implementation of the Geant4 stepping action sequence.
Definition: Geant4SteppingAction.h:40
dd4hep::sim::Geant4SteppingActionSequence::~Geant4SteppingActionSequence
virtual ~Geant4SteppingActionSequence()
Default destructor.
Definition: Geant4SteppingAction.cpp:89
dd4hep::sim::Geant4SteppingActionSequence::get
Geant4SteppingAction * get(const std::string &name) const
Get an action by name.
Definition: Geant4SteppingAction.cpp:108
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::Geant4SteppingAction::Geant4SteppingAction
Geant4SteppingAction(Geant4Context *context, const std::string &name)
Standard constructor.
Definition: Geant4SteppingAction.cpp:28
dd4hep::sim::Geant4SteppingActionSequence::m_actors
Actors< Geant4SteppingAction > m_actors
The list of action objects to be called.
Definition: Geant4SteppingAction.h:109
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
dd4hep::sim::Geant4SharedSteppingAction::operator()
virtual void operator()(const G4Step *step, G4SteppingManager *mgr) override
User stepping callback.
Definition: Geant4SteppingAction.cpp:72
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4SteppingActionSequence::configureFiber
virtual void configureFiber(Geant4Context *thread_context) override
Set or update client for the use in a new thread fiber.
Definition: Geant4SteppingAction.cpp:97
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
Geant4SteppingAction.h
dd4hep::sim::Geant4SteppingAction::operator()
virtual void operator()(const G4Step *step, G4SteppingManager *mgr)
User stepping callback.
Definition: Geant4SteppingAction.cpp:39
dd4hep::sim::Geant4SteppingActionSequence::Geant4SteppingActionSequence
Geant4SteppingActionSequence(Geant4Context *context, const std::string &name)
Standard constructor.
Definition: Geant4SteppingAction.cpp:82
dd4hep::sim::Geant4SharedSteppingAction::Geant4SharedSteppingAction
Geant4SharedSteppingAction(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4SteppingAction.cpp:43
dd4hep::sim::Geant4SteppingActionSequence::m_calls
CallbackSequence m_calls
Callback sequence for user stepping action calls.
Definition: Geant4SteppingAction.h:107
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::Geant4SharedSteppingAction::configureFiber
virtual void configureFiber(Geant4Context *thread_context) override
Set or update client for the use in a new thread fiber.
Definition: Geant4SteppingAction.cpp:67
dd4hep::sim::Geant4SharedSteppingAction::~Geant4SharedSteppingAction
virtual ~Geant4SharedSteppingAction()
Default destructor.
Definition: Geant4SteppingAction.cpp:50
dd4hep::PropertyManager::adopt
void adopt(const PropertyManager &copy)
Import properties of another instance.
Definition: ComponentProperties.cpp:97
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::sim::Geant4SteppingActionSequence::updateContext
virtual void updateContext(Geant4Context *ctxt) override
Set or update client context.
Definition: Geant4SteppingAction.cpp:102
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::Geant4SteppingActionSequence::operator()
virtual void operator()(const G4Step *step, G4SteppingManager *mgr)
User stepping callback.
Definition: Geant4SteppingAction.cpp:113
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::Geant4SteppingAction::~Geant4SteppingAction
virtual ~Geant4SteppingAction()
Default destructor.
Definition: Geant4SteppingAction.cpp:34
dd4hep::sim::Geant4SharedSteppingAction::use
virtual void use(Geant4SteppingAction *action)
Underlying object to be used during the execution of this thread.
Definition: Geant4SteppingAction.cpp:56
InstanceCount.h
dd4hep::sim::Geant4SteppingActionSequence::adopt
void adopt(Geant4SteppingAction *action)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4SteppingAction.cpp:119
dd4hep::sim::Geant4SharedSteppingAction::m_action
Geant4SteppingAction * m_action
Reference to the shared action.
Definition: Geant4SteppingAction.h:71
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