ATLAS Offline Software
AuxContainerBase.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_AUXCONTAINERBASE_ICC
6 #define XAODCORE_AUXCONTAINERBASE_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/AuxPersVector.h"
16 #include "xAODCore/tools/AuxVariable.h"
17 
18 namespace xAOD {
19 
20  template< typename T, typename ALLOC >
21  AuxContainerBase::auxid_t
22  AuxContainerBase::getAuxID( const std::string& name,
23  std::vector< T, ALLOC >& /*vec*/,
24  SG::AuxVarFlags flags,
25  const SG::auxid_t linkedVariable ) {
26 
27  return SG::AuxTypeRegistry::instance().template getAuxID< T >( name, "",
28  flags,
29  linkedVariable );
30  }
31 
32  template< typename T >
33  AuxContainerBase::auxid_t
34  AuxContainerBase::getAuxID( const std::string& name,
35  SG::PackedContainer< T >& /*vec*/,
36  SG::AuxVarFlags flags,
37  const SG::auxid_t linkedVariable ) {
38 
39  return SG::AuxTypeRegistry::instance().template getAuxID< T >( name, "",
40  flags,
41  linkedVariable );
42  }
43 
44  /// Common code between vector and PackedContainer cases.
45  template< typename ELT, typename CONT >
46  void AuxContainerBase::regAuxVar1( const auxid_t auxid,
47  const std::string& name, CONT& vec ) {
48 
49  // Make sure that the internal vector is big enough:
50  if( m_vecs.size() <= auxid ) {
51  m_vecs.resize( auxid + 1 );
52  }
53 
54  // Check if this variable name was already registered:
55  if( m_vecs[ auxid ] ) {
56  std::cout << "WARNING xAOD::AuxContainerBase::regAuxVec "
57  << "Re-registering variable with name \""
58  << name << "\"" << std::endl;
59  delete m_vecs[ auxid ];
60  }
61 
62  // Register the variable:
63  const SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
64  m_vecs[ auxid ] = new AuxPersVector< ELT, CONT >( auxid, vec, r.isLinked( auxid ), this );
65 
66  // Remember that we are now handling this variable:
67  m_auxids.insert( auxid );
68 
69  return;
70  }
71 
72  /// The user is expected to use this function inside the constructor of
73  /// the derived class.
74  ///
75  /// @param auxid The auxiliary ID to use for the variable
76  /// @param name The name of the variable. Same as the C++ variable's name.
77  /// @param vec A reference to the auxiliary variable inside the object
78  /// @param flags Optional flags qualifying the type. See AuxTypeRegistry.h.
79  template< typename T, typename ALLOC >
80  void AuxContainerBase::regAuxVar( const auxid_t auxid,
81  const std::string& name,
82  std::vector< T, ALLOC >& vec ) {
83  regAuxVar1<T> (auxid, name, vec);
84  return;
85  }
86 
87  /// The user is expected to use this function inside the constructor of
88  /// the derived class.
89  ///
90  /// @param auxid The auxiliary ID to use for the variable
91  /// @param name The name of the variable. Same as the C++ variable's name.
92  /// @param vec A reference to the auxiliary variable inside the object
93  /// @param flags Optional flags qualifying the type. See AuxTypeRegistry.h.
94  template< typename T >
95  void AuxContainerBase::regAuxVar( const auxid_t auxid,
96  const std::string& name,
97  SG::PackedContainer< T >& vec ) {
98  regAuxVar1<T> (auxid, name, vec);
99  return;
100  }
101 
102 } // namespace xAOD
103 
104 #endif // XAODCORE_AUXCONTAINERBASE_ICC