94 const std::string& clsname,
97 const std::type_info& ti,
98 const std::type_info* ti_alloc,
99 const std::string* alloc_name,
117 const std::type_info& ti,
118 const std::type_info& ti_alloc,
136 const std::type_info& ti,
137 const std::string& ti_alloc_name,
138 std::unique_ptr<const IAuxTypeVectorFactory> factory);
148 static bool checkName (std::string_view s)
noexcept;
162 const std::type_info& ti,
163 const std::type_info& ti_alloc);
170 AthContainers_detail::atomic<const IAuxTypeVectorFactory*>
m_factory;
195 bool checkAlloc (
const std::type_info* ti_alloc,
196 const std::string* alloc_name)
const;
202 AthContainers_detail::concurrent_vector<typeinfo_t>
m_types;
249#define ADD_FACTORY(T) AuxTypeRegistry::addFactory(typeid(T), typeid(AuxAllocator_t<T>), std::make_unique<AuxTypeVectorFactory<T> >())
298 if (p.first.find (
";TI;") == std::string::npos) {
333 const std::string& clsname,
336 const std::type_info& ti,
337 const std::type_info* ti_alloc,
338 const std::string* alloc_name,
343 const std::string& key = clsname.empty() ? name :
makeKey (name, clsname);
348 id_map_t::const_iterator i =
m_auxids.find (key);
355 (&ti == m.m_ti || strcmp(ti.name(), m.m_ti->name()) == 0) &&
356 m.checkAlloc (ti_alloc, alloc_name) &&
357 !(*m.m_factory).isDynamic())
366 id_map_t::const_iterator i =
m_auxids.find (key);
390 if ((&ti == m.m_ti || strcmp(ti.name(), m.m_ti->name()) == 0) &&
391 m.checkAlloc (ti_alloc, alloc_name))
394 if ((*m.m_factory).isDynamic()) {
395 std::unique_ptr<IAuxTypeVectorFactory> fac2 = (*this.*makeFactory)();
398 ti_alloc = fac2->tiAlloc();
400 std::string allocName = fac2->tiAllocName();
401 m.m_factory =
addFactory (lock, ti, allocName, std::move (fac2));
403 m.m_factory =
addFactory (lock, ti, *ti_alloc, m.m_factory);
419 if (!(flags & Flags::SkipNameCheck) &&
421 (!clsname.empty() && !
checkName (clsname))))
430 else if (alloc_name) {
435 if (def_alloc_name[def_alloc_name.size()-1] ==
'>') def_alloc_name +=
' ';
436 def_alloc_name +=
'>';
441 std::unique_ptr<IAuxTypeVectorFactory> fac2 = (*this.*makeFactory)();
444 ti_alloc = fac2->tiAlloc();
446 std::string allocName = fac2->tiAllocName();
447 fac =
addFactory (lock, ti, allocName, std::move (fac2));
454 if (!ti_alloc) ti_alloc = fac->
tiAlloc();
457 typeinfo_t& t =
m_types[auxid];
459 t.m_clsname = clsname;
461 t.m_ti_alloc = ti_alloc;
490 const std::type_info& ti,
491 const std::type_info& ti_alloc,
494 std::string key = std::string (ti.name()) +
";TI;" + ti_alloc.name();
495 ti_map_t::const_iterator it =
m_factories.find (key);
497 if (it->second->isDynamic() && !factory->
isDynamic()) {
503 factory = it->second;
512 m_allocMap.insert_or_assign (ti.name(), &ti_alloc);
533 const std::type_info& ti,
534 const std::string& ti_alloc_name,
535 std::unique_ptr<const IAuxTypeVectorFactory> factory)
537 std::string key = ti.name();
539 key += ti_alloc_name;
540 ti_map_t::const_iterator it =
m_factories.find (key);
543 if (it->second->isDynamic() && !factory->isDynamic()) {
549 fac =
m_factories.insert_or_assign (key, factory.release()).first->second;
556 fac =
m_factories.insert_or_assign (key, factory.release()).first->second;
571 if (s.empty())
return false;
573 if (!std::isalpha(
static_cast<unsigned char>(first)) && first !=
'_')
return false;
574 return std::all_of(s.begin() + 1, s.end(), [](
char c) {
575 return std::isalnum(static_cast<unsigned char>(c)) || c ==
'_';
592 const std::type_info& ti,
593 const std::type_info& ti_alloc)
595 std::string key = ti.name();
597 key += ti_alloc.name();
598 ti_map_t::const_iterator it =
m_factories.find (key);
618 const std::string* alloc_name)
const
622 return strcmp (ti_alloc->name(),
m_ti_alloc->name()) == 0;
643 return auxTypeRegistry;
655 return impl->m_types.size();
674 const std::string& name,
675 const std::string& clsname ,
681 ti,
nullptr,
nullptr,
704 const std::type_info& ti,
705 const std::string& name,
706 const std::string& clsname ,
713 ti, &ti_alloc,
nullptr,
734 const std::type_info& ti,
735 const std::string& name,
736 const std::string& clsname ,
742 ti,
nullptr, &alloc_type,
758 const std::string& clsname)
const
765 AuxTypeRegistryImpl::id_map_t::const_iterator i =
766 impl->m_auxids.find (clsname.empty() ?
769 if (i !=
impl->m_auxids.end()) {
788 const std::type_info& ti,
789 const std::type_info& ti_alloc,
795 if ( ! ((&ti == m.m_ti || strcmp(ti.name(), m.m_ti->name()) == 0) &&
796 m.checkAlloc (&ti_alloc,
nullptr)))
817std::unique_ptr<IAuxTypeVector>
820 size_t capacity)
const
823 assert (factory != 0);
845std::unique_ptr<IAuxTypeVector>
853 assert (factory != 0);
855 isPacked, ownMode,
isLinked (auxid));
865 const std::string& clsname)
867 if (clsname.empty()) {
870 std::string output = clsname;
885 if (auxid >=
impl->m_types.size())
887 return impl->m_types[auxid].m_name;
899 if (auxid >=
impl->m_types.size())
901 return impl->m_types[auxid].m_clsname;
912 if (auxid >=
impl->m_types.size())
914 return impl->m_types[auxid].m_ti;
927 if (auxid >=
impl->m_types.size())
941 return factory->
tiVec();
968 if (auxid >=
impl->m_types.size())
970 return impl->m_types[auxid].m_ti_alloc;
994 if (auxid >=
impl->m_types.size())
996 return impl->m_types[auxid].m_flags;
1010 if (auxid >=
impl->m_types.size())
1012 return impl->m_types[auxid].m_linked;
1034 factory->
copy (auxid, dst, dst_index, src, src_index, n);
1057 factory->
copyForOutput (auxid, dst, dst_index, src, src_index, n);
1081 factory->
swap (auxid,
a, aindex, b, bindex, n);
1098 factory->
clear (auxid, dst, dst_index, n);
1112 const std::type_info& ti_alloc)
1116 return impl->getFactory (lock, ti, ti_alloc);
1131 if (auxid >=
impl->m_types.size())
1133 return impl->m_types[auxid].m_factory;
1147 const std::string& alloc_name)
1151 std::string key = std::string (ti.name()) +
";" + alloc_name;
1152 AuxTypeRegistryImpl::ti_map_t::const_iterator it =
impl->m_factories.find (key);
1153 if (it !=
impl->m_factories.end()) {
1174 const std::type_info& ti_alloc,
1175 std::unique_ptr<const IAuxTypeVectorFactory> factory)
1181 impl->addFactory (lock, ti, name, std::move(factory));
1182 return impl->addFactory (lock, ti, ti_alloc, fac);
1199 const std::string& ti_alloc_name,
1200 std::unique_ptr<const IAuxTypeVectorFactory> factory)
1204 return impl->addFactory (lock, ti, ti_alloc_name, std::move (factory));
1226#ifndef XAOD_STANDALONE
1244 impl->m_renameMap.clear();
1246 for (
const auto& p : *
map) {
1248 sgkey_t to_sgkey = p.second.m_sgkey;
1250 const std::string* from_str =
pool.keyToString (from_sgkey);
1251 if (!from_str)
continue;
1252 std::string::size_type from_dpos = from_str->find (
'.');
1253 if (from_dpos == std::string::npos || from_dpos == from_str->size()-1)
continue;
1255 const std::string* to_str =
pool.keyToString (to_sgkey);
1256 if (!to_str)
continue;
1257 std::string::size_type to_dpos = to_str->find (
'.');
1258 if (to_dpos == std::string::npos || to_dpos == to_str->size()-1)
continue;
1260 impl->m_renameMap[*from_str] = to_str->substr (to_dpos+1, std::string::npos);
1275 const std::string& name)
const
1279 if (
impl->m_renameMap.empty())
1282 std::string fullkey = key +
"." + name;
1283 auto it =
impl->m_renameMap.find (fullkey);
1284 if (it !=
impl->m_renameMap.end())
1295 return name.ends_with (
"_linked");
1305 return name +
"_linked";
1315 if (className.find (
"SG::JaggedVecElt<") != std::string::npos) {
1318 if (className.find (
"SG::PackedLink<") != std::string::npos) {
Handle mappings between names and auxid_t.
Implementation of IAuxTypeVector for specific types.
Hash map from strings allowing concurrent, lockless reads.
Auxiliary variable type allowing storage as a jagged vector. That is, the payloads for all the DataVe...
Exceptions that can be thrown from AthContainers.
char data[hepevt_bytes_allocation_ATLAS]
Simple (non-deleting) Updater implementation.
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
Hash map from strings allowing concurrent, lockless reads.
std::pair< const_iterator, bool > insert_or_assign(const key_type &key, mapped_type val, const Context_t &ctx=Updater_t::defaultContext())
Add an element to the map, or overwrite an existing one.
Abstract interface for looking up strings/CLIDs in a pool.
Used as type_info when we read an aux data item but it doesn't exist in the registry.
mutex_t m_mutex
Mutex controlling access to the registry.
std::vector< const IAuxTypeVectorFactory * > m_oldFactories
Hold additional factory instances we need to delete.
AthContainers_detail::concurrent_vector< typeinfo_t > m_types
Table of aux data items, indexed by auxid.
CxxUtils::ConcurrentStrMap< const std::type_info *, CxxUtils::SimpleUpdater > allocMap_t
static bool checkName(std::string_view s) noexcept
Check for valid variable name.
SG::auxid_t findAuxID(const std::string &name, const std::string &clsname, const Flags flags, const SG::auxid_t linkedVariable, const std::type_info &ti, const std::type_info *ti_alloc, const std::string *alloc_name, std::unique_ptr< IAuxTypeVectorFactory >(AuxTypeRegistry::*makeFactory)() const)
Look up a name -> auxid_t mapping.
AuxTypeRegistryImpl()
Constructor.
std::unordered_map< std::string, std::string > renameMap_t
Save the information provided by setInputRenameMap.
~AuxTypeRegistryImpl()
Destructor.
CxxUtils::ConcurrentStrMap< const IAuxTypeVectorFactory *, CxxUtils::SimpleUpdater > ti_map_t
Map from type_info name + allocator ti name -> IAuxTypeVectorFactory.
CxxUtils::ConcurrentStrMap< SG::auxid_t, CxxUtils::SimpleUpdater > id_map_t
Map from name -> auxid.
const IAuxTypeVectorFactory * getFactory(lock_t &lock, const std::type_info &ti, const std::type_info &ti_alloc)
Return the vector factory for a given vector element type.
const IAuxTypeVectorFactory * addFactory(lock_t &lock, const std::type_info &ti, const std::type_info &ti_alloc, const IAuxTypeVectorFactory *factory)
Add a new type -> factory mapping.
Flags getFlags(SG::auxid_t auxid) const
Return flags associated with an auxiliary variable.
const std::type_info * getType(SG::auxid_t auxid) const
Return the type of an aux data item.
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.
SG::auxid_t findAuxID(const std::string &name, const std::string &clsname="") const
Look up a name -> auxid_t mapping.
static bool isLinkedName(const std::string &name)
Test if a variable name corresponds to a linked variable.
size_t getEltSize(SG::auxid_t auxid) const
Return size of an element in the STL vector.
std::unique_ptr< IAuxTypeVector > makeVectorFromData(SG::auxid_t auxid, void *data, IAuxTypeVector *linkedVector, bool isPacked, bool ownFlag) const
Construct an IAuxTypeVector object from a vector.
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
const std::string & inputRename(const std::string &key, const std::string &name) const
Check for an input renaming of an auxiliary variable.
~AuxTypeRegistry()
Destructor.
std::string getTypeName(SG::auxid_t auxid) const
Return the type name of an aux data item.
static std::string linkedName(const std::string &name)
Given a variable name, return the name of the corresponding linked variable.
friend class AuxTypeRegistryImpl
AuxTypeRegistry()
Constructor.
const std::type_info * getAllocType(SG::auxid_t auxid) const
Return the type of the vector allocator.
void checkAuxID(const SG::auxid_t auxid, const Flags flags=Flags::None)
Verify type for an aux variable.
void clear(SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, size_t n) const
Clear a range of elements within a vector.
std::unique_ptr< IAuxTypeVectorFactory > makeFactoryNull() const
makeFactory implementation that always returns nullptr.
void setInputRenameMap(const Athena::InputRenameMap_t *map, const IStringPool &pool)
Declare input renaming requests.
AthContainers_detail::mutex mutex_t
const IAuxTypeVectorFactory * getFactory(const std::type_info &ti, const std::type_info &ti_alloc)
Return the vector factory for a given vector element type.
std::string getVecTypeName(SG::auxid_t auxid) const
Return the type of the STL vector used to hold an aux data item.
const std::type_info * getVecType(SG::auxid_t auxid) const
Return the type of the STL vector used to hold an aux data item.
size_t numVariables() const
Return the total number of registered auxiliary variable.
SG::auxid_t linkedVariable(SG::auxid_t auxid) const
Return the auxid if the linked variable, if there is one.
static bool classNameHasLink(const std::string &className)
Test to see if a class name corresponds to a class with a linked variable.
void copy(SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, const AuxVectorData &src, size_t src_index, size_t n) const
Copy elements between vectors.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
const IAuxTypeVectorFactory * addFactory(const std::type_info &ti, const std::type_info &ti_alloc, std::unique_ptr< const IAuxTypeVectorFactory > factory)
Add a new type -> factory mapping.
std::unique_ptr< IAuxTypeVectorFactory > makeFactory() const
Create an AuxTypeVectorFactory instance.
AthContainers_detail::lock_guard< mutex_t > lock_t
SG::AuxVarFlags Flags
Additional flags to qualify an auxiliary variable.
void swap(SG::auxid_t auxid, AuxVectorData &a, size_t aindex, AuxVectorData &b, size_t bindex, size_t n) const
Swap elements between vectors.
void copyForOutput(SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, const AuxVectorData &src, size_t src_index, size_t n) const
Copy elements between vectors.
std::unique_ptr< IAuxTypeVector > makeVector(SG::auxid_t auxid, size_t size, size_t capacity) const
Construct a new vector to hold an aux item.
std::string getClassName(SG::auxid_t auxid) const
Return the class name associated with an aux data item (may be blank).
bool isLinked(SG::auxid_t auxid) const
Test whether this is a linked variable.
static std::string makeKey(const std::string &name, const std::string &clsname)
Return the key used to look up an entry in m_auxids.
Manage lookup of vectors of auxiliary data.
Exception — Type mismatch for aux variable.
Exception — Bad name for auxiliary variable.
Exception — Flag mismatch for aux variable.
Exception — Linked variable mismatch.
Interface for factory objects that create vectors.
virtual std::unique_ptr< IAuxTypeVector > create(SG::auxid_t auxid, size_t size, size_t capacity, bool isLinked) const =0
Create a vector object of this type.
virtual const std::type_info * tiAlloc() const =0
Return the type_info of the vector allocator.
virtual void clear(SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, size_t n) const =0
Clear a range of elements within a vector.
virtual void copyForOutput(SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, const AuxVectorData &src, size_t src_index, size_t n) const =0
Copy elements between vectors, possibly applying thinning.
virtual const std::type_info * tiVec() const =0
Return the type_info of the vector.
virtual size_t getEltSize() const =0
Return the size of an element of this vector type.
virtual void copy(SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, const AuxVectorData &src, size_t src_index, size_t n) const =0
Copy elements between vectors.
virtual std::unique_ptr< IAuxTypeVector > createFromData(SG::auxid_t auxid, void *data, IAuxTypeVector *linkedVector, bool isPacked, bool ownFlag, bool isLinked) const =0
Create a vector object of this type from a data blob.
virtual bool isDynamic() const =0
True if the vectors created by this factory work by dynamic emulation (via TVirtualCollectionProxy or...
virtual std::string tiAllocName() const =0
Return the (demangled) name of the vector allocator.
virtual void swap(SG::auxid_t auxid, AuxVectorData &a, size_t aindex, AuxVectorData &b, size_t bindex, size_t n) const =0
Swap elements between vectors.
Abstract interface for manipulating vectors of arbitrary types.
Describe one element of a jagged vector.
Helper for emitting error messages.
void fence_seq_cst()
A sequentially-consistent fence.
SG::SGKeyMap< InputRenameEntry > InputRenameMap_t
constexpr std::enable_if_t< is_bitmask_v< E >, bool > test(E lhs, E rhs)
Convenience function to test bits in a class enum bitmask.
constexpr const char * auxAllocatorNamePrefix
AuxVarFlags
Additional flags to qualify an auxiliary variable.
std::string normalizedTypeinfoName(const std::type_info &info)
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
static const auxid_t null_auxid
To signal no aux data item.
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
static const auxid_t auxid_set_size_hint
A hint for how large we should make the auxid bitsets.
size_t auxid_t
Identifier for a particular aux data item.
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
Hold information about one aux data item.
std::string m_clsname
Class name associated with this aux data item. May be blank.
bool checkAlloc(const std::type_info *ti_alloc, const std::string *alloc_name) const
Check that the allocator type for this entry matches the requested type.
const std::type_info * m_ti_alloc
Type of the vector allocator. May be null for a dynamic type;.
AthContainers_detail::atomic< const IAuxTypeVectorFactory * > m_factory
Factory object.
const std::type_info * m_ti
Type of the aux data item.
std::string m_alloc_name
Name of the vector allocator.
auxid_t m_linked
auxid of a linked variable, or null_auxid.
std::string m_name
Aux data name.
Flags m_flags
Additional type flags.