DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4ActionContainer.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/Printout.h>
16 #include <DD4hep/Primitives.h>
17 #include <DD4hep/InstanceCount.h>
18 
20 #include <DDG4/Geant4RunAction.h>
21 #include <DDG4/Geant4PhysicsList.h>
22 #include <DDG4/Geant4EventAction.h>
30 
31 // C/C++ include files
32 #include <stdexcept>
33 #include <algorithm>
34 
35 using namespace dd4hep::sim;
36 
39 {
42 }
43 
48 }
49 
52  detail::releasePtr (m_physicsList);
53  detail::releasePtr (m_constructionAction);
54  detail::releasePtr (m_stackingAction);
55  detail::releasePtr (m_steppingAction);
56  detail::releasePtr (m_trackingAction);
57  detail::releasePtr (m_eventAction);
58  detail::releasePtr (m_generatorAction);
59  detail::releasePtr (m_runAction);
60  detail::deletePtr (m_sensDetActions);
61  detail::deletePtr (m_context);
62  return 1;
63 }
64 
66  if ( m_context ) return m_context;
67  throw std::runtime_error(format("Geant4Kernel", "DDG4: Master kernel object has no thread context! [Invalid Handle]"));
68 }
69 
72  m_context = ctxt;
73 }
74 
75 template <class C> bool Geant4ActionContainer::registerSequence(C*& seq, const std::string& name) {
76  if (!name.empty()) {
77  seq = new C(m_context, name);
78  seq->installMessengers();
79  return true;
80  }
81  throw std::runtime_error(format("Geant4ActionContainer", "DDG4: The action '%s' not found. [Action-NotFound]", name.c_str()));
82 }
83 
86  if (!m_generatorAction && create)
87  registerSequence(m_generatorAction, "GeneratorAction");
88  return m_generatorAction;
89 }
90 
93  if (!m_runAction && create)
94  registerSequence(m_runAction, "RunAction");
95  return m_runAction;
96 }
97 
100  if (!m_eventAction && create)
101  registerSequence(m_eventAction, "EventAction");
102  return m_eventAction;
103 }
104 
107  if (!m_steppingAction && create)
108  registerSequence(m_steppingAction, "SteppingAction");
109  return m_steppingAction;
110 }
111 
114  if (!m_trackingAction && create)
115  registerSequence(m_trackingAction, "TrackingAction");
116  return m_trackingAction;
117 }
118 
121  if (!m_stackingAction && create)
122  registerSequence(m_stackingAction, "StackingAction");
123  return m_stackingAction;
124 }
125 
128  if (!m_constructionAction && create)
129  registerSequence(m_constructionAction, "DetectorConstructionAction");
130  return m_constructionAction;
131 }
132 
135  return *m_sensDetActions;
136 }
137 
141  if (ptr) {
142  return ptr;
143  }
144  ptr = new Geant4SensDetActionSequence(workerContext(), nam);
145  m_sensDetActions->insert(nam, ptr);
146  return ptr;
147 }
148 
151  if (!m_physicsList && create)
152  registerSequence(m_physicsList, "PhysicsList");
153  return m_physicsList;
154 }
155 
158  if (!m_userInit && create) {
159  registerSequence(m_userInit, "UserInitialization");
160  }
161  return m_userInit;
162 }
dd4hep::sim::Geant4ActionContainer::m_stackingAction
Geant4StackingActionSequence * m_stackingAction
Reference to the Geant4 stacking action.
Definition: Geant4ActionContainer.h:77
Geant4DetectorConstruction.h
dd4hep::sim::Geant4SensDetSequences::insert
void insert(const std::string &name, Geant4SensDetActionSequence *seq)
Insert sequence member.
Definition: Geant4SensDetAction.cpp:521
dd4hep::sim::Geant4UserInitializationSequence
Class to orchestrate a modular initializion of a multi- or single threaded Geant4 application.
Definition: Geant4UserInitialization.h:52
dd4hep::sim::Geant4ActionContainer::registerSequence
bool registerSequence(C *&seq, const std::string &name)
Helper to register an action sequence.
Definition: Geant4ActionContainer.cpp:75
dd4hep::sim::Geant4StackingActionSequence
Concrete implementation of the Geant4 stacking action sequence.
Definition: Geant4StackingAction.h:128
dd4hep::sim::Geant4ActionContainer::m_context
Geant4Context * m_context
Geant4 worker context (thread specific)
Definition: Geant4ActionContainer.h:64
dd4hep::sim::Geant4ActionContainer::sensitiveAction
Geant4SensDetActionSequence * sensitiveAction(const std::string &name)
Access to the sensitive detector action from the actioncontainer object.
Definition: Geant4ActionContainer.cpp:139
dd4hep::sim::Geant4ActionContainer::Geant4ActionContainer
Geant4ActionContainer(Geant4Context *ctxt=0)
Standard constructor.
Definition: Geant4ActionContainer.cpp:38
dd4hep::sim::Geant4ActionContainer::m_steppingAction
Geant4SteppingActionSequence * m_steppingAction
Reference to the Geant4 step action.
Definition: Geant4ActionContainer.h:75
Geant4SensDetAction.h
Geant4TrackingAction.h
Geant4RunAction.h
Geant4EventAction.h
dd4hep::sim::Geant4ActionContainer::detectorConstruction
Geant4DetectorConstructionSequence & detectorConstruction()
Access detector construcion action sequence (geometry+sensitives+field)
Definition: Geant4ActionContainer.h:152
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
Geant4PhysicsList.h
Geant4ActionContainer.h
dd4hep::sim::Geant4ActionContainer::userInitialization
Geant4UserInitializationSequence & userInitialization()
Access to the user initialization object.
Definition: Geant4ActionContainer.h:170
dd4hep::sim::Geant4ActionContainer::workerContext
Geant4Context * workerContext()
Thread's Geant4 execution context.
Definition: Geant4ActionContainer.cpp:65
Geant4SteppingAction.h
dd4hep::sim::Geant4ActionContainer::physicsList
Geant4PhysicsListActionSequence & physicsList()
Access to the physics list.
Definition: Geant4ActionContainer.h:164
dd4hep::sim::Geant4TrackingActionSequence
Concrete implementation of the Geant4 tracking action sequence.
Definition: Geant4TrackingAction.h:114
dd4hep::sim::Geant4ActionContainer::stackingAction
Geant4StackingActionSequence & stackingAction()
Access stacking action sequence.
Definition: Geant4ActionContainer.h:145
dd4hep::sim::Geant4ActionContainer::m_runAction
Geant4RunActionSequence * m_runAction
Reference to the Geant4 run action.
Definition: Geant4ActionContainer.h:69
dd4hep::sim::Geant4SensDetSequences::find
Geant4SensDetActionSequence * find(const std::string &name) const
Access sequence member by name.
Definition: Geant4SensDetAction.cpp:512
dd4hep::sim::Geant4ActionContainer::eventAction
Geant4EventActionSequence & eventAction()
Access run action sequence.
Definition: Geant4ActionContainer.h:124
Geant4GeneratorAction.h
dd4hep::sim::Geant4GeneratorActionSequence
Concrete implementation of the Geant4 generator action sequence.
Definition: Geant4GeneratorAction.h:115
dd4hep::sim::Geant4ActionContainer::setContext
void setContext(Geant4Context *ctxt)
Set the thread's context.
Definition: Geant4ActionContainer.cpp:71
Geant4StackingAction.h
dd4hep::sim::Geant4ActionContainer::trackingAction
Geant4TrackingActionSequence & trackingAction()
Access tracking action sequence.
Definition: Geant4ActionContainer.h:138
dd4hep::sim::Geant4ActionContainer::m_constructionAction
Geant4DetectorConstructionSequence * m_constructionAction
Reference to the Geant4 detector construction sequence.
Definition: Geant4ActionContainer.h:79
dd4hep::sim::Geant4ActionContainer::m_userInit
Geant4UserInitializationSequence * m_userInit
Reference to the user initialization object.
Definition: Geant4ActionContainer.h:86
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::sim::Geant4RunActionSequence
Concrete basic implementation of the Geant4 run action sequencer.
Definition: Geant4RunAction.h:117
dd4hep::sim::Geant4SensDetSequences
Geant4SensDetSequences: class to access groups of sensitive actions.
Definition: Geant4SensDetAction.h:464
dd4hep::sim::Geant4PhysicsListActionSequence
The implementation of the single Geant4 physics list action sequence.
Definition: Geant4PhysicsList.h:223
dd4hep::sim::Geant4ActionContainer::runAction
Geant4RunActionSequence & runAction()
Access run action sequence.
Definition: Geant4ActionContainer.h:117
dd4hep::sim::Geant4DetectorConstructionSequence
Concrete basic implementation of the Geant4 detector construction sequencer.
Definition: Geant4DetectorConstruction.h:135
dd4hep::sim::Geant4ActionContainer::steppingAction
Geant4SteppingActionSequence & steppingAction()
Access stepping action sequence.
Definition: Geant4ActionContainer.h:131
Primitives.h
dd4hep::sim::Geant4ActionContainer::terminate
virtual int terminate()
Terminate all associated action instances.
Definition: Geant4ActionContainer.cpp:51
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4ActionContainer::m_eventAction
Geant4EventActionSequence * m_eventAction
Reference to the Geant4 event action.
Definition: Geant4ActionContainer.h:71
dd4hep::sim::Geant4SensDetActionSequence
The sequencer to host Geant4 sensitive actions called if particles interact with sensitive elements.
Definition: Geant4SensDetAction.h:317
dd4hep::sim::Geant4ActionContainer::m_sensDetActions
Geant4SensDetSequences * m_sensDetActions
Reference to the Geant4 sensitive action sequences.
Definition: Geant4ActionContainer.h:82
dd4hep::sim::Geant4ActionContainer::m_generatorAction
Geant4GeneratorActionSequence * m_generatorAction
Reference to the Geant4 primary generator action.
Definition: Geant4ActionContainer.h:67
dd4hep::sim::Geant4ActionContainer::m_physicsList
Geant4PhysicsListActionSequence * m_physicsList
Reference to the Geant4 physics list.
Definition: Geant4ActionContainer.h:84
Geant4UserInitialization.h
dd4hep::sim::Geant4ActionContainer::generatorAction
Geant4GeneratorActionSequence & generatorAction()
Access generator action sequence.
Definition: Geant4ActionContainer.h:110
dd4hep::sim::Geant4EventActionSequence
Concrete implementation of the Geant4 event action sequence.
Definition: Geant4EventAction.h:124
dd4hep::sim::Geant4ActionContainer::sensitiveActions
Geant4SensDetSequences & sensitiveActions() const
Access to the sensitive detector sequences from the actioncontainer object.
Definition: Geant4ActionContainer.cpp:134
InstanceCount.h
dd4hep::sim::Geant4ActionContainer::m_trackingAction
Geant4TrackingActionSequence * m_trackingAction
Reference to the Geant4 track action.
Definition: Geant4ActionContainer.h:73
dd4hep::sim::Geant4SteppingActionSequence
Concrete implementation of the Geant4 stepping action sequence.
Definition: Geant4SteppingAction.h:104
Printout.h
dd4hep::sim::Geant4ActionContainer::~Geant4ActionContainer
virtual ~Geant4ActionContainer()
Default destructor.
Definition: Geant4ActionContainer.cpp:45
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201