ATLAS Offline Software
BinnedArray1D1D1D.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 // BinnedArray1D1D1D.h, (c) ATLAS Detector software
8 
9 #ifndef TRKDETDESCRUTILS_BINNEDARRAY1D1D1D_H
10 #define TRKDETDESCRUTILS_BINNEDARRAY1D1D1D_H
11 //
15 //
16 // STL
17 #include <cassert>
18 #include <vector>
19 #include <utility>
20 //
21 class MsgStream;
22 //
23 namespace Trk {
24 
37 template<class T>
38 class BinnedArray1D1D1D final : public BinnedArray<T>
39 {
40 
41 public:
44  : BinnedArray<T>()
45  , m_array{}
46  , m_arrayObjects(nullptr)
47  , m_binUtil1(nullptr)
48  , m_binUtil2(nullptr)
49  , m_binUtilArray(nullptr)
50  {}
51 
54  const std::vector<std::pair<SharedObject<T>, Amg::Vector3D>>& tclassvector,
55  BinUtility* binUtil1,
56  BinUtility* binUtil2,
57  std::vector<std::vector<BinUtility*>>* binUtilVec)
58  : BinnedArray<T>()
59  , m_array{}
60  , m_arrayObjects(nullptr)
61  , m_binUtil1(binUtil1)
62  , m_binUtil2(binUtil2)
63  , m_binUtilArray(binUtilVec)
64  {
65  // prepare the binned Array
66  if (!binUtil1 || !binUtil2 || !binUtilVec) {
67  throw std::logic_error("Invalid BinUtilities");
68  }
69 
70  {
71  int v1Size = binUtil1->bins();
72  int v2Size = binUtil2->bins();
73  m_array = std::vector<std::vector<std::vector<SharedObject<T>>>>(v1Size);
74  for (int i = 0; i < v1Size; ++i) {
75  m_array[i] = std::vector<std::vector<SharedObject<T>>>(v2Size);
76  for (int j = 0; j < v2Size; ++j) {
77  m_array[i][j] =
78  std::vector<SharedObject<T>>((*binUtilVec)[i][j]->bins());
79  }
80  }
81  }
82 
83  // fill the Volume vector into the array
84  int vecsize(tclassvector.size());
85  for (int ivec = 0; ivec < vecsize; ++ivec) {
86  Amg::Vector3D currentGlobal((tclassvector[ivec]).second);
87  if (binUtil1->inside(currentGlobal) && binUtil2->inside(currentGlobal)) {
88  int bin1 = binUtil1->bin(currentGlobal);
89  int bin2 = binUtil2->bin(currentGlobal);
90  assert((*binUtilVec)[bin1][bin2]);
91  int bin3 = (*binUtilVec)[bin1][bin2]->bin(currentGlobal);
92  std::vector<std::vector<SharedObject<T>>>& currArr = m_array[bin1];
93  std::vector<SharedObject<T>>& curVec = currArr[bin2];
94  curVec[bin3] = ((tclassvector)[ivec]).first;
95  } else
96  throw GaudiException(
97  "BinnedArray1D1D1D", "Object outside bounds", StatusCode::FAILURE);
98  }
99  }
100 
103  : BinnedArray<T>()
104  , m_array{}
105  , m_arrayObjects(nullptr)
106  , m_binUtil1(nullptr)
107  , m_binUtil2(nullptr)
108  , m_binUtilArray(nullptr)
109  {
110  // prepare the binUtilities
111  m_binUtil1 = (barr.m_binUtil1) ? barr.m_binUtil1->clone() : 0;
112  m_binUtil2 = (barr.m_binUtil2) ? barr.m_binUtil2->clone() : 0;
113  m_binUtilArray = new std::vector<std::vector<BinUtility*>>;
114  std::vector<std::vector<BinUtility*>>::iterator singleBinIter =
115  barr.m_binUtilArray->begin();
116  for (; singleBinIter != barr.m_binUtilArray->end(); ++singleBinIter) {
117  m_binUtilArray->push_back(
118  std::vector<BinUtility*>((*singleBinIter).size()));
119  for (unsigned int ibin = 0; ibin < m_binUtilArray->back().size(); ibin++)
120  m_binUtilArray->back()[ibin] = (*singleBinIter)[ibin]->clone();
121  }
122 
123  // prepare the binned Array
124  if (m_binUtil1 && m_binUtil2 && m_binUtilArray->size()) {
125  int v1Size = m_binUtil1->bins();
126  int v2Size = m_binUtil2->bins();
127  m_array = std::vector<std::vector<std::vector<SharedObject<T>>>>(v1Size);
128  for (int i = 0; i < v1Size; ++i) {
129  m_array[i] = std::vector<std::vector<SharedObject<T>>>(v2Size);
130  for (int j = 0; j < v2Size; ++j)
131  m_array[i][j] =
132  std::vector<SharedObject<T>>((*m_binUtilArray)[i][j]->bins());
133  }
134 
135  // assign the items
136  for (int ibin1 = 0; ibin1 < v1Size; ++ibin1) {
137  for (int ibin2 = 0; ibin2 < v2Size; ++ibin2) {
138  for (size_t ibin3 = 0;
139  ibin3 < (*m_binUtilArray)[ibin1][ibin2]->bins();
140  ++ibin3) {
141  m_array[ibin1][ibin2][ibin3] = (barr.m_array)[ibin1][ibin2][ibin3];
142  }
143  }
144  }
145  }
146  }
147 
150  {
151  if (this != &barr) {
152 
153  m_arrayObjects.release();
154  // bin utilities
155  size_t v1Size = m_binUtil1->bins();
156  size_t v2Size = m_binUtil2->bins();
157  delete m_binUtil1;
158  delete m_binUtil2;
159 
160  for (size_t ibin1 = 0; ibin1 < v1Size; ibin1++) {
161  for (size_t ibin2 = 0; ibin2 < v2Size; ibin2++)
162  delete (*m_binUtilArray)[ibin1][ibin2];
163  }
164  delete m_binUtilArray;
165  m_binUtilArray = new std::vector<std::vector<BinUtility*>>;
166 
167  // now assign the stuff
168  m_binUtil1 = (barr.m_binUtil1) ? (barr.m_binUtil1)->clone() : 0;
169  m_binUtil2 = (barr.m_binUtil2) ? (barr.m_binUtil2)->clone() : 0;
170 
171  std::vector<std::vector<BinUtility*>>::iterator singleBinIter =
172  barr.m_binUtilArray->begin();
173  for (; singleBinIter != barr.m_binUtilArray->end(); ++singleBinIter) {
174  m_binUtilArray->push_back(
175  std::vector<BinUtility*>((*singleBinIter).size()));
176  for (int ibin = 0; ibin < m_binUtilArray->back().size(); ibin++)
177  m_binUtilArray->back()[ibin] = (*singleBinIter)[ibin]->clone();
178  }
179 
180  // prepare the binned Array
181  if (m_binUtil1 && m_binUtil2 && m_binUtilArray->size()) {
182  size_t v1Size = m_binUtil1->bins();
183  size_t v2Size = m_binUtil2->bins();
184  m_array =
185  std::vector<std::vector<std::vector<SharedObject<T>>>>(v1Size);
186  for (size_t i = 0; i < v1Size; ++i) {
187  m_array[i] = std::vector<std::vector<SharedObject<T>>>(v2Size);
188  for (size_t j = 0; j < v2Size; ++j)
189  m_array[i][j] =
190  std::vector<SharedObject<T>>((*m_binUtilArray)[i][j]->bins());
191  }
192 
193  // assign the items
194  for (size_t ibin1 = 0; ibin1 < v1Size; ++ibin1) {
195  for (size_t ibin2 = 0; ibin2 < v2Size; ++ibin2) {
196  for (size_t ibin3 = 0;
197  ibin3 < (*m_binUtilArray)[ibin1][ibin2]->bins();
198  ++ibin3) {
199  m_array[ibin1][ibin2][ibin3] =
200  (barr.m_array)[ibin1][ibin2][ibin3];
201  }
202  }
203  }
204  }
205  }
206  return *this;
207  }
208 
210  BinnedArray1D1D1D* clone() const { return new BinnedArray1D1D1D(*this); }
211 
214  {
215  int v1Size = m_binUtil1->bins();
216  int v2Size = m_binUtil2->bins();
217  delete m_binUtil1;
218  delete m_binUtil2;
219 
220  for (int ibin1 = 0; ibin1 < v1Size; ibin1++) {
221  for (int ibin2 = 0; ibin2 < v2Size; ibin2++)
222  delete (*m_binUtilArray)[ibin1][ibin2];
223  }
224  delete m_binUtilArray;
225  }
226 
230  T* object(const Amg::Vector2D& lp) const
231  {
232  if (!m_binUtil1->inside(lp) || !m_binUtil2->inside(lp))
233  return 0;
234  int bin1 = m_binUtil1->bin(lp);
235  int bin2 = m_binUtil2->bin(lp);
236  if (!std::as_const(*m_binUtilArray)[bin1][bin2]->inside(lp))
237  return 0;
238  int bin3 = std::as_const(*m_binUtilArray)[bin1][bin2]->bin(lp);
239 
240  return (m_array[bin1][bin2][bin3]).get();
241  }
242 
246  T* object(const Amg::Vector3D& gp) const
247  {
248  if (!m_binUtil1->inside(gp) || !m_binUtil2->inside(gp))
249  return 0;
250  int bin1 = m_binUtil1->bin(gp);
251  int bin2 = m_binUtil2->bin(gp);
252  if (!std::as_const(*m_binUtilArray)[bin1][bin2]->inside(gp))
253  return 0;
254  unsigned int bin3 = std::as_const(*m_binUtilArray)[bin1][bin2]->bin(gp);
255 
256  if (bin3 >= std::as_const(*m_binUtilArray)[bin1][bin2]->bins())
257  return 0;
258 
259  return (m_array[bin1][bin2][bin3]).get();
260  }
261 
264  T* entryObject(const Amg::Vector3D& gp) const
265  {
266  int bin1 = m_binUtil1->entry(gp, 0);
267  int bin2 = m_binUtil2->entry(gp, 0);
268  int bin3 = std::as_const(*m_binUtilArray)[bin1][bin2]->entry(gp, 0);
269 
270  return (m_array[bin1][bin2][bin3]).get();
271  }
272 
275  T* nextObject(const Amg::Vector3D&, const Amg::Vector3D&, bool) const
276  {
277  return 0;
278  }
279 
282  {
284  return BinnedArraySpan<T* const>(&*(m_arrayObjects->begin()), &*(m_arrayObjects->end()));
285  }
286 
289  {
291  return BinnedArraySpan<T const * const>(&*(m_arrayObjects->begin()), &*(m_arrayObjects->end()));
292  }
293 
295  unsigned int arrayObjectsNumber() const { return arrayObjects().size(); }
296 
298  const BinUtility* binUtility() const { return (m_binUtil1); }
299 
300 private:
301  void createArrayCache() const
302  {
303  if (!m_arrayObjects) {
304  std::unique_ptr<std::vector<T*>> arrayObjects =
305  std::make_unique<std::vector<T*>>();
306  for (size_t ibin1 = 0; ibin1 < m_binUtil1->bins(); ++ibin1) {
307  for (size_t ibin2 = 0; ibin2 < m_binUtil2->bins(); ++ibin2) {
308  for (size_t ibin3 = 0;
309  ibin3 < std::as_const(*m_binUtilArray)[ibin1][ibin2]->bins();
310  ++ibin3) {
311  arrayObjects->push_back((m_array[ibin1][ibin2][ibin3]).get());
312  }
313  }
314  }
315  m_arrayObjects.set(std::move(arrayObjects));
316  }
317  }
319  std::vector<std::vector<std::vector<SharedObject<T>>>> m_array;
324  std::vector<std::vector<BinUtility*>>* m_binUtilArray;
326 };
327 } // end of namespace Trk
328 #endif // TRKSURFACES_BINNEDARRAY1D1D1D_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
Trk::BinnedArray1D1D1D::operator=
BinnedArray1D1D1D & operator=(const BinnedArray1D1D1D &barr)
Assignment operator.
Definition: BinnedArray1D1D1D.h:149
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
Trk::BinnedArray1D1D1D::m_binUtil2
BinUtility * m_binUtil2
binUtility for retrieving and filling the Array
Definition: BinnedArray1D1D1D.h:323
Trk::BinnedArray1D1D1D::BinnedArray1D1D1D
BinnedArray1D1D1D()
Default Constructor - needed for inherited classes.
Definition: BinnedArray1D1D1D.h:43
Trk::BinnedArray1D1D1D::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: BinnedArray1D1D1D.h:246
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
Trk::BinnedArray1D1D1D::createArrayCache
void createArrayCache() const
vector of pointers to the class T
Definition: BinnedArray1D1D1D.h:301
BinnedArray.h
CxxUtils::CachedUniquePtrT
Cached pointer with atomic update.
Definition: CachedUniquePtr.h:54
BinUtility.h
Trk::BinnedArray1D1D1D::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: BinnedArray1D1D1D.h:230
Trk::BinnedArray1D1D1D::BinnedArray1D1D1D
BinnedArray1D1D1D(const BinnedArray1D1D1D &barr)
Copy Constructor - copies only pointers!
Definition: BinnedArray1D1D1D.h:102
dqt_zlumi_pandas.bin3
bin3
Definition: dqt_zlumi_pandas.py:351
Trk::BinnedArray1D1D1D::clone
BinnedArray1D1D1D * clone() const
Implicit Constructor.
Definition: BinnedArray1D1D1D.h:210
dqt_zlumi_pandas.bin2
bin2
Definition: dqt_zlumi_pandas.py:337
Trk::BinnedArray1D1D1D::m_binUtil1
BinUtility * m_binUtil1
binUtility for retrieving and filling the Array
Definition: BinnedArray1D1D1D.h:322
Trk::BinnedArray1D1D1D::m_array
std::vector< std::vector< std::vector< SharedObject< T > > > > m_array
forced 1D vector of pointers to class T
Definition: BinnedArray1D1D1D.h:319
SharedObject
Trk::BinUtility::bins
size_t bins(size_t ba=0) const
Number of bins.
Definition: BinUtility.h:223
Trk::BinnedArray1D1D1D::arrayObjects
BinnedArraySpan< T const *const > arrayObjects() const
Return all objects of the Array const T.
Definition: BinnedArray1D1D1D.h:288
lumiFormat.i
int i
Definition: lumiFormat.py:85
Trk::BinnedArray1D1D1D::~BinnedArray1D1D1D
~BinnedArray1D1D1D()
Virtual Destructor.
Definition: BinnedArray1D1D1D.h:213
plotting.yearwise_luminosity_vs_mu.bins
bins
Definition: yearwise_luminosity_vs_mu.py:30
SharedObject.h
bin2
Definition: KillBinsByStrip.h:34
Trk::BinUtility
Definition: BinUtility.h:39
Trk::BinnedArray1D1D1D::arrayObjects
BinnedArraySpan< T *const > arrayObjects()
Return all objects of the Array const T.
Definition: BinnedArray1D1D1D.h:281
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::BinnedArray1D1D1D::m_binUtilArray
std::vector< std::vector< BinUtility * > > * m_binUtilArray
Definition: BinnedArray1D1D1D.h:325
Trk::BinUtility::inside
bool inside(const Amg::Vector3D &position) const
Check if bin is inside from Vector3D.
Definition: BinUtility.h:190
Trk::BinnedArray1D1D1D::nextObject
T * nextObject(const Amg::Vector3D &, const Amg::Vector3D &, bool) const
Returns the pointer to the templated class object from the BinnedArray dummy for multidimensional arr...
Definition: BinnedArray1D1D1D.h:275
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::BinnedArray1D1D1D::BinnedArray1D1D1D
BinnedArray1D1D1D(const std::vector< std::pair< SharedObject< T >, Amg::Vector3D >> &tclassvector, BinUtility *binUtil1, BinUtility *binUtil2, std::vector< std::vector< BinUtility * >> *binUtilVec)
Constructor with std::vector and a BinUtility.
Definition: BinnedArray1D1D1D.h:53
Trk::BinnedArray1D1D1D::binUtility
const BinUtility * binUtility() const
Return the BinUtility - returns the first binUtility in this case.
Definition: BinnedArray1D1D1D.h:298
Trk::inside
@ inside
Definition: PropDirection.h:29
Trk::SharedObject
std::shared_ptr< T > SharedObject
Definition: SharedObject.h:24
dqt_zlumi_pandas.bin1
bin1
Definition: dqt_zlumi_pandas.py:336
Trk::BinUtility::clone
BinUtility * clone() const
Implizit Constructor.
Definition: BinUtility.h:130
bin3
Definition: BinsOutOfRange.h:33
Trk::BinnedArray1D1D1D::arrayObjectsNumber
unsigned int arrayObjectsNumber() const
Number of Entries in the Array.
Definition: BinnedArray1D1D1D.h:295
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
Trk::BinnedArray1D1D1D::entryObject
T * entryObject(const Amg::Vector3D &gp) const
Returns the pointer to the templated class object from the BinnedArray - entry point.
Definition: BinnedArray1D1D1D.h:264
Trk::BinnedArray1D1D1D
Definition: BinnedArray1D1D1D.h:39
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::BinnedArray1D1D1D::m_arrayObjects
CxxUtils::CachedUniquePtr< std::vector< T * > > m_arrayObjects
Definition: BinnedArray1D1D1D.h:321