Belle II Software  release-05-02-19
CreatorManager.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <geometry/CreatorManager.h>
12 #include <framework/logging/Logger.h>
13 #include <framework/utilities/FileSystem.h>
14 #include <memory>
15 
16 using namespace std;
17 using namespace Belle2;
18 using namespace Belle2::geometry;
19 
20 CreatorManager& CreatorManager::getInstance()
21 {
22  static unique_ptr<CreatorManager> instance(new CreatorManager());
23  return *instance;
24 }
25 
26 //map<string, CreatorManager::CreatorFactory*> CreatorManager::m_creatorFactories;
27 
28 void CreatorManager::registerCreatorFactory(const std::string& name, CreatorFactory* factory)
29 {
30  getInstance().m_creatorFactories[name] = factory;
31 }
32 
33 CreatorBase* CreatorManager::getCreator(const string& name, const string& library)
34 {
35  if (!library.empty()) {
36  FileSystem::loadLibrary(library, false);
37  }
38 
39  CreatorManager& instance = getInstance();
40  auto it = instance.m_creatorFactories.find(name);
41  if (it == instance.m_creatorFactories.end()) {
42  B2ERROR("Could not find a geometry creator named " << name);
43  return nullptr;
44  }
45  return it->second();
46 }
Belle2::geometry::CreatorManager
Class to manage all creators and provide factory access.
Definition: CreatorManager.h:35
Belle2::geometry
Common code concerning the geometry representation of the detector.
Definition: CreatorBase.h:28
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::geometry::CreatorManager::m_creatorFactories
std::map< std::string, CreatorFactory * > m_creatorFactories
Static map to hold all registered factories.
Definition: CreatorManager.h:74
Belle2::geometry::CreatorBase
Pure virtual base class for all geometry creators.
Definition: CreatorBase.h:31
Belle2::geometry::CreatorFactory
Very simple class to provide an easy way to register creators with the CreatorManager.
Definition: CreatorFactory.h:42