ATLAS Offline Software
Decoration.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef ActsEvent_Decoration_h
5 #define ActsEvent_Decoration_h
6 
11 
12 namespace ActsTrk {
13 using IndexType = std::uint32_t; // TODO take from a common header
14 namespace detail {
15 using SetterType =
16  std::function<std::any(SG::IAuxStore*, ActsTrk::IndexType, SG::auxid_t)>;
17 using GetterType = std::function<const std::any(
19 using CopierType =
20  std::function<void(SG::IAuxStore*, ActsTrk::IndexType, SG::auxid_t, const std::any&)>;
21 
22 struct Decoration {
23  std::string name; // for our info
24  uint32_t hash = 0; // Acts API comes with this
25  SG::auxid_t auxid = SG::null_auxid; // xAOD talks with this
26  GetterType getter = nullptr; // type aware accessors
27  CopierType copier = nullptr;
28  SetterType setter = nullptr;
29 };
30 
31 template <typename T>
33  constexpr static bool value =
37 };
38 
39 // getter that is good for non-mutable containers
40 template <typename T>
41 const std::any constDecorationGetter(const SG::IConstAuxStore* container,
43  SG::auxid_t decorationId) {
44  const void* data = container->getData(decorationId);
45  return &(static_cast<const T*>(data)[idx]);
46 }
47 // getter that is good for mutable containers (returns const ptr wrapped in
48 template <typename T>
49 const std::any decorationGetter(const SG::IAuxStore* container,
51  SG::auxid_t decorationId) {
52  const void* data = container->getData(decorationId);
53  return &(static_cast<T*>(data)[idx]);
54 }
55 
56 // setter for mutable containers (i.e. provides non const ptr wrapped in
57 // std::any)
58 template <typename T>
60  SG::auxid_t decorationId) {
61  void* data = container->getData(decorationId, idx + 1, idx + 1);
62  return &(static_cast<T*>(data)[idx]);
63 }
64 
65 template <typename T>
67  SG::auxid_t decorationId, const std::any& src_ptr) {
68  *std::any_cast<T*>(decorationSetter<T>(dst, dst_idx, decorationId)) =
69  *std::any_cast<const T*>(src_ptr);
70 }
71 
72 template <typename T>
73 static Decoration decoration(std::string_view n, GetterType g, CopierType c,
74  SetterType s = static_cast<SetterType>(nullptr)) {
75  Decoration dec;
76  dec.name = n;
77  dec.hash = Acts::hashString(n);
78  dec.auxid = SG::AuxTypeRegistry::instance().getAuxID<T>(dec.name);
79  if (dec.auxid == SG::null_auxid)
80  throw std::runtime_error("ActsTrk::Decoration Aux ID for " + dec.name +
81  " could not be found");
82  dec.getter = std::move(g);
83  dec.copier = std::move(c);
84  dec.setter = std::move(s);
85  return dec;
86 }
87 
88 
93 std::vector<Decoration> restoreDecorations(
94  const SG::IConstAuxStore* container,
95  const std::set<std::string>& staticVariables);
96 
97 } // namespace detail
98 } // namespace ActsTrk
99 
100 #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:640
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
ActsTrk::detail::accepted_decoration_types::value
constexpr static bool value
Definition: Decoration.h:33
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:66
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:18
ActsTrk::detail::Decoration::copier
CopierType copier
Definition: Decoration.h:27
ActsTrk::detail::CopierType
std::function< void(SG::IAuxStore *, ActsTrk::IndexType, SG::auxid_t, const std::any &)> CopierType
Definition: Decoration.h:20
ActsTrk::detail::Decoration
Definition: Decoration.h:22
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:13
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:23
ActsTrk::detail::Decoration::setter
SetterType setter
Definition: Decoration.h:28
ActsTrk::detail::accepted_decoration_types
Definition: Decoration.h:32
ActsTrk::detail::constDecorationGetter
const std::any constDecorationGetter(const SG::IConstAuxStore *container, ActsTrk::IndexType idx, SG::auxid_t decorationId)
Definition: Decoration.h:41
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:26
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:49
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:24
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:49
ActsTrk::detail::Decoration::auxid
SG::auxid_t auxid
Definition: Decoration.h:25
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:59
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:16