2 * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
5 * @file AthContainers/TypelessConstAccessor.icc
6 * @author scott snyder <snyder@bnl.gov>
8 * @brief Helper class to provide const generic access to aux data.
12 #include "AthContainers/AuxTypeRegistry.h"
13 #include "AthContainers/exceptions.h"
21 * @param name Name of this aux variable.
23 * The name -> auxid lookup is done here.
26 TypelessConstAccessor::TypelessConstAccessor (const std::string& name)
28 SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
29 m_auxid = r.findAuxID(name);
30 if (m_auxid == null_auxid)
31 SG::throwExcUnknownAuxItem (name);
32 m_eltSize = r.getEltSize (m_auxid);
38 * @param ti The type for this aux data item.
39 * @param name Name of this aux variable.
41 * The name -> auxid lookup is done here.
44 TypelessConstAccessor::TypelessConstAccessor (const std::type_info& ti,
45 const std::string& name)
47 SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
48 m_auxid = r.getAuxID (ti, name);
49 if (m_auxid == null_auxid)
50 SG::throwExcUnknownAuxItem (name, "", &ti);
51 m_eltSize = r.getEltSize (m_auxid);
57 * @param name Name of this aux variable.
58 * @param clsname The name of its associated class. May be blank.
60 * The name -> auxid lookup is done here.
63 TypelessConstAccessor::TypelessConstAccessor (const std::string& name,
64 const std::string& clsname)
66 SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
67 m_auxid = r.findAuxID(name, clsname);
68 if (m_auxid == null_auxid)
69 SG::throwExcUnknownAuxItem (name, clsname);
70 m_eltSize = r.getEltSize (m_auxid);
76 * @param ti The type for this aux data item.
77 * @param name Name of this aux variable.
78 * @param clsname The name of its associated class. May be blank.
80 * The name -> auxid lookup is done here.
83 TypelessConstAccessor::TypelessConstAccessor (const std::type_info& ti,
84 const std::string& name,
85 const std::string& clsname)
87 SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance();
88 m_auxid = r.getAuxID (ti, name, clsname);
89 if (m_auxid == null_auxid)
90 SG::throwExcUnknownAuxItem (name, clsname, &ti);
91 m_eltSize = r.getEltSize (m_auxid);
96 * @brief Fetch the variable for one element, as a const pointer.
97 * @param e The element for which to fetch the variable.
100 ATH_REQUIRES( IsConstAuxElement<ELT> )
103 TypelessConstAccessor::operator() (const ELT& e) const
105 assert (e.container() != 0);
106 return (*this) (*e.container(), e.index());
111 * @brief Fetch the variable for one element, as a const pointer.
112 * @param container The container from which to fetch the variable.
113 * @param index The index of the desired element.
115 * This allows retrieving aux data by container / index.
116 * Looping over the index via this method will be faster then
117 * looping over the elements of the container.
121 TypelessConstAccessor::operator() (const AuxVectorData& container,
124 const char* ptr = reinterpret_cast<const char*> (getDataArray (container));
125 return ptr + index * m_eltSize;
130 * @brief Get a pointer to the start of the auxiliary data array.
131 * @param container The container from which to fetch the variable.
135 TypelessConstAccessor::getDataArray (const AuxVectorData& container) const
137 return container.getDataArray (m_auxid);
142 * @brief Test to see if this variable exists in the store.
143 * @param e An element of the container which to test the variable.
146 ATH_REQUIRES( IsConstAuxElement<ELT> )
149 TypelessConstAccessor::isAvailable (const ELT& e) const
151 return e.container() && e.container()->isAvailable (m_auxid);
156 * @brief Return the aux id for this variable.
160 TypelessConstAccessor::auxid() const