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
Geant4SteppingAction.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 // C/C++ include files
22 #include <stdexcept>
23 
24 using namespace std;
25 using namespace DD4hep::Simulation;
26 namespace {
27  G4Mutex action_mutex=G4MUTEX_INITIALIZER;
28 }
29 
31 Geant4SteppingAction::Geant4SteppingAction(Geant4Context* ctxt, const string& nam)
32 : Geant4Action(ctxt, nam) {
34 }
35 
39 }
40 
42 void Geant4SteppingAction::operator()(const G4Step*, G4SteppingManager*) {
43 }
44 
47  : Geant4SteppingAction(ctxt, nam)
48 {
50 }
51 
56 }
57 
60  if (action) {
61  action->addRef();
62  m_properties.adopt(action->properties());
63  m_action = action;
64  return;
65  }
66  throw runtime_error("Geant4SharedSteppingAction: Attempt to use invalid actor!");
67 }
68 
71  m_action->configureFiber(thread_context);
72 }
73 
75 void Geant4SharedSteppingAction::operator()(const G4Step* s, G4SteppingManager* m) {
76  if ( m_action ) {
77  G4AutoLock protection_lock(&action_mutex); {
79  (*m_action)(s,m);
80  }
81  }
82 }
83 
86 : Geant4Action(ctxt, nam) {
87  m_needsControl = true;
89 }
90 
94  m_actors.clear();
95  m_calls.clear();
97 }
98 
101  m_actors(&Geant4Action::configureFiber, thread_context);
102 }
103 
106  m_context = ctxt;
107  m_actors.updateContext(ctxt);
108 }
109 
112  return m_actors.get(FindByName(TypeName::split(nam).second));
113 }
114 
116 void Geant4SteppingActionSequence::operator()(const G4Step* step, G4SteppingManager* mgr) {
117  m_actors(&Geant4SteppingAction::operator(), step, mgr);
118  m_calls(step, mgr);
119 }
120 
123  if (action) {
124  G4AutoLock protection_lock(&action_mutex);
125  action->addRef();
126  m_actors.add(action);
127  return;
128  }
129  throw runtime_error("Geant4SteppingActionSequence: Attempt to add invalid actor!");
130 }
Functor to access elements by name.
Definition: Geant4Action.h:135
long release()
Decrease reference count. Implicit destruction.
Geant4SharedSteppingAction(const Geant4SteppingAction &copy)=delete
Inhibit copy constructor.
virtual ~Geant4SteppingAction()
Default destructor.
static void decrement(T *)
Decrement count according to type information.
virtual ~Geant4SharedSteppingAction()
Default destructor.
void adopt(const PropertyManager &copy)
Export properties of another instance.
CallbackSequence m_calls
Callback sequence for user stepping action calls.
TGeoShape * s
Definition: Volumes.cpp:294
virtual void updateContext(Geant4Context *ctxt)
Set or update client context.
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:261
Geant4Context * m_context
Reference to the Geant4 context.
Definition: Geant4Action.h:94
Concrete implementation of the Geant4 stepping action sequence.
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 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.
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.
long addRef()
Increase reference count.
void clear()
Clear the sequence and remove all callbacks.
Definition: Callback.h:358
Geant4SteppingAction * get(const std::string &name) const
Get an action by name.
virtual ~Geant4SteppingActionSequence()
Default destructor.
virtual void operator()(const G4Step *step, G4SteppingManager *mgr)
User stepping callback.
void adopt(Geant4SteppingAction *action)
Add an actor responding to all callbacks. Sequence takes ownership.
Geant4SteppingActionSequence(const Geant4SteppingAction &copy)=delete
Inhibit copy constructor.
Geant4SteppingAction * 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
virtual void use(Geant4SteppingAction *action)
Underlying object to be used during the execution of this thread.
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 ('/')
Actors< Geant4SteppingAction > m_actors
The list of action objects to be called.
Generic context to extend user, run and event information.
PropertyManager m_properties
Property pool.
Definition: Geant4Action.h:105
virtual void operator()(const G4Step *step, G4SteppingManager *mgr)
User stepping callback.
static const double second
Definition: DD4hepUnits.h:112
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:91
TGeoShape TGeoMedium * m
Definition: Volumes.cpp:294
virtual void operator()(const G4Step *step, G4SteppingManager *mgr)
User stepping callback.