DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4StackingAction.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 
40 Geant4StackingAction::classifyNewTrack(G4StackManager* /* manager */, const G4Track* /* track */) {
41  return TrackClassification();
42 }
43 
46  : Geant4StackingAction(ctxt, nam), m_action(0)
47 {
49 }
50 
53  detail::releasePtr(m_action);
55 }
56 
59  m_action->configureFiber(thread_context);
60 }
61 
64  if (action) {
65  action->addRef();
66  m_properties.adopt(action->properties());
67  m_action = action;
68  return;
69  }
70  except("Attempt to use invalid actor!");
71 }
72 
74 void Geant4SharedStackingAction::newStage(G4StackManager* stackManager) {
75  if ( m_action ) {
76  G4AutoLock protection_lock(&action_mutex); {
78  m_action->newStage(stackManager);
79  }
80  }
81 }
82 
84 void Geant4SharedStackingAction::prepare(G4StackManager* stackManager) {
85  if ( m_action ) {
86  G4AutoLock protection_lock(&action_mutex); {
88  m_action->prepare(stackManager);
89  }
90  }
91 }
92 
95 Geant4SharedStackingAction::classifyNewTrack(G4StackManager* stackManager,
96  const G4Track* track) {
97  if ( m_action ) {
98  G4AutoLock protection_lock(&action_mutex); {
100  return m_action->classifyNewTrack(stackManager, track);
101  }
102  }
103  return {};
104 }
105 
108  : Geant4Action(ctxt, nam) {
109  m_needsControl = true;
111 }
112 
116  m_actors.clear();
117  m_newStage.clear();
118  m_prepare.clear();
120 }
121 
124  if (action) {
125  action->addRef();
126  m_actors.add(action);
127  return;
128  }
129  except("Attempt to add invalid actor!");
130 }
131 
134  m_context = ctxt;
135  m_actors.updateContext(ctxt);
136 }
137 
140  m_actors(&Geant4Action::configureFiber, thread_context);
141 }
142 
145  return m_actors.get(FindByName(TypeName::split(nam).second));
146 }
147 
149 void Geant4StackingActionSequence::newStage(G4StackManager* stackManager) {
151  m_newStage(stackManager);
152 }
153 
155 void Geant4StackingActionSequence::prepare(G4StackManager* stackManager) {
156  m_actors(&Geant4StackingAction::prepare, stackManager);
157  m_prepare(stackManager);
158 }
159 
163  const G4Track* track) {
164  for( auto a : m_actors ) {
165  auto ret = a->classifyNewTrack(stackManager, track);
166  if ( ret.type != NoTrackClassification ) {
167  return ret;
168  }
169  }
170  return {};
171 }
dd4hep::sim::Geant4StackingActionSequence::updateContext
virtual void updateContext(Geant4Context *ctxt) override
Set or update client context.
Definition: Geant4StackingAction.cpp:133
dd4hep::sim::Geant4Action::m_needsControl
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:123
dd4hep::sim::Geant4SharedStackingAction::m_action
Geant4StackingAction * m_action
Reference to the shared action.
Definition: Geant4StackingAction.h:92
dd4hep::sim::Geant4StackingActionSequence::m_newStage
CallbackSequence m_newStage
Callback sequence for the newStage call.
Definition: Geant4StackingAction.h:131
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::Geant4Action::m_context
Geant4Context * m_context
Reference to the Geant4 context.
Definition: Geant4Action.h:116
dd4hep::sim::Geant4StackingAction::newStage
virtual void newStage(G4StackManager *)
New-stage callback.
Definition: Geant4StackingAction.h:66
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4Action::ContextSwap
Functor to update the context of a Geant4Action object.
Definition: Geant4Action.h:138
dd4hep::sim::Geant4StackingActionSequence::m_actors
Actors< Geant4StackingAction > m_actors
The list of action objects to be called.
Definition: Geant4StackingAction.h:135
dd4hep::sim::Geant4Action::m_properties
PropertyManager m_properties
Property pool.
Definition: Geant4Action.h:127
dd4hep::sim::Geant4SharedStackingAction::classifyNewTrack
virtual TrackClassification classifyNewTrack(G4StackManager *stackManager, const G4Track *track) override
Return TrackClassification with enum G4ClassificationOfNewTrack or NoTrackClassification.
Definition: Geant4StackingAction.cpp:95
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::Geant4StackingActionSequence::get
Geant4StackingAction * get(const std::string &name) const
Get an action by name.
Definition: Geant4StackingAction.cpp:144
dd4hep::sim::Geant4StackingAction::Geant4StackingAction
Geant4StackingAction(Geant4Context *ctxt, const std::string &name)
Standard constructor.
Definition: Geant4StackingAction.cpp:28
dd4hep::sim::Geant4StackingAction::~Geant4StackingAction
virtual ~Geant4StackingAction()
Default destructor.
Definition: Geant4StackingAction.cpp:34
dd4hep::sim::Geant4SharedStackingAction::~Geant4SharedStackingAction
virtual ~Geant4SharedStackingAction()
Default destructor.
Definition: Geant4StackingAction.cpp:52
Geant4StackingAction.h
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::Geant4StackingActionSequence::prepare
virtual void prepare(G4StackManager *stackManager)
Preparation callback.
Definition: Geant4StackingAction.cpp:155
dd4hep::sim::Geant4StackingActionSequence::m_prepare
CallbackSequence m_prepare
Definition: Geant4StackingAction.h:133
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::Geant4StackingAction::classifyNewTrack
virtual TrackClassification classifyNewTrack(G4StackManager *, const G4Track *track)
Return TrackClassification with enum G4ClassificationOfNewTrack or NoTrackClassification.
Definition: Geant4StackingAction.cpp:40
dd4hep::sim::Geant4SharedStackingAction::prepare
virtual void prepare(G4StackManager *stackManager) override
Preparation callback.
Definition: Geant4StackingAction.cpp:84
dd4hep::sim::Geant4StackingAction::prepare
virtual void prepare(G4StackManager *)
Preparation callback.
Definition: Geant4StackingAction.h:69
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::Geant4SharedStackingAction::configureFiber
virtual void configureFiber(Geant4Context *thread_context) override
Set or update client for the use in a new thread fiber.
Definition: Geant4StackingAction.cpp:58
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::Geant4SharedStackingAction::Geant4SharedStackingAction
Geant4SharedStackingAction(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4StackingAction.cpp:45
dd4hep::sim::TrackClassification
Definition: Geant4StackingAction.h:39
dd4hep::sim::Geant4SharedStackingAction::use
virtual void use(Geant4StackingAction *action)
Underlying object to be used during the execution of this thread.
Definition: Geant4StackingAction.cpp:63
dd4hep::sim::Geant4StackingAction
Concrete implementation of the Geant4 stacking action base class.
Definition: Geant4StackingAction.h:52
dd4hep::sim::Geant4StackingActionSequence::newStage
virtual void newStage(G4StackManager *stackManager)
New-stage callback.
Definition: Geant4StackingAction.cpp:149
dd4hep::sim::Geant4StackingActionSequence::~Geant4StackingActionSequence
virtual ~Geant4StackingActionSequence()
Default destructor.
Definition: Geant4StackingAction.cpp:114
dd4hep::sim::Geant4StackingActionSequence::adopt
void adopt(Geant4StackingAction *action)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4StackingAction.cpp:123
dd4hep::sim::Geant4SharedStackingAction::newStage
virtual void newStage(G4StackManager *stackManager) override
New-stage callback.
Definition: Geant4StackingAction.cpp:74
dd4hep::sim::Geant4StackingActionSequence::Geant4StackingActionSequence
Geant4StackingActionSequence(Geant4Context *ctxt, const std::string &name)
Standard constructor.
Definition: Geant4StackingAction.cpp:107
InstanceCount.h
dd4hep::sim::NoTrackClassification
@ NoTrackClassification
Definition: Geant4StackingAction.h:37
dd4hep::sim::Geant4StackingActionSequence::classifyNewTrack
virtual TrackClassification classifyNewTrack(G4StackManager *stackManager, const G4Track *track)
Classify new track: The first call in the sequence returning non-null pointer wins!
Definition: Geant4StackingAction.cpp:162
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::Geant4StackingActionSequence::configureFiber
virtual void configureFiber(Geant4Context *thread_context) override
Set or update client for the use in a new thread fiber.
Definition: Geant4StackingAction.cpp:139