ATLAS Offline Software
Loading...
Searching...
No Matches
L1Menu.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6using namespace std;
7
8#include <iterator>
9#include <utility>
12
13TrigConf::L1Menu::L1Menu(const boost::property_tree::ptree & data)
15{
16 load();
17}
18
19void
21{
22 if(! isInitialized() || empty() ) {
23 return;
24 }
25
26 m_run = getAttribute_optional<int>("run").value_or(3);
27
28 // thresholds
29 try {
30 m_name = getAttribute("name");
31 for( const std::string path : {"thresholds", "thresholds.legacyCalo" } ) {
32 for( auto & thrByType : data().get_child( path ) ) {
33 const std::string & thrType = thrByType.first;
34 if (thrType == "legacyCalo")
35 continue;
36
37 // first create the extraInfo object for this type of thresholds
38 auto extraInfo = m_thrExtraInfo.addExtraInfo(thrByType.first,thrByType.second);
39
40 auto & v = m_thresholdsByType[thrType] = std::vector<std::shared_ptr<TrigConf::L1Threshold>>();
41 if(thrType == "internal") {
42 for( auto & thr : data().get_child( path + ".internal.names") ) {
43 const std::string thrName = thr.second.data();
44 v.push_back( L1Threshold::createThreshold( thrName, thrType, extraInfo, thr.second ) );
45 }
46 } else {
47 for( auto & thr : data().get_child( path + "." + thrType + ".thresholds") ) {
48 const std::string thrName = thr.first;
49 v.push_back( L1Threshold::createThreshold( thrName, thrType, extraInfo, thr.second ) );
50 }
51 }
52 for( auto & thr : v ) {
53 m_thresholdsByName[ thr->name() ] = thr;
54 }
55 for (auto &thr : v) {
56 m_thresholdsByTypeAndMapping[thrType][thr->mapping()] = thr;
57 }
58 }
59 }
60 }
61 catch(std::exception & ex) {
62 std::cerr << "ERROR: problem when building L1 menu structure (thresholds). " << ex.what() << std::endl;
63 throw;
64 }
65
66 // boards
67 try {
68 for( auto & board : data().get_child( "boards" ) ) {
69 m_boards.emplace( std::piecewise_construct,
70 std::forward_as_tuple(board.first),
71 std::forward_as_tuple(board.first, board.second) );
72 }
73 }
74 catch(std::exception & ex) {
75 std::cerr << "ERROR: problem when building L1 menu structure (boards). " << ex.what() << std::endl;
76 throw;
77 }
78
79 // connectors
80 try {
81 for( auto & conn : data().get_child( "connectors" ) ) {
82 auto res = m_connectors.emplace( std::piecewise_construct,
83 std::forward_as_tuple(conn.first),
84 std::forward_as_tuple(conn.first, conn.second) );
85 for( auto & tl : res.first->second.triggerLineNames() ) {
86 m_threshold2ConnectorName.emplace( std::piecewise_construct,
87 std::forward_as_tuple(tl),
88 std::forward_as_tuple(conn.first));
89 }
90 }
91 }
92 catch(std::exception & ex) {
93 std::cerr << "ERROR: problem when building L1 menu structure (connectors). " << ex.what() << std::endl;
94 throw;
95 }
96
97 // algorithms
98 if(m_run>1) {
99 try {
100 auto topoCategories = isRun2() ? std::vector<std::string> {"R2TOPO"} : std::vector<std::string> {"TOPO", "MUTOPO", "MULTTOPO", "R2TOPO"};
101 for( const std::string& algoCategory : topoCategories ) {
102 auto & v = m_algorithmsByCategory[algoCategory] = std::vector<TrigConf::L1TopoAlgorithm>();
103 m_algorithmsByName.emplace(algoCategory, std::map<std::string, TrigConf::L1TopoAlgorithm*>());
104 m_algorithmsByOutput.emplace(algoCategory, std::map<std::string, TrigConf::L1TopoAlgorithm*>());
105 if(algoCategory == "MULTTOPO") {
106 for( auto & alg : data().get_child( "topoAlgorithms." + algoCategory + ".multiplicityAlgorithms" ) ) {
107 v.emplace_back( alg.first, L1TopoAlgorithm::AlgorithmType::MULTIPLICITY, algoCategory, alg.second );
108 }
109 } else {
111 std::string subpath = "topoAlgorithms." + algoCategory + (algoType==L1TopoAlgorithm::AlgorithmType::DECISION ? ".decisionAlgorithms" : ".sortingAlgorithms" );
112 for( auto & algorithm : data().get_child( subpath ) ) {
113 v.emplace_back( algorithm.first, algoType, algoCategory, algorithm.second );
114 }
115 }
116 }
117 for( auto & algo : v ) {
118 if( m_algorithmsByName[algoCategory].count(algo.name()) > 0 ) {
119 std::cerr << "ERROR : Topo algorithm with name " << algo.name() << " and of type " << algoCategory << " already exists" << std::endl;
120 throw std::runtime_error("Found duplicate topo algorithm name " + algo.name() + " of type " + algoCategory);
121 }
122 m_algorithmsByName[ algoCategory ][ algo.name() ] = & algo;
123 for( const std::string & output : algo.outputs() ) {
124 if( m_algorithmsByOutput[algoCategory].count(output) > 0 ) {
125 std::cerr << "ERROR : Topo algorithm output " << output << " already exists" << std::endl;
126 throw std::runtime_error("Found duplicate topo algorithm output " + output + " of type " + algoCategory);
127 }
128 m_algorithmsByOutput[algoCategory][output] = & algo;
129 }
130 }
131 }
132 }
133 catch(std::exception & ex) {
134 std::cerr << "ERROR: problem when building L1 menu structure (algorithms). " << ex.what() << std::endl;
135 throw;
136 }
137 }
138
139 // CTP
140 try {
141 m_ctp.setData(data().get_child("ctp"));
142 }
143 catch(std::exception & ex) {
144 std::cerr << "ERROR: problem when building L1 menu structure (CTP). " << ex.what() << std::endl;
145 throw;
146 }
147}
148
149void
151{
153
154 m_smk = 0;
155 m_run = 3;
156 m_connectors.clear();
158 m_boards.clear();
159 m_thresholdsByType.clear();
160 m_thresholdsByName.clear();
162
163 m_thrExtraInfo.clear();
164
166 m_algorithmsByName.clear();
167 m_algorithmsByOutput.clear();
168
169 m_ctp.clear();
170}
171
172unsigned int
174{
175 return getAttribute<unsigned int>("version");
176}
177
178unsigned int
180{
181 return getAttribute<unsigned int>("ctpVersion");
182}
183
184std::size_t
186{
187 return data().get_child("items").size();
188}
189
190unsigned int
192 return m_smk;
193}
194
195void
197 m_smk = smk;
198}
199
201TrigConf::L1Menu::item(const std::string & itemName) const
202{
203 if(itemName=="") {
204 throw std::runtime_error("L1Menu::item() was called with empty itemName");
205 }
206 const ptree * pt;
207 try {
208 pt = & data().get_child(ptree::path_type("items/"+itemName,'/')); // '/' is not used in any item Name, so we can use it as separator in the path
209 } catch(boost::property_tree::ptree_bad_path & ex) {
210 throw std::runtime_error("L1Item " + itemName + " does not exist in the menu");
211 }
212 return L1Item(*pt);
213}
214
217{
218 return {data().get_child("items"), 0, [](auto & x){return L1Item(x.second);}};
219}
220
221
224{
225 const auto & items = data().get_child("items");
226 return {items, items.size(), [](auto & x){return L1Item(x.second);}};
227}
228
229
230std::vector<std::string>
232{
233 std::vector<std::string> thrTypeNames;
234 thrTypeNames.reserve(m_thresholdsByType.size());
235 for( const auto & x : m_thresholdsByType ) {
236 thrTypeNames.emplace_back(x.first);
237 }
238 return thrTypeNames;
239}
240
241std::vector<std::string>
243{
244 std::vector<std::string> thrNames;
245 thrNames.reserve(m_thresholdsByName.size());
246 for( const auto & x : m_thresholdsByName ) {
247 thrNames.emplace_back(x.first);
248 }
249 return thrNames;
250}
251
252
253const std::vector<std::shared_ptr<TrigConf::L1Threshold>>&
254TrigConf::L1Menu::thresholds(std::string_view typeName) const
255{
256 const auto it = m_thresholdsByType.find(typeName);
257 if (it == m_thresholdsByType.end()) {
258 std::cerr << "No threshold type '" << typeName
259 << "' defined in the thresholds section of the L1 menu" << std::endl;
260 throw std::out_of_range("No threshold type defined in the thresholds section of the L1 menu");
261 }
262 return it->second;
263}
264
265std::vector<std::shared_ptr<TrigConf::L1Threshold>>
267{
268 std::vector<std::shared_ptr<TrigConf::L1Threshold>> thrlist;
269 for ( const std::string & type : thresholdTypes() ) {
270 const auto & thrOfType = thresholds(type);
271 std::copy(thrOfType.begin(), thrOfType.end(), std::back_inserter(thrlist));
272 }
273 return thrlist;
274}
275
276
278TrigConf::L1Menu::threshold(std::string_view thresholdName) const
279{
280 const auto it = m_thresholdsByName.find(thresholdName);
281 if (it == m_thresholdsByName.end()) {
282 std::cerr << "No threshold '" << thresholdName
283 << "' defined in the thresholds section of the L1 menu" << std::endl;
284 throw std::out_of_range("No threshold defined in the thresholds section of the L1 menu");
285 }
286
287 return *it->second;
288}
289
292TrigConf::L1Menu::threshold(std::string_view typeName, unsigned int mapping) const
293{
294 const auto typeIt = m_thresholdsByTypeAndMapping.find(typeName);
295 if (typeIt == m_thresholdsByTypeAndMapping.end()) {
296 std::cerr << "No threshold of type '" << typeName
297 << "' defined in the thresholds section of the L1 menu" << std::endl;
298 throw std::out_of_range("No threshold type defined in the thresholds section of the L1 menu");
299 }
300
301 const auto mappingIt = typeIt->second.find(mapping);
302 if (mappingIt == typeIt->second.end()) {
303 std::cerr << "No threshold of type '" << typeName
304 << "' with mapping " << mapping
305 << " defined in the thresholds section of the L1 menu" << std::endl;
306 throw std::out_of_range("No threshold mapping defined in the thresholds section of the L1 menu");
307 }
308
309 return *mappingIt->second;
310}
311
314{
315 return m_thrExtraInfo;
316}
317
318const std::string &
319TrigConf::L1Menu::connectorNameFromThreshold(const std::string & thresholdName) const
320{
321 try {
322 return m_threshold2ConnectorName.at(thresholdName);
323 }
324 catch(...) {
325 std::cerr << "Threshold '" << thresholdName << "' not defined as triggerline in the L1 menu" << std::endl;
326 throw;
327 }
328}
329
330std::vector<std::string>
332 std::vector<std::string> connNames;
333 connNames.reserve(m_connectors.size());
334 for( auto & x : m_connectors ) {
335 connNames.emplace_back(x.first);
336 }
337 return connNames;
338}
339
341TrigConf::L1Menu::connector(const std::string & connectorName) const {
342 try {
343 return m_connectors.at(connectorName);
344 }
345 catch(std::exception & ex) {
346 std::cerr << "No connector " << connectorName << " defined in the L1 menu" << std::endl;
347 throw;
348 }
349}
350
352std::vector<std::string>
353TrigConf::L1Menu::topoAlgorithmNames(const std::string & category) const
354{
355 std::vector<std::string> algoNames;
356 try {
357 for(auto & entry : m_algorithmsByName.at(category) ) {
358 algoNames.push_back(entry.first);
359 }
360 }
361 catch(std::exception & ex) {
362 std::cerr << "No algorithm category '" << category << "' defined in the L1 menu" << std::endl;
363 throw;
364 }
365 return algoNames;
366}
367
369std::vector<std::string>
370TrigConf::L1Menu::topoAlgorithmOutputNames(const std::string & category) const
371{
372 std::vector<std::string> outputNames;
373 try {
374 for(auto & entry : m_algorithmsByOutput.at(category) ) {
375 outputNames.push_back(entry.first);
376 }
377 }
378 catch(std::exception & ex) {
379 std::cerr << "No algorithm category '" << category << "' defined in the L1 menu" << std::endl;
380 throw;
381 }
382 return outputNames;
383}
384
385
386
388TrigConf::L1Menu::algorithm(const std::string & algoName, std::string_view category) const
389{
390 const auto itr = m_algorithmsByName.find(category);
391 if (itr == m_algorithmsByName.end()){
392 throw std::out_of_range("TrigConf::L1Menu::algorithm: No algorithm of category "+std::string{category}+ " found.");
393 }
394 try {
395 return * itr->second.at(algoName);
396 }
397 catch(std::exception & ex) {
398 std::cerr << "No algorithm " << algoName << " in the " << category << "category defined in the L1 menu" << std::endl;
399 throw;
400 }
401}
402
404TrigConf::L1Menu::algorithmFromTriggerline(const std::string & triggerlineName) const
405{
406 std::string category {"MULTTOPO"};
407 std::string outputName {triggerlineName};
408 if( std::size_t pos = triggerlineName.find('_'); pos != std::string::npos ) {
409 category = triggerlineName.substr(0,pos);
410 outputName = triggerlineName.substr(pos+1);
411 }
412 const static std::vector<string> topoTypes {"TOPO", "R2TOPO", "MULTTOPO", "MUTOPO"};
413 if( std::none_of(cbegin(topoTypes), cend(topoTypes), [&category](const std::string & str){return str==category;}) ) {
414 std::string msg = "L1Menu::algorithmFromTriggerLine(" + triggerlineName + "): triggerline " + triggerlineName + " is not produced by a topo algorithm.";
415 throw std::runtime_error(msg);
416 }
417 try {
418 return * m_algorithmsByOutput.at(category).at(outputName);
419 }
420 catch(std::exception & ex) {
421 std::cerr << "L1Menu::algorithmFromTriggerLine(): No output " << outputName << " defined by any algorithm of category " << category << " in the L1 menu. (It was asked for " << triggerlineName << ")" << std::endl;
422 throw;
423 }
424}
425
427TrigConf::L1Menu::algorithmFromOutput(const std::string & bareOutputName, const std::string & type) const
428{
429 try {
430 return * m_algorithmsByOutput.at(type).at(bareOutputName);
431 }
432 catch(std::exception & ex) {
433 std::cerr << "No output " << bareOutputName << " defined by any algorithm of type " << type << " in the L1 menu" << std::endl;
434 throw;
435 }
436}
437
438const TrigConf::L1Board &
439TrigConf::L1Menu::board(const std::string & boardName) const
440{
441 try {
442 return m_boards.at(boardName);
443 }
444 catch(std::exception & ex) {
445 std::cerr << "No board " << boardName << " defined in the L1 menu" << std::endl;
446 throw;
447 }
448}
449
450std::vector<std::string>
452{
453 std::vector<std::string> boardNames;
454 boardNames.reserve(m_boards.size());
455 for(auto & board : m_boards) {
456 boardNames.emplace_back(board.first);
457 }
458 return boardNames;
459}
460
461
462
463
464void
466{
467 cout << "L1 menu '" << name() << "'" << endl;
468 cout << "Items: " << size() << endl;
469 if(full) {
470 int c(0);
471 for(const L1Item & item : *this ) {
472 cout << " " << c++ << ": " << item.name() << endl;
473 }
474 }
475 cout << "Thresholds: " << thresholds().size() << "(of " << thresholdTypes().size() << " different types)" << endl;
476 if(full) {
477 int c(0);
478 for(const std::string & thrType : thresholdTypes() ) {
479 cout << thrType << " :" << endl;
480 for(auto & thr : thresholds(thrType)) {
481 cout << " " << c++ << ": " << thr->name() << "[" << thr->type() << "]" << endl;
482 }
483 }
484 }
485 if(m_run>1) {
486 cout << "Topo algorithms: " << endl;
487 cout << " new : " << data().get_child("topoAlgorithms.TOPO.decisionAlgorithms").size() << endl;
488 cout << " muon : " << data().get_child("topoAlgorithms.MUTOPO.decisionAlgorithms").size() << endl;
489 cout << " mult : " << data().get_child("topoAlgorithms.MULTTOPO.multiplicityAlgorithms").size() << endl;
490 cout << " legacy: " << data().get_child("topoAlgorithms.R2TOPO.decisionAlgorithms").size() << endl;
491 }
492 cout << "Boards: " << data().get_child("boards").size() << endl;
493 cout << "Connectors: " << data().get_child("connectors").size() << endl;
494 unsigned int ctpinputs = data().get_child("ctp.inputs.optical").size();
495 ctpinputs += data().get_child("ctp.inputs.electrical").size();
496 ctpinputs += data().get_child("ctp.inputs.ctpin.slot7").size();
497 ctpinputs += data().get_child("ctp.inputs.ctpin.slot8").size();
498 ctpinputs += data().get_child("ctp.inputs.ctpin.slot9").size();
499 cout << "CTP connections: " << ctpinputs << endl;
500}
501
std::pair< std::vector< unsigned int >, bool > res
size_t size() const
Number of registered mappings.
#define x
static const Attributes_t empty
virtual const std::string & name() const final
const ptree & data() const
Access to the underlying data, if needed.
DataStructure()
Default constructor, leading to an uninitialized configuration object.
virtual void clear()
Clearing the configuration data.
std::optional< T > getAttribute_optional(const std::string &key) const
T getAttribute(const std::string &key, bool ignoreIfMissing=false, const T &def=T()) const
Access to simple attribute.
boost::property_tree::ptree ptree
a TriggerLine entry describes the location of a threshold multiplicity on a cable (connector)
Definition L1Board.h:23
L1 connectors configuration.
Definition L1Connector.h:46
L1 threshold configuration.
Definition L1Item.h:18
std::vector< std::string > thresholdNames() const
List of L1 thresholds names.
Definition L1Menu.cxx:242
const TrigConf::L1TopoAlgorithm & algorithmFromTriggerline(const std::string &triggerlineName) const
Access to topo algorithm by name of triggerline as given in topo connector specification.
Definition L1Menu.cxx:404
std::vector< std::string > connectorNames() const
Connector names.
Definition L1Menu.cxx:331
std::vector< std::string > boardNames() const
Board names.
Definition L1Menu.cxx:451
const L1ThrExtraInfo & thrExtraInfo() const
Access to extra info for threshold types.
Definition L1Menu.cxx:313
unsigned int ctpVersion() const
Accessor to the version of the CTP format.
Definition L1Menu.cxx:179
std::map< std::string, std::map< std::string, TrigConf::L1TopoAlgorithm * >, std::less<> > m_algorithmsByOutput
Definition L1Menu.h:188
std::map< std::string, std::vector< std::shared_ptr< TrigConf::L1Threshold > >, std::less<> > m_thresholdsByType
threshold maps
Definition L1Menu.h:179
bool isRun2() const
Definition L1Menu.h:151
const TrigConf::L1TopoAlgorithm & algorithm(const std::string &algoName, std::string_view ategory) const
Access to topo algorithm by name.
Definition L1Menu.cxx:388
std::map< std::string, std::map< unsigned int, std::shared_ptr< TrigConf::L1Threshold > >, std::less<> > m_thresholdsByTypeAndMapping
Definition L1Menu.h:181
std::map< std::string, TrigConf::L1Connector > m_connectors
connector by name
Definition L1Menu.h:170
std::vector< std::shared_ptr< TrigConf::L1Threshold > > thresholds() const
Access to list of all L1Thresholds.
Definition L1Menu.cxx:266
unsigned int m_run
Definition L1Menu.h:167
void printMenu(bool full=false) const
print overview of L1 Menu
Definition L1Menu.cxx:465
const std::string & connectorNameFromThreshold(const std::string &thresholdName) const
Name of connector from name of threshold or triggerline.
Definition L1Menu.cxx:319
std::vector< std::string > topoAlgorithmNames(const std::string &category) const
Access to topo algorithm names.
Definition L1Menu.cxx:353
const TrigConf::L1Connector & connector(const std::string &connectorName) const
Access to connector by name.
Definition L1Menu.cxx:341
std::vector< std::string > topoAlgorithmOutputNames(const std::string &category) const
Access to topo algoritm output names.
Definition L1Menu.cxx:370
const_iterator begin() const
Begin of the L1 items list.
Definition L1Menu.cxx:216
std::map< std::string, TrigConf::L1Board > m_boards
board by name
Definition L1Menu.h:176
ConstIter< ptree, L1Item > const_iterator
Iterator over the L1 items.
Definition L1Menu.h:65
unsigned int version() const
Accessor to the menu version.
Definition L1Menu.cxx:173
std::vector< std::string > thresholdTypes() const
List of L1 thresholds types.
Definition L1Menu.cxx:231
unsigned int smk() const
setter and getter for the supermasterkey
Definition L1Menu.cxx:191
std::size_t size() const
Accessor to the number of L1 items.
Definition L1Menu.cxx:185
std::map< std::string, std::vector< TrigConf::L1TopoAlgorithm >, std::less<> > m_algorithmsByCategory
algorithm maps
Definition L1Menu.h:186
std::map< std::string, std::shared_ptr< TrigConf::L1Threshold >, std::less<> > m_thresholdsByName
Definition L1Menu.h:180
virtual void clear() override
Clearing the configuration data.
Definition L1Menu.cxx:150
TrigConf::L1CTP m_ctp
Definition L1Menu.h:190
const TrigConf::L1TopoAlgorithm & algorithmFromOutput(const std::string &bareOutputName, const std::string &category) const
Access to topo algorithm by name of the output as given in the algorithm definition.
Definition L1Menu.cxx:427
const TrigConf::L1Board & board(const std::string &boardName) const
Access to boards by name.
Definition L1Menu.cxx:439
const TrigConf::L1Threshold & threshold(std::string_view thresholdName) const
Access to L1Threshold by name.
Definition L1Menu.cxx:278
void setSMK(unsigned int psk)
Definition L1Menu.cxx:196
std::map< std::string, std::map< std::string, TrigConf::L1TopoAlgorithm * >, std::less<> > m_algorithmsByName
Definition L1Menu.h:187
unsigned int m_smk
the supermasterkey
Definition L1Menu.h:165
std::map< std::string, std::string > m_threshold2ConnectorName
connector name by threshold name
Definition L1Menu.h:173
const_iterator end() const
End of the L1 items list.
Definition L1Menu.cxx:223
L1Menu()
Constructor.
Definition L1Menu.cxx:10
TrigConf::L1ThrExtraInfo m_thrExtraInfo
Definition L1Menu.h:183
L1Item item(const std::string &itemName) const
Get item by name.
Definition L1Menu.cxx:201
Standard L1 threshold configuration.
static std::shared_ptr< L1Threshold > createThreshold(const std::string &name, const std::string &type, std::weak_ptr< L1ThrExtraInfoBase > extraInfo, const ptree &data)
static method to create type-specific L1Thresholds
L1Topo algorithm configuration.
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148
STL namespace.
MsgStream & msg
Definition testRead.cxx:32