DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4GeneratorAction.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 #include <DDG4/Geant4Kernel.h>
18 
19 // Geant4 headers
20 #include <G4Threading.hh>
21 #include <G4AutoLock.hh>
22 
23 using namespace dd4hep::sim;
24 
25 namespace {
26  G4Mutex action_mutex=G4MUTEX_INITIALIZER;
27 }
28 
31  : Geant4Action(ctxt, nam) {
33 }
34 
38 }
39 
42  : Geant4GeneratorAction(ctxt, nam), m_action(0)
43 {
45 }
46 
49  detail::releasePtr(m_action);
51 }
52 
55  m_action->configureFiber(thread_context);
56 }
57 
60  if (action) {
61  action->addRef();
62  m_action = action;
63  return;
64  }
65  throw std::runtime_error("Geant4SharedGeneratorAction: Attempt to use invalid actor!");
66 }
67 
70  if ( m_action ) {
71  G4AutoLock protection_lock(&action_mutex); {
73  (*m_action)(event);
74  }
75  }
76 }
77 
80  : Geant4Action(ctxt, nam) {
81  m_needsControl = true;
83 }
84 
88  m_actors.clear();
89  m_calls.clear();
91 }
92 
95  m_context = ctxt;
96  m_actors.updateContext(ctxt);
97 }
98 
101  m_actors(&Geant4Action::configureFiber, thread_context);
102 }
103 
106  return m_actors.get(FindByName(TypeName::split(nam).second));
107 }
108 
111  if (action) {
112  G4AutoLock protection_lock(&action_mutex);
113  action->addRef();
114  m_actors.add(action);
115  return;
116  }
117  except("Attempt to add invalid actor!");
118 }
119 
122  if ( context()->kernel().processEvents() ) {
123  m_actors(&Geant4GeneratorAction::operator(), event);
124  m_calls(event);
125  return;
126  }
127  throw DD4hep_Stop_Processing();
128 }
dd4hep::sim::Geant4GeneratorActionSequence::m_calls
CallbackSequence m_calls
Callback sequence to generate primary particles.
Definition: Geant4GeneratorAction.h:118
dd4hep::sim::Geant4Action::m_needsControl
bool m_needsControl
Default property: Flag to create control instance.
Definition: Geant4Action.h:123
dd4hep::sim::Geant4GeneratorActionSequence::m_actors
Actors< Geant4GeneratorAction > m_actors
The list of action objects to be called.
Definition: Geant4GeneratorAction.h:120
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::Geant4GeneratorActionSequence::~Geant4GeneratorActionSequence
virtual ~Geant4GeneratorActionSequence()
Default destructor.
Definition: Geant4GeneratorAction.cpp:86
dd4hep::sim::Geant4GeneratorAction::Geant4GeneratorAction
Geant4GeneratorAction(Geant4Context *context, const std::string &name)
Standard constructor.
Definition: Geant4GeneratorAction.cpp:30
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::sim::Geant4SharedGeneratorAction::configureFiber
virtual void configureFiber(Geant4Context *thread_context) override
Set or update client for the use in a new thread fiber.
Definition: Geant4GeneratorAction.cpp:54
dd4hep::sim::Geant4Action::ContextSwap
Functor to update the context of a Geant4Action object.
Definition: Geant4Action.h:138
dd4hep::sim::Geant4GeneratorActionSequence::Geant4GeneratorActionSequence
Geant4GeneratorActionSequence(Geant4Context *context, const std::string &name)
Standard constructor.
Definition: Geant4GeneratorAction.cpp:79
dd4hep::sim::Geant4Action::except
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
Definition: Geant4Action.cpp:256
Geant4GeneratorAction.h
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4GeneratorAction
Concrete implementation of the Geant4 generator action base class.
Definition: Geant4GeneratorAction.h:47
dd4hep::sim::Geant4GeneratorActionSequence::get
Geant4GeneratorAction * get(const std::string &name) const
Get an action by name.
Definition: Geant4GeneratorAction.cpp:105
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::Geant4GeneratorActionSequence::operator()
virtual void operator()(G4Event *event)
Callback to generate primary particles.
Definition: Geant4GeneratorAction.cpp:121
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::Geant4SharedGeneratorAction::m_action
Geant4GeneratorAction * m_action
Reference to the shared action.
Definition: Geant4GeneratorAction.h:81
dd4hep::sim::Geant4GeneratorActionSequence::configureFiber
virtual void configureFiber(Geant4Context *thread_context) override
Set or update client for the use in a new thread fiber.
Definition: Geant4GeneratorAction.cpp:100
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::Geant4GeneratorAction::~Geant4GeneratorAction
virtual ~Geant4GeneratorAction()
Default destructor.
Definition: Geant4GeneratorAction.cpp:36
dd4hep::sim::Geant4SharedGeneratorAction::~Geant4SharedGeneratorAction
virtual ~Geant4SharedGeneratorAction()
Default destructor.
Definition: Geant4GeneratorAction.cpp:48
dd4hep::sim::Geant4SharedGeneratorAction::use
virtual void use(Geant4GeneratorAction *action)
Underlying object to be used during the execution of this thread.
Definition: Geant4GeneratorAction.cpp:59
dd4hep::sim::Geant4SharedGeneratorAction::Geant4SharedGeneratorAction
Geant4SharedGeneratorAction(Geant4Context *context, const std::string &nam)
Standard constructor.
Definition: Geant4GeneratorAction.cpp:41
dd4hep::sim::Geant4GeneratorActionSequence::updateContext
virtual void updateContext(Geant4Context *ctxt) override
Set or update client context.
Definition: Geant4GeneratorAction.cpp:94
Geant4Kernel.h
InstanceCount.h
dd4hep::sim::Geant4SharedGeneratorAction::operator()
virtual void operator()(G4Event *event) override
User generator callback.
Definition: Geant4GeneratorAction.cpp:69
dd4hep::sim::DD4hep_Stop_Processing
Helper class to indicate the stop of processing.
Definition: Geant4Kernel.h:50
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201
dd4hep::sim::Geant4GeneratorActionSequence::adopt
void adopt(Geant4GeneratorAction *action)
Add an actor responding to all callbacks. Sequence takes ownership.
Definition: Geant4GeneratorAction.cpp:110
dd4hep::sim::Geant4Action::context
Geant4Context * context() const
Access the context.
Definition: Geant4Action.h:270