ATLAS Offline Software
AuxTypeRegistry.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 /**
5  * @file AthContainers/AuxTypeRegistry.icc
6  * @author scott snyder <snyder@bnl.gov>
7  * @date Sep, 2013
8  * @brief Handle mappings between names and auxid_t.
9  */
10 
11 
12 namespace SG {
13 
14 
15 /**
16  * @brief Look up a name -> @c auxid_t mapping.
17  * @param name The name of the aux data item.
18  * @param clsname The name of its associated class. May be blank.
19  * @param flags Optional flags qualifying the type. See above.
20  * @param linkedVariable auxid of a linked variable, or null_auxid.
21  *
22  * The type of the item is given by the template parameter @c T,
23  * and the @c ALLOC gives the type of the vector allocator.
24  * If an item with the same name was previously requested
25  * with a different type, then throw an @c AuxTypeMismatch exception.
26  */
27 template <class T, class ALLOC>
28 SG::auxid_t
29 AuxTypeRegistry::getAuxID (const std::string& name,
30  const std::string& clsname /*= ""*/,
31  const Flags flags /*= Flags::None*/,
32  const SG::auxid_t linkedVariable /*= SG::null_auxid*/)
33 {
34  return findAuxID (name, clsname, flags, linkedVariable,
35  typeid(T), &typeid(ALLOC), nullptr,
36  &AuxTypeRegistry::makeFactory<T, ALLOC>);
37 }
38 
39 
40 /**
41  * @brief Verify type for an aux variable.
42  * @param auxid The ID of the variable to check.
43  * @param flags Optional flags qualifying the type. See above.
44  *
45  * If the type of @c auxid is not compatible with the supplied
46  * types @c T / @c ALLOC, then throw a @c SG::ExcAuxTypeMismatch exception.
47  * Also may throw @c SG::ExcFlagMismatch.
48  */
49 template <class T, class ALLOC>
50 void
51 AuxTypeRegistry::checkAuxID (const SG::auxid_t auxid,
52  const Flags flags /*= Flags::None*/)
53 {
54  return checkAuxID (auxid, typeid(T), typeid(ALLOC), flags);
55 }
56 
57 
58 /**
59  * @brief Return the vector factory for a given auxid.
60  * @param auxid The desired aux data item.
61  *
62  * Returns nullptr if the type is not known.
63  * (Use @c addFactory to add new mappings.)
64  */
65 inline
66 const IAuxTypeVectorFactory*
67 AuxTypeRegistry::getFactory (SG::auxid_t auxid) const
68 {
69  if (auxid >= m_types.size())
70  return 0;
71  return m_types[auxid].m_factory;
72 }
73 
74 
75 /**
76  * @brief Return flags associated with an auxiliary variable.
77  * @param auxid The desired aux data item.
78  */
79 inline
80 AuxVarFlags AuxTypeRegistry::getFlags (SG::auxid_t auxid) const
81 {
82  if (auxid >= m_types.size())
83  return Flags::None;
84  return m_types[auxid].m_flags;
85 }
86 
87 
88 /**
89  * @brief Copy elements between vectors.
90  * @param auxid The aux data item being operated on.
91  * @param dst Container for the destination vector.
92  * Declared as a rvalue reference to allow passing a temporary
93  * here (such as from AuxVectorInterface).
94  * @param dst_index Index of the first destination element in the vector.
95  * @param src Container for the source vector.
96  * @param src_index Index of the first source element in the vector.
97  * @param n Number of elements to copy.
98  *
99  * @c dst and @ src can be either the same or different.
100  */
101 inline
102 void AuxTypeRegistry::copy (SG::auxid_t auxid,
103  AuxVectorData&& dst, size_t dst_index,
104  const AuxVectorData& src, size_t src_index,
105  size_t n) const
106 {
107  return copy (auxid, dst, dst_index, src, src_index, n);
108 }
109 
110 
111 /*
112  * @brief Test whether this is a linked variable.
113  */
114 inline
115 bool AuxTypeRegistry::isLinked (SG::auxid_t auxid) const
116 {
117  return getFlags (auxid) & Flags::Linked;
118 }
119 
120 
121 /**
122  * @brief Create an @c AuxTypeVectorFactory instance.
123  *
124  * This is passed to @c findAuxID when we're looking up an item
125  * for which we know the type at compile-time.
126  *
127  * The ALLOC template parameter is the allocator to use
128  * for the resulting vector.
129  */
130 template <class T, class ALLOC>
131 inline
132 std::unique_ptr<IAuxTypeVectorFactory> AuxTypeRegistry::makeFactory() const
133 {
134  return std::make_unique<SG::AuxTypeVectorFactory<T, ALLOC> >();
135 }
136 
137 
138 /**
139  * @brief @c makeFactory implementation that always returns 0.
140  *
141  * This is passed to @c findAuxID when we're looking up an item
142  * for which we do not know the type at compile-time.
143  */
144 inline
145 std::unique_ptr<IAuxTypeVectorFactory> AuxTypeRegistry::makeFactoryNull() const
146 {
147  return nullptr;
148 }
149 
150 
151 } // namespace SG