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
15namespace ActsTrk {
16using IndexType = std::uint32_t; // TODO take from a common header
17namespace detail {
19 std::function<std::any(SG::IAuxStore*, ActsTrk::IndexType, SG::auxid_t)>;
20using GetterType = std::function<const std::any(
21 const SG::IConstAuxStore*, ActsTrk::IndexType, SG::auxid_t)>;
23 std::function<void(SG::IAuxStore*, ActsTrk::IndexType, SG::auxid_t, const std::any&)>;
24
25struct Decoration {
26 std::string name; // for our info
27 uint32_t hash = 0; // Acts API comes with this
28 SG::auxid_t auxid = SG::null_auxid; // xAOD talks with this
29 GetterType getter = nullptr; // type aware accessors
30 CopierType copier = nullptr;
31 SetterType setter = nullptr;
32};
33
34template <typename T>
36 constexpr static bool value =
37 std::is_same<T, float>::value or std::is_same<T, double>::value or
38 std::is_same<T, short>::value or std::is_same<T, int>::value or
39 std::is_same<T, std::uint8_t>::value or
40 std::is_same<T, std::uint16_t>::value or
41 std::is_same<T, std::uint32_t>::value or
42 std::is_same<T, std::uint64_t>::value or
43 std::is_same<T, std::int8_t>::value or
44 std::is_same<T, std::int16_t>::value or
45 std::is_same<T, std::int32_t>::value or
46 std::is_same<T, std::int64_t>::value;
47};
48
49// getter that is good for non-mutable containers
50template <typename T>
51const std::any constDecorationGetter(const SG::IConstAuxStore* container,
53 SG::auxid_t decorationId) {
54 const void* data = container->getData(decorationId);
55 return &(static_cast<const T*>(data)[idx]);
56}
57// getter that is good for mutable containers (returns const ptr wrapped in
58template <typename T>
59const std::any decorationGetter(const SG::IAuxStore* container,
61 SG::auxid_t decorationId) {
62 const void* data = container->getData(decorationId);
63 return &(static_cast<T*>(data)[idx]);
64}
65
66// setter for mutable containers (i.e. provides non const ptr wrapped in
67// std::any)
68template <typename T>
70 SG::auxid_t decorationId) {
71 assert (idx < container->size());
72 // The size requested for the decoration must match the size of the container.
73 void* data = container->getData(decorationId, container->size(), container->size());
74 return &(static_cast<T*>(data)[idx]);
75}
76
77template <typename T>
79 SG::auxid_t decorationId, const std::any& src_ptr) {
80 *std::any_cast<T*>(decorationSetter<T>(dst, dst_idx, decorationId)) =
81 *std::any_cast<const T*>(src_ptr);
82}
83
84template <typename T>
85static Decoration decoration(std::string_view n, GetterType g, CopierType c,
86 SetterType s = static_cast<SetterType>(nullptr)) {
87 Decoration dec;
88 dec.name = n;
89 dec.hash = Acts::hashStringDynamic(n);
91 if (dec.auxid == SG::null_auxid)
92 throw std::runtime_error("ActsTrk::Decoration Aux ID for " + dec.name +
93 " could not be found");
94 dec.getter = std::move(g);
95 dec.copier = std::move(c);
96 dec.setter = std::move(s);
97 return dec;
98}
99
100
105std::vector<Decoration> restoreDecorations(
106 const SG::IConstAuxStore* container,
107 const std::set<std::string>& staticVariables);
108
109} // namespace detail
110
114std::optional<ActsTrk::TrackContainer::ConstTrackProxy> getActsTrack(const xAOD::TrackParticle& trkPart);
115
116} // namespace ActsTrk
117
118#endif
Basic definitions for auxiliary types.
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
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:78
const std::any constDecorationGetter(const SG::IConstAuxStore *container, ActsTrk::IndexType idx, SG::auxid_t decorationId)
Definition Decoration.h:51
const std::any decorationGetter(const SG::IAuxStore *container, ActsTrk::IndexType idx, SG::auxid_t decorationId)
Definition Decoration.h:59
static Decoration decoration(std::string_view n, GetterType g, CopierType c, SetterType s=static_cast< SetterType >(nullptr))
Definition Decoration.h:85
std::function< std::any(SG::IAuxStore *, ActsTrk::IndexType, SG::auxid_t)> SetterType
Definition Decoration.h:18
std::function< void(SG::IAuxStore *, ActsTrk::IndexType, SG::auxid_t, const std::any &)> CopierType
Definition Decoration.h:22
std::function< const std::any( const SG::IConstAuxStore *, ActsTrk::IndexType, SG::auxid_t)> GetterType
Definition Decoration.h:20
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:69
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
std::uint32_t IndexType
Definition Decoration.h:16
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: