ATLAS Offline Software
Loading...
Searching...
No Matches
BinnedArray1D.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// BinnedArray1D.h, (c) ATLAS Detector software
8
9#ifndef TRKDETDESCRUTILS_BINNEDARRAY1D_H
10#define TRKDETDESCRUTILS_BINNEDARRAY1D_H
11
14
15// STL
16#include <vector>
17#include <memory>
18
20
21
22namespace Trk {
23
32
33template<class T>
34class BinnedArray1D final : public BinnedArray<T>
35{
36
37public:
38 //defaults, copy assignment can not be defaulted (CachedPtr)
39 BinnedArray1D() = default;
42 ~BinnedArray1D() = default;
45 const std::vector<std::pair<std::shared_ptr<T>, Amg::Vector3D>>& tclassvector,
46 const BinUtility& bingen)
47 : BinnedArray<T>(),
48 m_array{},
49 m_arrayObjects(nullptr),
50 m_binUtility(bingen) {
51 initialize(tclassvector);
52 }
54 const std::vector<std::pair<std::shared_ptr<T>, Amg::Vector3D>>& tclassvector,
55 BinUtility&& bingen)
56 : BinnedArray<T>()
57 , m_array{}
58 , m_arrayObjects(nullptr)
59 , m_binUtility(std::move(bingen))
60 {
61 initialize(tclassvector);
62 }
63
65 : BinnedArray<T>()
66 , m_array{barr.m_array}
67 , m_arrayObjects(nullptr)
69 {
70 }
71
73 {
74 if (this != &barr) {
76 m_array.clear();
77 m_arrayObjects.release();
78 m_array = barr.m_array;
79 }
80 return *this;
81 }
82
83 BinnedArray1D* clone() const { return new BinnedArray1D(*this); }
84
88 T* object(const Amg::Vector2D& lp) const
89 {
90 if (m_binUtility.inside(lp)) {
91 return (m_array[m_binUtility.bin(lp, 0)]).get();
92 }
93 return nullptr;
94 }
95
99 T* object(const Amg::Vector3D& gp) const
100 {
101 return (m_array[m_binUtility.bin(gp, 0)]).get();
102 }
103
106 T* entryObject(const Amg::Vector3D& gp) const
107 {
108 return (m_array[m_binUtility.entry(gp, 0)]).get();
109 }
110
114 const Amg::Vector3D& mom,
115 bool associatedResult = true) const
116 {
117 // the bins
118 size_t bin = associatedResult ? m_binUtility.bin(gp, 0)
119 : m_binUtility.next(gp, mom, 0);
120 return (m_array[bin]).get();
121 }
122
124 std::span<T* const> arrayObjects()
125 {
127 return std::span<T* const>(m_arrayObjects->begin(), m_arrayObjects->end());
128 }
129
131 std::span<T const * const > arrayObjects() const
132 {
134 return std::span<const T* const>(m_arrayObjects->begin(), m_arrayObjects->end());
135 }
136
138 unsigned int arrayObjectsNumber() const { return arrayObjects().size(); }
139
141 const BinUtility* binUtility() const { return &m_binUtility; }
142
143private:
144 void createArrayCache() const
145 {
146 if (!m_arrayObjects) {
147 std::unique_ptr<std::vector<T*>> arrayObjects = std::make_unique<std::vector<T*>>();
148 auto bins = m_binUtility.bins(0);
149 arrayObjects->reserve(bins);
150 for (size_t ill = 0; ill < bins; ++ill) {
151 arrayObjects->push_back((m_array[ill]).get());
152 }
153 m_arrayObjects.set(std::move(arrayObjects));
154 }
155 }
156
157 void initialize(const std::vector<std::pair<std::shared_ptr<T>, Amg::Vector3D>>& tclassvector) {
158 // prepare the binned Array
159 size_t vecsize = tclassvector.size();
160 m_array = std::vector<std::shared_ptr<T>>(vecsize);
161 for (size_t ivec = 0; ivec < vecsize; ++ivec) {
162 const Amg::Vector3D currentGlobal(((tclassvector[ivec]).second));
163 if (m_binUtility.inside(currentGlobal)) {
164 m_array[m_binUtility.bin(currentGlobal, 0)] =
165 ((tclassvector)[ivec]).first;
166 } else
167 throw GaudiException("BinnedArray1D constructor",
168 "Object outside bounds", StatusCode::FAILURE);
169 }
170 }
172 std::vector<std::shared_ptr<T>> m_array{};
177};
178
179} // end of namespace Trk
180
181#endif // TRKSURFACES_BINNEDARRAY1D_H
Cached unique_ptr with atomic update.
A generic symmetric BinUtility, for fully symmetric binning in terms of binning grid and binning type...
Definition BinUtility.h:39
T * nextObject(const Amg::Vector3D &gp, const Amg::Vector3D &mom, bool associatedResult=true) const
Returns the pointer to the templated class object from the BinnedArray.
BinnedArray1D & operator=(BinnedArray1D &&)=default
BinUtility m_binUtility
const BinUtility * binUtility() const
Return the BinUtility.
CxxUtils::CachedUniquePtr< std::vector< T * > > m_arrayObjects
binUtility for retrieving and filling the Array
void createArrayCache() const
T * object(const Amg::Vector2D &lp) const
Returns the pointer to the templated class object from the BinnedArray, it returns nullptr if not def...
T * object(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray it returns nullptr if not defi...
std::span< T *const > arrayObjects()
Return all objects of the Array non-const T.
~BinnedArray1D()=default
BinnedArray1D * clone() const
Implicit Constructor.
std::span< T const *const > arrayObjects() const
Return all objects of the Array const T.
BinnedArray1D(BinnedArray1D &&)=default
BinnedArray1D & operator=(const BinnedArray1D &barr)
Assignment.
BinnedArray1D(const std::vector< std::pair< std::shared_ptr< T >, Amg::Vector3D > > &tclassvector, const BinUtility &bingen)
ctors with arguments
BinnedArray1D()=default
BinnedArray1D(const std::vector< std::pair< std::shared_ptr< T >, Amg::Vector3D > > &tclassvector, BinUtility &&bingen)
T * entryObject(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray - entry point.
BinnedArray1D(const BinnedArray1D &barr)
Copy.
unsigned int arrayObjectsNumber() const
Number of Entries in the Array.
void initialize(const std::vector< std::pair< std::shared_ptr< T >, Amg::Vector3D > > &tclassvector)
vector of pointers to the class T
std::vector< std::shared_ptr< T > > m_array
1D vector of cached not owning pointers to class T
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()