ATLAS Offline Software
Loading...
Searching...
No Matches
CellContainerProxy.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3 */
4#ifndef INPLACECLUSTERIZATION_CELLCONTAINERPROXY_H
5#define INPLACECLUSTERIZATION_CELLCONTAINERPROXY_H
6// helper classes to provide proxies to access hierarchical cell data:
7// cell_proxy = module_cluster_collection_proxy[module_index][cluster_index][cell_index]
8// and provide the means to iterate over the cells using range based for loops:
9// for (auto module_proxy : module_cluster_collection_proxy) {
10// for (auto cluster_proxy : module_proxy) {
11// for(auto cell_proxy : cluster_proxy) {
12// .. cell_proxy.coordinates();
13// .. rdo_index = cell_proxy.srcIndex();
14// }
15// }
16// }
18#include <cstdint>
19
21
22using namespace Utils;
23
24// Cell data proxy providing access to the coordinates of a cell, and the index of the rdo it is representing
25// i.e. pixel colum and row, or strip number,
26template <class T_CellContainer>
27class CellProxy : public Utils::ElementProxyBase<T_CellContainer,unsigned int> {
28
29public:
31 using BASE::BASE;
32
33 auto srcIndex() const {
34 assert(this->index() < this->container().m_cells.size());
35 return this->container().m_cells[this->index()].srcIndex;
36 }
37 const auto &coordinates() const {
38 assert(this->index() < this->container().m_cells.size());
39 return this->container().m_cells[this->index()].coordinates;
40 }
41 auto &coordinates() requires (!BASE::isConst) {
42 assert(this->index() < this->container().m_cells.size());
43 return this->container().m_cells[this->index()].coordinates;
44 }
45};
46
47// An extended cluster index which also provides the module id hash (unused; for debugging)
48// and the index of the first cell of all clusters.
51 bool operator==(const IndexWithBeginIndexCache &other) const {
52 // should only be executed if the indices refer to the same module,
53 // thus the cached begin index should always be identical.
54 assert(m_cellBeginIndex == other.m_cellBeginIndex);
55 return m_clusterIndex == other.m_clusterIndex;
56 }
57 std::size_t operator-(const IndexWithBeginIndexCache &other) const {
58 assert( m_clusterIndex >= other.m_clusterIndex);
59 return m_clusterIndex - other.m_clusterIndex;
60 }
61 // @TODO ugly that "+" and "-" return differnt types
62 // but operator - is used to compute the size
63 // and operator + to create an element index for random access
64 IndexWithBeginIndexCache operator+(std::size_t counter) const {
65 IndexWithBeginIndexCache ret(*this);
66 ret.m_clusterIndex += counter;
67 return ret;
68 }
69 unsigned int m_clusterIndex;
70 unsigned int m_cellBeginIndex;
71 unsigned int m_idHash; // for debugging
72};
73
74// A proxy representing a cluster of a module which gives access to the cells this
75// cluster is comprised of.
76template <class T_CellContainer>
77class ClusterProxy : public Utils::ContainerProxy<T_CellContainer,
78 ClusterProxy<T_CellContainer>,
79 CellProxy<T_CellContainer>,
80 IndexWithBeginIndexCache>
81{
82public:
83 using BASE = Utils::ContainerProxy<T_CellContainer,
87 using BASE::BASE;
88
89 unsigned int identifyHash() const {
90 return this->index().m_idHash;
91 }
92 // return the index of the first cell of this cluster
93 static unsigned int beginIndex(const T_CellContainer *container, IndexWithBeginIndexCache cluster_index)
94 {
95 assert(container != nullptr);
96 // the cluster index (cluster_index.m_clusterIndex) should point at the end index of a cluster in container->m_relativeClusterCellIndex
97 assert(cluster_index.m_clusterIndex>0);
98 assert(cluster_index.m_clusterIndex < container->m_relativeClusterCellIndex.size());
99 // a cluster must contain at least one cell, thus "<" not "<="
100 assert(cluster_index.m_cellBeginIndex + container->m_relativeClusterCellIndex[cluster_index.m_clusterIndex-1] < container->m_cells.size());
101 return static_cast<unsigned int> ( cluster_index.m_cellBeginIndex + container->m_relativeClusterCellIndex[cluster_index.m_clusterIndex-1]);
102 }
103 // return the index after the last cell of this cluster
104 static unsigned int endIndex(const T_CellContainer *container,IndexWithBeginIndexCache cluster_index) {
105 assert(container != nullptr);
106 assert(cluster_index.m_clusterIndex < container->m_relativeClusterCellIndex.size());
107 // the end cell index must not exceed the size of the cells but can be equal.
108 assert(cluster_index.m_cellBeginIndex + container->m_relativeClusterCellIndex[cluster_index.m_clusterIndex] <= container->m_cells.size());
109 return static_cast<unsigned int> ( cluster_index.m_cellBeginIndex + container->m_relativeClusterCellIndex[cluster_index.m_clusterIndex]);
110 }
111 // compute the index of the next cell of a cluster defined by the given cell index
112 static unsigned int nextElementIndex([[maybe_unused]] const T_CellContainer *container, unsigned int element_index)
113 {
114 assert( element_index < container->m_cells.size());
115 return ++element_index;
116 }
117};
118
119// Proxy representing the clusters of a module
120template <class T_CellContainer>
121class ModuleProxy : public Utils::ContainerProxy<T_CellContainer,
122 ModuleProxy<T_CellContainer>,
123 ClusterProxy<T_CellContainer>,
124 unsigned int > {
125public:
126 using BASE = Utils::ContainerProxy<T_CellContainer,
129 unsigned int >;
130 using BASE::BASE;
131 unsigned int identifyHash() const {
132 assert( this->index() < this->container().m_moduleClusterRange.size());
133 return this->container().m_moduleClusterRange[this->index()].idHash;
134 }
135
136 // index referring to the first cluster of a module
137 static IndexWithBeginIndexCache beginIndex(const T_CellContainer *container, unsigned int module_index)
138 {
139 assert(container != nullptr);
140 assert(module_index < container->m_moduleClusterRange.size());
141 const typename T_CellContainer::ClusterRange &cluster_range = container->m_moduleClusterRange[module_index];
142 assert( cluster_range.clusterRangeBeginIndex <= container->m_relativeClusterCellIndex.size());
143 assert( cluster_range.cellBeginIndex <= container->m_cells.size());
144 return IndexWithBeginIndexCache{cluster_range.clusterRangeBeginIndex, cluster_range.cellBeginIndex, cluster_range.idHash/*for debugging*/};
145 }
146 // index after the last cluster of a module
147 static IndexWithBeginIndexCache endIndex(const T_CellContainer *container,unsigned int module_index) {
148 assert(container != nullptr);
149 assert(module_index < container->m_moduleClusterRange.size());
150 const typename T_CellContainer::ClusterRange &cluster_range = container->m_moduleClusterRange[module_index];
151 assert( cluster_range.clusterRangeEndIndex <= container->m_relativeClusterCellIndex.size());
152 assert( cluster_range.cellBeginIndex <= container->m_cells.size());
153 return IndexWithBeginIndexCache{cluster_range.clusterRangeEndIndex, cluster_range.cellBeginIndex, cluster_range.idHash /*for debugging*/};
154 }
155 // compute the index of the next cluster, where the cluster is defined by the given cluster index
156 static IndexWithBeginIndexCache nextElementIndex([[maybe_unused]] const T_CellContainer *container, IndexWithBeginIndexCache element_index)
157 {
158 assert( container != nullptr);
159 assert( element_index.m_clusterIndex < container->m_relativeClusterCellIndex.size());
160 return ++element_index;
161 }
162
163};
164
165// Top level proxy representing all cells of all clusters of all modules.
166// It provides access to all the modules which provide access to the clusters which provide access to the cells.
167template <class T_CellContainer>
168class CellContainerProxy : public Utils::ContainerProxy<T_CellContainer,
169 CellContainerProxy<T_CellContainer>,
170 ModuleProxy<T_CellContainer>,
171 RootNodeIndex > {
172 using BASE = Utils::ContainerProxy<T_CellContainer,
176 using BASE::BASE;
177};
178
179}
180#endif
Utils::ContainerProxy< T_CellContainer, CellContainerProxy< T_CellContainer >, ModuleProxy< T_CellContainer >, RootNodeIndex > BASE
Utils::ElementProxyBase< T_CellContainer, unsigned int > BASE
Utils::ContainerProxy< T_CellContainer, ClusterProxy< T_CellContainer >, CellProxy< T_CellContainer >, IndexWithBeginIndexCache > BASE
static unsigned int nextElementIndex(const T_CellContainer *container, unsigned int element_index)
static unsigned int beginIndex(const T_CellContainer *container, IndexWithBeginIndexCache cluster_index)
static unsigned int endIndex(const T_CellContainer *container, IndexWithBeginIndexCache cluster_index)
static IndexWithBeginIndexCache beginIndex(const T_CellContainer *container, unsigned int module_index)
Utils::ContainerProxy< T_CellContainer, ModuleProxy< T_CellContainer >, ClusterProxy< T_CellContainer >, unsigned int > BASE
static IndexWithBeginIndexCache nextElementIndex(const T_CellContainer *container, IndexWithBeginIndexCache element_index)
static IndexWithBeginIndexCache endIndex(const T_CellContainer *container, unsigned int module_index)
IndexWithBeginIndexCache operator+(std::size_t counter) const
std::size_t operator-(const IndexWithBeginIndexCache &other) const
bool operator==(const IndexWithBeginIndexCache &other) const
The proxy container object which provides the means to iterate over its elements and create element p...
Helper struct to indicate the "index" of a top level container proxy.