ATLAS Offline Software
Loading...
Searching...
No Matches
TCS::AlgFactory Class Reference

#include <AlgFactory.h>

Collaboration diagram for TCS::AlgFactory:

Public Types

typedef std::unique_ptr< ConfigurableAlg >(* Creator) (const std::string &methodName)
 function type to create an algorithm

Public Member Functions

bool Register (const std::string &algType, Creator creator)
 Register creator function for algorithm type.
ConfigurableAlgcreate (const std::string &algType, const std::string &algName)
 Create algorithm of given type and name.
ConfigurableAlgalgorithm (const std::string &algName)
 Retrieve algorithm by name.
std::vector< std::string > getAllClassNames () const
void printAlgorithmNames () const

Static Public Member Functions

static const AlgFactoryinstance ()
 read-only access
static AlgFactory &mutable_instance ATLAS_NOT_THREAD_SAFE ()
 non-const access

Private Member Functions

 AlgFactory ()=default
 AlgFactory (const AlgFactory &)=delete
 no copy
AlgFactoryoperator= (const AlgFactory &)=delete
 no assign

Private Attributes

std::map< std::string, Creatorm_callMap
std::map< std::string, std::unique_ptr< TCS::ConfigurableAlg > > m_algs

Detailed Description

Definition at line 16 of file AlgFactory.h.

Member Typedef Documentation

◆ Creator

typedef std::unique_ptr< ConfigurableAlg >(* TCS::AlgFactory::Creator) (const std::string &methodName)

function type to create an algorithm

Definition at line 19 of file AlgFactory.h.

Constructor & Destructor Documentation

◆ AlgFactory() [1/2]

TCS::AlgFactory::AlgFactory ( )
privatedefault

◆ AlgFactory() [2/2]

TCS::AlgFactory::AlgFactory ( const AlgFactory & )
privatedelete

no copy

Member Function Documentation

◆ algorithm()

TCS::ConfigurableAlg * AlgFactory< ConcreteAlgorithm >::algorithm ( const std::string & algName)

Retrieve algorithm by name.

Definition at line 66 of file AlgFactory.cxx.

66 {
67 auto findRes = m_algs.find(algName);
68
69 if(findRes == m_algs.end())
70 return nullptr;
71
72 return findRes->second.get();
73}
std::map< std::string, std::unique_ptr< TCS::ConfigurableAlg > > m_algs
Definition AlgFactory.h:42

◆ ATLAS_NOT_THREAD_SAFE()

AlgFactory &mutable_instance TCS::AlgFactory::ATLAS_NOT_THREAD_SAFE ( )
static

non-const access

◆ create()

TCS::ConfigurableAlg * AlgFactory< ConcreteAlgorithm >::create ( const std::string & algType,
const std::string & algName )

Create algorithm of given type and name.

Definition at line 21 of file AlgFactory.cxx.

21 {
22
23 if( algorithm(algName) ) {
24 TCS_EXCEPTION("AlgFactory: algorithm " << algName << " already exists. Serious configuration error.")
25 }
26
27 // find creator function
28 const auto& it = m_callMap.find(algType);
29
30 // handle unknown algorithm request
31 if (it == m_callMap.end()) {
32 std::cout << "Registered algorithms are:" << std::endl;
33 for(const auto & x: m_callMap)
34 std::cout << " " << x.first << std::endl;
35 TCS_EXCEPTION("AlgFactory: trying to instantiate algorithm of type " << algType << " with name " << algName << ", but it has not been registered.");
36 }
37
38 auto createdAlg = (it->second)(algName);
39 auto [itr,inserted] = m_algs.emplace(algName, std::move(createdAlg));
40
41 return itr->second.get();
42}
#define x
std::map< std::string, Creator > m_callMap
Definition AlgFactory.h:41
std::string algorithm
Definition hcg.cxx:85

◆ getAllClassNames()

std::vector< std::string > AlgFactory< ConcreteAlgorithm >::getAllClassNames ( ) const

Definition at line 56 of file AlgFactory.cxx.

56 {
57 std::vector<std::string> classNames;
58 classNames.reserve(m_callMap.size());
59 for (const auto& [key, _] : m_callMap) {
60 classNames.push_back(key);
61 }
62 return classNames;
63}

◆ instance()

const TCS::AlgFactory & AlgFactory< ConcreteAlgorithm >::instance ( )
static

read-only access

Definition at line 7 of file AlgFactory.cxx.

8{
9 static const TCS::AlgFactory factory;
10 return factory;
11}

◆ operator=()

AlgFactory & TCS::AlgFactory::operator= ( const AlgFactory & )
privatedelete

no assign

◆ printAlgorithmNames()

void AlgFactory< ConcreteAlgorithm >::printAlgorithmNames ( ) const

Definition at line 77 of file AlgFactory.cxx.

77 {
78 for(const auto& [name, alg] : m_algs) {
79 std::cout << name << " --> " << alg->fullname() << std::endl;
80 }
81}

◆ Register()

bool AlgFactory< ConcreteAlgorithm >::Register ( const std::string & algType,
Creator creator )

Register creator function for algorithm type.

Definition at line 46 of file AlgFactory.cxx.

46 {
47 const auto& [itr, inserted] = m_callMap.emplace(algType, creator);
48 // registers a algorithm creator function under the algorithm class name
49 if (!inserted) {
50 TCS_EXCEPTION ("TCS::AlgFactory: registration of algorithm " << algType << " failed since it already exists");
51 }
52 return inserted;
53}

Member Data Documentation

◆ m_algs

std::map<std::string, std::unique_ptr<TCS::ConfigurableAlg> > TCS::AlgFactory::m_algs
private

Definition at line 42 of file AlgFactory.h.

◆ m_callMap

std::map<std::string, Creator> TCS::AlgFactory::m_callMap
private

Definition at line 41 of file AlgFactory.h.


The documentation for this class was generated from the following files: