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
Geant4Context.h
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 #ifndef DD4HEP_DDG4_GEANT4CONTEXT_H
16 #define DD4HEP_DDG4_GEANT4CONTEXT_H
17 
18 // Framework incloude files
19 #include "DD4hep/Primitives.h"
21 
22 // Forward declarations
23 class G4Run;
24 class G4Track;
25 class G4Event;
26 class G4VTrajectory;
27 class G4TrackingManager;
28 
30 namespace DD4hep {
31 
32  // Forward declarations
33  namespace Geometry {
34  class LCDD;
35  class DetElement;
36  }
37 
39  namespace Simulation {
40 
41  class Geant4Run;
42  class Geant4Event;
43  class Geant4Kernel;
44  class Geant4Random;
45  class ContextUpdate;
46  class Geant4RunActionSequence;
47  class Geant4EventActionSequence;
48  class Geant4SteppingActionSequence;
49  class Geant4TrackingActionSequence;
50  class Geant4StackingActionSequence;
51  class Geant4GeneratorActionSequence;
52  class Geant4SensDetSequences;
53 
55 
71  class Geant4Run : public ObjectExtensions {
73  const G4Run* m_run;
74  protected:
75 
76  public:
78  Geant4Run(const G4Run* run);
80  virtual ~Geant4Run();
82  operator const G4Run&() const { return *m_run; }
84  const G4Run& run() const { return *m_run; }
86 
90  void* addExtension(void* ptr, const std::type_info& info, destruct_t dtor) {
91  return ObjectExtensions::addExtension(ptr,info,dtor);
92  }
94  template <typename T> T* addExtension(T* ptr, bool take_ownership=true) {
95  destruct_t dt = ObjectExtensions::_delete<T>;
96  return (T*)ObjectExtensions::addExtension(ptr,typeid(T),take_ownership ? dt : 0);
97  }
99  template <typename T> T* extension(bool alert=true) {
100  return (T*)ObjectExtensions::extension(typeid(T),alert);
101  }
102  };
103 
105 
125  class Geant4Event : public ObjectExtensions {
127  const G4Event* m_event;
130 
131  public:
133  Geant4Event(const G4Event* run, Geant4Random* rndm);
135  virtual ~Geant4Event();
137  operator const G4Event&() const { return *m_event; }
139  const G4Event& event() const { return *m_event; }
141  Geant4Random& random() const { return *m_random; }
142 
144 
148  void* addExtension(void* ptr, const std::type_info& info, destruct_t dtor) {
149  return ObjectExtensions::addExtension(ptr,info,dtor);
150  }
152  template <typename T> T* addExtension(T* ptr, bool take_ownership=true) {
153  destruct_t dt = ObjectExtensions::_delete<T>;
154  return (T*)ObjectExtensions::addExtension(ptr,typeid(T),take_ownership ? dt : 0);
155  }
157  template <typename T> T* extension(bool alert=true) {
158  return (T*)ObjectExtensions::extension(typeid(T),alert);
159  }
160  };
161 
163 
169  friend class Geant4Kernel;
170  public:
171 #ifdef R__DICTIONARY_FILENAME
172  public:
174  typedef Geometry::LCDD LCDD;
175 #endif
176  protected:
182  public:
184  virtual ~Geant4Context();
186  void setRun(Geant4Run* new_run);
188  Geant4Run& run() const;
190  Geant4Run* runPtr() const { return m_run; }
192  void setEvent(Geant4Event* new_event);
194  Geant4Event& event() const;
196  Geant4Event* eventPtr() const { return m_event; }
198  Geant4Kernel& kernel() const { return *m_kernel; }
200  Geometry::LCDD& lcdd() const;
202  G4TrackingManager* trackMgr() const;
204  virtual G4VTrajectory* createTrajectory(const G4Track* track) const;
219  };
220 
221  } // End namespace Simulation
222 } // End namespace DD4hep
223 
224 #endif // DD4HEP_DDG4_GEANT4CONTEXT_H
Concrete implementation of the Geant4 stepping action sequence.
Geant4Event & event() const
Access the geant4 event – valid only between BeginEvent() and EndEvent()!
virtual ~Geant4Event()
Default destructor.
User event context for DDG4.
Geant4Kernel & kernel() const
Access to the kernel object.
Geant4Run(const G4Run *run)
Intializing constructor.
G4TrackingManager * trackMgr() const
Access the tracking manager.
void * addExtension(void *ptr, const std::type_info &info, destruct_t dtor)
Add an extension object to the detector element.
Definition: Geant4Context.h:90
Geant4Random & random() const
Access the random number generator.
const G4Run & run() const
Access the G4Event directly: Explicit G4Run accessor.
Definition: Geant4Context.h:84
Concrete implementation of the Geant4 event action sequence.
Concrete implementation of the Geant4 tracking action sequence.
DD4hep::Geometry::DetElement DetElement
Geant4StackingActionSequence & stackingAction() const
Access to the main stacking action sequence from the kernel object.
Concrete implementation of the Geant4 stacking action sequence.
Class, which allows all Geant4Action derivatives to access the DDG4 kernel structures.
Definition: Geant4Kernel.h:43
Geant4Run & run() const
Access the geant4 run – valid only between BeginRun() and EndRun()!
Geant4RunActionSequence & runAction() const
Access to the main run action sequence from the kernel object.
void * addExtension(void *ptr, const std::type_info &info, destruct_t dtor)
Add an extension object to the detector element.
const G4Run * m_run
Reference to the original Geant4 run object.
Definition: Geant4Context.h:73
virtual ~Geant4Context()
Default destructor.
T * extension(bool alert=true)
Access to type safe extension object. Exception is thrown if the object is invalid.
Geant4Event(const G4Event *run, Geant4Random *rndm)
Intializing constructor.
User run context for DDG4.
Definition: Geant4Context.h:71
const G4Event & event() const
Access the G4Event directly: Explicit G4Event accessor.
Geant4GeneratorActionSequence & generatorAction() const
Access to the main generator action sequence from the kernel object.
Concrete implementation of the Geant4 generator action sequence.
Concrete basic implementation of the Geant4 run action sequencer.
virtual ~Geant4Run()
Default destructor.
Geant4Context(Geant4Kernel *kernel)
Default constructor.
Geant4Random * m_random
Reference to the main random number generator.
void setEvent(Geant4Event *new_event)
Set the geant4 event reference.
Geant4SensDetSequences & sensitiveActions() const
Access to the sensitive detector sequences from the kernel object.
virtual G4VTrajectory * createTrajectory(const G4Track *track) const
Create a user trajectory.
void setRun(Geant4Run *new_run)
Set the geant4 run reference.
Geometry::LCDD & lcdd() const
Access to detector description.
Geant4Event * eventPtr() const
Access the geant4 event by ptr. Must be checked by clients!
Geant4EventActionSequence & eventAction() const
Access to the main event action sequence from the kernel object.
Generic context to extend user, run and event information.
void * extension(const std::type_info &info, bool alert) const
Access an existing extension object from the detector element.
void * addExtension(void *ptr, const std::type_info &info, copy_t ctor, destruct_t dtor)
Add an extension object to the detector element.
The main interface to the DD4hep detector description package.
Definition: LCDD.h:82
Geant4SteppingActionSequence & steppingAction() const
Access to the main stepping action sequence from the kernel object.
Mini interface to THE random generator of the application.
Definition: Geant4Random.h:60
void(* destruct_t)(void *)
Extensions destructor type.
T * addExtension(T *ptr, bool take_ownership=true)
Add user extension object. Ownership is transferred and object deleted at the end of the event...
Geant4SensDetSequences: class to access groups of sensitive actions.
Implementation of an object supporting arbitrary user extensions.
T * extension(bool alert=true)
Access to type safe extension object. Exception is thrown if the object is invalid.
Definition: Geant4Context.h:99
Geant4Run * runPtr() const
Access the geant4 run by ptr. Must be checked by clients!
Geant4TrackingActionSequence & trackingAction() const
Access to the main tracking action sequence from the kernel object.
T * addExtension(T *ptr, bool take_ownership=true)
Add user extension object. Ownership is transferred!
Definition: Geant4Context.h:94
const G4Event * m_event
Reference to the original Geant4 event object.