ATLAS Offline Software
AuxDataTraits.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 
3 /*
4  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5 */
14 #ifndef ATHCONTAINERS_AUXDATATRAITS_H
15 #define ATHCONTAINERS_AUXDATATRAITS_H
16 
17 
18 #include "CxxUtils/span.h"
19 #include <vector>
20 #include <cstdlib>
21 
22 
23 namespace SG {
24 
25 
27 template <class T>
28 using AuxAllocator_t = std::allocator<T>;
29 constexpr const char* auxAllocatorNamePrefix = "std::allocator<";
30 
31 
38 template <class T, class ALLOC = AuxAllocator_t<T> >
40 {
41 public:
43  using element_type = T;
44 
48 
50  using allocator_type = ALLOC;
51 
53  using vector_type = std::vector<T, allocator_type>;
54  using container_value_type = typename vector_type::value_type;
55 
57  using container_pointer_type = typename vector_type::pointer;
58  using const_container_pointer_type = typename vector_type::const_pointer;
59 
62  static reference_type index (void* ptr, size_t ndx)
63  {
64  return reinterpret_cast<container_pointer_type>(ptr)[ndx];
65  }
66 
69  static const_reference_type index (const void* ptr, size_t ndx)
70  {
71  return reinterpret_cast<const_container_pointer_type>(ptr)[ndx];
72  }
73 
76 };
77 
78 
87 template <class ALLOC>
88 class AuxDataTraits<bool, ALLOC>
89 {
90 public:
92  using element_type = bool;
93 
97 
99  using allocator_type = typename std::allocator_traits<ALLOC>::template rebind_alloc<char>;
100 
102  using vector_type = std::vector<char, allocator_type>;
103  using container_value_type = typename vector_type::value_type;
104 
106  using container_pointer_type = typename vector_type::pointer;
107  using const_container_pointer_type = typename vector_type::const_pointer;
108 
111  static reference_type index (void* ptr, size_t ndx)
112  {
113  return reinterpret_cast<bool*>(ptr)[ndx];
114  }
115 
118  static const_reference_type index (const void* ptr, size_t ndx)
119  {
120  return reinterpret_cast<const bool*>(ptr)[ndx];
121  }
122 
125 };
126 
127 
133 template <class T>
134 struct Zero
135 {
136  static T zero()
137  {
138  return T();
139  }
140 };
141 
142 
143 } // namespace SG
144 
145 
146 #endif // not ATHCONTAINERS_AUXDATATRAITS_H
SG::AuxDataTraits::container_pointer_type
typename vector_type::pointer container_pointer_type
Pointers to the data within the container.
Definition: AuxDataTraits.h:57
SG::AuxDataTraits::reference_type
element_type & reference_type
Reference types returned by aux data accessors.
Definition: AuxDataTraits.h:46
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::AuxDataTraits::index
static reference_type index(void *ptr, size_t ndx)
Look up an element in the container by index.
Definition: AuxDataTraits.h:62
SG::AuxAllocator_t
std::allocator< T > AuxAllocator_t
The default allocator type to use for auxiliary variables.
Definition: AuxDataTraits.h:28
SG::AuxDataTraits::const_reference_type
const element_type & const_reference_type
Definition: AuxDataTraits.h:47
SG::AuxDataTraits< bool, ALLOC >::index
static reference_type index(void *ptr, size_t ndx)
Look up an element in the container by index.
Definition: AuxDataTraits.h:111
taskman.template
dictionary template
Definition: taskman.py:317
SG::AuxDataTraits< bool, ALLOC >::const_reference_type
const element_type & const_reference_type
Definition: AuxDataTraits.h:96
SG::AuxDataTraits< bool, ALLOC >::allocator_type
typename std::allocator_traits< ALLOC >::template rebind_alloc< char > allocator_type
Allocator type used to store this variable.
Definition: AuxDataTraits.h:99
SG::AuxDataTraits::allocator_type
ALLOC allocator_type
Allocator type used to store this variable.
Definition: AuxDataTraits.h:50
SG::AuxDataTraits< bool, ALLOC >::const_container_pointer_type
typename vector_type::const_pointer const_container_pointer_type
Definition: AuxDataTraits.h:107
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
SG::AuxDataTraits::vector_type
std::vector< T, allocator_type > vector_type
Container type used to store this variable.
Definition: AuxDataTraits.h:53
SG::AuxDataTraits::const_container_pointer_type
typename vector_type::const_pointer const_container_pointer_type
Definition: AuxDataTraits.h:58
SG::AuxDataTraits::index
static const_reference_type index(const void *ptr, size_t ndx)
Look up an element in the container by index.
Definition: AuxDataTraits.h:69
CxxUtils::span
Simplified version of the C++20 std::span.
Definition: span.h:67
SG::AuxDataTraits< bool, ALLOC >::index
static const_reference_type index(const void *ptr, size_t ndx)
Look up an element in the container by index.
Definition: AuxDataTraits.h:118
SG::Zero::zero
static T zero()
Definition: AuxDataTraits.h:136
SG::AuxDataTraits< bool, ALLOC >::vector_type
std::vector< char, allocator_type > vector_type
Container type used to store this variable.
Definition: AuxDataTraits.h:102
span.h
Simplified version of the C++20 std::span.
SG::AuxDataTraits
Allow customizing how aux data types are treated.
Definition: AuxDataTraits.h:40
SG::AuxDataTraits::container_value_type
typename vector_type::value_type container_value_type
Definition: AuxDataTraits.h:54
SG::AuxDataTraits< bool, ALLOC >::reference_type
element_type & reference_type
Reference types returned by aux data accessors.
Definition: AuxDataTraits.h:95
SG::AuxDataTraits::element_type
T element_type
The type the user sees.
Definition: AuxDataTraits.h:43
SG::AuxDataTraits< bool, ALLOC >::container_value_type
typename vector_type::value_type container_value_type
Definition: AuxDataTraits.h:103
SG::AuxDataTraits< bool, ALLOC >::element_type
bool element_type
The type the user sees.
Definition: AuxDataTraits.h:92
SG::AuxDataTraits< bool, ALLOC >::container_pointer_type
typename vector_type::pointer container_pointer_type
Pointers to the data within the container.
Definition: AuxDataTraits.h:106
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
SG::Zero
Helper to specialize how to make an initialized instance of T.
Definition: AuxDataTraits.h:135
SG::auxAllocatorNamePrefix
constexpr const char * auxAllocatorNamePrefix
Definition: AuxDataTraits.h:29