ATLAS Offline Software
NavBinnedArray1D.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // NavBinnedArray1D.h, (c) ATLAS Detector software
8 
9 #ifndef TRKDETDESCRUTILS_NAVBINNEDARRAY1D_H
10 #define TRKDETDESCRUTILS_NAVBINNEDARRAY1D_H
11 
14 
15 // STL
16 #include <vector>
17 
18 class MsgStream;
19 
20 namespace Trk {
21 
34 template<class T>
35 class NavBinnedArray1D final : public BinnedArray<T>
36 {
37 
38 public:
41  : BinnedArray<T>()
42  , m_array{}
43  , m_arrayObjects(nullptr)
44  , m_binUtility()
45  , m_transf(nullptr)
46  {}
47 
52  NavBinnedArray1D(const std::vector<SharedObject<T>>& tclassvector,
53  BinUtility* bingen,
55  : BinnedArray<T>()
56  , m_array{}
57  , m_arrayObjects(nullptr)
60  {
61  // prepare the binned Array // simplify as the array is ordered when defined
62  if (bingen) {
63  m_array = std::vector<SharedObject<T>>(tclassvector);
64  }
65  }
66 
69  std::vector<SharedObject<T>>&& vec,
70  Amg::Transform3D& shift)
71  : BinnedArray<T>()
72  , m_array(std::move(vec))
73  , m_arrayObjects{}
74  , m_binUtility(barr.m_binUtility)
75  , m_transf(new Amg::Transform3D(shift * (*barr.m_transf)))
76  {}
77 
80  : BinnedArray<T>()
81  , m_array{}
82  , m_arrayObjects(nullptr)
83  , m_binUtility(barr.m_binUtility)
84  , m_transf(nullptr)
85  {
86  if (m_binUtility.get()) {
87  m_array = std::vector<SharedObject<T>>(m_binUtility.get()->bins(0));
88  for (size_t ient = 0; ient < m_binUtility.get()->bins(0); ++ient) {
89  m_array[ient] = (barr.m_array)[ient];
90  }
91  }
92  m_transf =
93  (barr.m_transf) ? new Amg::Transform3D(*(barr.m_transf)) : nullptr;
94  }
95 
98  {
99  if (this != &barr) {
100  m_arrayObjects.release();
101  delete m_transf;
102  // now refill
103  m_binUtility = barr.m_binUtility;
104  // --------------------------------------------------------------------------
105  if (m_binUtility.get()) {
106  m_array = std::vector<SharedObject<T>>(m_binUtility.get()->bins(0));
107  for (size_t ient = 0; ient < m_binUtility.get()->bins(0); ++ient) {
108  m_array[ient] = (barr.m_array)[ient];
109  }
110  }
111  m_transf =
112  (barr.m_transf) ? new Amg::Transform3D(*barr.m_transf) : nullptr;
113  }
114  return *this;
115  }
116 
118  NavBinnedArray1D* clone() const { return new NavBinnedArray1D(*this); }
119 
122 
126  T* object(const Amg::Vector2D& lp) const
127  {
128  if (m_binUtility.get()->inside(lp)) {
129  return (m_array[m_binUtility.get()->bin(lp)]).get();
130  }
131  return nullptr;
132  }
133 
137  T* object(const Amg::Vector3D& gp) const
138  {
139  // transform into navig.coordinates
140  const Amg::Vector3D navGP((m_transf->inverse()) * gp);
141  if (m_binUtility.get()->inside(navGP)) {
142  return (m_array[m_binUtility.get()->bin(navGP)]).get();
143  }
144  return nullptr;
145  }
146 
149  T* entryObject(const Amg::Vector3D&) const { return (m_array[0]).get(); }
150 
153  T* nextObject(const Amg::Vector3D& gp,
154  const Amg::Vector3D& mom,
155  bool associatedResult = true) const
156  {
157  // transform into navig.coordinates
158  const Amg::Vector3D navGP((m_transf->inverse()) * gp);
159  const Amg::Vector3D navMom((m_transf->inverse()).linear() * mom);
160  // the bins
161  size_t firstBin = m_binUtility.get()->next(navGP, navMom, 0);
162  // use the information of the associated result
163  if (associatedResult) {
164  if (firstBin <= m_binUtility.get()->max(0)) {
165  return (m_array[firstBin]).get();
166  } else {
167  return nullptr;
168  }
169  }
170  // the associated result was 0 -> set to boundary
171  firstBin = (firstBin < m_binUtility.get()->bins(0))
172  ? firstBin
173  : m_binUtility.get()->max(0);
174  return (m_array[m_binUtility.get()->bin(navGP)]).get();
175  }
176 
179  {
181  return BinnedArraySpan<T* const>(&*(m_arrayObjects->begin()), &*(m_arrayObjects->end()));
182  }
183 
186  {
188  return BinnedArraySpan<T const * const>(&*(m_arrayObjects->begin()), &*(m_arrayObjects->end()));
189  }
190 
192  unsigned int arrayObjectsNumber() const { return arrayObjects().size(); }
193 
195  const BinUtility* binUtility() const { return (m_binUtility.get()); }
196 
198  Amg::Transform3D* transform() const { return (m_transf); }
199 
202  {
205  delete tr;
206  }
207 
208 private:
209  void createArrayCache() const
210  {
211  if (!m_arrayObjects) {
212  std::unique_ptr<std::vector<T*>> arrayObjects =
213  std::make_unique<std::vector<T*>>();
214  for (unsigned int ill = 0; ill < m_array.size(); ++ill) {
215  arrayObjects->push_back((m_array[ill]).get());
216  }
217  m_arrayObjects.set(std::move(arrayObjects));
218  }
219  }
220 
222  std::vector<SharedObject<T>> m_array;
227  // !< transform into local navigation coordinates
229 };
230 
231 } // end of namespace Trk
232 
233 #endif // TRKDETDESCRUTILS_NAVBINNEDARRAY1D_H
Trk::NavBinnedArray1D::m_binUtility
SharedObject< BinUtility > m_binUtility
Definition: NavBinnedArray1D.h:226
Trk::NavBinnedArray1D::arrayObjectsNumber
unsigned int arrayObjectsNumber() const
Number of Entries in the Array.
Definition: NavBinnedArray1D.h:192
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
Trk::NavBinnedArray1D::~NavBinnedArray1D
~NavBinnedArray1D()
Virtual Destructor.
Definition: NavBinnedArray1D.h:121
CxxUtils::CachedUniquePtrT
Cached pointer with atomic update.
Definition: CachedUniquePtr.h:54
BinUtility.h
Trk::NavBinnedArray1D::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: NavBinnedArray1D.h:153
Trk::NavBinnedArray1D::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: NavBinnedArray1D.h:126
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
Trk::NavBinnedArray1D::binUtility
const BinUtility * binUtility() const
Return the BinUtility.
Definition: NavBinnedArray1D.h:195
Trk::NavBinnedArray1D::NavBinnedArray1D
NavBinnedArray1D(const NavBinnedArray1D &barr)
Copy Constructor - copies only pointers !
Definition: NavBinnedArray1D.h:79
Trk::NavBinnedArray1D::m_transf
Amg::Transform3D * m_transf
Definition: NavBinnedArray1D.h:228
Trk::NavBinnedArray1D::m_arrayObjects
CxxUtils::CachedUniquePtr< std::vector< T * > > m_arrayObjects
binUtility for retrieving and filling the Array
Definition: NavBinnedArray1D.h:224
Trk::NavBinnedArray1D::arrayObjects
BinnedArraySpan< T const *const > arrayObjects() const
Return all objects of the Array const T.
Definition: NavBinnedArray1D.h:185
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
Trk::NavBinnedArray1D::transform
Amg::Transform3D * transform() const
Return the transform.
Definition: NavBinnedArray1D.h:198
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Trk::NavBinnedArray1D::NavBinnedArray1D
NavBinnedArray1D()
Default Constructor - needed for inherited classes.
Definition: NavBinnedArray1D.h:40
Trk::NavBinnedArray1D::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: NavBinnedArray1D.h:137
SharedObject.h
Trk::NavBinnedArray1D::m_array
std::vector< SharedObject< T > > m_array
forced 1D vector of pointers to class T
Definition: NavBinnedArray1D.h:222
Trk::BinUtility
Definition: BinUtility.h:39
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::NavBinnedArray1D::NavBinnedArray1D
NavBinnedArray1D(const NavBinnedArray1D &barr, std::vector< SharedObject< T >> &&vec, Amg::Transform3D &shift)
Copy Constructor with shift.
Definition: NavBinnedArray1D.h:68
Trk::NavBinnedArray1D::NavBinnedArray1D
NavBinnedArray1D(const std::vector< SharedObject< T >> &tclassvector, BinUtility *bingen, Amg::Transform3D *transform)
Constructor with std::vector and a BinUtility - reference counted, will delete objects at the end,...
Definition: NavBinnedArray1D.h:52
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::NavBinnedArray1D::arrayObjects
BinnedArraySpan< T *const > arrayObjects()
Return all objects of the Array non-const T.
Definition: NavBinnedArray1D.h:178
Trk::NavBinnedArray1D::operator=
NavBinnedArray1D & operator=(const NavBinnedArray1D &barr)
Assignment operator.
Definition: NavBinnedArray1D.h:97
Trk::SharedObject
std::shared_ptr< T > SharedObject
Definition: SharedObject.h:24
Trk::NavBinnedArray1D
Definition: NavBinnedArray1D.h:36
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
Trk::NavBinnedArray1D::updateTransform
void updateTransform(Amg::Transform3D &transform)
Reposition.
Definition: NavBinnedArray1D.h:201
Trk::NavBinnedArray1D::entryObject
T * entryObject(const Amg::Vector3D &) const
Returns the pointer to the templated class object from the BinnedArray - entry point.
Definition: NavBinnedArray1D.h:149
Trk::BinnedArray
Definition: BinnedArray.h:38
Trk::BinnedArraySpan
std::span< T > BinnedArraySpan
Definition: BinnedArray.h:34
Trk::NavBinnedArray1D::clone
NavBinnedArray1D * clone() const
Implicit Constructor.
Definition: NavBinnedArray1D.h:118
Trk::NavBinnedArray1D::createArrayCache
void createArrayCache() const
vector of pointers to the class T
Definition: NavBinnedArray1D.h:209