ATLAS Offline Software
Loading...
Searching...
No Matches
Decoration.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef ActsEvent_Decoration_h
5#define ActsEvent_Decoration_h
6
11#include <any>
12
13namespace ActsTrk {
14using IndexType = std::uint32_t; // TODO take from a common header
15namespace detail {
17 std::function<std::any(SG::IAuxStore*, ActsTrk::IndexType, SG::auxid_t)>;
18using GetterType = std::function<const std::any(
21 std::function<void(SG::IAuxStore*, ActsTrk::IndexType, SG::auxid_t, const std::any&)>;
22
23struct Decoration {
24 std::string name; // for our info
25 uint32_t hash = 0; // Acts API comes with this
26 SG::auxid_t auxid = SG::null_auxid; // xAOD talks with this
27 GetterType getter = nullptr; // type aware accessors
28 CopierType copier = nullptr;
29 SetterType setter = nullptr;
30};
31
32template <typename T>
34 constexpr static bool value =
35 std::is_same<T, float>::value or std::is_same<T, double>::value or
36 std::is_same<T, short>::value or std::is_same<T, int>::value or
37 std::is_same<T, std::uint8_t>::value or
38 std::is_same<T, std::uint16_t>::value or
39 std::is_same<T, std::uint32_t>::value or
40 std::is_same<T, std::uint64_t>::value or
41 std::is_same<T, std::int8_t>::value or
42 std::is_same<T, std::int16_t>::value or
43 std::is_same<T, std::int32_t>::value or
44 std::is_same<T, std::int64_t>::value;
45};
46
47// getter that is good for non-mutable containers
48template <typename T>
51 SG::auxid_t decorationId) {
52 const void* data = container->getData(decorationId);
53 return &(static_cast<const T*>(data)[idx]);
54}
55// getter that is good for mutable containers (returns const ptr wrapped in
56template <typename T>
59 SG::auxid_t decorationId) {
60 const void* data = container->getData(decorationId);
61 return &(static_cast<T*>(data)[idx]);
62}
63
64// setter for mutable containers (i.e. provides non const ptr wrapped in
65// std::any)
66template <typename T>
68 SG::auxid_t decorationId) {
69 assert (idx < container->size());
70 // The size requested for the decoration must match the size of the container.
71 void* data = container->getData(decorationId, container->size(), container->size());
72 return &(static_cast<T*>(data)[idx]);
73}
74
75template <typename T>
77 SG::auxid_t decorationId, const std::any& src_ptr) {
78 *std::any_cast<T*>(decorationSetter<T>(dst, dst_idx, decorationId)) =
79 *std::any_cast<const T*>(src_ptr);
80}
81
82template <typename T>
83static Decoration decoration(std::string_view n, GetterType g, CopierType c,
84 SetterType s = static_cast<SetterType>(nullptr)) {
85 Decoration dec;
86 dec.name = n;
87 dec.hash = Acts::hashStringDynamic(n);
89 if (dec.auxid == SG::null_auxid)
90 throw std::runtime_error("ActsTrk::Decoration Aux ID for " + dec.name +
91 " could not be found");
92 dec.getter = std::move(g);
93 dec.copier = std::move(c);
94 dec.setter = std::move(s);
95 return dec;
96}
97
98
103std::vector<Decoration> restoreDecorations(
105 const std::set<std::string>& staticVariables);
106
107} // namespace detail
108} // namespace ActsTrk
109
110#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.
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.
Interface for non-const operations on an auxiliary store.
Definition IAuxStore.h:48
Interface for const operations on an auxiliary store.
std::function< void(SG::IAuxStore *, ActsTrk::IndexType, SG::auxid_t, const std::any &)> CopierType
Definition Decoration.h:20
void decorationCopier(SG::IAuxStore *dst, ActsTrk::IndexType dst_idx, SG::auxid_t decorationId, const std::any &src_ptr)
Definition Decoration.h:76
std::function< const std::any( const SG::IConstAuxStore *, ActsTrk::IndexType, SG::auxid_t)> GetterType
Definition Decoration.h:18
const std::any constDecorationGetter(const SG::IConstAuxStore *container, ActsTrk::IndexType idx, SG::auxid_t decorationId)
Definition Decoration.h:49
const std::any decorationGetter(const SG::IAuxStore *container, ActsTrk::IndexType idx, SG::auxid_t decorationId)
Definition Decoration.h:57
std::function< std::any(SG::IAuxStore *, ActsTrk::IndexType, SG::auxid_t)> SetterType
Definition Decoration.h:16
static Decoration decoration(std::string_view n, GetterType g, CopierType c, SetterType s=static_cast< SetterType >(nullptr))
Definition Decoration.h:83
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:67
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
std::uint32_t IndexType
Definition Decoration.h:14
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