ATLAS Offline Software
AuxInfoBase.icc
Go to the documentation of this file.
1 // Dear emacs, this is -*- c++ -*-
2 /*
3  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 */
5 #ifndef XAODCORE_AUXINFOBASE_ICC
6 #define XAODCORE_AUXINFOBASE_ICC
7 
8 // System include(s):
9 #include <iostream>
10 
11 // EDM include(s):
12 #include "AthContainers/AuxTypeRegistry.h"
13 
14 // Local include(s):
15 #include "xAODCore/tools/AuxPersInfo.h"
16 #include "xAODCore/tools/AuxPersVector.h"
17 #include "xAODCore/tools/AuxVariable.h"
18 
19 namespace xAOD {
20 
21  template< typename T >
22  AuxInfoBase::auxid_t
23  AuxInfoBase::getAuxID( const std::string& name,
24  T& /*info*/,
25  SG::AuxVarFlags flags,
26  const SG::auxid_t linkedVariable ) {
27 
28  return SG::AuxTypeRegistry::instance().template getAuxID< T >( name, "",
29  flags,
30  linkedVariable );
31  }
32 
33  template< typename T >
34  SG::IAuxTypeVector* makeVector( SG::auxid_t auxid, T& info, bool isLinked, SG::IAuxStore* store ) {
35  if( isLinked ) {
36  throw std::runtime_error( "Non-vector linked variable" );
37  }
38  return new AuxPersInfo< T >( auxid, info, store );
39  }
40 
41  template< typename T >
42  SG::IAuxTypeVector* makeVector( SG::auxid_t auxid, std::vector<T>& info, bool isLinked, SG::IAuxStore* store ) {
43  if( isLinked ) {
44  return new AuxPersVector< T >( auxid, info, true, store );
45  }
46  else {
47  return new AuxPersInfo< std::vector<T> >( auxid, info, store );
48  }
49  }
50 
51  /// The user is expected to use this function inside the constructor of
52  /// the derived class.
53  ///
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,
59  T& info ) {
60 
61  // Make sure that the internal vector is big enough:
62  if( m_vecs.size() <= auxid ) {
63  m_vecs.resize( auxid + 1 );
64  }
65 
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 ];
72  }
73 
74  // Register the variable:
75  const SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
76  m_vecs[ auxid ] = makeVector( auxid, info, r.isLinked( auxid ), this );
77 
78  // Remember that we are now handling this variable:
79  m_auxids.insert( auxid );
80 
81  return;
82  }
83 
84 } // namespace xAOD
85 
86 #endif // XAODCORE_AUXINFOBASE_ICC