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