ATLAS Offline Software
Loading...
Searching...
No Matches
L1Connector.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6using namespace std;
7
8#include <stdexcept>
9
12
13TrigConf::L1Connector::L1Connector(const std::string & connName, const boost::property_tree::ptree & data)
15{
16 m_name = connName;
18}
19
20std::string
22 return "L1Connector";
23}
24
25void
27{
28 m_name = getAttribute("name", true, m_name);
29
30 std::string connType(getAttribute("type"));
31 if( connType == "electrical" ) {
33 } else if( connType == "optical" ) {
35 } else if( connType == "ctpin" ) {
37 } else {
38 throw std::runtime_error("Unknown connector type " + connType);
39 }
40
41 // triggerlines
42 bool oldConfiguration = hasChild("triggerlines.clock0") || hasChild("triggerlines.fpga0");
43 // old configuration
44 if(oldConfiguration){
45 bool hasMultipleFPGAs = ! hasChild("triggerlines.clock0"); // connector from merger board (no fpga)
47 m_maxClock = 2;
48 m_maxFpga = hasMultipleFPGAs ? 2 : 1;
49 }
50
51 for( size_t fpga = 0; fpga < m_maxFpga; ++fpga ) {
52 for( size_t clock = 0; clock < m_maxClock; ++clock ) {
53 std::string path = "triggerlines";
55 if(hasMultipleFPGAs) {
56 path += ".fpga";
57 path += std::to_string(fpga);
58 }
59 path += ".clock";
60 path += std::to_string(clock);
61 }
62 const auto & triggerlines = data().get_child(path);
63 m_triggerLines[fpga][clock].reserve(triggerlines.size());
64 for( auto & tl : triggerlines ) {
65 const std::string & name = tl.second.get_child("name").data();
66 m_triggerLines[fpga][clock].emplace_back( name,
67 tl.second.get_child("startbit").get_value<unsigned int>(),
68 tl.second.get_child("nbits").get_value<unsigned int>(),
69 tl.second.get_child("startbit").get_value<unsigned int>(),
70 fpga, clock, m_name);
71 m_lineByName[name] = & m_triggerLines[fpga][clock].back();
72 }
73 }
74 }
75 }
76 // new configuration
77 else {
78 std::string path = "triggerlines";
79 int ntl[2][2] = {{0,0},{0,0}};
81 m_maxClock = 2;
82 }
83 const auto & triggerlines = data().get_child(path);
84 for( auto & tl : triggerlines ) {
85 unsigned int fpga = 0;
86 unsigned int clock = 0;
88 if( m_name.find("MuCTPiEl") != std::string::npos || m_name.find("Topo2El") != std::string::npos || m_name.find("Topo3El") != std::string::npos || m_name.find("LegacyTopo0") != std::string::npos || m_name.find("LegacyTopo1") != std::string::npos){
89 fpga = tl.second.get_child("fpga").get_value<unsigned int>();
90 m_maxFpga = 2;
91 }
92 clock = tl.second.get_child("clock").get_value<unsigned int>();
93 }
94 ntl[fpga][clock] += 1;
95 }
96 for( size_t fpga = 0; fpga < m_maxFpga; ++fpga ) {
97 for( size_t clock = 0; clock < m_maxClock; ++clock ) {
98 m_triggerLines[fpga][clock].reserve(ntl[fpga][clock]);
99 }
100 }
101 for( auto & tl : triggerlines ) {
102 unsigned int fpga = 0;
103 unsigned int clock = 0;
104 unsigned int flatindex = 0;
106 if(m_maxFpga==2) fpga = tl.second.get_child("fpga").get_value<unsigned int>();
107 clock = tl.second.get_child("clock").get_value<unsigned int>();
108 }
109 flatindex = tl.second.get_optional<unsigned int>("flatindex").get_value_or(0);
110 const std::string & name = tl.second.get_child("name").data();
111 m_triggerLines[fpga][clock].emplace_back( name,
112 tl.second.get_child("startbit").get_value<unsigned int>(),
113 tl.second.get_child("nbits").get_value<unsigned int>(),
114 flatindex, fpga, clock, m_name);
115 m_lineByName[name] = & m_triggerLines[fpga][clock].back();
116 }
117 }
118 m_isLegacy = getAttribute<bool>("legacy", true, false);
119}
120
121
122std::string
124{
125 switch( m_type ) {
127 return "electrical";
129 return "optical";
131 return "ctpin";
132 default:
133 return "";
134 }
135}
136
139{
140 return m_type;
141}
142
143std::size_t
145{
146 size_t nlines{0};
147 for( size_t fpga = 0; fpga<m_maxFpga; ++fpga) {
148 for( size_t clock = 0; clock<m_maxClock; ++clock) {
149 nlines += m_triggerLines[fpga][clock].size();
150 }
151 }
152 return nlines;
153}
154
155std::vector<std::string>
157{
158 std::vector<std::string> tln{};
159 for( size_t fpga = 0; fpga<m_maxFpga; ++fpga) {
160 for( size_t clock = 0; clock<m_maxClock; ++clock) {
161 for( auto & tl : m_triggerLines[fpga][clock] ) {
162 tln.emplace_back(tl.name());
163 }
164 }
165 }
166 return tln;
167}
168
169const std::vector<TrigConf::TriggerLine> &
170TrigConf::L1Connector::triggerLines(unsigned int fpga, unsigned int clock) const
171{
172 return m_triggerLines[fpga][clock];
173}
174
175bool
176TrigConf::L1Connector::hasLine( const std::string & lineName ) const
177{
178 return m_lineByName.count(lineName);
179}
180
182TrigConf::L1Connector::triggerLine( const std::string & lineName ) const
183{
184 return *m_lineByName.at(lineName);
185}
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
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.
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.
std::vector< TrigConf::TriggerLine > m_triggerLines[2][2]
bool hasLine(const std::string &lineName) const
std::string type() const
ConnectorType connectorType() const
Accessor to the connector type.
virtual std::string className() const override
A string that is the name of the class.
const TrigConf::TriggerLine & triggerLine(const std::string &lineName) const
const std::vector< TrigConf::TriggerLine > & triggerLines(unsigned int fpga=0, unsigned int clock=0) const
Accessor to the triggerlines on the connector.
std::size_t size() const
Accessor to the number of trigger lines.
ConnectorType m_type
std::map< std::string, TrigConf::TriggerLine * > m_lineByName
virtual void update() override
Update the internal members.
L1Connector()
Constructor.
std::vector< std::string > triggerLineNames() const
names of all trigger lines
a TriggerLine entry describes the location of a threshold multiplicity on a cable (connector)
Definition L1Connector.h:22
STL namespace.