ATLAS Offline Software
Loading...
Searching...
No Matches
BinnedArray1D1D1D.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6// BinnedArray1D1D1D.h, (c) ATLAS Detector software
8
9#ifndef TRKDETDESCRUTILS_BINNEDARRAY1D1D1D_H
10#define TRKDETDESCRUTILS_BINNEDARRAY1D1D1D_H
11//
15//
16// STL
17#include <cassert>
18#include <vector>
19#include <utility>
20#include <memory>
21//
22class MsgStream;
23//
24namespace Trk {
25
34
35template<class T>
36class BinnedArray1D1D1D final : public BinnedArray<T>
37{
38public:
39 //defaults, copy assignment can not be defaulted (CachedPtr)
40 BinnedArray1D1D1D() = default;
43 ~BinnedArray1D1D1D() = default;
44
47 const std::vector<std::pair<std::shared_ptr<T>, Amg::Vector3D>>& tclassvector,
48 const BinUtility& binUtil1, const BinUtility& binUtil2,
49 const std::vector<std::vector<BinUtility>>& binUtilVec)
50 : BinnedArray<T>(),
51 m_array{},
52 m_arrayObjects(nullptr),
53 m_binUtil1(binUtil1),
54 m_binUtil2(binUtil2),
55 m_binUtilArray(binUtilVec) {
56 initialize(tclassvector);
57 }
59 const std::vector<std::pair<std::shared_ptr<T>, Amg::Vector3D>>& tclassvector,
60 BinUtility&& binUtil1,
61 BinUtility&& binUtil2,
62 std::vector<std::vector<BinUtility>>&& binUtilVec)
63 : BinnedArray<T>(),
64 m_array{},
65 m_arrayObjects(nullptr),
66 m_binUtil1(std::move(binUtil1)),
67 m_binUtil2(std::move(binUtil2)),
68 m_binUtilArray(std::move(binUtilVec)) {
69 initialize(tclassvector);
70 }
71
80
83 if (this != &barr) {
84 // bin utilities
88 m_array = barr.m_array;
89 m_arrayObjects.release();
90 }
91 return *this;
92 }
93
94 BinnedArray1D1D1D* clone() const { return new BinnedArray1D1D1D(*this); }
95
99 T* object(const Amg::Vector2D& lp) const
100 {
101 if (!m_binUtil1.inside(lp) || !m_binUtil2.inside(lp)){
102 return nullptr;
103 }
104 int bin1 = m_binUtil1.bin(lp);
105 int bin2 = m_binUtil2.bin(lp);
106 if (!std::as_const(m_binUtilArray)[bin1][bin2].inside(lp)){
107 return nullptr;
108 }
109 int bin3 = std::as_const(m_binUtilArray)[bin1][bin2].bin(lp);
110
111 return (m_array[bin1][bin2][bin3]).get();
112 }
113
117 T* object(const Amg::Vector3D& gp) const
118 {
119 if (!m_binUtil1.inside(gp) || !m_binUtil2.inside(gp)){
120 return nullptr;
121 }
122 int bin1 = m_binUtil1.bin(gp);
123 int bin2 = m_binUtil2.bin(gp);
124 if (!std::as_const(m_binUtilArray)[bin1][bin2].inside(gp)){
125 return nullptr;
126 }
127 unsigned int bin3 = std::as_const(m_binUtilArray)[bin1][bin2].bin(gp);
128 if (bin3 >= std::as_const(m_binUtilArray)[bin1][bin2].bins()){
129 return nullptr;
130 }
131 return (m_array[bin1][bin2][bin3]).get();
132 }
133
136 T* entryObject(const Amg::Vector3D& gp) const
137 {
138 int bin1 = m_binUtil1.entry(gp, 0);
139 int bin2 = m_binUtil2.entry(gp, 0);
140 int bin3 = std::as_const(m_binUtilArray)[bin1][bin2].entry(gp, 0);
141 return (m_array[bin1][bin2][bin3]).get();
142 }
143
146 T* nextObject(const Amg::Vector3D&, const Amg::Vector3D&, bool) const
147 {
148 return nullptr;
149 }
150
152 std::span<T* const> arrayObjects()
153 {
155 return std::span<T* const>(m_arrayObjects->begin(), m_arrayObjects->end());
156 }
157
159 std::span<T const * const> arrayObjects() const
160 {
162 return std::span<T const * const>(m_arrayObjects->begin(), m_arrayObjects->end());
163 }
164
166 unsigned int arrayObjectsNumber() const { return arrayObjects().size(); }
167
169 const BinUtility* binUtility() const { return &m_binUtil1; }
170
171private:
172 void createArrayCache() const {
173 if (!m_arrayObjects) {
174 std::unique_ptr<std::vector<T*>> arrayObjects = std::make_unique<std::vector<T*>>();
175 for (size_t ibin1 = 0; ibin1 < m_binUtil1.bins(); ++ibin1) {
176 for (size_t ibin2 = 0; ibin2 < m_binUtil2.bins(); ++ibin2) {
177 for (size_t ibin3 = 0; ibin3 < std::as_const(m_binUtilArray)[ibin1][ibin2].bins(); ++ibin3) {
178 arrayObjects->push_back((m_array[ibin1][ibin2][ibin3]).get());
179 }
180 }
181 }
182 m_arrayObjects.set(std::move(arrayObjects));
183 }
184 }
185
186 void initialize(const std::vector<std::pair<std::shared_ptr<T>, Amg::Vector3D>>& tclassvector) {
187 int v1Size = m_binUtil1.bins();
188 int v2Size = m_binUtil2.bins();
189 m_array = std::vector<std::vector<std::vector<std::shared_ptr<T>>>>(v1Size);
190 for (int i = 0; i < v1Size; ++i) {
191 m_array[i] = std::vector<std::vector<std::shared_ptr<T>>>(v2Size);
192 for (int j = 0; j < v2Size; ++j) {
193 m_array[i][j] = std::vector<std::shared_ptr<T>>(m_binUtilArray[i][j].bins());
194 }
195 }
196 // fill the Volume vector into the array
197 int vecsize(tclassvector.size());
198 for (int ivec = 0; ivec < vecsize; ++ivec) {
199 Amg::Vector3D currentGlobal((tclassvector[ivec]).second);
200 if (m_binUtil1.inside(currentGlobal) && m_binUtil2.inside(currentGlobal)) {
201 int bin1 = m_binUtil1.bin(currentGlobal);
202 int bin2 = m_binUtil2.bin(currentGlobal);
203 int bin3 = m_binUtilArray[bin1][bin2].bin(currentGlobal);
204 std::vector<std::vector<std::shared_ptr<T>>>& currArr = m_array[bin1];
205 std::vector<std::shared_ptr<T>>& curVec = currArr[bin2];
206 curVec[bin3] = (tclassvector[ivec]).first;
207 } else
208 throw GaudiException("BinnedArray1D1D1D", "Object outside bounds",
209 StatusCode::FAILURE);
210 }
211 }
212
214 std::vector<std::vector<std::vector<std::shared_ptr<T>>>> m_array{};
220 std::vector<std::vector<BinUtility>> m_binUtilArray{};
221};
222} // end of namespace Trk
223#endif // TRKSURFACES_BINNEDARRAY1D1D1D_H
Cached unique_ptr with atomic update.
static const std::vector< std::string > bins
A generic symmetric BinUtility, for fully symmetric binning in terms of binning grid and binning type...
Definition BinUtility.h:39
BinnedArray1D1D1D(const BinnedArray1D1D1D &barr)
Copy.
unsigned int arrayObjectsNumber() const
Number of Entries in the Array.
T * nextObject(const Amg::Vector3D &, const Amg::Vector3D &, bool) const
Returns the pointer to the templated class object from the BinnedArray dummy for multidimensional arr...
BinnedArray1D1D1D & operator=(const BinnedArray1D1D1D &barr)
Assignment operator.
BinnedArray1D1D1D(const std::vector< std::pair< std::shared_ptr< T >, Amg::Vector3D > > &tclassvector, const BinUtility &binUtil1, const BinUtility &binUtil2, const std::vector< std::vector< BinUtility > > &binUtilVec)
ctors
const BinUtility * binUtility() const
Return the BinUtility - returns the first binUtility in this case.
void initialize(const std::vector< std::pair< std::shared_ptr< T >, Amg::Vector3D > > &tclassvector)
vector of pointers to the class T
~BinnedArray1D1D1D()=default
T * object(const Amg::Vector2D &lp) const
Returns the pointer to the templated class object from the BinnedArray, it returns nullptr if not def...
std::span< T const *const > arrayObjects() const
Return all objects of the Array const T.
BinUtility m_binUtil2
binUtility for retrieving and filling the Array
std::span< T *const > arrayObjects()
Return all objects of the Array const T.
std::vector< std::vector< std::vector< std::shared_ptr< T > > > > m_array
1D cache of non owning pointers to class T
BinnedArray1D1D1D(BinnedArray1D1D1D &&)=default
T * object(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray, it returns nullptr if not def...
BinnedArray1D1D1D & operator=(BinnedArray1D1D1D &&)=default
CxxUtils::CachedUniquePtr< std::vector< T * > > m_arrayObjects
BinnedArray1D1D1D * clone() const
Implicit Constructor.
BinUtility m_binUtil1
binUtility for retrieving and filling the Array
BinnedArray1D1D1D(const std::vector< std::pair< std::shared_ptr< T >, Amg::Vector3D > > &tclassvector, BinUtility &&binUtil1, BinUtility &&binUtil2, std::vector< std::vector< BinUtility > > &&binUtilVec)
T * entryObject(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray - entry point.
std::vector< std::vector< BinUtility > > m_binUtilArray
BinnedArray()=default
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
CachedUniquePtrT< const T > CachedUniquePtr
Ensure that the ATLAS eigen extensions are properly loaded.
STL namespace.
void initialize()