ATLAS Offline Software
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
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 More...
 

Public Member Functions

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

Static Public Member Functions

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

Private Member Functions

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

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 }

◆ ATLAS_NOT_THREAD_SAFE()

static 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 }

◆ 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:
TCS::AlgFactory::m_callMap
std::map< std::string, Creator > m_callMap
Definition: AlgFactory.h:41
SGout2dot.alg
alg
Definition: SGout2dot.py:243
Run3DQTestingDriver._
_
Definition: Run3DQTestingDriver.py:35
xAOD::JetAlgorithmType::algName
const std::string & algName(ID id)
Converts a JetAlgorithmType::ID into a string.
Definition: JetContainerInfo.cxx:67
skel.it
it
Definition: skel.GENtoEVGEN.py:423
x
#define x
TCS::AlgFactory::algorithm
ConfigurableAlg * algorithm(const std::string &algName)
Retrieve algorithm by name.
Definition: AlgFactory.cxx:66
TCS::AlgFactory::m_algs
std::map< std::string, std::unique_ptr< TCS::ConfigurableAlg > > m_algs
Definition: AlgFactory.h:42
TCS_EXCEPTION
#define TCS_EXCEPTION(MSG)
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Exception.h:14
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
TCS::AlgFactory
Definition: AlgFactory.h:16
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37