ATLAS Offline Software
Loading...
Searching...
No Matches
AlgFactory.h
Go to the documentation of this file.
1// Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
2#ifndef L1TopoInterfaces_AlgFactory
3#define L1TopoInterfaces_AlgFactory
4
6
7#include <string>
8#include <vector>
9#include <map>
10#include <memory>
11
12namespace TCS {
13
14 class ConfigurableAlg;
15
16 class AlgFactory {
17 public:
19 typedef std::unique_ptr<ConfigurableAlg> (*Creator)(const std::string & methodName);
20
21 static const AlgFactory& instance();
22 static AlgFactory& mutable_instance ATLAS_NOT_THREAD_SAFE();
23
25 bool Register( const std::string &algType, Creator creator );
26
28 ConfigurableAlg* create(const std::string & algType, const std::string & algName);
29
31 ConfigurableAlg* algorithm(const std::string & algName);
32
33 std::vector<std::string> getAllClassNames() const;
34 void printAlgorithmNames() const;
35
36 private:
37 AlgFactory() = default; //<! singleton created via instance()
38 AlgFactory(const AlgFactory&) = delete;
39 AlgFactory& operator=(const AlgFactory&) = delete;
40
41 std::map<std::string, Creator> m_callMap;
42 std::map<std::string, std::unique_ptr<TCS::ConfigurableAlg>> m_algs;
43 };
44
45}
46
47// Macro to register algorithm in arbitrary namespace
48#define REGISTER_ALG_NS(NS,CLASS) \
49 namespace { \
50 std::unique_ptr<TCS::ConfigurableAlg> Create##NS__##CLASS(const std::string & methodName) { \
51 auto alg = std::make_unique<NS::CLASS>(methodName); \
52 alg->setClassName( std::string(#NS) + "__" + #CLASS ); \
53 alg->msg().setName( alg->fullname() ); \
54 return alg; \
55 } \
56 \
57 const bool success = TCS::AlgFactory::mutable_instance().Register( std::string(#NS) + "__" + #CLASS, Create##NS__##CLASS); \
58 }
59
60
61// Macro to register algorithm in TCS namespace
62#define REGISTER_ALG_TCS(CLASS) \
63 namespace { \
64 std::unique_ptr<TCS::ConfigurableAlg> Create##CLASS(const std::string & methodName) { \
65 auto alg = std::make_unique<TCS::CLASS>(methodName); \
66 alg->setClassName( #CLASS ); \
67 alg->msg().setName( alg->fullname() ); \
68 return alg; \
69 } \
70 \
71 const bool success = TCS::AlgFactory::mutable_instance().Register( #CLASS, Create##CLASS); \
72 }
73
74
75#endif
Define macros for attributes used to control the static checker.
bool Register(const std::string &algType, Creator creator)
Register creator function for algorithm type.
static AlgFactory &mutable_instance ATLAS_NOT_THREAD_SAFE()
non-const access
ConfigurableAlg * create(const std::string &algType, const std::string &algName)
Create algorithm of given type and name.
std::unique_ptr< ConfigurableAlg >(* Creator)(const std::string &methodName)
function type to create an algorithm
Definition AlgFactory.h:19
std::map< std::string, Creator > m_callMap
Definition AlgFactory.h:41
std::map< std::string, std::unique_ptr< TCS::ConfigurableAlg > > m_algs
Definition AlgFactory.h:42
static const AlgFactory & instance()
read-only access
Definition AlgFactory.cxx:7
AlgFactory()=default
void printAlgorithmNames() const
std::vector< std::string > getAllClassNames() const
AlgFactory & operator=(const AlgFactory &)=delete
no assign
AlgFactory(const AlgFactory &)=delete
no copy
std::string algorithm
Definition hcg.cxx:85