ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalLArCellContainer.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <ranges>
7#include <algorithm>
8
9namespace GlobalSim {
10
11 // Main constructor setting up FEB2 LUTs
12 GlobalLArCellContainer::GlobalLArCellContainer(const std::map<std::string,Feb2MuxInfo>& febMap) {
13
14 std::map<std::string, std::vector<std::pair<int,std::string>>> tempMap;
15
16 // Loop over map of FEB2s to establish LUTs and lists
17 for (const auto & [feb2, muxInfo] : febMap) {
18 m_feb2Flags.insert({feb2, {false, false}});
19 m_feb2Keys.insert(feb2);
20 m_muxKeys.insert(muxInfo.muxName);
21 m_muxFlags.insert({muxInfo.muxName, {false, false}});
22 m_feb2ToMux.insert({feb2, muxInfo.muxName});
23
24 tempMap[muxInfo.muxName].emplace_back(muxInfo.indexOnMux, feb2);
25 }
26
27 // Sort FEB2 vectors for each MUX
28 for (auto& [muxName, vec] : tempMap) {
29 std::sort(vec.begin(), vec.end(), [](const auto& a, const auto& b) {
30 return a.first < b.first; // sort by indexOnMux
31 });
32
33 // Copy only the FEB2 names into m_muxToFeb2Ordered
34 std::vector<std::string> orderedFeb2s;
35 orderedFeb2s.reserve(vec.size());
36 for (const auto& [idx, feb2] : vec) {
37 orderedFeb2s.push_back(feb2);
38 }
39 m_muxToFeb2Ordered[muxName] = std::move(orderedFeb2s);
40 }
41 }
42
43
44 // Copy constructor
47 {
48 // Deep-copy DataVector elements
49 for (const auto cellPtr : other) {
50 DataVector<GlobalLArCell>::push_back(std::make_unique<GlobalLArCell>(*cellPtr));
51 }
52
53 // Copy the maps and sets
54 m_feb2Flags = other.m_feb2Flags;
55 m_feb2Keys = other.m_feb2Keys;
56 m_muxKeys = other.m_muxKeys;
57 m_muxFlags = other.m_muxFlags;
58 m_maxCellsPerFeb2 = other.m_maxCellsPerFeb2;
59 m_muxToFeb2Ordered = other.m_muxToFeb2Ordered;
60 m_feb2ToMux = other.m_feb2ToMux;
61 }
62
63
64 // Reimplementation of the push_back function to fill GlobalLArCells
66 auto cell = std::make_unique<GlobalLArCell>(theCell);
67 auto* cellPtr = cell.get();
69
70 m_feb2ToCells[cellPtr->getFEB2()].push_back(cellPtr);
71 }
72
73
74 // Function to get all GlobalLArCells for a given FEB2 name
75 const std::vector<GlobalLArCell*>& GlobalLArCellContainer::getCellsForFeb2(const std::string& feb2) const {
76
77 static const std::vector<GlobalLArCell*> emptyCellVector; // fallback if not found
78 auto it = m_feb2ToCells.find(feb2);
79
80 if (it != m_feb2ToCells.end()) {
81 return it->second;
82 }
83
84 return emptyCellVector;
85 }
86
87
88 // Function to get ordered list of FEB2s for a given MUX name
89 const std::vector<std::string>& GlobalLArCellContainer::getOrderedFeb2sForMux(const std::string& mux) const {
90
91 static const std::vector<std::string> emptyMux;
92 auto it = m_muxToFeb2Ordered.find(mux);
93 if (it != m_muxToFeb2Ordered.end()) {
94 return it->second;
95 }
96
97 return emptyMux;
98 }
99
100
101 // Function to get the associated MUX name for a given FEB2
102 const std::string& GlobalLArCellContainer::getMuxForFeb2(const std::string& feb2Key) const {
103 auto it = m_feb2ToMux.find(feb2Key);
104 if (it == m_feb2ToMux.end()) {
105 throw std::runtime_error("Unknown FEB2 key: " + feb2Key);
106 }
107 return it->second;
108 }
109
110
111 // Function to set overflow and error flag for a FEB2
112 void GlobalLArCellContainer::setFeb2Flags(const std::string& feb2Key, bool overflow, bool error) {
113 auto& flags = m_feb2Flags[feb2Key];
114 flags.overflow = overflow;
115 flags.error = error;
116
117 // Propagate FEB2 flags to the MUX
118 if (overflow) {
119 auto& muxFlags = m_muxFlags[m_feb2ToMux[feb2Key]];
120 muxFlags.overflow = overflow;
121 }
122 if (error) {
123 auto& muxFlags = m_muxFlags[m_feb2ToMux[feb2Key]];
124 muxFlags.error = error;
125 }
126 }
127
128
129 // Function to check whether a given FEB2 is in overflow
130 bool GlobalLArCellContainer::feb2InOverflow(const std::string& feb2Key) const {
131 auto it = m_feb2Flags.find(feb2Key);
132 return (it != m_feb2Flags.end()) ? it->second.overflow : false;
133 }
134
135
136 // Function to check if a given FEB2 is in error
137 bool GlobalLArCellContainer::feb2InError(const std::string& feb2Key) const {
138 auto it = m_feb2Flags.find(feb2Key);
139 return (it != m_feb2Flags.end()) ? it->second.error : false;
140 }
141
142
143 // Function to check whether a given MUX is in overflow
144 bool GlobalLArCellContainer::muxInOverflow(const std::string& muxKey) const {
145 auto it = m_muxFlags.find(muxKey);
146 return (it != m_muxFlags.end()) ? it->second.overflow : false;
147 }
148
149
150 // Function to check if a given MUX is in error
151 bool GlobalLArCellContainer::muxInError(const std::string& muxKey) const {
152 auto it = m_muxFlags.find(muxKey);
153 return (it != m_muxFlags.end()) ? it->second.error : false;
154 }
155
156} // namespace GlobalSim
std::vector< size_t > vec
static Double_t a
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataVector(SG::OwnershipPolicy ownPolicy=SG::OWN_ELEMENTS, SG::IndexTrackingPolicy trackIndices=SG::DEFAULT_TRACK_INDICES)
bool muxInError(const std::string &muxKey) const
Check if a given MUX is in error.
std::unordered_set< std::string > m_muxKeys
vector of all MUX names
void setFeb2Flags(const std::string &feb2Key, bool overflow, bool error)
Set overflow and error flag for a FEB2.
GlobalLArCellContainer()=default
Default constructor.
std::map< std::string, std::string > m_feb2ToMux
map which acts as lookuptable to get the associated MUX from a FEB2 name
std::map< std::string, std::vector< GlobalLArCell * > > m_feb2ToCells
map which keeps track of which cells are associated with which FEB2
bool feb2InOverflow(const std::string &feb2Key) const
Check if a given FEB2 is in overflow.
std::unordered_set< std::string > m_feb2Keys
vector of all FEB2 names
std::map< std::string, StatusFlags > m_muxFlags
map which stores overflow and error bits for each MUX
void push_back(const GlobalLArCell &theCell)
Reimplementation of the push_back function to fill LArCells.
const std::string & getMuxForFeb2(const std::string &feb2Key) const
Function to get the associated MUX name for a given FEB2.
bool muxInOverflow(const std::string &muxKey) const
Check if a given MUX is in overflow.
const std::vector< GlobalLArCell * > & getCellsForFeb2(const std::string &feb2) const
Function to get all GlobalLArCells for a given FEB2 name.
bool feb2InError(const std::string &feb2Key) const
Check if a given FEB2 is in error.
std::map< std::string, StatusFlags > m_feb2Flags
map which stores overflow and error bits for each FEB2
std::map< std::string, std::vector< std::string > > m_muxToFeb2Ordered
map which holds the ordered list of FEB2s for each MUX
const std::vector< std::string > & getOrderedFeb2sForMux(const std::string &mux) const
Function to get ordered list of FEB2s for a given MUX name.
std::size_t m_maxCellsPerFeb2
Maximum number of cells per FEB2 in given energy encoding scheme.
AlgTool that to test whether expected the TIP values generated by data supplied by eEmMultTestBench c...
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.