Belle II Software  release-05-02-19
ModuleManager.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Andreas Moll *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/core/FrameworkExceptions.h>
14 
15 #include <memory>
16 
17 #include <string>
18 #include <map>
19 #include <list>
20 
21 namespace boost {
22  namespace filesystem {
23  class directory_entry;
24  }
25 }
26 
27 namespace Belle2 {
33  class Module;
34  class ModuleProxyBase;
35 
60  class ModuleManager {
61 
62  public:
63 
64  //Define exceptions
66  BELLE2_DEFINE_EXCEPTION(ModuleNotCreatedError, "Cannot create module %1%: %2%")
67 
68 
73  static ModuleManager& Instance();
74 
82  void registerModuleProxy(ModuleProxyBase* moduleProxy);
83 
94  void addModuleSearchPath(const std::string& path);
95 
101  const std::list<std::string>& getModuleSearchPaths() const;
102 
110  const std::map<std::string, std::string>& getAvailableModules() const;
111 
128  std::shared_ptr<Module> registerModule(const std::string& moduleName,
129  std::string sharedLibPath = "") noexcept(false);
130 
136  const std::list< std::shared_ptr<Module> >& getCreatedModules() const;
137 
148  static std::list< std::shared_ptr<Module> > getModulesByProperties(const std::list< std::shared_ptr<Module> >& modulePathList,
149  unsigned int propertyFlags);
150 
152  static bool allModulesHaveFlag(const std::list<std::shared_ptr<Module>>& list, unsigned int flag);
153 
155  void reset();
156 
157 
158  private:
160  std::list<std::string> m_moduleSearchPathList;
161 
163  std::map<std::string, std::string> m_moduleNameLibMap;
164 
165  std::map<std::string, ModuleProxyBase*> m_registeredProxyMap;
166  std::list< std::shared_ptr<Module> > m_createdModulesList;
176  static void fillModuleNameLibMap(std::map<std::string, std::string>& moduleNameLibMap,
177  const boost::filesystem::directory_entry& mapPath);
178 
182  ModuleManager();
183 
188 
193 
198  ~ModuleManager();
199  };
200 
202 } //end of namespace Belle2
Belle2::ModuleManager::getModuleSearchPaths
const std::list< std::string > & getModuleSearchPaths() const
Returns a reference to the list of the modules search filepaths.
Definition: ModuleManager.cc:72
Belle2::ModuleManager::registerModule
std::shared_ptr< Module > registerModule(const std::string &moduleName, std::string sharedLibPath="") noexcept(false)
Creates an instance of a module and registers it to the ModuleManager.
Definition: ModuleManager.cc:84
Belle2::ModuleManager::Instance
static ModuleManager & Instance()
Exception is thrown if the requested module could not be created by the ModuleManager.
Definition: ModuleManager.cc:28
Belle2::ModuleManager::addModuleSearchPath
void addModuleSearchPath(const std::string &path)
Adds a new filepath to the list of filepaths which are searched for a requested module.
Definition: ModuleManager.cc:47
Belle2::ModuleManager::getAvailableModules
const std::map< std::string, std::string > & getAvailableModules() const
Returns a map of all modules that were found in the module search paths.
Definition: ModuleManager.cc:78
Belle2::ModuleManager::getModulesByProperties
static std::list< std::shared_ptr< Module > > getModulesByProperties(const std::list< std::shared_ptr< Module > > &modulePathList, unsigned int propertyFlags)
Returns a list of those modules which carry property flags matching the specified ones.
Definition: ModuleManager.cc:134
Belle2::ModuleManager::fillModuleNameLibMap
static void fillModuleNameLibMap(std::map< std::string, std::string > &moduleNameLibMap, const boost::filesystem::directory_entry &mapPath)
Adds the module names defined in the map file to the list of known module names.
Definition: ModuleManager.cc:158
Belle2::ModuleProxyBase
The base module proxy class is used to create new instances of a module.
Definition: Module.h:599
Belle2::ModuleManager::allModulesHaveFlag
static bool allModulesHaveFlag(const std::list< std::shared_ptr< Module >> &list, unsigned int flag)
Returns true if and only if all modules in list have the given flag (or list is empty).
Definition: ModuleManager.cc:144
Belle2::ModuleManager::registerModuleProxy
void registerModuleProxy(ModuleProxyBase *moduleProxy)
Registers a module proxy.
Definition: ModuleManager.cc:35
Belle2::ModuleManager::m_createdModulesList
std::list< std::shared_ptr< Module > > m_createdModulesList
List of all created modules.
Definition: ModuleManager.h:166
Belle2::ModuleManager::getCreatedModules
const std::list< std::shared_ptr< Module > > & getCreatedModules() const
Returns a reference to the list of created modules.
Definition: ModuleManager.cc:128
Belle2::ModuleManager::m_moduleNameLibMap
std::map< std::string, std::string > m_moduleNameLibMap
Maps the module name to the filename of the shared library which containes the module.
Definition: ModuleManager.h:163
Belle2::ModuleManager::operator=
ModuleManager & operator=(const ModuleManager &)
Disable/Hide the copy assignment operator.
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ModuleManager::reset
void reset()
Delete all created modules.
Definition: ModuleManager.cc:203
Belle2::ModuleManager::~ModuleManager
~ModuleManager()
The ModuleManager destructor.
Belle2::ModuleManager
The ModuleManager Class.
Definition: ModuleManager.h:60
Belle2::ModuleManager::m_moduleSearchPathList
std::list< std::string > m_moduleSearchPathList
List of all checked and validated filepaths that are searched for map files.
Definition: ModuleManager.h:160
BELLE2_DEFINE_EXCEPTION
#define BELLE2_DEFINE_EXCEPTION(ClassName, Message)
Macro that defines an exception with the given message template.
Definition: FrameworkExceptions.h:46
Belle2::ModuleManager::m_registeredProxyMap
std::map< std::string, ModuleProxyBase * > m_registeredProxyMap
Maps the module name to a pointer of its proxy.
Definition: ModuleManager.h:165
Belle2::ModuleManager::ModuleManager
ModuleManager()
The constructor is hidden to avoid that someone creates an instance of this class.