ATLAS Offline Software
Loading...
Searching...
No Matches
L1Menu.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 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(const std::string & typeName) const
255{
256 try {
257 return m_thresholdsByType.at(typeName);
258 }
259 catch(std::exception & ex) {
260 std::cerr << "No threshold type '" << typeName << "' defined in the thresholds section of the L1 menu" << std::endl;
261 throw;
262 }
263}
264
265
266std::vector<std::shared_ptr<TrigConf::L1Threshold>>
268{
269 std::vector<std::shared_ptr<TrigConf::L1Threshold>> thrlist;
270 for ( const std::string & type : thresholdTypes() ) {
271 const auto & thrOfType = thresholds(type);
272 std::copy(thrOfType.begin(), thrOfType.end(), std::back_inserter(thrlist));
273 }
274 return thrlist;
275}
276
277
279TrigConf::L1Menu::threshold(const std::string & thresholdName) const
280{
281 try {
282 return * m_thresholdsByName.at(thresholdName);
283 }
284 catch(std::exception & ex) {
285 std::cerr << "No threshold '" << thresholdName << "' defined in the thresholds section of the L1 menu" << std::endl;
286 throw;
287 }
288}
289
292TrigConf::L1Menu::threshold(const std::string &typeName, unsigned int mapping) const
293{
294 try
295 {
296 return *m_thresholdsByTypeAndMapping.at(typeName).at(mapping);
297 }
298 catch (std::exception &ex)
299 {
300 std::cerr << "No threshold of type '" << typeName << "' with mapping " << mapping
301 << " defined in the thresholds section of the L1 menu" << std::endl;
302 throw;
303 }
304}
305
308{
309 return m_thrExtraInfo;
310}
311
312const std::string &
313TrigConf::L1Menu::connectorNameFromThreshold(const std::string & thresholdName) const
314{
315 try {
316 return m_threshold2ConnectorName.at(thresholdName);
317 }
318 catch(...) {
319 std::cerr << "Threshold '" << thresholdName << "' not defined as triggerline in the L1 menu" << std::endl;
320 throw;
321 }
322}
323
324std::vector<std::string>
326 std::vector<std::string> connNames;
327 connNames.reserve(m_connectors.size());
328 for( auto & x : m_connectors ) {
329 connNames.emplace_back(x.first);
330 }
331 return connNames;
332}
333
335TrigConf::L1Menu::connector(const std::string & connectorName) const {
336 try {
337 return m_connectors.at(connectorName);
338 }
339 catch(std::exception & ex) {
340 std::cerr << "No connector " << connectorName << " defined in the L1 menu" << std::endl;
341 throw;
342 }
343}
344
346std::vector<std::string>
347TrigConf::L1Menu::topoAlgorithmNames(const std::string & category) const
348{
349 std::vector<std::string> algoNames;
350 try {
351 for(auto & entry : m_algorithmsByName.at(category) ) {
352 algoNames.push_back(entry.first);
353 }
354 }
355 catch(std::exception & ex) {
356 std::cerr << "No algorithm category '" << category << "' defined in the L1 menu" << std::endl;
357 throw;
358 }
359 return algoNames;
360}
361
363std::vector<std::string>
364TrigConf::L1Menu::topoAlgorithmOutputNames(const std::string & category) const
365{
366 std::vector<std::string> outputNames;
367 try {
368 for(auto & entry : m_algorithmsByOutput.at(category) ) {
369 outputNames.push_back(entry.first);
370 }
371 }
372 catch(std::exception & ex) {
373 std::cerr << "No algorithm category '" << category << "' defined in the L1 menu" << std::endl;
374 throw;
375 }
376 return outputNames;
377}
378
379
380
382TrigConf::L1Menu::algorithm(const std::string & algoName, const std::string & category) const
383{
384 try {
385 return * m_algorithmsByName.at(category).at(algoName);
386 }
387 catch(std::exception & ex) {
388 std::cerr << "No algorithm " << algoName << " of category " << category << " defined in the L1 menu" << std::endl;
389 throw;
390 }
391}
392
394TrigConf::L1Menu::algorithmFromTriggerline(const std::string & triggerlineName) const
395{
396 std::string category {"MULTTOPO"};
397 std::string outputName {triggerlineName};
398 if( std::size_t pos = triggerlineName.find('_'); pos != std::string::npos ) {
399 category = triggerlineName.substr(0,pos);
400 outputName = triggerlineName.substr(pos+1);
401 }
402 const static std::vector<string> topoTypes {"TOPO", "R2TOPO", "MULTTOPO", "MUTOPO"};
403 if( std::none_of(cbegin(topoTypes), cend(topoTypes), [&category](const std::string & str){return str==category;}) ) {
404 std::string msg = "L1Menu::algorithmFromTriggerLine(" + triggerlineName + "): triggerline " + triggerlineName + " is not produced by a topo algorithm.";
405 throw std::runtime_error(msg);
406 }
407 try {
408 return * m_algorithmsByOutput.at(category).at(outputName);
409 }
410 catch(std::exception & ex) {
411 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;
412 throw;
413 }
414}
415
417TrigConf::L1Menu::algorithmFromOutput(const std::string & bareOutputName, const std::string & type) const
418{
419 try {
420 return * m_algorithmsByOutput.at(type).at(bareOutputName);
421 }
422 catch(std::exception & ex) {
423 std::cerr << "No output " << bareOutputName << " defined by any algorithm of type " << type << " in the L1 menu" << std::endl;
424 throw;
425 }
426}
427
428const TrigConf::L1Board &
429TrigConf::L1Menu::board(const std::string & boardName) const
430{
431 try {
432 return m_boards.at(boardName);
433 }
434 catch(std::exception & ex) {
435 std::cerr << "No board " << boardName << " defined in the L1 menu" << std::endl;
436 throw;
437 }
438}
439
440std::vector<std::string>
442{
443 std::vector<std::string> boardNames;
444 boardNames.reserve(m_boards.size());
445 for(auto & board : m_boards) {
446 boardNames.emplace_back(board.first);
447 }
448 return boardNames;
449}
450
451
452
453
454void
456{
457 cout << "L1 menu '" << name() << "'" << endl;
458 cout << "Items: " << size() << endl;
459 if(full) {
460 int c(0);
461 for(const L1Item & item : *this ) {
462 cout << " " << c++ << ": " << item.name() << endl;
463 }
464 }
465 cout << "Thresholds: " << thresholds().size() << "(of " << thresholdTypes().size() << " different types)" << endl;
466 if(full) {
467 int c(0);
468 for(const std::string & thrType : thresholdTypes() ) {
469 cout << thrType << " :" << endl;
470 for(auto & thr : thresholds(thrType)) {
471 cout << " " << c++ << ": " << thr->name() << "[" << thr->type() << "]" << endl;
472 }
473 }
474 }
475 if(m_run>1) {
476 cout << "Topo algorithms: " << endl;
477 cout << " new : " << data().get_child("topoAlgorithms.TOPO.decisionAlgorithms").size() << endl;
478 cout << " muon : " << data().get_child("topoAlgorithms.MUTOPO.decisionAlgorithms").size() << endl;
479 cout << " mult : " << data().get_child("topoAlgorithms.MULTTOPO.multiplicityAlgorithms").size() << endl;
480 cout << " legacy: " << data().get_child("topoAlgorithms.R2TOPO.decisionAlgorithms").size() << endl;
481 }
482 cout << "Boards: " << data().get_child("boards").size() << endl;
483 cout << "Connectors: " << data().get_child("connectors").size() << endl;
484 unsigned int ctpinputs = data().get_child("ctp.inputs.optical").size();
485 ctpinputs += data().get_child("ctp.inputs.electrical").size();
486 ctpinputs += data().get_child("ctp.inputs.ctpin.slot7").size();
487 ctpinputs += data().get_child("ctp.inputs.ctpin.slot8").size();
488 ctpinputs += data().get_child("ctp.inputs.ctpin.slot9").size();
489 cout << "CTP connections: " << ctpinputs << endl;
490}
491
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
std::pair< std::vector< unsigned int >, bool > res
#define x
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.
bool empty() const
Check if children exist.
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:45
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:394
const TrigConf::L1TopoAlgorithm & algorithm(const std::string &algoName, const std::string &category) const
Access to topo algorithm by name.
Definition L1Menu.cxx:382
std::map< std::string, std::vector< TrigConf::L1TopoAlgorithm > > m_algorithmsByCategory
algorithm maps
Definition L1Menu.h:185
std::vector< std::string > connectorNames() const
Connector names.
Definition L1Menu.cxx:325
std::vector< std::string > boardNames() const
Board names.
Definition L1Menu.cxx:441
const L1ThrExtraInfo & thrExtraInfo() const
Access to extra info for threshold types.
Definition L1Menu.cxx:307
unsigned int ctpVersion() const
Accessor to the version of the CTP format.
Definition L1Menu.cxx:179
std::map< std::string, std::vector< std::shared_ptr< TrigConf::L1Threshold > > > m_thresholdsByType
threshold maps
Definition L1Menu.h:178
bool isRun2() const
Definition L1Menu.h:150
std::map< std::string, TrigConf::L1Connector > m_connectors
connector by name
Definition L1Menu.h:169
std::vector< std::shared_ptr< TrigConf::L1Threshold > > thresholds() const
Access to list of all L1Thresholds.
Definition L1Menu.cxx:267
unsigned int m_run
Definition L1Menu.h:166
void printMenu(bool full=false) const
print overview of L1 Menu
Definition L1Menu.cxx:455
const std::string & connectorNameFromThreshold(const std::string &thresholdName) const
Name of connector from name of threshold or triggerline.
Definition L1Menu.cxx:313
std::vector< std::string > topoAlgorithmNames(const std::string &category) const
Access to topo algorithm names.
Definition L1Menu.cxx:347
const TrigConf::L1Connector & connector(const std::string &connectorName) const
Access to connector by name.
Definition L1Menu.cxx:335
std::vector< std::string > topoAlgorithmOutputNames(const std::string &category) const
Access to topo algoritm output names.
Definition L1Menu.cxx:364
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:175
ConstIter< ptree, L1Item > const_iterator
Iterator over the L1 items.
Definition L1Menu.h:64
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
const TrigConf::L1Threshold & threshold(const std::string &thresholdName) const
Access to L1Threshold by name.
Definition L1Menu.cxx:279
virtual void clear() override
Clearing the configuration data.
Definition L1Menu.cxx:150
TrigConf::L1CTP m_ctp
Definition L1Menu.h:189
std::map< std::string, std::map< unsigned int, std::shared_ptr< TrigConf::L1Threshold > > > m_thresholdsByTypeAndMapping
Definition L1Menu.h:180
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:417
std::map< std::string, std::map< std::string, TrigConf::L1TopoAlgorithm * > > m_algorithmsByName
Definition L1Menu.h:186
std::map< std::string, std::map< std::string, TrigConf::L1TopoAlgorithm * > > m_algorithmsByOutput
Definition L1Menu.h:187
std::map< std::string, std::shared_ptr< TrigConf::L1Threshold > > m_thresholdsByName
Definition L1Menu.h:179
const TrigConf::L1Board & board(const std::string &boardName) const
Access to boards by name.
Definition L1Menu.cxx:429
void setSMK(unsigned int psk)
Definition L1Menu.cxx:196
unsigned int m_smk
the supermasterkey
Definition L1Menu.h:164
std::map< std::string, std::string > m_threshold2ConnectorName
connector name by threshold name
Definition L1Menu.h:172
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:182
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:146
STL namespace.
MsgStream & msg
Definition testRead.cxx:32