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
Geant4StackingAction.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"
18 // Geant4 headers
19 #include "G4Threading.hh"
20 #include "G4AutoLock.hh"
21 
22 // C/C++ include files
23 #include <stdexcept>
24 
25 using namespace std;
26 using namespace DD4hep::Simulation;
27 namespace {
28  G4Mutex action_mutex=G4MUTEX_INITIALIZER;
29 }
30 
32 Geant4StackingAction::Geant4StackingAction(Geant4Context* ctxt, const string& nam)
33  : Geant4Action(ctxt, nam) {
35 }
36 
40 }
41 
44  : Geant4StackingAction(ctxt, nam)
45 {
47 }
48 
53 }
54 
57  m_action->configureFiber(thread_context);
58 }
59 
62  if (action) {
63  action->addRef();
64  m_properties.adopt(action->properties());
65  m_action = action;
66  return;
67  }
68  throw runtime_error("Geant4SharedStackingAction: Attempt to use invalid actor!");
69 }
70 
73  if ( m_action ) {
74  G4AutoLock protection_lock(&action_mutex); {
76  m_action->newStage();
77  }
78  }
79 }
80 
83  if ( m_action ) {
84  G4AutoLock protection_lock(&action_mutex); {
86  m_action->prepare();
87  }
88  }
89 }
90 
93  : Geant4Action(ctxt, nam) {
94  m_needsControl = true;
96 }
97 
101  m_actors.clear();
102  m_newStage.clear();
103  m_prepare.clear();
105 }
106 
109  if (action) {
110  action->addRef();
111  m_actors.add(action);
112  return;
113  }
114  throw runtime_error("Geant4StackingActionSequence: Attempt to add invalid actor!");
115 }
116 
119  m_context = ctxt;
120  m_actors.updateContext(ctxt);
121 }
122 
125  m_actors(&Geant4Action::configureFiber, thread_context);
126 }
127 
130  return m_actors.get(FindByName(TypeName::split(nam).second));
131 }
132 
136  m_newStage();
137 }
138 
142  m_prepare();
143 }
Functor to access elements by name.
Definition: Geant4Action.h:135
virtual void prepare()
Preparation callback.
long release()
Decrease reference count. Implicit destruction.
virtual void prepare()
Preparation callback.
virtual void configureFiber(Geant4Context *thread_context)
Set or update client for the use in a new thread fiber.
virtual void configureFiber(Geant4Context *thread_context)
Set or update client for the use in a new thread fiber.
CallbackSequence m_newStage
Callback sequence for the newStage call.
static void decrement(T *)
Decrement count according to type information.
void adopt(const PropertyManager &copy)
Export properties of another instance.
Concrete implementation of the Geant4 stacking action base class.
Geant4SharedStackingAction(Geant4Context *context, const std::string &nam)
Standard constructor.
virtual void use(Geant4StackingAction *action)
Underlying object to be used during the execution of this thread.
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:261
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
PropertyManager & properties()
Access to the properties of the object.
Definition: Geant4Action.h:283
Geant4StackingActionSequence(Geant4Context *ctxt, const std::string &name)
Standard constructor.
virtual void configureFiber(Geant4Context *thread_context)
Set or update client for the use in a new thread fiber.
Actors< Geant4StackingAction > m_actors
The list of action objects to be called.
long addRef()
Increase reference count.
void clear()
Clear the sequence and remove all callbacks.
Definition: Callback.h:358
Geant4StackingAction * m_action
Reference to the shared action.
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:101
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 ('/')
Geant4StackingAction * get(const std::string &name) const
Get an action by name.
Generic context to extend user, run and event information.
PropertyManager m_properties
Property pool.
Definition: Geant4Action.h:105
virtual ~Geant4StackingActionSequence()
Default destructor.
static const double second
Definition: DD4hepUnits.h:112
virtual void updateContext(Geant4Context *ctxt)
Set or update client context.
virtual ~Geant4SharedStackingAction()
Default destructor.
virtual void newStage()
New-stage callback.
void adopt(Geant4StackingAction *action)
Add an actor responding to all callbacks. Sequence takes ownership.
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:91
virtual ~Geant4StackingAction()
Default destructor.