2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5 * @file AthContainers/AuxTypeRegistry.icc
6 * @author scott snyder <snyder@bnl.gov>
8 * @brief Handle mappings between names and auxid_t.
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.
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.
27 template <class T, class ALLOC>
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*/)
34 return findAuxID (name, clsname, flags, linkedVariable,
35 typeid(T), &typeid(ALLOC), nullptr,
36 &AuxTypeRegistry::makeFactory<T, ALLOC>);
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.
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.
49 template <class T, class ALLOC>
51 AuxTypeRegistry::checkAuxID (const SG::auxid_t auxid,
52 const Flags flags /*= Flags::None*/)
54 return checkAuxID (auxid, typeid(T), typeid(ALLOC), flags);
59 * @brief Return the vector factory for a given auxid.
60 * @param auxid The desired aux data item.
62 * Returns nullptr if the type is not known.
63 * (Use @c addFactory to add new mappings.)
66 const IAuxTypeVectorFactory*
67 AuxTypeRegistry::getFactory (SG::auxid_t auxid) const
69 if (auxid >= m_types.size())
71 return m_types[auxid].m_factory;
76 * @brief Return flags associated with an auxiliary variable.
77 * @param auxid The desired aux data item.
80 AuxVarFlags AuxTypeRegistry::getFlags (SG::auxid_t auxid) const
82 if (auxid >= m_types.size())
84 return m_types[auxid].m_flags;
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.
99 * @c dst and @ src can be either the same or different.
102 void AuxTypeRegistry::copy (SG::auxid_t auxid,
103 AuxVectorData&& dst, size_t dst_index,
104 const AuxVectorData& src, size_t src_index,
107 return copy (auxid, dst, dst_index, src, src_index, n);
112 * @brief Test whether this is a linked variable.
115 bool AuxTypeRegistry::isLinked (SG::auxid_t auxid) const
117 return getFlags (auxid) & Flags::Linked;
122 * @brief Create an @c AuxTypeVectorFactory instance.
124 * This is passed to @c findAuxID when we're looking up an item
125 * for which we know the type at compile-time.
127 * The ALLOC template parameter is the allocator to use
128 * for the resulting vector.
130 template <class T, class ALLOC>
132 std::unique_ptr<IAuxTypeVectorFactory> AuxTypeRegistry::makeFactory() const
134 return std::make_unique<SG::AuxTypeVectorFactory<T, ALLOC> >();
139 * @brief @c makeFactory implementation that always returns 0.
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.
145 std::unique_ptr<IAuxTypeVectorFactory> AuxTypeRegistry::makeFactoryNull() const