ATLAS Offline Software
Loading...
Searching...
No Matches
BinnedArrayArray2D.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// BinnedArrayArray2D.h, (c) ATLAS Detector software
8
9#ifndef TRKDETDESCRUTILS_BINNEDARRAYARRAY2D_H
10#define TRKDETDESCRUTILS_BINNEDARRAYARRAY2D_H
11
14// GaudiKernel
15#include "GaudiKernel/GaudiException.h"
16// Eigen
18// STD
19#include <vector>
20#include <memory>
21
22namespace Trk {
28
29template<class T>
30class BinnedArrayArray2D final : public BinnedArray<T>
31{
32
33public:
34
35 BinnedArrayArray2D(std::vector< std::pair<BinnedArray2D<T>, Amg::Vector3D > >&& tbas,
36 const BinUtility& bUtility)
37 : m_binUtility(bUtility),
38 m_binnedArrays(bUtility.bins(0)),
40 // looping over the contained binned arrays so as to flatten
41 for (auto& barray : tbas) {
42 // flat ordered binned array
43 auto index = m_binUtility.bin(barray.second, 0);
44 m_binnedArrays[index] = std::move(barray.first);
45 }
46 buildCache();
47 }
48
50 virtual BinnedArrayArray2D* clone() const override
51 {
52 return new BinnedArrayArray2D(*this);
53 }
54
55
58 virtual T* object(const Amg::Vector2D& lp) const override {
59 if (m_binUtility.inside(lp)) {
60 const BinnedArray2D<T>& ba = m_binnedArrays[m_binUtility.bin(lp, 0)];
61 return ba.object(lp);
62 }
63 return nullptr;
64 }
65
68 virtual T* object(const Amg::Vector3D& gp) const override
69 {
70 if (m_binUtility.inside(gp)) {
71 const BinnedArray2D<T>& ba = m_binnedArrays[m_binUtility.bin(gp, 0)];
72 return ba.object(gp);
73 }
74 return nullptr;
75 }
76
79 virtual T* entryObject(const Amg::Vector3D& gp) const override
80 {
81 return object(gp);
82 }
83
86 virtual T* nextObject(const Amg::Vector3D& gp,
87 const Amg::Vector3D&,
88 bool) const override
89 {
90 return object(gp);
91 }
92
94 virtual std::span<T* const > arrayObjects() override final
95 {
96 return std::span<T* const >(m_arrayObjects.begin(), m_arrayObjects.end());
97 }
98
100 virtual std::span<T const * const> arrayObjects() const override final
101 {
102 return std::span<T const* const>(m_arrayObjects.begin(), m_arrayObjects.end());
103 }
104
106 virtual unsigned int arrayObjectsNumber() const override final
107 {
108 return m_arrayObjects.size();
109 };
110
112 virtual const BinUtility* binUtility() const override { return &m_binUtility; }
113
114
115private:
116 void buildCache() {
117 // flattened array object
118 size_t numArrrays = m_binnedArrays.size();
119 //reserve num of Bin Arrays times num of Bins
120 m_arrayObjects.reserve(numArrrays * m_binUtility.bins(0));
121 for (size_t index = 0; index <numArrrays; ++index) {
122 std::span<T* const> aObjects = m_binnedArrays[index].arrayObjects();
123 for (auto& o : aObjects) {
124 m_arrayObjects.push_back(o);
125 }
126 }
127 }
128
130 std::vector<BinnedArray2D<T>> m_binnedArrays{};
131 //cached view of the elements. The element lifetimes
132 //are managed by the 2D BinnedArrays
133 std::vector<T*> m_arrayObjects {};
134};
135} // end of namespace Trk
136
137#endif // TRKDETDESCRUTILS_BINNEDARRAYARRAY_H
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
Avoiding a map search, the templated BinnedArray class can help ordereing geometrical objects by prov...
T * object(const Amg::Vector2D &lp) const
Returns the pointer to the templated class object from the BinnedArray, it returns nullptr if not def...
virtual std::span< T *const > arrayObjects() override final
Return all objects of the Array non-const T.
virtual T * object(const Amg::Vector3D &gp) const override
Returns the pointer to the templated class object from the BinnedArrayArray2D it returns nullptr if n...
BinnedArrayArray2D(std::vector< std::pair< BinnedArray2D< T >, Amg::Vector3D > > &&tbas, const BinUtility &bUtility)
virtual T * nextObject(const Amg::Vector3D &gp, const Amg::Vector3D &, bool) const override
Returns the pointer to the templated class object from the BinnedArrayArray2D, takes 3D position & di...
virtual BinnedArrayArray2D * clone() const override
Implicit constructor.
std::vector< T * > m_arrayObjects
virtual T * object(const Amg::Vector2D &lp) const override
Returns the pointer to the templated class object from the BinnedArrayArray2D.
virtual unsigned int arrayObjectsNumber() const override final
Number of Entries in the Array.
virtual std::span< T const *const > arrayObjects() const override final
Return all objects of the Array const T.
virtual const BinUtility * binUtility() const override
Return the BinUtility.
std::vector< BinnedArray2D< T > > m_binnedArrays
virtual T * entryObject(const Amg::Vector3D &gp) const override
Returns the pointer to the templated class object from the BinnedArrayArray2D - entry point.
BinnedArray()=default
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
Ensure that the ATLAS eigen extensions are properly loaded.
Definition index.py:1