ATLAS Offline Software
Loading...
Searching...
No Matches
AlgFactory.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5
8{
9 static const TCS::AlgFactory factory;
10 return factory;
11}
12
14TCS::AlgFactory::mutable_instance ATLAS_NOT_THREAD_SAFE()
15{
16 auto nc_instance = const_cast<TCS::AlgFactory*>(&instance());
17 return *nc_instance;
18}
19
20TCS::ConfigurableAlg *
21TCS::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
45bool
46TCS::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
55std::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
66TCS::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
76void
78 for(const auto& [name, alg] : m_algs) {
79 std::cout << name << " --> " << alg->fullname() << std::endl;
80 }
81}
std::map< std::string, double > instance
#define x
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
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
ConfigurableAlg * algorithm(const std::string &algName)
Retrieve algorithm by name.
void printAlgorithmNames() const
std::vector< std::string > getAllClassNames() const
std::string algorithm
Definition hcg.cxx:85