ATLAS Offline Software
BinnedArray1D1D.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 // BinnedArray1D1D.h, (c) ATLAS Detector software
8 
9 #ifndef TRKDETDESCRUTILS_BINNEDARRAY1D1D_H
10 #define TRKDETDESCRUTILS_BINNEDARRAY1D1D_H
11 
15 
17 #include <vector>
18 #include <utility>
19 
20 class MsgStream;
21 
22 namespace Trk {
23 
34 template<class T>
35 class BinnedArray1D1D final : public BinnedArray<T>
36 {
37 
38 public:
41  : BinnedArray<T>()
42  , m_array{}
43  , m_arrayObjects(nullptr)
44  , m_steeringBinUtility(nullptr)
45  , m_singleBinUtilities(nullptr)
46  {}
47 
50  const std::vector<std::pair<SharedObject<T>, Amg::Vector3D>>& tclassvector,
51  BinUtility* steeringBinGen1D,
52  std::vector<BinUtility*>* singleBinGen)
53  : BinnedArray<T>()
54  , m_array{}
55  , m_arrayObjects(nullptr)
56  , m_steeringBinUtility(steeringBinGen1D)
57  , m_singleBinUtilities(singleBinGen)
58  {
59 
60  // prepare the binned Array
61  if (steeringBinGen1D) {
62  m_array =
63  std::vector<std::vector<SharedObject<T>>>(steeringBinGen1D->bins());
64  for (size_t i = 0; i < steeringBinGen1D->bins(); ++i) {
65  size_t sizeOfSubBin = ((*m_singleBinUtilities)[i])->bins();
66  m_array[i] = std::vector<SharedObject<T>>(sizeOfSubBin);
67  }
68 
69  // fill the Volume vector into the array
70  int vecsize(tclassvector.size());
71  for (int ivec = 0; ivec < vecsize; ++ivec) {
72  const Amg::Vector3D currentGlobal((tclassvector[ivec]).second);
73  if (steeringBinGen1D->inside(currentGlobal)) {
74  int steeringBin = steeringBinGen1D->bin(currentGlobal, 0);
75  int singleBin =
76  ((*m_singleBinUtilities)[steeringBin])->bin(currentGlobal, 0);
77  std::vector<SharedObject<T>>& curVec = m_array[steeringBin];
78  curVec[singleBin] = ((tclassvector)[ivec]).first;
79  } else
80  throw GaudiException(
81  "BinnedArray1D1D", "Object outside bounds", StatusCode::FAILURE);
82  }
83  }
84  }
85 
88  : BinnedArray<T>()
89  , m_array{}
90  , m_arrayObjects(nullptr)
91  , m_steeringBinUtility(nullptr)
92  , m_singleBinUtilities(nullptr)
93  {
94  // prepare the binUtilities
95  m_steeringBinUtility = (barr.m_steeringBinUtility)
96  ? barr.m_steeringBinUtility->clone()
97  : nullptr;
98  m_singleBinUtilities = new std::vector<BinUtility*>;
100  barr.m_singleBinUtilities->begin();
101  for (; singleBinIter != barr.m_singleBinUtilities->end(); ++singleBinIter) {
102  m_singleBinUtilities->push_back((*singleBinIter)->clone());
103  }
104 
105  // prepare the binned Array
106  if (m_steeringBinUtility && !m_singleBinUtilities->empty()) {
107  // prepare the array
108  m_array = std::vector<std::vector<SharedObject<T>>>(
110  for (size_t i = 0; i < m_steeringBinUtility->bins(0); ++i) {
111  size_t sizeOfSubBin = ((*m_singleBinUtilities)[i])->bins(0);
112  m_array[i] = std::vector<SharedObject<T>>(sizeOfSubBin, nullptr);
113  }
114 
115  // assign the items
116  for (size_t isteer = 0; isteer < m_steeringBinUtility->bins(0);
117  ++isteer) {
118  for (size_t isingle = 0;
119  isingle < (*m_singleBinUtilities)[isteer]->bins(0);
120  ++isteer) {
121  m_array[isteer][isingle] = (barr.m_array)[isteer][isingle];
122  }
123  }
124  }
125  }
126 
129  {
130  if (this != &barr) {
131 
132  m_arrayObjects.release();
133  delete m_steeringBinUtility;
134 
135  std::vector<BinUtility*>::iterator singleBinIter =
136  m_singleBinUtilities->begin();
137  for (; singleBinIter != m_singleBinUtilities->end(); ++singleBinIter) {
138  delete *singleBinIter;
139  }
140  delete m_singleBinUtilities;
141  m_singleBinUtilities = new std::vector<BinUtility*>;
142 
143  // now assign the stuff
145  (barr.m_steeringBinUtility) ? (barr.m_steeringBinUtility)->clone() : 0;
146 
147  singleBinIter = barr.m_singleBinUtilties->begin();
148  for (; singleBinIter != barr.m_singleBinUtilities->end(); ++singleBinIter)
149  m_singleBinUtilities->push_back((*singleBinIter)->clone());
150 
151  // prepare the binned Array
153  // prepare the array
154  m_array = std::vector<std::vector<SharedObject<T>>>(
156  for (int i = 0; i < m_steeringBinUtility->bins(0); ++i) {
157  unsigned int sizeOfSubBin = ((*m_singleBinUtilities)[i])->bins(0);
158  m_array[i] = std::vector<SharedObject<T>>(sizeOfSubBin);
159  }
160 
161  // assign the items
162  for (int isteer = 0; isteer < m_steeringBinUtility->bins(0); ++isteer) {
163  for (int isingle = 0;
164  isingle < (*m_singleBinUtilities)[isteer]->bins(0);
165  ++isteer) {
166  m_array[isteer][isingle] = (barr.m_array)[isteer][isingle];
167  }
168  }
169  }
170  }
171  return *this;
172  }
173 
175  BinnedArray1D1D* clone() const { return new BinnedArray1D1D(*this); }
176 
179  {
180  delete m_steeringBinUtility;
181  if (m_singleBinUtilities) {
183  m_singleBinUtilities->begin();
184  for (; binIter != m_singleBinUtilities->end(); ++binIter) {
185  delete *binIter;
186  }
187  }
188  delete m_singleBinUtilities;
189  }
190 
194  T* object(const Amg::Vector2D& lp) const
195  {
196  int steerBin = m_steeringBinUtility->bin(lp, 0);
197  int singleBin = std::as_const(*m_singleBinUtilities)[steerBin]->bin(lp, 0);
198  return (m_array[steerBin][singleBin]).get();
199  }
200 
204  T* object(const Amg::Vector3D& gp) const
205  {
206  int steerBin = m_steeringBinUtility->bin(gp, 0);
207  int singleBin = std::as_const(*m_singleBinUtilities)[steerBin]->bin(gp, 0);
208  return (m_array[steerBin][singleBin]).get();
209  }
210 
213  T* entryObject(const Amg::Vector3D& gp) const
214  {
215  int steerBin = m_steeringBinUtility->entry(gp, 0);
216  int singleBin = std::as_const(*m_singleBinUtilities)[steerBin]->entry(gp, 0);
217  return (m_array[steerBin][singleBin]).get();
218  }
219 
221  T* nextObject(const Amg::Vector3D&, const Amg::Vector3D&, bool) const
222  {
223  return nullptr;
224  }
225 
228  {
230  return Trk::BinnedArraySpan<T* const>(&*(m_arrayObjects->begin()), &*(m_arrayObjects->end()));
231  }
232 
235  {
237  return BinnedArraySpan<const T* const>(&*(m_arrayObjects->begin()), &*(m_arrayObjects->end()));
238  }
239 
241  unsigned int arrayObjectsNumber() const { return arrayObjects().size(); }
242 
244  const BinUtility* binUtility() const { return (m_steeringBinUtility); }
245 
246 private:
247  void createArrayCache() const
248  {
249  if (!m_arrayObjects) {
250  std::unique_ptr<std::vector<T*>> arrayObjects =
251  std::make_unique<std::vector<T*>>();
252  for (size_t isteer = 0; isteer < m_steeringBinUtility->bins(); ++isteer) {
253  for (size_t isingle = 0;
254  isingle < std::as_const(*m_singleBinUtilities)[isteer]->bins();
255  ++isingle) {
256  arrayObjects->push_back((m_array[isteer][isingle]).get());
257  }
258  }
259  m_arrayObjects.set(std::move(arrayObjects));
260  }
261  }
263  std::vector<std::vector<SharedObject<T>>> m_array;
268  std::vector<BinUtility*>* m_singleBinUtilities;
269 };
270 } // end of namespace Trk
271 
272 #endif // TRKSURFACES_BINNEDARRAY1D1D_H
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
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::BinnedArray1D1D::BinnedArray1D1D
BinnedArray1D1D(const BinnedArray1D1D &barr)
Copy Constructor - copies only pointers!
Definition: BinnedArray1D1D.h:87
Trk::BinnedArray1D1D::m_steeringBinUtility
BinUtility * m_steeringBinUtility
Definition: BinnedArray1D1D.h:267
Trk::BinnedArray1D1D::entryObject
T * entryObject(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray - entry point.
Definition: BinnedArray1D1D.h:213
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
BinnedArray.h
Trk::BinnedArray1D1D::operator=
BinnedArray1D1D & operator=(const BinnedArray1D1D &barr)
Assignment operator.
Definition: BinnedArray1D1D.h:128
CxxUtils::CachedUniquePtrT
Cached pointer with atomic update.
Definition: CachedUniquePtr.h:54
BinUtility.h
Trk::BinnedArray1D1D::m_arrayObjects
CxxUtils::CachedUniquePtr< std::vector< T * > > m_arrayObjects
binUtility for retrieving and filling the Array
Definition: BinnedArray1D1D.h:265
Trk::BinnedArray1D1D::m_singleBinUtilities
std::vector< BinUtility * > * m_singleBinUtilities
single bin utilities
Definition: BinnedArray1D1D.h:268
Trk::BinnedArray1D1D::m_array
std::vector< std::vector< SharedObject< T > > > m_array
forced 1D vector of pointers to class T
Definition: BinnedArray1D1D.h:263
Trk::BinUtility::bins
size_t bins(size_t ba=0) const
Number of bins.
Definition: BinUtility.h:223
Trk::BinnedArray1D1D::arrayObjects
BinnedArraySpan< T *const > arrayObjects()
Return all objects of the Array non-const T.
Definition: BinnedArray1D1D.h:227
lumiFormat.i
int i
Definition: lumiFormat.py:85
Trk::BinnedArray1D1D::arrayObjectsNumber
unsigned int arrayObjectsNumber() const
Number of Entries in the Array.
Definition: BinnedArray1D1D.h:241
Trk::BinnedArray1D1D::createArrayCache
void createArrayCache() const
vector of pointers to the class T
Definition: BinnedArray1D1D.h:247
Trk::BinnedArray1D1D::BinnedArray1D1D
BinnedArray1D1D()
Default Constructor - needed for inherited classes.
Definition: BinnedArray1D1D.h:40
Trk::BinnedArray1D1D::BinnedArray1D1D
BinnedArray1D1D(const std::vector< std::pair< SharedObject< T >, Amg::Vector3D >> &tclassvector, BinUtility *steeringBinGen1D, std::vector< BinUtility * > *singleBinGen)
Constructor with std::vector and a BinUtility.
Definition: BinnedArray1D1D.h:49
Trk::BinnedArray1D1D::clone
BinnedArray1D1D * clone() const
Implicit Constructor.
Definition: BinnedArray1D1D.h:175
Trk::BinnedArray1D1D::binUtility
const BinUtility * binUtility() const
Return the BinUtility - returns the steering binUtility in this case.
Definition: BinnedArray1D1D.h:244
Trk::BinnedArray1D1D::nextObject
T * nextObject(const Amg::Vector3D &, const Amg::Vector3D &, bool) const
Returns the pointer to the templated class object from the BinnedArray.
Definition: BinnedArray1D1D.h:221
CachedUniquePtr.h
Cached unique_ptr with atomic update.
Trk::BinnedArray1D1D::~BinnedArray1D1D
virtual ~BinnedArray1D1D()
Virtual Destructor.
Definition: BinnedArray1D1D.h:178
Trk::BinnedArray1D1D
Definition: BinnedArray1D1D.h:36
plotting.yearwise_luminosity_vs_mu.bins
bins
Definition: yearwise_luminosity_vs_mu.py:30
Trk::BinnedArray1D1D::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: BinnedArray1D1D.h:194
SharedObject.h
Trk::BinUtility
Definition: BinUtility.h:39
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::BinnedArray1D1D::arrayObjects
BinnedArraySpan< T const *const > arrayObjects() const
Return all objects of the Array const T.
Definition: BinnedArray1D1D.h:234
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::BinnedArray1D1D::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: BinnedArray1D1D.h:204
Trk::SharedObject
std::shared_ptr< T > SharedObject
Definition: SharedObject.h:24
Trk::BinUtility::clone
BinUtility * clone() const
Implizit Constructor.
Definition: BinUtility.h:130
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