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
Geant4ActionContainer.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/Printout.h"
17 #include "DD4hep/Primitives.h"
18 #include "DD4hep/InstanceCount.h"
19 
21 #include "DDG4/Geant4RunAction.h"
22 #include "DDG4/Geant4PhysicsList.h"
23 #include "DDG4/Geant4EventAction.h"
31 
32 // C/C++ include files
33 #include <stdexcept>
34 #include <algorithm>
35 
36 using namespace std;
37 using namespace DD4hep::Simulation;
38 
40 Geant4ActionContainer::Geant4ActionContainer(Geant4Context* ctxt)
41  : m_context(ctxt),
42  m_generatorAction(0), m_runAction(0), m_eventAction(0), m_trackingAction(0),
43  m_steppingAction(0), m_stackingAction(0), m_constructionAction(0),
44  m_sensDetActions(0), m_physicsList(0), m_userInit(0)
45 {
48 }
49 
54 }
55 
68  return 1;
69 }
70 
72  if ( m_context ) return m_context;
73  throw runtime_error(format("Geant4Kernel", "DDG4: Master kernel object has no thread context! [Invalid Handle]"));
74 }
75 
78  m_context = ctxt;
79 }
80 
81 template <class C> bool Geant4ActionContainer::registerSequence(C*& seq, const std::string& name) {
82  if (!name.empty()) {
83  seq = new C(m_context, name);
84  seq->installMessengers();
85  return true;
86  }
87  throw runtime_error(format("Geant4ActionContainer", "DDG4: The action '%s' not found. [Action-NotFound]", name.c_str()));
88 }
89 
92  if (!m_generatorAction && create)
93  registerSequence(m_generatorAction, "GeneratorAction");
94  return m_generatorAction;
95 }
96 
99  if (!m_runAction && create)
100  registerSequence(m_runAction, "RunAction");
101  return m_runAction;
102 }
103 
106  if (!m_eventAction && create)
107  registerSequence(m_eventAction, "EventAction");
108  return m_eventAction;
109 }
110 
113  if (!m_steppingAction && create)
114  registerSequence(m_steppingAction, "SteppingAction");
115  return m_steppingAction;
116 }
117 
120  if (!m_trackingAction && create)
121  registerSequence(m_trackingAction, "TrackingAction");
122  return m_trackingAction;
123 }
124 
127  if (!m_stackingAction && create)
128  registerSequence(m_stackingAction, "StackingAction");
129  return m_stackingAction;
130 }
131 
134  if (!m_constructionAction && create)
135  registerSequence(m_constructionAction, "StackingAction");
136  return m_constructionAction;
137 }
138 
141  return *m_sensDetActions;
142 }
143 
147  if (ptr) {
148  return ptr;
149  }
150  ptr = new Geant4SensDetActionSequence(workerContext(), nam);
151  m_sensDetActions->insert(nam, ptr);
152  return ptr;
153 }
154 
157  if (!m_physicsList && create)
158  registerSequence(m_physicsList, "PhysicsList");
159  return m_physicsList;
160 }
161 
164  if (!m_userInit && create) {
165  registerSequence(m_userInit, "UserInitialization");
166  }
167  return m_userInit;
168 }
Geant4DetectorConstructionSequence & detectorConstruction()
Access detector construcion action sequence (geometry+sensitives+field)
Concrete implementation of the Geant4 stepping action sequence.
Geant4StackingActionSequence & stackingAction()
Access stacking action sequence.
Class to orchestrate a modular initializion of a multi- or single threaded Geant4 application...
void deletePtr(T *&p)
Helper to delete objects from heap and reset the pointer. Saves many many lines of code...
Definition: Primitives.h:234
void setContext(Geant4Context *ctxt)
Set the thread's context.
static void decrement(T *)
Decrement count according to type information.
Concrete basic implementation of the Geant4 detector construction sequencer.
Geant4SensDetActionSequence * find(const std::string &name) const
Access sequence member by name.
Geant4SensDetSequences * m_sensDetActions
Reference to the Geant4 sensitive action sequences.
Geant4UserInitializationSequence * m_userInit
Reference to the user initialization object.
Geant4SensDetActionSequence * sensitiveAction(const std::string &name)
Access to the sensitive detector action from the actioncontainer object.
Geant4EventActionSequence & eventAction()
Access run action sequence.
Concrete implementation of the Geant4 event action sequence.
Geant4SteppingActionSequence * m_steppingAction
Reference to the Geant4 step action.
Concrete implementation of the Geant4 tracking action sequence.
std::string format(const std::string &src, const std::string &fmt,...)
Build formatted string.
Definition: Printout.cpp:267
void releasePtr(T &p)
Helper to delete objects from heap and reset the pointer. Saves many many lines of code...
Definition: Primitives.h:316
Geant4StackingActionSequence * m_stackingAction
Reference to the Geant4 stacking action.
Geant4PhysicsListActionSequence * m_physicsList
Reference to the Geant4 physics list.
Concrete implementation of the Geant4 stacking action sequence.
Geant4RunActionSequence * m_runAction
Reference to the Geant4 run action.
Geant4PhysicsListActionSequence & physicsList()
Access to the physics list.
The implementation of the single Geant4 physics list action sequence.
Geant4GeneratorActionSequence & generatorAction()
Access generator action sequence.
virtual ~Geant4ActionContainer()
Default destructor.
Geant4TrackingActionSequence * m_trackingAction
Reference to the Geant4 track action.
Geant4Context * m_context
Geant4 worker context (thread specific)
Concrete implementation of the Geant4 generator action sequence.
Concrete basic implementation of the Geant4 run action sequencer.
Geant4Context * workerContext()
Thread's Geant4 execution context.
The sequencer to host Geant4 sensitive actions called if particles interact with sensitive elements...
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
bool registerSequence(C *&seq, const std::string &name)
Helper to register an action sequence.
Geant4GeneratorActionSequence * m_generatorAction
Reference to the Geant4 primary generator action.
Geant4TrackingActionSequence & trackingAction()
Access tracking action sequence.
Generic context to extend user, run and event information.
void insert(const std::string &name, Geant4SensDetActionSequence *seq)
Insert sequence member.
Geant4UserInitializationSequence & userInitialization()
Access to the user initialization object.
Geant4RunActionSequence & runAction()
Access run action sequence.
Geant4SensDetSequences & sensitiveActions() const
Access to the sensitive detector sequences from the actioncontainer object.
Geant4DetectorConstructionSequence * m_constructionAction
Reference to the Geant4 detector construction sequence.
Geant4EventActionSequence * m_eventAction
Reference to the Geant4 event action.
Geant4SensDetSequences: class to access groups of sensitive actions.
virtual int terminate()
Terminate all associated action instances.
Geant4SteppingActionSequence & steppingAction()
Access stepping action sequence.