Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
13 namespace ActsTrk {
14 using IndexType = std::uint32_t; // TODO take from a common header
15 namespace detail {
16 using SetterType =
17  std::function<std::any(SG::IAuxStore*, ActsTrk::IndexType, SG::auxid_t)>;
18 using GetterType = std::function<const std::any(
20 using CopierType =
21  std::function<void(SG::IAuxStore*, ActsTrk::IndexType, SG::auxid_t, const std::any&)>;
22 
23 struct 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 
32 template <typename T>
34  constexpr static bool value =
45 };
46 
47 // getter that is good for non-mutable containers
48 template <typename T>
49 const std::any constDecorationGetter(const SG::IConstAuxStore* container,
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
56 template <typename T>
57 const std::any decorationGetter(const SG::IAuxStore* container,
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)
66 template <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 
75 template <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 
82 template <typename T>
83 static 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);
88  dec.auxid = SG::AuxTypeRegistry::instance().getAuxID<T>(dec.name);
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 
103 std::vector<Decoration> restoreDecorations(
104  const SG::IConstAuxStore* container,
105  const std::set<std::string>& staticVariables);
106 
107 } // namespace detail
108 } // namespace ActsTrk
109 
110 #endif
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
SG::IConstAuxStore::getData
virtual const void * getData(SG::auxid_t auxid) const =0
Return the data vector for one aux data item.
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:639
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
ActsTrk::detail::accepted_decoration_types::value
constexpr static bool value
Definition: Decoration.h:34
AuxContainerBase.h
ActsTrk::detail::decorationCopier
void decorationCopier(SG::IAuxStore *dst, ActsTrk::IndexType dst_idx, SG::auxid_t decorationId, const std::any &src_ptr)
Definition: Decoration.h:76
athena.value
value
Definition: athena.py:124
detail
Definition: extract_histogram_tag.cxx:14
ActsTrk::detail::GetterType
std::function< const std::any(const SG::IConstAuxStore *, ActsTrk::IndexType, SG::auxid_t)> GetterType
Definition: Decoration.h:19
ActsTrk::detail::Decoration::copier
CopierType copier
Definition: Decoration.h:28
SG::IConstAuxStore::size
virtual size_t size() const =0
Return the number of elements in the store.
ActsTrk::detail::CopierType
std::function< void(SG::IAuxStore *, ActsTrk::IndexType, SG::auxid_t, const std::any &)> CopierType
Definition: Decoration.h:21
ActsTrk::detail::Decoration
Definition: Decoration.h:23
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
ActsTrk::IndexType
std::uint32_t IndexType
Definition: Decoration.h:14
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
beamspotman.n
n
Definition: beamspotman.py:731
ActsTrk::detail::Decoration::name
std::string name
Definition: Decoration.h:24
ActsTrk::detail::Decoration::setter
SetterType setter
Definition: Decoration.h:29
ActsTrk::detail::accepted_decoration_types
Definition: Decoration.h:33
ActsTrk::detail::constDecorationGetter
const std::any constDecorationGetter(const SG::IConstAuxStore *container, ActsTrk::IndexType idx, SG::auxid_t decorationId)
Definition: Decoration.h:49
ActsTrk::detail::restoreDecorations
std::vector< Decoration > restoreDecorations(const SG::IConstAuxStore *container, const std::set< std::string > &staticVariables)
Definition: Decoration.cxx:9
ActsTrk::detail::Decoration::getter
GetterType getter
Definition: Decoration.h:27
AuxTypes.h
Basic definitions for auxiliary types.
SG::IAuxStore
Interface for non-const operations on an auxiliary store.
Definition: IAuxStore.h:48
ActsTrk::detail::decorationGetter
const std::any decorationGetter(const SG::IAuxStore *container, ActsTrk::IndexType idx, SG::auxid_t decorationId)
Definition: Decoration.h:57
SG::IAuxStore::getData
virtual void * getData(auxid_t auxid, size_t size, size_t capacity)=0
Return the data vector for one aux data item.
ActsTrk::detail::Decoration::hash
uint32_t hash
Definition: Decoration.h:25
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
IAuxStore.h
Interface for non-const operations on an auxiliary store.
ActsTrk
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
Definition: MuonDetectorBuilderTool.cxx:55
ActsTrk::detail::Decoration::auxid
SG::auxid_t auxid
Definition: Decoration.h:26
IConstAuxStore.h
Interface for const operations on an auxiliary store.
SG::IConstAuxStore
Interface for const operations on an auxiliary store.
Definition: IConstAuxStore.h:64
ActsTrk::detail::decorationSetter
std::any decorationSetter(SG::IAuxStore *container, ActsTrk::IndexType idx, SG::auxid_t decorationId)
Definition: Decoration.h:67
python.compressB64.c
def c
Definition: compressB64.py:93
SG::AuxTypeRegistry::getAuxID
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.
ActsTrk::detail::SetterType
std::function< std::any(SG::IAuxStore *, ActsTrk::IndexType, SG::auxid_t)> SetterType
Definition: Decoration.h:17