ATLAS Offline Software
Loading...
Searching...
No Matches
Decoration.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef ActsEvent_Decoration_h
5#define ActsEvent_Decoration_h
6
13#include <any>
14
15#include "Acts/EventData/BoundTrackParameters.hpp"
16
17namespace ActsTrk {
18using IndexType = std::uint32_t; // TODO take from a common header
19namespace detail {
21 std::function<std::any(SG::IAuxStore*, ActsTrk::IndexType, SG::auxid_t)>;
22using GetterType = std::function<const std::any(
23 const SG::IConstAuxStore*, ActsTrk::IndexType, SG::auxid_t)>;
25 std::function<void(SG::IAuxStore*, ActsTrk::IndexType, SG::auxid_t, const std::any&)>;
26
27struct Decoration {
28 std::string name; // for our info
29 uint32_t hash = 0; // Acts API comes with this
30 SG::auxid_t auxid = SG::null_auxid; // xAOD talks with this
31 GetterType getter = nullptr; // type aware accessors
32 CopierType copier = nullptr;
33 SetterType setter = nullptr;
34};
35
36template <typename T>
38 constexpr static bool value =
39 std::is_same<T, float>::value or std::is_same<T, double>::value or
40 std::is_same<T, short>::value or std::is_same<T, int>::value or
41 std::is_same<T, std::uint8_t>::value or
42 std::is_same<T, std::uint16_t>::value or
43 std::is_same<T, std::uint32_t>::value or
44 std::is_same<T, std::uint64_t>::value or
45 std::is_same<T, std::int8_t>::value or
46 std::is_same<T, std::int16_t>::value or
47 std::is_same<T, std::int32_t>::value or
48 std::is_same<T, std::int64_t>::value;
49};
50
51// getter that is good for non-mutable containers
52template <typename T>
53const std::any constDecorationGetter(const SG::IConstAuxStore* container,
55 SG::auxid_t decorationId) {
56 const void* data = container->getData(decorationId);
57 return &(static_cast<const T*>(data)[idx]);
58}
59// getter that is good for mutable containers (returns const ptr wrapped in
60template <typename T>
61const std::any decorationGetter(const SG::IAuxStore* container,
63 SG::auxid_t decorationId) {
64 const void* data = container->getData(decorationId);
65 return &(static_cast<T*>(data)[idx]);
66}
67
68// setter for mutable containers (i.e. provides non const ptr wrapped in
69// std::any)
70template <typename T>
72 SG::auxid_t decorationId) {
73 assert (idx < container->size());
74 // The size requested for the decoration must match the size of the container.
75 void* data = container->getData(decorationId, container->size(), container->size());
76 return &(static_cast<T*>(data)[idx]);
77}
78
79template <typename T>
81 SG::auxid_t decorationId, const std::any& src_ptr) {
82 *std::any_cast<T*>(decorationSetter<T>(dst, dst_idx, decorationId)) =
83 *std::any_cast<const T*>(src_ptr);
84}
85
86template <typename T>
87static Decoration decoration(std::string_view n, GetterType g, CopierType c,
88 SetterType s = static_cast<SetterType>(nullptr)) {
89 Decoration dec;
90 dec.name = n;
91 dec.hash = Acts::hashStringDynamic(n);
93 if (dec.auxid == SG::null_auxid)
94 throw std::runtime_error("ActsTrk::Decoration Aux ID for " + dec.name +
95 " could not be found");
96 dec.getter = std::move(g);
97 dec.copier = std::move(c);
98 dec.setter = std::move(s);
99 return dec;
100}
101
102
107std::vector<Decoration> restoreDecorations(
108 const SG::IConstAuxStore* container,
109 const std::set<std::string>& staticVariables);
110
111} // namespace detail
112
116std::optional<ActsTrk::TrackContainer::ConstTrackProxy> getActsTrack(const xAOD::TrackParticle& trkPart);
117
123std::optional<ActsTrk::TrackContainer::ConstTrackStateProxy>
125 const bool skipOutlier = true);
131std::optional<ActsTrk::TrackContainer::ConstTrackStateProxy>
133 const bool skipOutlier = true);
134
139std::optional<Acts::BoundTrackParameters>
141 const bool skipOutlier = true);
142
147std::optional<Acts::BoundTrackParameters>
149 const bool skipOutlier = true);
150
151} // namespace ActsTrk
152
153#endif
Basic definitions for auxiliary types.
Interface for non-const operations on an auxiliary store.
Interface for const operations on an auxiliary store.
size_t size() const
Number of registered mappings.
SG::auxid_t getAuxID(const std::string &name, const std::string &clsname="", const Flags flags=Flags::None, const SG::auxid_t linkedVariable=SG::null_auxid)
Look up a name -> auxid_t mapping.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
AuxDataTraits< T >::reference_type getData(SG::auxid_t auxid, size_t ndx)
Return reference to an aux data item.
Interface for non-const operations on an auxiliary store.
Definition IAuxStore.h:51
void decorationCopier(SG::IAuxStore *dst, ActsTrk::IndexType dst_idx, SG::auxid_t decorationId, const std::any &src_ptr)
Definition Decoration.h:80
const std::any constDecorationGetter(const SG::IConstAuxStore *container, ActsTrk::IndexType idx, SG::auxid_t decorationId)
Definition Decoration.h:53
const std::any decorationGetter(const SG::IAuxStore *container, ActsTrk::IndexType idx, SG::auxid_t decorationId)
Definition Decoration.h:61
static Decoration decoration(std::string_view n, GetterType g, CopierType c, SetterType s=static_cast< SetterType >(nullptr))
Definition Decoration.h:87
std::function< std::any(SG::IAuxStore *, ActsTrk::IndexType, SG::auxid_t)> SetterType
Definition Decoration.h:20
std::function< void(SG::IAuxStore *, ActsTrk::IndexType, SG::auxid_t, const std::any &)> CopierType
Definition Decoration.h:24
std::function< const std::any( const SG::IConstAuxStore *, ActsTrk::IndexType, SG::auxid_t)> GetterType
Definition Decoration.h:22
std::vector< Decoration > restoreDecorations(const SG::IConstAuxStore *container, const std::set< std::string > &staticVariables)
std::any decorationSetter(SG::IAuxStore *container, ActsTrk::IndexType idx, SG::auxid_t decorationId)
Definition Decoration.h:71
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
std::optional< ActsTrk::TrackContainer::ConstTrackStateProxy > firstMeasurementState(const xAOD::TrackParticle &trkPart, const bool skipOutlier=true)
Returns the track state proxy corresponding to the measurement that is closest to the defining track ...
std::optional< ActsTrk::TrackContainer::ConstTrackStateProxy > lastMeasurementState(const xAOD::TrackParticle &trkPart, const bool skipOutlier=true)
Returns the track state proxy corresponding to the last measurement on track.
std::optional< Acts::BoundTrackParameters > firstTrackParameters(const xAOD::TrackParticle &trkPart, const bool skipOutlier=true)
Returns the first MeasurementState in form of Acts::BoundTrackParameters.
std::uint32_t IndexType
Definition Decoration.h:18
std::optional< Acts::BoundTrackParameters > lastTrackParameters(const xAOD::TrackParticle &trkPart, const bool skipOutlier=true)
Returns the last MeasurementState in form of Acts::BoundTrackParameters.
std::optional< ActsTrk::TrackContainer::ConstTrackProxy > getActsTrack(const xAOD::TrackParticle &trkPart)
Return the proxy to the Acts track from which the track particle was made frome.
Definition Decoration.cxx:9
static const auxid_t null_auxid
To signal no aux data item.
Definition AuxTypes.h:30
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
TrackParticle_v1 TrackParticle
Reference the current persistent version: