ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
Acts
ActsDataPreparation
src
details
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
// }
17
#include "
InDetRawData/ProxyContainer.h
"
18
#include <cstdint>
19
20
namespace
InPlaceClusterization
{
21
22
using 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,
26
template
<
class
T_CellContainer>
27
class
CellProxy
:
public
Utils::ElementProxyBase
<T_CellContainer,unsigned int> {
28
29
public
:
30
using
BASE
=
Utils::ElementProxyBase<T_CellContainer,unsigned int>
;
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.
49
struct
IndexWithBeginIndexCache
{
50
IndexWithBeginIndexCache
&
operator++
() { ++
m_clusterIndex
;
return
*
this
; }
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.
76
template
<
class
T_CellContainer>
77
class
ClusterProxy
:
public
Utils::ContainerProxy
<T_CellContainer,
78
ClusterProxy<T_CellContainer>,
79
CellProxy<T_CellContainer>,
80
IndexWithBeginIndexCache>
81
{
82
public
:
83
using
BASE
=
Utils::ContainerProxy
<T_CellContainer,
84
ClusterProxy<T_CellContainer>
,
85
CellProxy<T_CellContainer>
,
86
IndexWithBeginIndexCache
>;
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
120
template
<
class
T_CellContainer>
121
class
ModuleProxy
:
public
Utils::ContainerProxy
<T_CellContainer,
122
ModuleProxy<T_CellContainer>,
123
ClusterProxy<T_CellContainer>,
124
unsigned int > {
125
public
:
126
using
BASE
=
Utils::ContainerProxy
<T_CellContainer,
127
ModuleProxy<T_CellContainer>
,
128
ClusterProxy<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.
167
template
<
class
T_CellContainer>
168
class
CellContainerProxy
:
public
Utils::ContainerProxy
<T_CellContainer,
169
CellContainerProxy<T_CellContainer>,
170
ModuleProxy<T_CellContainer>,
171
RootNodeIndex > {
172
using
BASE
=
Utils::ContainerProxy
<T_CellContainer,
173
CellContainerProxy<T_CellContainer>
,
174
ModuleProxy<T_CellContainer>
,
175
RootNodeIndex
>;
176
using
BASE::BASE
;
177
};
178
179
}
180
#endif
ProxyContainer.h
InPlaceClusterization::CellContainerProxy
Definition
CellContainerProxy.h:171
InPlaceClusterization::CellContainerProxy::BASE
Utils::ContainerProxy< T_CellContainer, CellContainerProxy< T_CellContainer >, ModuleProxy< T_CellContainer >, RootNodeIndex > BASE
Definition
CellContainerProxy.h:172
InPlaceClusterization::CellProxy
Definition
CellContainerProxy.h:27
InPlaceClusterization::CellProxy::coordinates
auto & coordinates()
Definition
CellContainerProxy.h:41
InPlaceClusterization::CellProxy::BASE
Utils::ElementProxyBase< T_CellContainer, unsigned int > BASE
Definition
CellContainerProxy.h:30
InPlaceClusterization::CellProxy::coordinates
const auto & coordinates() const
Definition
CellContainerProxy.h:37
InPlaceClusterization::CellProxy::srcIndex
auto srcIndex() const
Definition
CellContainerProxy.h:33
InPlaceClusterization::ClusterProxy
Definition
CellContainerProxy.h:81
InPlaceClusterization::ClusterProxy::BASE
Utils::ContainerProxy< T_CellContainer, ClusterProxy< T_CellContainer >, CellProxy< T_CellContainer >, IndexWithBeginIndexCache > BASE
Definition
CellContainerProxy.h:83
InPlaceClusterization::ClusterProxy::nextElementIndex
static unsigned int nextElementIndex(const T_CellContainer *container, unsigned int element_index)
Definition
CellContainerProxy.h:112
InPlaceClusterization::ClusterProxy::beginIndex
static unsigned int beginIndex(const T_CellContainer *container, IndexWithBeginIndexCache cluster_index)
Definition
CellContainerProxy.h:93
InPlaceClusterization::ClusterProxy::endIndex
static unsigned int endIndex(const T_CellContainer *container, IndexWithBeginIndexCache cluster_index)
Definition
CellContainerProxy.h:104
InPlaceClusterization::ClusterProxy::identifyHash
unsigned int identifyHash() const
Definition
CellContainerProxy.h:89
InPlaceClusterization::ModuleProxy
Definition
CellContainerProxy.h:124
InPlaceClusterization::ModuleProxy::beginIndex
static IndexWithBeginIndexCache beginIndex(const T_CellContainer *container, unsigned int module_index)
Definition
CellContainerProxy.h:137
InPlaceClusterization::ModuleProxy::identifyHash
unsigned int identifyHash() const
Definition
CellContainerProxy.h:131
InPlaceClusterization::ModuleProxy::BASE
Utils::ContainerProxy< T_CellContainer, ModuleProxy< T_CellContainer >, ClusterProxy< T_CellContainer >, unsigned int > BASE
Definition
CellContainerProxy.h:126
InPlaceClusterization::ModuleProxy::nextElementIndex
static IndexWithBeginIndexCache nextElementIndex(const T_CellContainer *container, IndexWithBeginIndexCache element_index)
Definition
CellContainerProxy.h:156
InPlaceClusterization::ModuleProxy::endIndex
static IndexWithBeginIndexCache endIndex(const T_CellContainer *container, unsigned int module_index)
Definition
CellContainerProxy.h:147
InPlaceClusterization
Definition
CellContainerProxy.h:20
Utils
Definition
ProxyContainer.h:28
InPlaceClusterization::IndexWithBeginIndexCache
Definition
CellContainerProxy.h:49
InPlaceClusterization::IndexWithBeginIndexCache::operator++
IndexWithBeginIndexCache & operator++()
Definition
CellContainerProxy.h:50
InPlaceClusterization::IndexWithBeginIndexCache::operator+
IndexWithBeginIndexCache operator+(std::size_t counter) const
Definition
CellContainerProxy.h:64
InPlaceClusterization::IndexWithBeginIndexCache::m_clusterIndex
unsigned int m_clusterIndex
Definition
CellContainerProxy.h:69
InPlaceClusterization::IndexWithBeginIndexCache::m_idHash
unsigned int m_idHash
Definition
CellContainerProxy.h:71
InPlaceClusterization::IndexWithBeginIndexCache::m_cellBeginIndex
unsigned int m_cellBeginIndex
Definition
CellContainerProxy.h:70
InPlaceClusterization::IndexWithBeginIndexCache::operator-
std::size_t operator-(const IndexWithBeginIndexCache &other) const
Definition
CellContainerProxy.h:57
InPlaceClusterization::IndexWithBeginIndexCache::operator==
bool operator==(const IndexWithBeginIndexCache &other) const
Definition
CellContainerProxy.h:51
InPlaceClusterization::ClusterProxy< const typename IClusteringToolType::CellContainer >::container
const ContainerNonConst & container() const
Definition
ProxyContainer.h:190
Utils::ContainerProxy
The proxy container object which provides the means to iterate over its elements and create element p...
Definition
ProxyContainer.h:367
Utils::ContainerProxy< T_CellContainer, ClusterProxy< T_CellContainer >, CellProxy< T_CellContainer >, IndexWithBeginIndexCache >::index
const index_t & index() const
Definition
ProxyContainer.h:417
Utils::ContainerProxy< T_CellContainer, ClusterProxy< T_CellContainer >, CellProxy< T_CellContainer >, IndexWithBeginIndexCache >::BASE
ContainerProxyBase< T_CellContainer, typename CellProxy< T_CellContainer >::index_t > BASE
Definition
ProxyContainer.h:369
Utils::ElementProxyBase
Definition
ProxyContainer.h:113
Utils::ElementProxyBase< T_CellContainer, unsigned int >::index
index_t index() const
Definition
ProxyContainer.h:148
Utils::ElementProxyBase< T_CellContainer, unsigned int >::isConst
static constexpr bool isConst
Definition
ProxyContainer.h:114
Utils::ElementProxyBase< T_CellContainer, unsigned int >::container
const ContainerNonConst & container() const
Definition
ProxyContainer.h:152
Utils::RootNodeIndex
Helper struct to indicate the "index" of a top level container proxy.
Definition
ProxyContainer.h:98
Generated on
for ATLAS Offline Software by
1.17.0