ATLAS Offline Software
Loading...
Searching...
No Matches
L1TopoAlgorithm.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <map>
7
8TrigConf::L1TopoAlgorithm::L1TopoAlgorithm(const std::string & algoName, AlgorithmType algoType, const std::string & algoCategory, const boost::property_tree::ptree & data)
10 m_type(algoType),
11 m_category(algoCategory)
12{
13 if( m_category != "TOPO" && m_category != "MUTOPO" && m_category != "R2TOPO" && m_category != "MULTTOPO") {
14 throw std::runtime_error("Algorithm category must be TOPO, R2TOPO, MUTOPO or MULTTOPO, but is '" + algoCategory + "'");
15 }
16 m_name = algoName;
17 load();
18}
19
20std::string
22 return "L1TopoAlgorithm";
23}
24
25void
27{
28 if(! isInitialized() || empty() ) {
29 return;
30 }
31 if( m_type == AlgorithmType::DECISION ) { // DECISION algo
32 if( hasChild("input") ) {
33 for( auto & inp : getList("input")) {
34 m_inputs.push_back(inp.getValue());
35 }
36 } else if( hasChild("fixedParameters.inputs") ) { // backwards compatibility, to be removed when we stop using DEV db
37 for( auto & inp : getList("fixedParameters.inputs")) {
38 m_inputs.push_back(inp["value"]);
39 }
40 }
41 for( auto & o : getList("output")) {
42 m_outputs.push_back(o.getValue());
43 }
44 } else if( m_type == AlgorithmType::MULTIPLICITY ) { // MULTIPLICITY algo
45
46 if(auto & input = getAttribute("input"); input!="null") {
47 m_inputs.push_back(input);
48 }
49 if(hasAttribute("flavour")){ // EnergyThreshold
50 m_parameters.emplace_back("flavour", TrigConf::XEFlavour::flavourStrToInt(getAttribute("flavour")));
51 }
52 m_outputs.push_back(getAttribute("output"));
53 } else { // SORTING algo
54 if( hasAttribute("input") ) {
55 m_inputs.push_back( getAttribute("input") );
56 } else if( hasChild("fixedParameters.input") ) { // backwards compatibility, to be removed when we stop using DEV db
57 auto inp = getObject("fixedParameters.input");
58 for( auto & k : inp.getKeys() ) {
59 m_inputs.push_back(inp[k]);
60 break;
61 }
62 }
63 m_outputs.push_back(getAttribute("output"));
64 }
65
67 for( auto & p : getList("variableParameters") ) {
68 if (p["name"] == "MaxMSqr") {
69 unsigned int val = p.getAttribute<unsigned int>("value");
70 // Work around overflow in the database...
71 if (val >= 1u<<31) {
72 // Expected maximum value of Inv M^2 in 100 MeV unit
73 val = 1024*1024*10*10*10;
74 }
75 m_parameters.emplace_back(p["name"], val, p.getAttribute_optional<unsigned int>("selection"));
76 }
77 else {
78 m_parameters.emplace_back(p["name"], p.getAttribute<int>("value"), p.getAttribute_optional<unsigned int>("selection"));
79 }
80 }
81 }
82
83}
84
87{
88 return m_type;
89}
90
91const std::string &
96
97const std::string &
99{
100 if(hasAttribute("klass")) {
101 return getAttribute("klass");
102 }
103 return getAttribute("type");
104}
105
106const std::vector<std::string> &
108{
109 return m_inputs;
110}
111
112const std::vector<std::string> &
114{
115 return m_outputs;
116}
117
118std::vector<std::string>
120{
121 std::vector<std::string> out;
122 for( auto & s : m_outputs ) {
123 out.push_back(m_category + "_" + s);
124 }
125 return out;
126}
127
128std::string
129TrigConf::L1TopoAlgorithm::genericParameter(const std::string & parName) const
130{
131 return operator[]("fixedParameters.generics." + parName + ".value");
132}
133
136{
137 return getObject("fixedParameters.generics");
138}
139
140const std::vector<TrigConf::L1TopoAlgorithm::VariableParameter> &
145
146
147void
148TrigConf::L1TopoAlgorithm::print(std::ostream & os) const
149{
150 os << "Algorithm " << name() << " (class " << klass() << ", category " << m_category << ")" << std::endl;
151 os << " input:" << std::endl;
152 for( auto & input : inputs() ) {
153 os << " " << input << std::endl;
154 }
155 os << " output:" << std::endl;
156 for( auto & output : outputs() ) {
157 os << " " << output << std::endl;
158 }
159 os << " full output:" << std::endl;
160 for( auto & output : fullOutputs() ) {
161 os << " " << output << std::endl;
162 }
164 os << " threshold definition: " << getAttribute("threshold") << std::endl;
165 os << " number of output bits: " << getAttribute<unsigned int>("nbits") << std::endl;
166 } else {
167 os << " generic parameters:" << std::endl;
168 auto genPars = generics();
169 for( auto & k : genPars.getKeys() ) {
170 os << " " << k << " ==> " << genericParameter(k) << std::endl;
171 }
172 os << " parameters:" << std::endl;
173 auto pars = parameters();
174 unsigned int idx{0};
175 for( auto & p : pars ) {
176 os << " " << idx++ << " " << p.name() << "[" << p.selection() << "] ==> " << p.value() << std::endl;
177 }
178 }
179 os << std::endl;
180}
static const Attributes_t empty
Base class for Trigger configuration data and wrapper around underlying representation.
virtual const std::string & name() const final
std::vector< DataStructure > getList(const std::string &pathToChild, bool ignoreIfMissing=false) const
Access to array structure.
const ptree & data() const
Access to the underlying data, if needed.
bool hasAttribute(const std::string &key) const
Check for attribute.
DataStructure()
Default constructor, leading to an uninitialized configuration object.
T getAttribute(const std::string &key, bool ignoreIfMissing=false, const T &def=T()) const
Access to simple attribute.
bool hasChild(const std::string &path) const
Check if child exists.
DataStructure getObject(const std::string &pathToChild, bool ignoreIfMissing=false) const
Access to configuration object.
std::string operator[](const std::string &key) const
Access to simple attribute.
virtual std::string className() const override
A string that is the name of the class.
L1TopoAlgorithm()=default
Constructor.
DataStructure generics() const
Accessors to generic parameters.
std::vector< std::string > fullOutputs() const
void print(std::ostream &os=std::cout) const override
print main info
std::string genericParameter(const std::string &parName) const
const std::vector< std::string > & inputs() const
Accessor to input collections Sorting and Multiplicity algorithms have only one input.
const std::vector< std::string > & outputs() const
Accessor to output collections Sorting and Multiplicity algorithms have only one output.
std::vector< VariableParameter > m_parameters
const std::vector< VariableParameter > & parameters() const
Accessor to register parameters which can change for each algorithm instance.
const std::string & category() const
void load()
Update the internal data after modification of the data object.
AlgorithmType type() const
std::vector< std::string > m_inputs
std::vector< std::string > m_outputs
const std::string & klass() const
Accessor to algorithm class type.
static unsigned int flavourStrToInt(const std::string &flavStr)