ATLAS Offline Software
AlgFactory.cxx
Go to the documentation of this file.
1 // Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 
6 const TCS::AlgFactory&
8 {
9  static const TCS::AlgFactory factory;
10  return factory;
11 }
12 
14 TCS::AlgFactory::mutable_instance ATLAS_NOT_THREAD_SAFE()
15 {
16  auto nc_instance = const_cast<TCS::AlgFactory*>(&instance());
17  return *nc_instance;
18 }
19 
21 TCS::AlgFactory::create(const std::string & algType, const std::string & algName) ATLAS_NOT_THREAD_SAFE {
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 }
43 
44 
45 bool
46 TCS::AlgFactory::Register( const std::string &algType, Creator creator ) {
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 }
54 
55 std::vector<std::string>
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 }
64 
66 TCS::AlgFactory::algorithm(const std::string & algName) {
67  auto findRes = m_algs.find(algName);
68 
69  if(findRes == m_algs.end())
70  return nullptr;
71 
72  return findRes->second.get();
73 }
74 
75 
76 void
78  for(const auto& [name, alg] : m_algs) {
79  std::cout << name << " --> " << alg->fullname() << std::endl;
80  }
81 }
algorithm
std::string algorithm
Definition: hcg.cxx:82
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
TCS::AlgFactory::printAlgorithmNames
void printAlgorithmNames() const
Definition: AlgFactory.cxx:77
skel.it
it
Definition: skel.GENtoEVGEN.py:396
ConfigurableAlg.h
TCS::AlgFactory::getAllClassNames
std::vector< std::string > getAllClassNames() const
Definition: AlgFactory.cxx:56
x
#define x
TCS::AlgFactory::instance
static const AlgFactory & instance()
read-only access
Definition: AlgFactory.cxx:7
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
AlgFactory.h
TCS::AlgFactory::algorithm
ConfigurableAlg * algorithm(const std::string &algName)
Retrieve algorithm by name.
Definition: AlgFactory.cxx:66
TCS_EXCEPTION
#define TCS_EXCEPTION(MSG)
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Exception.h:14
TCS::ConfigurableAlg
Definition: ConfigurableAlg.h:30
ATLAS_NOT_THREAD_SAFE
TCS::AlgFactory &TCS::AlgFactory::mutable_instance ATLAS_NOT_THREAD_SAFE()
Install fatal handler with default options.
Definition: AlgFactory.cxx:14
TCS::AlgFactory::Register
bool Register(const std::string &algType, Creator creator)
Register creator function for algorithm type.
Definition: AlgFactory.cxx:46
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TCS::AlgFactory::create
ConfigurableAlg * create(const std::string &algType, const std::string &algName)
Create algorithm of given type and name.
Definition: AlgFactory.cxx:21
Exception.h
TCS::AlgFactory
Definition: AlgFactory.h:16
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37