ATLAS Offline Software
Loading...
Searching...
No Matches
BinnedArray1D1D.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// BinnedArray1D1D.h, (c) ATLAS Detector software
8
9#ifndef TRKDETDESCRUTILS_BINNEDARRAY1D1D_H
10#define TRKDETDESCRUTILS_BINNEDARRAY1D1D_H
11
14
16#include <vector>
17#include <utility>
18#include <memory>
19
20namespace Trk {
21
31
32template<class T>
33class BinnedArray1D1D final : public BinnedArray<T>
34{
35
36public:
37 // defaults, copy assignment can not be defaulted (CachedPtr)
38 BinnedArray1D1D() = default;
41 ~BinnedArray1D1D() = default;
45 const std::vector<std::pair<std::shared_ptr<T>, Amg::Vector3D>>& tclassvector,
46 const BinUtility& steeringBinGen1D,
47 const std::vector<BinUtility>& singleBinGen)
48 : BinnedArray<T>(),
49 m_array{},
50 m_arrayObjects(nullptr),
51 m_steeringBinUtility(steeringBinGen1D),
52 m_singleBinUtilities(singleBinGen) {
53 initialize(tclassvector);
54 }
56 const std::vector<std::pair<std::shared_ptr<T>, Amg::Vector3D>>& tclassvector,
57 BinUtility&& steeringBinGen1D,
58 std::vector<BinUtility>&& singleBinGen)
59 : BinnedArray<T>(),
60 m_array{},
61 m_arrayObjects(nullptr),
62 m_steeringBinUtility(std::move(steeringBinGen1D)),
63 m_singleBinUtilities(std::move(singleBinGen)) {
64 initialize(tclassvector);
65 }
66
74
77 if (this != &barr) {
78 m_arrayObjects.release();
81 m_array = barr.m_array;
82 }
83 return *this;
84 }
85
87 BinnedArray1D1D* clone() const { return new BinnedArray1D1D(*this); }
88
92 T* object(const Amg::Vector2D& lp) const
93 {
94 int steerBin = m_steeringBinUtility.bin(lp, 0);
95 int singleBin = std::as_const(m_singleBinUtilities)[steerBin].bin(lp, 0);
96 return (m_array[steerBin][singleBin]).get();
97 }
98
102 T* object(const Amg::Vector3D& gp) const
103 {
104 int steerBin = m_steeringBinUtility.bin(gp, 0);
105 int singleBin = std::as_const(m_singleBinUtilities)[steerBin].bin(gp, 0);
106 return (m_array[steerBin][singleBin]).get();
107 }
108
111 T* entryObject(const Amg::Vector3D& gp) const
112 {
113 int steerBin = m_steeringBinUtility.entry(gp, 0);
114 int singleBin = std::as_const(m_singleBinUtilities)[steerBin].entry(gp, 0);
115 return (m_array[steerBin][singleBin]).get();
116 }
117
119 T* nextObject(const Amg::Vector3D&, const Amg::Vector3D&, bool) const
120 {
121 return nullptr;
122 }
123
125 std::span<T* const> arrayObjects()
126 {
128 return std::span<T* const>(m_arrayObjects->begin(), m_arrayObjects->end());
129 }
130
132 std::span<T const * const> arrayObjects() const
133 {
135 return std::span<const T* const>(m_arrayObjects->begin(), m_arrayObjects->end());
136 }
137
139 unsigned int arrayObjectsNumber() const { return arrayObjects().size(); }
140
142 const BinUtility* binUtility() const { return &m_steeringBinUtility; }
143
144private:
145 void createArrayCache() const
146 {
147 if (!m_arrayObjects) {
148 std::unique_ptr<std::vector<T*>> arrayObjects = std::make_unique<std::vector<T*>>();
149 for (size_t isteer = 0; isteer < m_steeringBinUtility.bins(); ++isteer) {
150 for (size_t isingle = 0;
151 isingle < std::as_const(m_singleBinUtilities)[isteer].bins(); ++isingle) {
152 arrayObjects->push_back((m_array[isteer][isingle]).get());
153 }
154 }
155 m_arrayObjects.set(std::move(arrayObjects));
156 }
157 }
158
159 void initialize(const std::vector<std::pair<std::shared_ptr<T>, Amg::Vector3D>>& tclassvector) {
160 m_array = std::vector<std::vector<std::shared_ptr<T>>>(m_steeringBinUtility.bins());
161 for (size_t i = 0; i < m_steeringBinUtility.bins(); ++i) {
162 size_t sizeOfSubBin = ((m_singleBinUtilities)[i]).bins();
163 m_array[i] = std::vector<std::shared_ptr<T>>(sizeOfSubBin);
164 }
165 // fill the Volume vector into the array
166 int vecsize(tclassvector.size());
167 for (int ivec = 0; ivec < vecsize; ++ivec) {
168 const Amg::Vector3D currentGlobal((tclassvector[ivec]).second);
169 if (m_steeringBinUtility.inside(currentGlobal)) {
170 int steeringBin = m_steeringBinUtility.bin(currentGlobal, 0);
171 int singleBin = (m_singleBinUtilities[steeringBin]).bin(currentGlobal, 0);
172 std::vector<std::shared_ptr<T>>& curVec = m_array[steeringBin];
173 curVec[singleBin] = ((tclassvector)[ivec]).first;
174 } else {
175 throw GaudiException("BinnedArray1D1D", "Object outside bounds",
176 StatusCode::FAILURE);
177 }
178 }
179 }
180
182 std::vector<std::vector<std::shared_ptr<T>>> m_array{};
187 std::vector<BinUtility> m_singleBinUtilities{};
188};
189} // end of namespace Trk
190
191#endif // TRKSURFACES_BINNEDARRAY1D1D_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
unsigned int arrayObjectsNumber() const
Number of Entries in the Array.
std::vector< BinUtility > m_singleBinUtilities
single bin utilities
BinnedArray1D1D(const std::vector< std::pair< std::shared_ptr< T >, Amg::Vector3D > > &tclassvector, BinUtility &&steeringBinGen1D, std::vector< BinUtility > &&singleBinGen)
CxxUtils::CachedUniquePtr< std::vector< T * > > m_arrayObjects
binUtility for retrieving and filling the Array
std::vector< std::vector< std::shared_ptr< T > > > m_array
forced 1D vector of pointers to class T
std::span< T const *const > arrayObjects() const
Return all objects of the Array const T.
~BinnedArray1D1D()=default
T * entryObject(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray - entry point.
std::span< T *const > arrayObjects()
Return all objects of the Array non-const T.
T * nextObject(const Amg::Vector3D &, const Amg::Vector3D &, bool) const
Returns the pointer to the templated class object from the BinnedArray.
BinnedArray1D1D & operator=(BinnedArray1D1D &&)=default
void initialize(const std::vector< std::pair< std::shared_ptr< T >, Amg::Vector3D > > &tclassvector)
vector of pointers to the class T
T * object(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray, it returns 0 if not defined.
BinnedArray1D1D * clone() const
Implicit Constructor.
BinUtility m_steeringBinUtility
const BinUtility * binUtility() const
Return the BinUtility - returns the steering binUtility in this case.
T * object(const Amg::Vector2D &lp) const
Returns the pointer to the templated class object from the BinnedArray, it returns 0 if not defined.
void createArrayCache() const
BinnedArray1D1D(const BinnedArray1D1D &barr)
Copy Constructor.
BinnedArray1D1D(const std::vector< std::pair< std::shared_ptr< T >, Amg::Vector3D > > &tclassvector, const BinUtility &steeringBinGen1D, const std::vector< BinUtility > &singleBinGen)
ctors with arguments
BinnedArray1D1D(BinnedArray1D1D &&)=default
BinnedArray1D1D()=default
BinnedArray1D1D & operator=(const BinnedArray1D1D &barr)
Assignment operator.
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()