Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VectorTrackContainer.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VectorTrackContainer.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
19 
20 #include <any>
21 #include <cassert>
22 #include <cstddef>
23 #include <memory>
24 #include <stdexcept>
25 #include <string>
26 #include <type_traits>
27 #include <unordered_map>
28 #include <utility>
29 #include <vector>
30 
31 namespace Acts {
32 class Surface;
33 template <typename T>
35 
36 namespace detail_vtc {
37 
39  public:
41  static constexpr auto kInvalid = MultiTrajectoryTraits::kInvalid;
42  static constexpr auto MeasurementSizeMax =
44 
45  using Parameters =
47  using Covariance =
49 
50  using ConstParameters =
52  using ConstCovariance =
54 
55  protected:
56  VectorTrackContainerBase() = default;
57 
59 
61 
62  // BEGIN INTERFACE HELPER
63 
64  template <bool EnsureConst, typename T>
65  static std::any component_impl(T& instance, HashedString key,
66  IndexType itrack) {
67  using namespace Acts::HashedStringLiteral;
68  if constexpr (EnsureConst) {
69  static_assert(std::is_const_v<std::remove_reference_t<T>>,
70  "Is not const");
71  }
72 
73  using namespace Acts::HashedStringLiteral;
74  switch (key) {
75  case "tipIndex"_hash:
76  return &instance.m_tipIndex[itrack];
77  case "stemIndex"_hash:
78  return &instance.m_stemIndex[itrack];
79  case "particleHypothesis"_hash:
80  return &instance.m_particleHypothesis[itrack];
81  case "params"_hash:
82  return &instance.m_params[itrack];
83  case "cov"_hash:
84  return &instance.m_cov[itrack];
85  case "nMeasurements"_hash:
86  return &instance.m_nMeasurements[itrack];
87  case "nHoles"_hash:
88  return &instance.m_nHoles[itrack];
89  case "chi2"_hash:
90  return &instance.m_chi2[itrack];
91  case "ndf"_hash:
92  return &instance.m_ndf[itrack];
93  case "nOutliers"_hash:
94  return &instance.m_nOutliers[itrack];
95  case "nSharedHits"_hash:
96  return &instance.m_nSharedHits[itrack];
97  default:
98  auto it = instance.m_dynamic.find(key);
99  if (it == instance.m_dynamic.end()) {
100  throw std::runtime_error("Unable to handle this component");
101  }
102 
103  std::conditional_t<EnsureConst, const detail::DynamicColumnBase*,
104  detail::DynamicColumnBase*>
105  col = it->second.get();
106  assert(col && "Dynamic column is null");
107  return col->get(itrack);
108  }
109  }
110 
111  bool checkConsistency() const {
112  size_t size = m_tipIndex.size();
113  (void)size;
114 
115  bool result = true;
116  result = result && m_tipIndex.size() == size;
117  assert(result);
118  result = result && m_stemIndex.size() == size;
119  assert(result);
120  result = result && m_particleHypothesis.size() == size;
121  assert(result);
122  result = result && m_params.size() == size;
123  assert(result);
124  result = result && m_cov.size() == size;
125  assert(result);
126  result = result && m_referenceSurfaces.size() == size;
127  assert(result);
128  result = result && m_nMeasurements.size() == size;
129  assert(result);
130  result = result && m_nHoles.size() == size;
131  assert(result);
132  result = result && m_chi2.size() == size;
133  assert(result);
134  result = result && m_ndf.size() == size;
135  assert(result);
136  result = result && m_nOutliers.size() == size;
137  assert(result);
138  result = result && m_nSharedHits.size() == size;
139 
140  for (const auto& [key, col] : m_dynamic) {
141  (void)key;
142  result = result && col->size() == size;
143  }
144 
145  return result;
146  }
147 
148  public:
149  constexpr bool hasColumn_impl(HashedString key) const {
150  using namespace Acts::HashedStringLiteral;
151  switch (key) {
152  default:
153  return m_dynamic.find(key) != m_dynamic.end();
154  }
155  }
156 
157  const Surface* referenceSurface_impl(IndexType itrack) const {
158  return m_referenceSurfaces[itrack].get();
159  }
160 
161  std::size_t size_impl() const {
163  return m_tipIndex.size();
164  }
165  // END INTERFACE HELPER
166 
167  std::vector<IndexType> m_tipIndex;
168  std::vector<IndexType> m_stemIndex;
169  std::vector<ParticleHypothesis> m_particleHypothesis;
170  std::vector<typename detail_lt::Types<eBoundSize>::Coefficients> m_params;
172  std::vector<std::shared_ptr<const Surface>> m_referenceSurfaces;
173 
174  std::vector<unsigned int> m_nMeasurements;
175  std::vector<unsigned int> m_nHoles;
176  std::vector<float> m_chi2;
177  std::vector<unsigned int> m_ndf;
178  std::vector<unsigned int> m_nOutliers;
179  std::vector<unsigned int> m_nSharedHits;
180 
181  std::unordered_map<HashedString, std::unique_ptr<detail::DynamicColumnBase>>
183 };
184 
185 } // namespace detail_vtc
186 
189 
190 template <>
192 
194  public:
196  VectorTrackContainer(const VectorTrackContainer& other) = default;
197  VectorTrackContainer(VectorTrackContainer&&) = default;
198 
199  VectorTrackContainer(const ConstVectorTrackContainer& other);
200 
201  public:
202  // BEGIN INTERFACE
203 
204  std::any component_impl(HashedString key, IndexType itrack) {
205  return detail_vtc::VectorTrackContainerBase::component_impl<false>(
206  *this, key, itrack);
207  }
208 
209  std::any component_impl(HashedString key, IndexType itrack) const {
210  return detail_vtc::VectorTrackContainerBase::component_impl<true>(
211  *this, key, itrack);
212  }
213 
214  IndexType addTrack_impl();
215 
216  void removeTrack_impl(IndexType itrack);
217 
218  template <typename T>
219  constexpr void addColumn_impl(const std::string& key) {
220  m_dynamic.insert(
221  {hashString(key), std::make_unique<detail::DynamicColumn<T>>()});
222  }
223 
225  return Parameters{m_params[itrack].data()};
226  }
227 
229  return ConstParameters{m_params[itrack].data()};
230  }
231 
233  return Covariance{m_cov[itrack].data()};
234  }
235 
237  return ConstCovariance{m_cov[itrack].data()};
238  }
239 
240  void copyDynamicFrom_impl(IndexType dstIdx,
241  const VectorTrackContainerBase& src,
242  IndexType srcIdx);
243 
244  void ensureDynamicColumns_impl(
246 
247  void reserve(IndexType size);
248  void clear();
249 
250  void setReferenceSurface_impl(IndexType itrack,
251  std::shared_ptr<const Surface> surface) {
252  m_referenceSurfaces[itrack] = std::move(surface);
253  }
254 
255  void setParticleHypothesis_impl(
258  }
259 
260  // END INTERFACE
261 };
262 
263 ACTS_STATIC_CHECK_CONCEPT(TrackContainerBackend, VectorTrackContainer);
264 
265 class ConstVectorTrackContainer;
266 
267 template <>
269 
272  public:
274 
275  ConstVectorTrackContainer(const ConstVectorTrackContainer& other) = default;
277  : VectorTrackContainerBase{other} {
279  }
280 
281  ConstVectorTrackContainer(ConstVectorTrackContainer&&) = default;
285  }
286 
287  public:
288  // BEGIN INTERFACE
289 
290  std::any component_impl(HashedString key, IndexType itrack) const {
291  return detail_vtc::VectorTrackContainerBase::component_impl<true>(
292  *this, key, itrack);
293  }
294 
296  return ConstParameters{m_params[itrack].data()};
297  }
298 
300  return ConstCovariance{m_cov[itrack].data()};
301  }
302 
303  // END INTERFACE
304 };
305 
306 ACTS_STATIC_CHECK_CONCEPT(ConstTrackContainerBackend,
307  ConstVectorTrackContainer);
308 
310  const ConstVectorTrackContainer& other)
311  : VectorTrackContainerBase{other} {
312  assert(checkConsistency());
313 }
314 
315 } // namespace Acts