1 // Dear emacs, this is -*- c++ -*-
3 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5 #ifndef XAODCORE_AUXINFOBASE_ICC
6 #define XAODCORE_AUXINFOBASE_ICC
12 #include "AthContainers/AuxTypeRegistry.h"
15 #include "xAODCore/tools/AuxPersInfo.h"
16 #include "xAODCore/tools/AuxPersVector.h"
17 #include "xAODCore/tools/AuxVariable.h"
21 template< typename T >
23 AuxInfoBase::getAuxID( const std::string& name,
25 SG::AuxVarFlags flags,
26 const SG::auxid_t linkedVariable ) {
28 return SG::AuxTypeRegistry::instance().template getAuxID< T >( name, "",
33 template< typename T >
34 SG::IAuxTypeVector* makeVector( SG::auxid_t auxid, T& info, bool isLinked, SG::IAuxStore* store ) {
36 throw std::runtime_error( "Non-vector linked variable" );
38 return new AuxPersInfo< T >( auxid, info, store );
41 template< typename T >
42 SG::IAuxTypeVector* makeVector( SG::auxid_t auxid, std::vector<T>& info, bool isLinked, SG::IAuxStore* store ) {
44 return new AuxPersVector< T >( auxid, info, true, store );
47 return new AuxPersInfo< std::vector<T> >( auxid, info, store );
51 /// The user is expected to use this function inside the constructor of
52 /// the derived class.
54 /// @param auxid The auxiliary ID to use for the variable
55 /// @param name The name of the variable. Same as the C++ variable's name.
56 /// @param vec A reference to the auxiliary variable inside the object
57 template< typename T >
58 void AuxInfoBase::regAuxVar( const auxid_t auxid, const std::string& name,
61 // Make sure that the internal vector is big enough:
62 if( m_vecs.size() <= auxid ) {
63 m_vecs.resize( auxid + 1 );
66 // Check if this variable name was already registered:
67 if( m_vecs[ auxid ] ) {
68 std::cout << "WARNING xAOD::AuxInfoBase::regAuxVar "
69 << "Re-registering variable with name \""
70 << name.c_str() << "\"" << std::endl;
71 delete m_vecs[ auxid ];
74 // Register the variable:
75 const SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
76 m_vecs[ auxid ] = makeVector( auxid, info, r.isLinked( auxid ), this );
78 // Remember that we are now handling this variable:
79 m_auxids.insert( auxid );
86 #endif // XAODCORE_AUXINFOBASE_ICC