MarlinMT  0.1.0
GeometryManager.cc
Go to the documentation of this file.
2 
3 // -- marlinmt headers
5 #include "marlinmt/Application.h"
6 
7 namespace marlinmt {
8 
10  Component( "GeometryManager" ) {
11  setName( "Geometry" ) ;
12  }
13 
14  //--------------------------------------------------------------------------
15 
17  auto &config = application().configuration() ;
18  if( config.hasSection("geometry") ) {
19  const auto &section = config.section("geometry") ;
20  setParameters( section ) ;
21  }
22  auto geomType = _geometryType.get() ;
23  message() << "Loading geometry plugin: " << geomType << std::endl ;
24  auto &mgr = PluginManager::instance() ;
25  _plugin = mgr.create<GeometryPlugin>( geomType ) ;
26  if ( nullptr == _plugin ) {
27  MARLINMT_THROW( "Couldn't find geometry plugin '" + geomType + "'" ) ;
28  }
29  if( config.hasSection("geometry") ) {
30  const auto &section = config.section("geometry") ;
31  _plugin->setParameters( section ) ;
32  }
33  _plugin->setup( &application() ) ;
34  _plugin->print() ;
35  }
36 
37  //--------------------------------------------------------------------------
38 
39  std::type_index GeometryManager::typeIndex() const {
40  if ( nullptr == _plugin ) {
41  MARLINMT_THROW( "Geometry not initialized !" ) ;
42  }
43  return _plugin->typeIndex() ;
44  }
45 
46  //--------------------------------------------------------------------------
47 
49  if ( nullptr != _plugin ) {
50  _plugin->destroy() ;
51  _plugin = nullptr ;
52  }
53  }
54 
55 } // namespace marlinmt
void setName(const std::string &n)
Set the component name.
Definition: Component.cc:29
void setParameters(const ConfigSection &section, bool throwIfNotFound=false)
Set the parameters from the configuration section.
Definition: Component.cc:124
Logging::StreamType message() const
Shortcut for log<MESSAGE>()
Definition: Component.cc:53
#define MARLINMT_THROW(message)
Definition: Exceptions.h:8
std::shared_ptr< GeometryPlugin > _plugin
The geometry plugin created on initialization.
Component class.
Definition: Component.h:22
void clear()
Clear the geometry content.
ConfigSection & section(const std::string &sn)
Get a section by name.
std::type_index typeIndex() const
Get the underlying geometry type info.
void initialize() override
Initialize geometry manager.
const Application & application() const
Get the application in which the component is registered.
Definition: Component.cc:83
T get() const
Get the parameter value.
Definition: Parameter.h:556
GeometryManager()
Default constructor.
GeometryPlugin class Responsible for loading geometry in Marlin and providing access to it through th...
StringParameter _geometryType
The geometry type, read as <geometry type="DD4hepGeometry">
static PluginManager & instance()
Get the plugin manager instance.
const Configuration & configuration() const
Get the main application configuration object.
Definition: Application.cc:278