ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigT1
L1Topo
L1TopoInterfaces
Root
AlgFactory.cxx
Go to the documentation of this file.
1
// Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
#include "
L1TopoInterfaces/AlgFactory.h
"
3
#include "
L1TopoInterfaces/ConfigurableAlg.h
"
4
#include "
L1TopoCommon/Exception.h
"
5
6
const
TCS::AlgFactory
&
7
TCS::AlgFactory::instance
()
8
{
9
static
const
TCS::AlgFactory
factory;
10
return
factory;
11
}
12
13
TCS::AlgFactory
&
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
20
TCS::ConfigurableAlg *
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>
56
TCS::AlgFactory::getAllClassNames
()
const
{
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
65
TCS::ConfigurableAlg
*
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
77
TCS::AlgFactory::printAlgorithmNames
()
const
{
78
for
(
const
auto
& [name, alg] :
m_algs
) {
79
std::cout << name <<
" --> "
<< alg->fullname() << std::endl;
80
}
81
}
AlgFactory.h
ConfigurableAlg.h
instance
std::map< std::string, double > instance
Definition
Run_To_Get_Tags.h:8
Exception.h
TCS_EXCEPTION
#define TCS_EXCEPTION(MSG)
Definition
Trigger/TrigT1/L1Topo/L1TopoCommon/L1TopoCommon/Exception.h:15
x
#define x
ATLAS_NOT_THREAD_SAFE
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
Definition
checker_macros.h:212
TCS::AlgFactory
Definition
AlgFactory.h:16
TCS::AlgFactory::Register
bool Register(const std::string &algType, Creator creator)
Register creator function for algorithm type.
Definition
AlgFactory.cxx:46
TCS::AlgFactory::ATLAS_NOT_THREAD_SAFE
static AlgFactory &mutable_instance ATLAS_NOT_THREAD_SAFE()
non-const access
TCS::AlgFactory::create
ConfigurableAlg * create(const std::string &algType, const std::string &algName)
Create algorithm of given type and name.
Definition
AlgFactory.cxx:21
TCS::AlgFactory::Creator
std::unique_ptr< ConfigurableAlg >(* Creator)(const std::string &methodName)
function type to create an algorithm
Definition
AlgFactory.h:19
TCS::AlgFactory::m_callMap
std::map< std::string, Creator > m_callMap
Definition
AlgFactory.h:41
TCS::AlgFactory::m_algs
std::map< std::string, std::unique_ptr< TCS::ConfigurableAlg > > m_algs
Definition
AlgFactory.h:42
TCS::AlgFactory::instance
static const AlgFactory & instance()
read-only access
Definition
AlgFactory.cxx:7
TCS::AlgFactory::algorithm
ConfigurableAlg * algorithm(const std::string &algName)
Retrieve algorithm by name.
Definition
AlgFactory.cxx:66
TCS::AlgFactory::printAlgorithmNames
void printAlgorithmNames() const
Definition
AlgFactory.cxx:77
TCS::AlgFactory::getAllClassNames
std::vector< std::string > getAllClassNames() const
Definition
AlgFactory.cxx:56
TCS::ConfigurableAlg
Definition
ConfigurableAlg.h:31
algorithm
std::string algorithm
Definition
hcg.cxx:87
Generated on
for ATLAS Offline Software by
1.17.0