ATLAS Offline Software
TrackContainer.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ACTSTRKEVENT_TRACKCONTAINER_H
6 #define ACTSTRKEVENT_TRACKCONTAINER_H 1
7 
10 #include "Acts/EventData/TrackContainer.hpp"
11 #include "Acts/EventData/VectorTrackContainer.hpp"
12 #include "Acts/EventData/VectorMultiTrajectory.hpp"
13 
14 namespace ActsTrk {
15  using TrackBackend = Acts::ConstVectorTrackContainer;
16  using MutableTrackBackend = Acts::VectorTrackContainer;
17  using TrackStateBackend = Acts::ConstVectorMultiTrajectory;
18  using MutableTrackStateBackend = Acts::VectorMultiTrajectory;
19 
20  // Containers without xAOD backends - this is for transient objects
21  using TrackContainerBase = Acts::TrackContainer<TrackBackend,
23  Acts::detail::ValueHolder>;
24 
25  using MutableTrackContainer = Acts::TrackContainer<MutableTrackBackend,
27  Acts::detail::ValueHolder>;
28 
29 
31  : public TrackContainerBase {
32  public:
33  //coverity[pass_by_value]
35  using value_type = typename TrackContainerBase::ConstTrackProxy;
36 
37  ConstTrackProxy operator[](unsigned int index) const { return getTrack(index); }
38  bool empty() const { return size() == 0; }
39  };
40 
41 
42  // Special indexing policy which will dereference element links
43  // into an std::optional rather than a pointer or reference to an
44  // existing element in the destination collection. This is
45  // needed because the Acts track container does have physical
46  // representations of tracks, but only creats proxy objects
47  // for tracks which are created on demand.
48  template <typename track_container_t>
50  public:
52  using ConstTrackProxy = typename track_container_t::ConstTrackProxy;
54  using ElementType = std::optional<ConstTrackProxy>;
55 
58  if (src) {
59  m_proxy = *src;
60  }
61  }
66 
68  return m_proxy.value();
69  }
70  const ConstTrackProxy *operator->() const {
71  return &m_proxy.value();
72  }
73  bool operator!() const {
74  return !m_proxy.has_value();
75  }
77  if (src) {
78  m_proxy = *src;
79  }
80  else {
81  m_proxy.reset();
82  }
83  return *this;
84  }
85 
86  std::optional<ConstTrackProxy> m_proxy {std::nullopt};
87  };
88 
89  using ElementConstReference = std::optional<ConstTrackProxy>;
91 
94 
97 
98  static bool isValid (const stored_index_type& index) {
99  return index != ConstTrackProxy::kInvalid;
100  }
101 
103  return index;
104  }
105 
106  static void reset (stored_index_type& index) {
107  index=ConstTrackProxy::kInvalid;
108  }
109 
110  static
111  ElementType lookup(const stored_index_type& index, const track_container_t& container) {
112  return container.getTrack(index);
113  }
114 
115  static void
116  reverseLookup([[maybe_unused]] const track_container_t& container,
117  ElementConstReference element,
118  index_type& index) {
119  index = element.has_value() ? element.value().index() : ConstTrackProxy::kInvalid;
120  }
121  };
122 
123 } // namespace ActsTrk
124 
125 // register special indexing policy for element links to Acts tracks i.e.
126 // ElementLink<ActsTrk::TrackContainer>
127 template <>
128 struct DefaultIndexingPolicy < ActsTrk::TrackContainer > {
130 };
131 
132 #include "AthenaKernel/CLASS_DEF.h"
133 CLASS_DEF(ActsTrk::TrackContainer, 1210898253, 1)
134 
135 #endif
DefaultIndexingPolicy< ActsTrk::TrackContainer >::type
typename ActsTrk::IndexingPolicy< ActsTrk::TrackContainer > type
Definition: TrackContainer.h:129
ActsTrk::TrackContainer
Definition: TrackContainer.h:31
ActsTrk::TrackContainer::operator[]
ConstTrackProxy operator[](unsigned int index) const
Definition: TrackContainer.h:37
ActsTrk::IndexingPolicy::ConstTrackProxyPtr::m_proxy
std::optional< ConstTrackProxy > m_proxy
Definition: TrackContainer.h:86
ActsTrk::TrackBackend
Acts::ConstVectorTrackContainer TrackBackend
Definition: TrackContainer.h:15
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
index
Definition: index.py:1
ActsTrk::IndexingPolicy::ConstTrackProxyPtr
Definition: TrackContainer.h:56
ActsTrk::MutableTrackBackend
Acts::VectorTrackContainer MutableTrackBackend
Definition: TrackContainer.h:16
ActsTrk::MutableTrackContainer
Acts::TrackContainer< MutableTrackBackend, MutableTrackStateBackend, Acts::detail::ValueHolder > MutableTrackContainer
Definition: TrackContainer.h:27
ActsTrk::IndexingPolicy::ConstTrackProxyPtr::operator->
const ConstTrackProxy * operator->() const
Definition: TrackContainer.h:70
ActsTrk::IndexingPolicy
Definition: TrackContainer.h:49
ActsTrk::IndexingPolicy::lookup
static ElementType lookup(const stored_index_type &index, const track_container_t &container)
Definition: TrackContainer.h:111
ActsTrk::IndexingPolicy::ConstTrackProxyPtr::operator=
ConstTrackProxyPtr & operator=(const ElementType *src)
Definition: TrackContainer.h:76
ActsTrk::IndexingPolicy::ConstTrackProxyPtr::ConstTrackProxyPtr
ConstTrackProxyPtr(const ConstTrackProxy &val)
Definition: TrackContainer.h:64
ActsTrk::IndexingPolicy::ConstTrackProxyPtr::operator*
ConstTrackProxy operator*() const
Definition: TrackContainer.h:67
ActsTrk::IndexingPolicy::reverseLookup
static void reverseLookup([[maybe_unused]] const track_container_t &container, ElementConstReference element, index_type &index)
Definition: TrackContainer.h:116
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
GeoPrimitives.h
ActsTrk::IndexingPolicy::storedToExternal
static index_type storedToExternal(stored_index_type index)
Definition: TrackContainer.h:102
ActsTrk::IndexingPolicy::reset
static void reset(stored_index_type &index)
Definition: TrackContainer.h:106
ActsTrk::IndexType
std::uint32_t IndexType
Definition: Decoration.h:14
DefaultIndexingPolicy.h
ActsTrk::IndexingPolicy::ConstTrackProxyPtr::operator!
bool operator!() const
Definition: TrackContainer.h:73
ActsTrk::TrackStateBackend
Acts::ConstVectorMultiTrajectory TrackStateBackend
Definition: TrackContainer.h:17
ActsTrk::TrackContainer::empty
bool empty() const
Definition: TrackContainer.h:38
DefaultIndexingPolicy
Definition: DefaultIndexingPolicy.h:23
ActsTrk::MutableTrackStateBackend
Acts::VectorMultiTrajectory MutableTrackStateBackend
Definition: TrackContainer.h:18
DeMoScan.index
string index
Definition: DeMoScan.py:362
ActsTrk::IndexingPolicy::index_type
track_container_t::IndexType index_type
The type of an index, as provided to or returned from a link.
Definition: TrackContainer.h:93
ActsTrk::IndexingPolicy::ElementConstReference
std::optional< ConstTrackProxy > ElementConstReference
Definition: TrackContainer.h:89
ActsTrk::IndexingPolicy::ElementType
std::optional< ConstTrackProxy > ElementType
The type we get when we dereference a link, and derived types.
Definition: TrackContainer.h:54
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
CLASS_DEF
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
Definition: Control/AthenaKernel/AthenaKernel/CLASS_DEF.h:67
ActsTrk::IndexingPolicy::isValid
static bool isValid(const stored_index_type &index)
Definition: TrackContainer.h:98
ActsTrk::IndexingPolicy::ConstTrackProxyPtr::ConstTrackProxyPtr
ConstTrackProxyPtr(ConstTrackProxy &&val)
Definition: TrackContainer.h:65
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MdtCalibInput.h:31
ActsTrk::IndexingPolicy::ConstTrackProxyPtr::ConstTrackProxyPtr
ConstTrackProxyPtr(const ElementType *src)
Definition: TrackContainer.h:57
ActsTrk::IndexingPolicy::ConstTrackProxyPtr::ConstTrackProxyPtr
ConstTrackProxyPtr(ConstTrackProxyPtr &&)=default
ActsTrk::IndexingPolicy::stored_index_type
index_type stored_index_type
The type of an index, as stored internally within a link.
Definition: TrackContainer.h:96
ActsTrk::IndexingPolicy::ConstTrackProxy
typename track_container_t::ConstTrackProxy ConstTrackProxy
The type of the const track proxy.
Definition: TrackContainer.h:52
value_type
Definition: EDM_MasterSearch.h:11
CLASS_DEF.h
macros to associate a CLID to a type
ActsTrk::IndexingPolicy::ConstTrackProxyPtr::ConstTrackProxyPtr
ConstTrackProxyPtr(const ConstTrackProxyPtr &)=default
ActsTrk::TrackContainerBase
Acts::TrackContainer< TrackBackend, TrackStateBackend, Acts::detail::ValueHolder > TrackContainerBase
Definition: TrackContainer.h:23