DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4Handle.h
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 #ifndef DDG4_GEANT4HANDLE_H
15 #define DDG4_GEANT4HANDLE_H
16 
19 #include <DD4hep/Detector.h>
20 
22 #include <string>
23 #include <memory>
24 
26 namespace dd4hep {
27 
29  namespace sim {
30 
32  class Geant4Kernel;
33  class Geant4Action;
34 
36 
41  template <typename TYPE> class Geant4Handle {
42  protected:
43  void checked_assign(TYPE* p);
44  TYPE* null() { return nullptr; }
45  public:
47  mutable TYPE* value {nullptr};
49  explicit Geant4Handle() = default;
51  Geant4Handle(TYPE* typ);
53  template <typename T> Geant4Handle(T* typ) : value(0) {
54  checked_assign(dynamic_cast<TYPE*>(typ));
55  }
61  Geant4Handle(Geant4Kernel&, const char* type_name, bool shared=false);
63  Geant4Handle(Geant4Kernel&, const std::string& type_name, bool shared=false);
65  Geant4Handle(Geant4Kernel& ctxt, const std::string& type_name, const std::string& detector, bool shared=false);
67  ~Geant4Handle();
69  Property& operator[](const std::string& property_name) const;
75  Geant4Handle& operator=(TYPE* ptr);
77  bool operator!() const;
79  Geant4Action* action() const;
81  TYPE* operator->() const;
83  operator TYPE*() const;
85  TYPE* get() const;
87  TYPE* release();
88  };
89 
91 
96  class KernelHandle {
97  public:
99  mutable Geant4Kernel* value {nullptr};
101  explicit KernelHandle();
103  explicit KernelHandle(Geant4Kernel* k);
109  operator Geant4Kernel*() const { return value; }
111  Geant4Kernel* get() const { return value; }
113  Geant4Kernel* operator->() const { return value; }
117  void destroy();
118  };
119 
120  } // End namespace sim
121 } // End namespace dd4hep
122 
123 #endif // DDG4_GEANT4HANDLE_H
dd4hep::sim::Geant4Handle::value
TYPE * value
Pointer to referenced object.
Definition: Geant4Handle.h:47
dd4hep::Property
The property class to assign options to actions.
Definition: ComponentProperties.h:48
Detector.h
dd4hep::sim::KernelHandle::operator->
Geant4Kernel * operator->() const
Access to the underlying object.
Definition: Geant4Handle.h:113
dd4hep::sim::Geant4Handle::operator[]
Property & operator[](const std::string &property_name) const
Property accessor.
Definition: Geant4Handle.cpp:162
dd4hep::sim::KernelHandle::get
Geant4Kernel * get() const
Access to the underlying object.
Definition: Geant4Handle.h:111
dd4hep::sim::Geant4Kernel
Class, which allows all Geant4Action derivatives to access the DDG4 kernel structures.
Definition: Geant4Kernel.h:64
dd4hep::sim::KernelHandle
Handle to Geant4 actions with built-in creation mechanism.
Definition: Geant4Handle.h:96
dd4hep::sim::KernelHandle::worker
KernelHandle worker()
Access to worker thread.
Definition: Geant4Handle.cpp:224
dd4hep::sim::Geant4Handle::Geant4Handle
Geant4Handle(T *typ)
Cross type initialization.
Definition: Geant4Handle.h:53
dd4hep::sim::Geant4Handle::~Geant4Handle
~Geant4Handle()
Default destructor.
Definition: Geant4Handle.cpp:142
dd4hep::sim::KernelHandle::value
Geant4Kernel * value
Pointer to referenced object.
Definition: Geant4Handle.h:99
ComponentProperties.h
dd4hep::sim::KernelHandle::~KernelHandle
~KernelHandle()
Default destructor.
Definition: Geant4Handle.h:107
dd4hep::sim::Geant4Handle::operator=
Geant4Handle & operator=(const Geant4Handle &handle)
Assignment operator.
Definition: Geant4Handle.cpp:188
dd4hep::sim::Geant4Action
Default base class for all Geant 4 actions and derivates thereof.
Definition: Geant4Action.h:113
dd4hep::sim::Geant4Handle::release
TYPE * release()
Release the underlying object.
Definition: Geant4Handle.cpp:148
dd4hep::sim::Geant4Handle::operator->
TYPE * operator->() const
Access to the underlying object.
Definition: Geant4Handle.cpp:179
dd4hep::sim::Geant4Handle::Geant4Handle
Geant4Handle()=default
Default constructor.
dd4hep::sim::KernelHandle::destroy
void destroy()
Destroy referenced object (program termination)
Definition: Geant4Handle.cpp:230
dd4hep::sim::Geant4Handle
Handle to Geant4 actions with built-in creation mechanism.
Definition: Geant4Config.h:28
dd4hep::sim::Geant4Handle::operator!
bool operator!() const
Validity check.
Definition: Geant4Handle.cpp:171
dd4hep::sim::KernelHandle::KernelHandle
KernelHandle()
Default constructor.
Definition: Geant4Handle.cpp:219
dd4hep::sim::Geant4Handle::get
TYPE * get() const
Access to the underlying object.
Definition: Geant4Handle.cpp:175
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::sim::Geant4Handle::checked_assign
void checked_assign(TYPE *p)
Definition: Geant4Handle.cpp:154
dd4hep::sim::Geant4Handle::Geant4Handle
Geant4Handle(Geant4Kernel &ctxt, const std::string &type_name, const std::string &detector, bool shared=false)
Constructor only implemented for sensitive objects.
dd4hep::sim::KernelHandle::KernelHandle
KernelHandle(const KernelHandle &k)
Copy constructor.
Definition: Geant4Handle.h:105
handle
void handle(const O *o, const C &c, F pmf)
Definition: LCDDConverter.cpp:1105
dd4hep::sim::Geant4Handle::action
Geant4Action * action() const
Access to the underlying object.
Definition: Geant4Handle.cpp:183