ATLAS Offline Software
BinnedArray1D.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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 
15 
16 // STL
17 #include <vector>
18 
20 
21 class MsgStream;
22 
23 namespace Trk {
24 
34 template<class T>
35 class BinnedArray1D final : public BinnedArray<T>
36 {
37 
38 public:
41  : BinnedArray<T>()
42  , m_array{}
43  , m_arrayObjects(nullptr)
44  , m_binUtility(nullptr)
45  {}
46 
49  const std::vector<std::pair<SharedObject<T>, Amg::Vector3D>>& tclassvector,
50  BinUtility* bingen)
51  : BinnedArray<T>()
52  , m_array{}
53  , m_arrayObjects(nullptr)
54  , m_binUtility(bingen)
55  {
56  // prepare the binned Array
57  if (bingen) {
58  size_t vecsize = tclassvector.size();
59  m_array = std::vector<SharedObject<T>>(vecsize);
60  for (size_t ivec = 0; ivec < vecsize; ++ivec) {
61  const Amg::Vector3D currentGlobal(((tclassvector[ivec]).second));
62  if (bingen->inside(currentGlobal)) {
63  m_array[bingen->bin(currentGlobal, 0)] = ((tclassvector)[ivec]).first;
64  } else
65  throw GaudiException("BinnedArray1D constructor",
66  "Object outside bounds",
67  StatusCode::FAILURE);
68  }
69  }
70  }
71 
74  : BinnedArray<T>()
75  , m_array{}
76  , m_arrayObjects(nullptr)
77  , m_binUtility(nullptr)
78  {
79  m_binUtility = (barr.m_binUtility) ? barr.m_binUtility->clone() : nullptr;
80  if (m_binUtility) {
81  m_array = std::vector<SharedObject<T>>(barr.m_array.size());
82  for (unsigned int ient = 0; ient < barr.m_array.size(); ++ient) {
83  m_array[ient] = (barr.m_array)[ient];
84  }
85  }
86  }
89  {
90  if (this != &barr) {
91  m_array.clear();
92  m_arrayObjects.release();
93  delete m_binUtility;
94  // now refill
95  m_binUtility = (barr.m_binUtility) ? barr.m_binUtility->clone() : 0;
96 
97  if (m_binUtility) {
98  m_array = std::vector<SharedObject<T>>(barr.m_array.size());
99  for (unsigned int ient = 0; ient < barr.m_array.size(); ++ient) {
100  m_array[ient] = (barr.m_array)[ient];
101  }
102  }
103  }
104  return *this;
105  }
107  BinnedArray1D* clone() const { return new BinnedArray1D(*this); }
108 
111 
115  T* object(const Amg::Vector2D& lp) const
116  {
117  if (m_binUtility->inside(lp)) {
118  return (m_array[m_binUtility->bin(lp, 0)]).get();
119  }
120  return nullptr;
121  }
122 
126  T* object(const Amg::Vector3D& gp) const
127  {
128  return (m_array[m_binUtility->bin(gp, 0)]).get();
129  }
130 
133  T* entryObject(const Amg::Vector3D& gp) const
134  {
135  return (m_array[m_binUtility->entry(gp, 0)]).get();
136  }
137 
140  T* nextObject(const Amg::Vector3D& gp,
141  const Amg::Vector3D& mom,
142  bool associatedResult = true) const
143  {
144  // the bins
145  size_t bin = associatedResult ? m_binUtility->bin(gp, 0)
146  : m_binUtility->next(gp, mom, 0);
147  return (m_array[bin]).get();
148  }
149 
152  {
154  return Trk::BinnedArraySpan<T* const>(&*(m_arrayObjects->begin()), &*(m_arrayObjects->end()));
155  }
156 
159  {
161  return Trk::BinnedArraySpan<const T* const>(&*(m_arrayObjects->begin()), &*(m_arrayObjects->end()));
162  }
163 
165  unsigned int arrayObjectsNumber() const { return arrayObjects().size(); }
166 
168  const BinUtility* binUtility() const { return (m_binUtility); }
169 
170 private:
171  void createArrayCache() const
172  {
173  if (!m_arrayObjects) {
174  std::unique_ptr<std::vector<T*>> arrayObjects =
175  std::make_unique<std::vector<T*>>();
176  auto bins = m_binUtility->bins(0);
177  arrayObjects->reserve(bins);
178  for (size_t ill = 0; ill < bins; ++ill) {
179  arrayObjects->push_back((m_array[ill]).get());
180  }
181  m_arrayObjects.set(std::move(arrayObjects));
182  }
183  }
184 
186  std::vector<SharedObject<T>> m_array;
191 };
192 
193 } // end of namespace Trk
194 
195 #endif // TRKSURFACES_BINNEDARRAY1D_H
Trk::BinUtility::entry
size_t entry(const Amg::Vector3D &position, size_t ba=0) const
Bin from a 3D vector (already in binning frame)
Definition: BinUtility.h:145
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
Trk::BinnedArray1D::m_array
std::vector< SharedObject< T > > m_array
forced 1D vector of pointers to class T
Definition: BinnedArray1D.h:186
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
BinnedArray.h
Trk::BinnedArray1D::~BinnedArray1D
~BinnedArray1D()
Virtual Destructor.
Definition: BinnedArray1D.h:110
CxxUtils::CachedUniquePtrT
Cached pointer with atomic update.
Definition: CachedUniquePtr.h:54
BinUtility.h
bin
Definition: BinsDiffFromStripMedian.h:43
Trk::BinnedArray1D::arrayObjects
BinnedArraySpan< T *const > arrayObjects()
Return all objects of the Array non-const T.
Definition: BinnedArray1D.h:151
Trk::BinnedArray1D::clone
BinnedArray1D * clone() const
Implicit Constructor.
Definition: BinnedArray1D.h:107
Trk::BinUtility::bins
size_t bins(size_t ba=0) const
Number of bins.
Definition: BinUtility.h:223
Trk::BinnedArray1D::BinnedArray1D
BinnedArray1D(const BinnedArray1D &barr)
Copy Constructor - copies only pointers !
Definition: BinnedArray1D.h:73
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
Trk::BinnedArray1D::entryObject
T * entryObject(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray - entry point.
Definition: BinnedArray1D.h:133
Trk::BinnedArray1D::binUtility
const BinUtility * binUtility() const
Return the BinUtility.
Definition: BinnedArray1D.h:168
Trk::BinnedArray1D::operator=
BinnedArray1D & operator=(const BinnedArray1D &barr)
Assignment operator.
Definition: BinnedArray1D.h:88
Trk::BinnedArray1D::BinnedArray1D
BinnedArray1D(const std::vector< std::pair< SharedObject< T >, Amg::Vector3D >> &tclassvector, BinUtility *bingen)
Constructor with std::vector and a BinUtility.
Definition: BinnedArray1D.h:48
Trk::BinnedArray1D::createArrayCache
void createArrayCache() const
vector of pointers to the class T
Definition: BinnedArray1D.h:171
CachedUniquePtr.h
Cached unique_ptr with atomic update.
Trk::BinnedArray1D::nextObject
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.
Definition: BinnedArray1D.h:140
plotting.yearwise_luminosity_vs_mu.bins
bins
Definition: yearwise_luminosity_vs_mu.py:30
SharedObject.h
Trk::BinnedArray1D::object
T * object(const Amg::Vector2D &lp) const
Returns the pointer to the templated class object from the BinnedArray, it returns 0 if not defined;.
Definition: BinnedArray1D.h:115
Trk::BinnedArray1D::arrayObjects
BinnedArraySpan< T const *const > arrayObjects() const
Return all objects of the Array const T.
Definition: BinnedArray1D.h:158
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:190
Trk::BinnedArray1D::BinnedArray1D
BinnedArray1D()
Default Constructor - needed for inherited classes.
Definition: BinnedArray1D.h:40
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::BinnedArray1D::object
T * object(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray it returns 0 if not defined;.
Definition: BinnedArray1D.h:126
Trk::SharedObject
std::shared_ptr< T > SharedObject
Definition: SharedObject.h:24
Trk::BinnedArray1D::m_arrayObjects
CxxUtils::CachedUniquePtr< std::vector< T * > > m_arrayObjects
binUtility for retrieving and filling the Array
Definition: BinnedArray1D.h:188
Trk::BinUtility::clone
BinUtility * clone() const
Implizit Constructor.
Definition: BinUtility.h:130
Trk::BinnedArray1D::arrayObjectsNumber
unsigned int arrayObjectsNumber() const
Number of Entries in the Array.
Definition: BinnedArray1D.h:165
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:136
Trk::BinnedArray
Definition: BinnedArray.h:38
CxxUtils::ivec
vec_fb< typename boost::int_t< sizeof(T) *8 >::exact, N > ivec
Definition: vec_fb.h:53
Trk::BinnedArraySpan
std::span< T > BinnedArraySpan
Definition: BinnedArray.h:34
Trk::BinnedArray1D
Definition: BinnedArray1D.h:36
Trk::BinUtility::next
size_t next(const Amg::Vector3D &position, const Amg::Vector3D &direction, size_t ba=0) const
Bin from a 3D vector (already in binning frame)
Definition: BinUtility.h:153
Trk::BinnedArray1D::m_binUtility
BinUtility * m_binUtility
Definition: BinnedArray1D.h:190