ATLAS Offline Software
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 
22 namespace Trk {
29 template<class T>
31 {
32 
33 public:
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)),
39  m_arrayObjects() {
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 
115 private:
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
Trk::BinnedArrayArray2D
Definition: BinnedArrayArray2D.h:31
Trk::BinnedArray2D::object
T * object(const Amg::Vector2D &lp) const
Returns the pointer to the templated class object from the BinnedArray, it returns nullptr if not def...
Definition: BinnedArray2D.h:89
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
index
Definition: index.py:1
BinnedArray2D.h
BinUtility.h
Trk::BinnedArrayArray2D::BinnedArrayArray2D
BinnedArrayArray2D(std::vector< std::pair< BinnedArray2D< T >, Amg::Vector3D > > &&tbas, const BinUtility &bUtility)
Definition: BinnedArrayArray2D.h:35
Trk::BinnedArrayArray2D::m_binnedArrays
std::vector< BinnedArray2D< T > > m_binnedArrays
Definition: BinnedArrayArray2D.h:130
Trk::BinnedArrayArray2D::arrayObjectsNumber
virtual unsigned int arrayObjectsNumber() const override final
Number of Entries in the Array.
Definition: BinnedArrayArray2D.h:106
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
Trk::BinnedArrayArray2D::entryObject
virtual T * entryObject(const Amg::Vector3D &gp) const override
Returns the pointer to the templated class object from the BinnedArrayArray2D - entry point.
Definition: BinnedArrayArray2D.h:79
Trk::BinUtility::bins
size_t bins(size_t ba=0) const
Number of bins.
Definition: BinUtility.h:221
Trk::BinnedArrayArray2D::clone
virtual BinnedArrayArray2D * clone() const override
Implicit constructor.
Definition: BinnedArrayArray2D.h:50
GeoPrimitives.h
Trk::BinnedArrayArray2D::arrayObjects
virtual std::span< T *const > arrayObjects() override final
Return all objects of the Array non-const T.
Definition: BinnedArrayArray2D.h:94
Trk::BinnedArrayArray2D::m_arrayObjects
std::vector< T * > m_arrayObjects
Definition: BinnedArrayArray2D.h:133
Trk::BinnedArrayArray2D::arrayObjects
virtual std::span< T const *const > arrayObjects() const override final
Return all objects of the Array const T.
Definition: BinnedArrayArray2D.h:100
Trk::BinnedArrayArray2D::object
virtual T * object(const Amg::Vector2D &lp) const override
Returns the pointer to the templated class object from the BinnedArrayArray2D.
Definition: BinnedArrayArray2D.h:58
plotting.yearwise_luminosity_vs_mu.bins
bins
Definition: yearwise_luminosity_vs_mu.py:30
columnar::final
CM final
Definition: ColumnAccessor.h:106
Trk::BinnedArray2D
Definition: BinnedArray2D.h:37
Trk::BinUtility
Definition: BinUtility.h:39
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::BinUtility::inside
bool inside(const Amg::Vector3D &position) const
Check if bin is inside from Vector3D.
Definition: BinUtility.h:186
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
DeMoScan.index
string index
Definition: DeMoScan.py:362
Trk::BinnedArrayArray2D::m_binUtility
BinUtility m_binUtility
Definition: BinnedArrayArray2D.h:129
Trk::BinnedArrayArray2D::binUtility
virtual const BinUtility * binUtility() const override
Return the BinUtility.
Definition: BinnedArrayArray2D.h:112
Trk::BinnedArrayArray2D::buildCache
void buildCache()
Definition: BinnedArrayArray2D.h:116
Trk::BinUtility::bin
size_t bin(const Amg::Vector3D &position, size_t ba=0) const
Bin from a 3D vector (already in binning frame)
Definition: BinUtility.h:126
Trk::BinnedArray
Definition: BinnedArray.h:36
Trk::BinnedArrayArray2D::nextObject
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...
Definition: BinnedArrayArray2D.h:86
Trk::BinnedArrayArray2D::object
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...
Definition: BinnedArrayArray2D.h:68