Belle II Software development
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
14using namespace std;
15using namespace Belle2;
16using namespace Belle2::geometry;
17
19{
20 static unique_ptr<CreatorManager> instance(new CreatorManager());
21 return *instance;
22}
23
24//map<string, CreatorManager::CreatorFactory*> CreatorManager::m_creatorFactories;
25
26void CreatorManager::registerCreatorFactory(const std::string& name, CreatorFactory* factory)
27{
28 getInstance().m_creatorFactories[name] = factory;
29}
30
31CreatorBase* 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}
static bool loadLibrary(std::string library, bool fullname=true)
Load a shared library.
Definition: FileSystem.cc:63
Pure virtual base class for all geometry creators.
Definition: CreatorBase.h:28
Class to manage all creators and provide factory access.
static void registerCreatorFactory(const std::string &name, CreatorFactory *factory)
Register a new creator by providing a name and a pointer to a factory for this kind of creator.
static CreatorBase * getCreator(const std::string &name, const std::string &library="")
Return a new instance of a creator with the given name.
std::map< std::string, CreatorFactory * > m_creatorFactories
Static map to hold all registered factories.
CreatorManager()
singleton, hide constructor
static CreatorManager & getInstance()
getter for the singleton instance
Common code concerning the geometry representation of the detector.
Definition: CreatorBase.h:25
Abstract base class for different kinds of events.
STL namespace.
Very simple class to provide an easy way to register creators with the CreatorManager.