MarlinMT  0.1.0
GeometryManager.h
Go to the documentation of this file.
1 #ifndef MARLINMT_GEOMETRYMANAGER_h
2 #define MARLINMT_GEOMETRYMANAGER_h 1
3 
4 // -- std headers
5 #include <typeindex>
6 
7 // -- marlinmt headers
8 #include <marlinmt/Logging.h>
9 #include <marlinmt/Exceptions.h>
10 #include <marlinmt/Component.h>
12 
13 namespace marlinmt {
14 
15  class Application ;
16 
22  class GeometryManager : public Component {
23  public:
24  GeometryManager(const GeometryManager &) = delete ;
25  GeometryManager& operator=(const GeometryManager &) = delete ;
26  ~GeometryManager() = default ;
27 
31  GeometryManager() ;
32 
44  template <typename T>
45  const T *geometry() const ;
46 
50  std::type_index typeIndex() const ;
51 
55  void clear() ;
56 
57  private:
59  void initialize() override ;
60 
61  private:
63  std::shared_ptr<GeometryPlugin> _plugin {nullptr} ;
65  StringParameter _geometryType {*this, "GeometryType", "The geometry plugin type", "EmptyGeometry"} ;
66  };
67 
68  //--------------------------------------------------------------------------
69  //--------------------------------------------------------------------------
70 
71  template <typename T>
72  inline const T *GeometryManager::geometry() const {
73  if ( nullptr == _plugin ) {
74  throw Exception( "GeometryManager::geometry: geometry plugin not created !" ) ;
75  }
76  auto ptr = _plugin->handle() ;
77  if ( nullptr == ptr ) {
78  return nullptr ;
79  }
80  const T *castHandle = static_cast<const T*>( ptr ) ;
81  if ( nullptr == castHandle ) {
82  throw Exception( "GeometryManager::geometry: invalid geometry cast !" ) ;
83  }
84  return castHandle ;
85  }
86 
87 } // end namespace marlinmt
88 
89 #endif
GeometryManager class.
std::shared_ptr< GeometryPlugin > _plugin
The geometry plugin created on initialization.
Component class.
Definition: Component.h:22
void clear()
Clear the geometry content.
const T * geometry() const
Get the underlying geometry handle Example:
std::type_index typeIndex() const
Get the underlying geometry type info.
GeometryManager & operator=(const GeometryManager &)=delete
void initialize() override
Initialize geometry manager.
GeometryManager()
Default constructor.
StringParameter _geometryType
The geometry type, read as <geometry type="DD4hepGeometry">
Exception class.
Definition: Exceptions.h:60