ATLAS Offline Software
AuxTypeRegistry.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  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 */
13 #ifndef ATHCONTAINERS_AUXTYPEREGISTRY_H
14 #define ATHCONTAINERS_AUXTYPEREGISTRY_H
15 
16 
24 #include "CxxUtils/SimpleUpdater.h"
25 #ifndef XAOD_STANDALONE
28 #endif
29 #include <cstddef>
30 #include <typeinfo>
31 #include <vector>
32 #include <unordered_map>
33 #include <functional>
34 
35 
36 namespace SG {
37 
38 
62 {
63 public:
65  // Now in AuxTypes.h to avoid cyclic header dependencies.
67 
68 
72  static AuxTypeRegistry& instance();
73 
74 
80  size_t numVariables() const;
81 
82 
94  template <class T, class ALLOC = AuxAllocator_t<T> >
95  SG::auxid_t getAuxID (const std::string& name,
96  const std::string& clsname = "",
97  const Flags flags = Flags::None);
98 
99 
113  SG::auxid_t getAuxID (const std::type_info& ti,
114  const std::string& name,
115  const std::string& clsname = "",
116  const Flags flags = Flags::None);
117 
118 
133  SG::auxid_t getAuxID (const std::type_info& ti_alloc,
134  const std::type_info& ti,
135  const std::string& name,
136  const std::string& clsname = "",
137  const Flags flags = Flags::None);
138 
139 
154  SG::auxid_t getAuxID (const std::string& alloc_type,
155  const std::type_info& ti,
156  const std::string& name,
157  const std::string& clsname = "",
158  const Flags flags = Flags::None);
159 
160 
170  SG::auxid_t findAuxID( const std::string& name,
171  const std::string& clsname = "") const;
172 
173 
183  template <class T, class ALLOC = AuxAllocator_t<T> >
184  void checkAuxID (const SG::auxid_t auxid,
185  const Flags flags = Flags::None);
186 
187 
199  void checkAuxID (const SG::auxid_t auxid,
200  const std::type_info& ti,
201  const std::type_info& ti_alloc,
202  const Flags flags);
203 
204 
213  std::unique_ptr<IAuxTypeVector> makeVector (SG::auxid_t auxid,
214  size_t size,
215  size_t capacity) const;
216 
217 
232  std::unique_ptr<IAuxTypeVector> makeVectorFromData (SG::auxid_t auxid,
233  void* data,
234  bool isPacked,
235  bool ownFlag) const;
236 
237 
242  std::string getName (SG::auxid_t auxid) const;
243 
244 
250  std::string getClassName (SG::auxid_t auxid) const;
251 
252 
257  const std::type_info* getType (SG::auxid_t auxid) const;
258 
259 
266  std::string getTypeName (SG::auxid_t auxid) const;
267 
268 
273  const std::type_info* getVecType (SG::auxid_t auxid) const;
274 
275 
282  std::string getVecTypeName (SG::auxid_t auxid) const;
283 
284 
289  const std::type_info* getAllocType (SG::auxid_t auxid) const;
290 
291 
296  size_t getEltSize (SG::auxid_t auxid) const;
297 
298 
303  Flags getFlags (SG::auxid_t auxid) const;
304 
305 
317  void copy (SG::auxid_t auxid,
318  AuxVectorData& dst, size_t dst_index,
319  const AuxVectorData& src, size_t src_index,
320  size_t n) const;
321 
322 
336  void copy (SG::auxid_t auxid,
337  AuxVectorData&& dst, size_t dst_index,
338  const AuxVectorData& src, size_t src_index,
339  size_t n) const;
340 
341 
354  void copyForOutput (SG::auxid_t auxid,
355  AuxVectorData& dst, size_t dst_index,
356  const AuxVectorData& src, size_t src_index,
357  size_t n) const;
358 
359 
372  void swap (SG::auxid_t auxid,
373  AuxVectorData& a, size_t aindex,
374  AuxVectorData& b, size_t bindex,
375  size_t n) const;
376 
377 
385  void clear (SG::auxid_t auxid,
386  AuxVectorData& dst, size_t dst_index,
387  size_t n) const;
388 
389 
398  const IAuxTypeVectorFactory* getFactory (const std::type_info& ti,
399  const std::type_info& ti_alloc);
400 
401 
410  const IAuxTypeVectorFactory* getFactory (const std::type_info& ti,
411  const std::string& alloc_name);
412 
413 
422 
423 
435  const IAuxTypeVectorFactory*
436  addFactory (const std::type_info& ti,
437  const std::type_info& ti_alloc,
438  std::unique_ptr<const IAuxTypeVectorFactory> factory);
439 
440 
452  const IAuxTypeVectorFactory*
453  addFactory (const std::type_info& ti,
454  const std::string& ti_alloc_name,
455  std::unique_ptr<const IAuxTypeVectorFactory> factory);
456 
457 
458 #ifndef XAOD_STANDALONE
459 
470  const IStringPool& pool);
471 #endif
472 
473 
482  const std::string& inputRename (const std::string& key,
483  const std::string& name) const;
484 
485 
486 private:
488  typedef AthContainers_detail::lock_guard<mutex_t> lock_t;
489 
495  AuxTypeRegistry();
496 
497 
504 
505 
509 
510 
535  findAuxID (const std::string& name,
536  const std::string& clsname,
537  const Flags flags,
538  const std::type_info& ti,
539  const std::type_info* ti_alloc,
540  const std::string* alloc_name,
541  std::unique_ptr<IAuxTypeVectorFactory> (AuxTypeRegistry::*makeFactory) () const);
542 
543 
556  const IAuxTypeVectorFactory*
557  addFactory (lock_t& lock,
558  const std::type_info& ti,
559  const std::type_info& ti_alloc,
560  const IAuxTypeVectorFactory* factory);
561 
562 
575  const IAuxTypeVectorFactory*
576  addFactory (lock_t& /*lock*/,
577  const std::type_info& ti,
578  const std::string& ti_alloc_name,
579  std::unique_ptr<const IAuxTypeVectorFactory> factory);
580 
581 
591  template <class T, class ALLOC = AuxAllocator_t<T> >
592  std::unique_ptr<IAuxTypeVectorFactory> makeFactory() const;
593 
594 
601  std::unique_ptr<IAuxTypeVectorFactory> makeFactoryNull() const;
602 
603 
609  static std::string makeKey (const std::string& name,
610  const std::string& clsname);
611 
612 
620  static bool checkName (const std::string& s);
621 
622 
634  const std::type_info& ti,
635  const std::type_info& ti_alloc);
636 
637 
639  struct typeinfo_t
640  {
642  AthContainers_detail::atomic<const IAuxTypeVectorFactory*> m_factory;
643 
645  const std::type_info* m_ti;
646 
648  const std::type_info* m_ti_alloc;
649 
651  std::string m_alloc_name;
652 
654  std::string m_name;
655 
657  std::string m_clsname;
658 
661 
664  bool checkAlloc (const std::type_info* ti_alloc,
665  const std::string* alloc_name) const;
666  };
667 
668 
670  // A concurrent vector, so we don't need to take a lock to read it.
671  AthContainers_detail::concurrent_vector<typeinfo_t> m_types;
672 
673 
675  using id_map_t = CxxUtils::ConcurrentStrMap<SG::auxid_t, CxxUtils::SimpleUpdater>;
677 
679  using ti_map_t = CxxUtils::ConcurrentStrMap<const IAuxTypeVectorFactory*, CxxUtils::SimpleUpdater>;
681 
683  std::vector<const IAuxTypeVectorFactory*> m_oldFactories;
684 
687  typedef std::unordered_map<std::string, std::string> renameMap_t;
689 
691  // We originally used an upgrading mutex here.
692  // But that's relatively slow, and most of the locked sections are short,
693  // so it's not really a win.
694  // This guards write access to all members, and read access to all members
695  // except for m_types.
696  mutable mutex_t m_mutex;
697 
698  // Map from the TI name for T to the TI for AuxAllocator_t<T>.
699  // Filled in by addFactory(). Used in findAuxID() if the allocator
700  // type is not specified.
701  using allocMap_t = CxxUtils::ConcurrentStrMap<const std::type_info*, CxxUtils::SimpleUpdater>;
703 };
704 
705 
706 } // namespace SG
707 
708 
710 
711 
712 #endif // not ATHCONTAINERS_AUXTYPEREGISTRY_H
SG::AuxTypeRegistry::getFactory
const IAuxTypeVectorFactory * getFactory(const std::type_info &ti, const std::type_info &ti_alloc)
Return the vector factory for a given vector element type.
Definition: AuxTypeRegistry.cxx:457
SG::AuxTypeRegistry::allocMap_t
CxxUtils::ConcurrentStrMap< const std::type_info *, CxxUtils::SimpleUpdater > allocMap_t
Definition: AuxTypeRegistry.h:701
SG::AuxTypeRegistry::m_allocMap
allocMap_t m_allocMap
Definition: AuxTypeRegistry.h:702
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
IStringPool
Abstract interface for looking up strings/CLIDs in a pool.
Definition: IStringPool.h:28
SG::AuxTypeRegistry::makeVectorFromData
std::unique_ptr< IAuxTypeVector > makeVectorFromData(SG::auxid_t auxid, void *data, bool isPacked, bool ownFlag) const
Construct an IAuxTypeVector object from a vector.
Definition: AuxTypeRegistry.cxx:231
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
SG::AuxTypeRegistry::addFactory
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.
Definition: AuxTypeRegistry.cxx:530
SG::AuxTypeRegistry::typeinfo_t::m_ti_alloc
const std::type_info * m_ti_alloc
Type of the vector allocator. May be null for a dynamic type;.
Definition: AuxTypeRegistry.h:648
SG::AuxTypeRegistry::getAuxID
SG::auxid_t getAuxID(const std::string &name, const std::string &clsname="", const Flags flags=Flags::None)
Look up a name -> auxid_t mapping.
SG::AuxTypeRegistry::m_oldFactories
std::vector< const IAuxTypeVectorFactory * > m_oldFactories
Hold additional factory instances we need to delete.
Definition: AuxTypeRegistry.h:683
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:49
SG::AuxTypeRegistry::findAuxID
SG::auxid_t findAuxID(const std::string &name, const std::string &clsname="") const
Look up a name -> auxid_t mapping.
Definition: AuxTypeRegistry.cxx:150
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
SG::AuxTypeRegistry::setInputRenameMap
void setInputRenameMap(const Athena::IInputRename::InputRenameMap_t *map, const IStringPool &pool)
Declare input renaming requests.
Definition: AuxTypeRegistry.cxx:873
AthenaPoolTestRead.flags
flags
Definition: AthenaPoolTestRead.py:8
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
SG::AuxTypeRegistry::lock_t
AthContainers_detail::lock_guard< mutex_t > lock_t
Definition: AuxTypeRegistry.h:488
SG::AuxTypeRegistry::makeKey
static std::string makeKey(const std::string &name, const std::string &clsname)
Return the key used to look up an entry in m_auxids.
Definition: AuxTypeRegistry.cxx:247
SG::AuxTypeRegistry::getName
std::string getName(SG::auxid_t auxid) const
Return the name of an aux data item.
Definition: AuxTypeRegistry.cxx:262
AuxTypeVectorFactory.h
Factory object that creates vectors using AuxTypeVector.
SG::AuxTypeRegistry::getVecTypeName
std::string getVecTypeName(SG::auxid_t auxid) const
Return the type of the STL vector used to hold an aux data item.
Definition: AuxTypeRegistry.cxx:328
pool
pool namespace
Definition: libname.h:15
ConcurrentStrMap.h
Hash map from strings allowing concurrent, lockless reads.
SG::AuxTypeRegistry::inputRename
const std::string & inputRename(const std::string &key, const std::string &name) const
Check for an input renaming of an auxiliary variable.
Definition: AuxTypeRegistry.cxx:907
SG::AuxTypeRegistry::getAllocType
const std::type_info * getAllocType(SG::auxid_t auxid) const
Return the type of the vector allocator.
Definition: AuxTypeRegistry.cxx:341
SG::AuxTypeRegistry::ti_map_t
CxxUtils::ConcurrentStrMap< const IAuxTypeVectorFactory *, CxxUtils::SimpleUpdater > ti_map_t
Map from type_info name + allocator ti name -> IAuxTypeVectorFactory.
Definition: AuxTypeRegistry.h:679
SG::AuxTypeRegistry::typeinfo_t::m_clsname
std::string m_clsname
Class name associated with this aux data item. May be blank.
Definition: AuxTypeRegistry.h:657
SG::AuxTypeRegistry::typeinfo_t::m_ti
const std::type_info * m_ti
Type of the aux data item.
Definition: AuxTypeRegistry.h:645
SG::AuxTypeRegistry::m_types
AthContainers_detail::concurrent_vector< typeinfo_t > m_types
Table of aux data items, indexed by auxid.
Definition: AuxTypeRegistry.h:671
IInputRename.h
Interface to retrieve input rename map.
SG::AuxTypeRegistry::AuxTypeRegistry
AuxTypeRegistry()
Constructor.
Definition: AuxTypeRegistry.cxx:653
SG::AuxTypeRegistry::copyForOutput
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.
Definition: AuxTypeRegistry.cxx:396
IAuxTypeVector.h
Abstract interface for manipulating vectors of arbitrary types.
SG::AuxTypeRegistry::~AuxTypeRegistry
~AuxTypeRegistry()
Destructor.
Definition: AuxTypeRegistry.cxx:692
SG::AuxTypeRegistry::copy
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.
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:62
SG::AuxTypeRegistry::mutex_t
AthContainers_detail::mutex mutex_t
Definition: AuxTypeRegistry.h:487
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
SG::AuxTypeRegistry::typeinfo_t::m_name
std::string m_name
Aux data name.
Definition: AuxTypeRegistry.h:654
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
SG::AuxTypeRegistry::getType
const std::type_info * getType(SG::auxid_t auxid) const
Return the type of an aux data item.
Definition: AuxTypeRegistry.cxx:287
SG::AuxTypeRegistry::m_factories
ti_map_t m_factories
Definition: AuxTypeRegistry.h:680
SG::AuxTypeRegistry::swap
void swap(SG::auxid_t auxid, AuxVectorData &a, size_t aindex, AuxVectorData &b, size_t bindex, size_t n) const
Swap elements between vectors.
Definition: AuxTypeRegistry.cxx:420
IStringPool.h
Abstract interface for looking up strings/CLIDs in a pool.
SG::AuxTypeRegistry::getTypeName
std::string getTypeName(SG::auxid_t auxid) const
Return the type name of an aux data item.
Definition: AuxTypeRegistry.cxx:301
SG::AuxTypeRegistry::typeinfo_t::m_flags
Flags m_flags
Additional type flags.
Definition: AuxTypeRegistry.h:660
beamspotman.n
n
Definition: beamspotman.py:731
SG::IAuxTypeVectorFactory
Interface for factory objects that create vectors.
Definition: IAuxTypeVectorFactory.h:50
readCCLHist.None
None
Definition: readCCLHist.py:82
AuxTypeRegistry.icc
SG::AuxTypeRegistry::getFlags
Flags getFlags(SG::auxid_t auxid) const
Return flags associated with an auxiliary variable.
SG::AuxTypeRegistry::getEltSize
size_t getEltSize(SG::auxid_t auxid) const
Return size of an element in the STL vector.
Definition: AuxTypeRegistry.cxx:353
SG::AuxTypeRegistry::makeFactory
std::unique_ptr< IAuxTypeVectorFactory > makeFactory() const
Create an AuxTypeVectorFactory instance.
SG::AuxTypeRegistry::getFactory
const IAuxTypeVectorFactory * getFactory(SG::auxid_t auxid) const
Return the vector factory for a given auxid.
SG::AuxTypeRegistry::getVecType
const std::type_info * getVecType(SG::auxid_t auxid) const
Return the type of the STL vector used to hold an aux data item.
Definition: AuxTypeRegistry.cxx:313
SG::AuxTypeRegistry::numVariables
size_t numVariables() const
Return the total number of registered auxiliary variable.
Definition: AuxTypeRegistry.cxx:61
SG::AuxVarFlags
AuxVarFlags
Additional flags to qualify an auxiliary variable.
Definition: AuxTypes.h:58
SG::AuxTypeRegistry::clear
void clear(SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, size_t n) const
Clear a range of elements within a vector.
Definition: AuxTypeRegistry.cxx:438
SG::AuxTypeRegistry::getClassName
std::string getClassName(SG::auxid_t auxid) const
Return the class name associated with an aux data item (may be blank).
Definition: AuxTypeRegistry.cxx:275
AuxTypeVector.h
Implementation of IAuxTypeVector for specific types.
SG::AuxTypeRegistry::makeVector
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.
Definition: AuxTypeRegistry.cxx:206
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
SG::AuxTypeRegistry::typeinfo_t::m_factory
AthContainers_detail::atomic< const IAuxTypeVectorFactory * > m_factory
Factory object.
Definition: AuxTypeRegistry.h:642
SG::AuxTypeRegistry::checkAuxID
void checkAuxID(const SG::auxid_t auxid, const Flags flags=Flags::None)
Verify type for an aux variable.
threading.h
Threading definitions.
SG::AuxTypeRegistry::typeinfo_t
Hold information about one aux data item.
Definition: AuxTypeRegistry.h:640
SG::AuxTypeRegistry::m_mutex
mutex_t m_mutex
Mutex controlling access to the registry.
Definition: AuxTypeRegistry.h:696
AuxTypes.h
Basic definitions for auxiliary types.
SG::AuxTypeRegistry::checkName
static bool checkName(const std::string &s)
Check for valid variable name.
Definition: AuxTypeRegistry.cxx:929
a
TList * a
Definition: liststreamerinfos.cxx:10
SG::AuxTypeRegistry::makeFactoryNull
std::unique_ptr< IAuxTypeVectorFactory > makeFactoryNull() const
makeFactory implementation that always returns nullptr.
SimpleUpdater.h
Simple (non-deleting) Updater implementation.
SG::AuxTypeRegistry::renameMap_t
std::unordered_map< std::string, std::string > renameMap_t
Save the information provided by setInputRenameMap.
Definition: AuxTypeRegistry.h:687
SG::AuxTypeRegistry::id_map_t
CxxUtils::ConcurrentStrMap< SG::auxid_t, CxxUtils::SimpleUpdater > id_map_t
Map from name -> auxid.
Definition: AuxTypeRegistry.h:675
IAuxTypeVectorFactory.h
Interface for factory objects that create vectors.
SG::AuxTypeRegistry::typeinfo_t::m_alloc_name
std::string m_alloc_name
Name of the vector allocator.
Definition: AuxTypeRegistry.h:651
SG::AuxTypeRegistry::operator=
AuxTypeRegistry & operator=(const AuxTypeRegistry &)
SG::AuxVectorData
Manage lookup of vectors of auxiliary data.
Definition: AuxVectorData.h:167
SG::AuxTypeRegistry::AuxTypeRegistry
AuxTypeRegistry(const AuxTypeRegistry &)
Disallow copy construction and assignment.
Athena::IInputRename::InputRenameMap_t
SG::SGKeyMap< Rename > InputRenameMap_t
Definition: IInputRename.h:45
SG::AuxTypeRegistry::copy
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.
Definition: AuxTypeRegistry.cxx:373
SG::AuxTypeRegistry::m_renameMap
renameMap_t m_renameMap
Definition: AuxTypeRegistry.h:688
SG::AuxTypeRegistry::typeinfo_t::checkAlloc
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.
Definition: AuxTypeRegistry.cxx:29
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
SG::AuxTypeRegistry::m_auxids
id_map_t m_auxids
Definition: AuxTypeRegistry.h:676