diff --git a/Control/AthContainers/AthContainers/AuxVectorBase.h b/Control/AthContainers/AthContainers/AuxVectorBase.h index f78b533ed353f6b12d8ab776cb627d1cb32ec9a9..3a9d01ee158a6b2d467d0e76b240e4c47f168777 100644 --- a/Control/AthContainers/AthContainers/AuxVectorBase.h +++ b/Control/AthContainers/AthContainers/AuxVectorBase.h @@ -1,7 +1,7 @@ // This file's extension implies that it's C, but it's really -*- C++ -*-. /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ /** * @file AthContainers/AuxVectorBase.h @@ -21,6 +21,7 @@ #include "AthContainers/AuxElement.h" #include "AthContainers/AuxTypeRegistry.h" #include "AthContainers/exceptions.h" +#include "AthContainers/tools/AuxDataTraits.h" #include "AthContainers/tools/ATHCONTAINERS_ASSERT.h" #include "AthContainersInterfaces/IAuxStore.h" #include "AthContainersInterfaces/AuxStore_traits.h" @@ -96,6 +97,11 @@ class AuxVectorBase : public AuxVectorData { public: + /// Spans over auxiliary variables. + template <class T> using span = typename AuxDataTraits<T>::span; + template <class T> using const_span = typename AuxDataTraits<T>::const_span; + + /** * @brief Default constructor. * @@ -190,6 +196,113 @@ public: void setNonConstStore (SG::IAuxStore* store); + // Templated versions of isAvailable, etc. + // We put them here rather than in AuxVectorData so that AuxVectorData.h + // doesn't need to include AuxTypeRegistry.h. Otherwise we get a + // a cyclic header dependency: + // AuxTypeRegistry -> AuxTypeVectorFactory -> AuxVectorData -> AuxTypeRegistry + + using AuxVectorData::isAvailable; + using AuxVectorData::isAvailableWritable; + using AuxVectorData::isAvailableWritableAsDecoration; + + + /** + * @brief Test to see if a variable exists in the store. + * @param name Name of the aux variable. + * @param clsname The name of the associated class. May be blank. + */ + template <class T> + bool isAvailable (const std::string& name, + const std::string& clsname = "") const; + + + /** + * @brief Test to see if a variable is available for writing. + * @param name Name of the aux variable. + * @param clsname The name of the associated class. May be blank. + */ + template <class T> + bool isAvailableWritable (const std::string& name, + const std::string& clsname = ""); + + + /** + * @brief Test to see if a variable is available for writing as a decoration. + * @param name Name of the aux variable. + * @param clsname The name of the associated class. May be blank. + */ + template <class T> + bool isAvailableWritableAsDecoration (const std::string& name, + const std::string& clsname = "") const; + + + /** + * @brief Return a span over an aux data item. + * @param auxid The desired aux data item. + * + * This will return a span containing the value of the requested + * auxiliary variable for all elements in the container. + * If the item doesn't exist, it will be created. + * Errors are signaled by raising an exception. + * Note that the @c value_type of the span is not necessarily @c T; + * an example is @c bool for which we return a span of @c char. + */ + template <class T> + span<T> getDataSpan (const std::string& name); + + + /** + * @brief Return a span over an aux data item. + * @param auxid The desired aux data item. + * + * This will return a span containing the value of the requested + * auxiliary variable for all elements in the container. + * If the item doesn't exist, it will be created. + * Errors are signaled by raising an exception. + * Note that the @c value_type of the span is not necessarily @c T; + * an example is @c bool for which we return a span of @c char. + */ + template <class T> + const_span<T> getDataSpan (const std::string& name) const; + + + /** + * @brief Return a span over an aux data item. + * @param auxid The desired aux data item. + * + * This will return a span containing the value of the requested + * auxiliary variable for all elements in the container. + * If the item doesn't exist, it will be created. + * Errors are signaled by raising an exception. + * Note that the @c value_type of the span is not necessarily @c T; + * an example is @c bool for which we return a span of @c char. + */ + template <class T> + const_span<T> getConstDataSpan (const std::string& name) const; + + + /** + * @brief Return a span over an aux data item for a decoration. + * @param auxid The desired aux data item. + * + * This will return a span containing the value of the requested + * auxiliary variable for all elements in the container. + * If the item doesn't exist, it will be created. + * Errors are signaled by raising an exception. + * Note that the @c value_type of the span is not necessarily @c T; + * an example is @c bool for which we return a span of @c char. + * + * The difference between @c getDecorationSpan and @c getDataSpan is that + * @c getDecorationSpan takes a const container as input, but returns + * a span over non-const objects. This will only succeed if either the + * container is not locked or the item was first accessed + * as a decoration. + */ + template <class T> + span<T> getDecorationSpan (const std::string& name) const; + + /// Mark that this type supports thinning operations. /// See AthContainers/supportsThinning.h and /// AthenaPoolCnvSvc/T_AthenaPoolCnv.h. diff --git a/Control/AthContainers/AthContainers/AuxVectorBase.icc b/Control/AthContainers/AthContainers/AuxVectorBase.icc index 5dcccbb52c63354dac81b9cac26df5aca785e20a..2ec691cde01bc23a338c4aad467ea259f193571b 100644 --- a/Control/AthContainers/AthContainers/AuxVectorBase.icc +++ b/Control/AthContainers/AthContainers/AuxVectorBase.icc @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ /** @@ -45,6 +45,146 @@ void AuxVectorBase::setNonConstStore (SG::IAuxStore* store) } +/** + * @brief Test to see if a variable exists in the store. + * @param name Name of the aux variable. + * @param clsname The name of the associated class. May be blank. + */ +template <class T> +inline +bool AuxVectorBase::isAvailable (const std::string& name, + const std::string& clsname /*= ""*/) const +{ + auxid_t id = SG::AuxTypeRegistry::instance().getAuxID<T> (name, clsname); + return AuxVectorData::isAvailable (id); +} + + +/** + * @brief Test to see if a variable is available for writing. + * @param name Name of the aux variable. + * @param clsname The name of the associated class. May be blank. + */ +template <class T> +inline +bool +AuxVectorBase::isAvailableWritable (const std::string& name, + const std::string& clsname /*= ""*/) +{ + auxid_t id = SG::AuxTypeRegistry::instance().getAuxID<T> (name, clsname); + return AuxVectorData::isAvailableWritable (id); +} + + +/** + * @brief Test to see if a variable is available for writing as a decoration. + * @param name Name of the aux variable. + * @param clsname The name of the associated class. May be blank. + */ +template <class T> +inline +bool +AuxVectorBase::isAvailableWritableAsDecoration (const std::string& name, + const std::string& clsname /*= ""*/) const +{ + auxid_t id = SG::AuxTypeRegistry::instance().getAuxID<T> (name, clsname); + return AuxVectorData::isAvailableWritableAsDecoration (id); +} + + +/** + * @brief Return a span over an aux data item. + * @param auxid The desired aux data item. + * + * This will return a span containing the value of the requested + * auxiliary variable for all elements in the container. + * If the item doesn't exist, it will be created. + * Errors are signaled by raising an exception. + * Note that the @c value_type of the span is not necessarily @c T; + * an example is @c bool for which we return a span of @c char. + */ +template <class T> +AuxVectorBase::span<T> AuxVectorBase::getDataSpan (const std::string& name) +{ + using container_pointer_type = typename AuxDataTraits<T>::container_pointer_type; + auxid_t id = SG::AuxTypeRegistry::instance().getAuxID<T> (name); + auto beg = reinterpret_cast<container_pointer_type> (AuxVectorData::getDataArray (id)); + return span<T> (beg, size_v()); +} + + +/** + * @brief Return a span over an aux data item. + * @param auxid The desired aux data item. + * + * This will return a span containing the value of the requested + * auxiliary variable for all elements in the container. + * If the item doesn't exist, it will be created. + * Errors are signaled by raising an exception. + * Note that the @c value_type of the span is not necessarily @c T; + * an example is @c bool for which we return a span of @c char. + */ +template <class T> +AuxVectorBase::const_span<T> +AuxVectorBase::getDataSpan (const std::string& name) const +{ + using const_container_pointer_type = typename AuxDataTraits<T>::const_container_pointer_type; + auxid_t id = SG::AuxTypeRegistry::instance().getAuxID<T> (name); + auto beg = reinterpret_cast<const_container_pointer_type> (AuxVectorData::getDataArray (id)); + return const_span<T> (beg, size_v()); +} + + +/** + * @brief Return a span over an aux data item for a decoration. + * @param auxid The desired aux data item. + * + * This will return a span containing the value of the requested + * auxiliary variable for all elements in the container. + * If the item doesn't exist, it will be created. + * Errors are signaled by raising an exception. + * Note that the @c value_type of the span is not necessarily @c T; + * an example is @c bool for which we return a span of @c char. + * + * The difference between @c getDecorationSpan and @c getDataSpan is that + * @c getDecorationSpan takes a const container as input, but returns + * a span over non-const objects. This will only succeed if either the + * container is not locked or the item was first accessed + * as a decoration. + */ +template <class T> +AuxVectorBase::span<T> +AuxVectorBase::getDecorationSpan (const std::string& name) const +{ + using container_pointer_type = typename AuxDataTraits<T>::container_pointer_type; + auxid_t id = SG::AuxTypeRegistry::instance().getAuxID<T> (name); + auto beg = reinterpret_cast<container_pointer_type> (AuxVectorData::getDecorationArray (id)); + return span<T> (beg, size_v()); +} + + +/** + * @brief Return a span over an aux data item. + * @param auxid The desired aux data item. + * + * This will return a span containing the value of the requested + * auxiliary variable for all elements in the container. + * If the item doesn't exist, it will be created. + * Errors are signaled by raising an exception. + * Note that the @c value_type of the span is not necessarily @c T; + * an example is @c bool for which we return a span of @c char. + */ +template <class T> +AuxVectorBase::const_span<T> +AuxVectorBase::getConstDataSpan (const std::string& name) const +{ + using const_container_pointer_type = typename AuxDataTraits<T>::const_container_pointer_type; + auxid_t id = SG::AuxTypeRegistry::instance().getAuxID<T> (name); + auto beg = reinterpret_cast<const_container_pointer_type> (AuxVectorData::getDataArray (id)); + return const_span<T> (beg, size_v()); +} + + /** * @brief Initialize index tracking mode. * @param ownPolicy The container ownership policy. diff --git a/Control/AthContainers/AthContainers/AuxVectorData.h b/Control/AthContainers/AthContainers/AuxVectorData.h index 8e1881832e84b45d0506927945921b3b5aa01142..0ecfbe1480467ec07ee880f796cfeb9ee567ea35 100644 --- a/Control/AthContainers/AthContainers/AuxVectorData.h +++ b/Control/AthContainers/AthContainers/AuxVectorData.h @@ -1,7 +1,6 @@ // This file's extension implies that it's C, but it's really -*- C++ -*-. - /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ /** * @file AthContainers/AuxVectorData.h @@ -167,11 +166,6 @@ class AuxVectorData #endif // not XAOD_STANDALONE { public: - /// Spans over auxiliary variables. - template <class T> using span = typename AuxDataTraits<T>::span; - template <class T> using const_span = typename AuxDataTraits<T>::const_span; - - /// Constructor. AuxVectorData(); @@ -444,16 +438,6 @@ public: bool isAvailable (auxid_t id) const; - /** - * @brief Test to see if a variable exists in the store. - * @param name Name of the aux variable. - * @param clsname The name of the associated class. May be blank. - */ - template <class T> - bool isAvailable (const std::string& name, - const std::string& clsname = "") const; - - /** * @brief Test to see if a variable is available for writing. * @param id The variable to test. @@ -461,16 +445,6 @@ public: bool isAvailableWritable (auxid_t id); - /** - * @brief Test to see if a variable is available for writing. - * @param name Name of the aux variable. - * @param clsname The name of the associated class. May be blank. - */ - template <class T> - bool isAvailableWritable (const std::string& name, - const std::string& clsname = ""); - - /** * @brief Test to see if a variable is available for writing as a decoration. * @param id The variable to test. @@ -478,14 +452,8 @@ public: bool isAvailableWritableAsDecoration (auxid_t id) const; - /** - * @brief Test to see if a variable is available for writing as a decoration. - * @param name Name of the aux variable. - * @param clsname The name of the associated class. May be blank. - */ - template <class T> - bool isAvailableWritableAsDecoration (const std::string& name, - const std::string& clsname = "") const; + // Versions of isAvailable* that take a name rather than an ID are + // in the derived class AuxVectorBase. /** @@ -595,70 +563,6 @@ public: void* getDataArray (SG::auxid_t auxid); - /** - * @brief Return a span over an aux data item. - * @param auxid The desired aux data item. - * - * This will return a span containing the value of the requested - * auxiliary variable for all elements in the container. - * If the item doesn't exist, it will be created. - * Errors are signaled by raising an exception. - * Note that the @c value_type of the span is not necessarily @c T; - * an example is @c bool for which we return a span of @c char. - */ - template <class T> - span<T> getDataSpan (const std::string& name); - - - /** - * @brief Return a span over an aux data item. - * @param auxid The desired aux data item. - * - * This will return a span containing the value of the requested - * auxiliary variable for all elements in the container. - * If the item doesn't exist, it will be created. - * Errors are signaled by raising an exception. - * Note that the @c value_type of the span is not necessarily @c T; - * an example is @c bool for which we return a span of @c char. - */ - template <class T> - const_span<T> getDataSpan (const std::string& name) const; - - - /** - * @brief Return a span over an aux data item. - * @param auxid The desired aux data item. - * - * This will return a span containing the value of the requested - * auxiliary variable for all elements in the container. - * If the item doesn't exist, it will be created. - * Errors are signaled by raising an exception. - * Note that the @c value_type of the span is not necessarily @c T; - * an example is @c bool for which we return a span of @c char. - */ - template <class T> - const_span<T> getConstDataSpan (const std::string& name) const; - - - /** - * @brief Return a span over an aux data item for a decoration. - * @param auxid The desired aux data item. - * - * This will return a span containing the value of the requested - * auxiliary variable for all elements in the container. - * If the item doesn't exist, it will be created. - * Errors are signaled by raising an exception. - * Note that the @c value_type of the span is not necessarily @c T; - * an example is @c bool for which we return a span of @c char. - * - * The difference between @c getDecorationSpan and @c getDataSpan is that - * @c getDecorationSpan takes a const container as input, but returns - * a span over non-const objects. This will only succeed if either the - * container is not locked or the item was first accessed - * as a decoration. - */ - template <class T> - span<T> getDecorationSpan (const std::string& name) const; protected: diff --git a/Control/AthContainers/AthContainers/AuxVectorData.icc b/Control/AthContainers/AthContainers/AuxVectorData.icc index ea16db8b2f603733b014a9e0e868b70a8d66d9b1..258fb2ee45ccf492b14bb0122adbf955b7035c3c 100644 --- a/Control/AthContainers/AthContainers/AuxVectorData.icc +++ b/Control/AthContainers/AthContainers/AuxVectorData.icc @@ -1,9 +1,7 @@ // Dear emacs, this is -*- c++ -*- - /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ - /** * @file AthContainers/AuxVectorData.icc * @author scott snyder <snyder@bnl.gov> @@ -12,7 +10,6 @@ */ -#include "AthContainers/AuxTypeRegistry.h" #include "AthContainersInterfaces/IAuxStore.h" #include "AthContainersInterfaces/IConstAuxStore.h" #include "AthContainers/tools/likely.h" @@ -129,21 +126,6 @@ bool AuxVectorData::isAvailable (auxid_t id) const } -/** - * @brief Test to see if a variable exists in the store. - * @param name Name of the aux variable. - * @param clsname The name of the associated class. May be blank. - */ -template <class T> -inline -bool AuxVectorData::isAvailable (const std::string& name, - const std::string& clsname /*= ""*/) const -{ - auxid_t id = SG::AuxTypeRegistry::instance().getAuxID<T> (name, clsname); - return isAvailable (id); -} - - /** * @brief Test to see if a variable is available for writing. * @param id The variable to test. @@ -157,22 +139,6 @@ bool AuxVectorData::isAvailableWritable (auxid_t id) } -/** - * @brief Test to see if a variable is available for writing. - * @param name Name of the aux variable. - * @param clsname The name of the associated class. May be blank. - */ -template <class T> -inline -bool -AuxVectorData::isAvailableWritable (const std::string& name, - const std::string& clsname /*= ""*/) -{ - auxid_t id = SG::AuxTypeRegistry::instance().getAuxID<T> (name, clsname); - return isAvailableWritable (id); -} - - /** * @brief Test to see if a variable is available for writing as a decoration. * @param id The variable to test. @@ -186,22 +152,6 @@ bool AuxVectorData::isAvailableWritableAsDecoration (auxid_t id) const } -/** - * @brief Test to see if a variable is available for writing as a decoration. - * @param name Name of the aux variable. - * @param clsname The name of the associated class. May be blank. - */ -template <class T> -inline -bool -AuxVectorData::isAvailableWritableAsDecoration (const std::string& name, - const std::string& clsname /*= ""*/) const -{ - auxid_t id = SG::AuxTypeRegistry::instance().getAuxID<T> (name, clsname); - return isAvailableWritableAsDecoration (id); -} - - /** * @brief Return reference to an aux data item. * @param auxid The desired aux data item. @@ -342,99 +292,6 @@ void* AuxVectorData::getDecorationArray (SG::auxid_t auxid) const } -/** - * @brief Return a span over an aux data item. - * @param auxid The desired aux data item. - * - * This will return a span containing the value of the requested - * auxiliary variable for all elements in the container. - * If the item doesn't exist, it will be created. - * Errors are signaled by raising an exception. - * Note that the @c value_type of the span is not necessarily @c T; - * an example is @c bool for which we return a span of @c char. - */ -template <class T> -AuxVectorData::span<T> AuxVectorData::getDataSpan (const std::string& name) -{ - using container_pointer_type = typename AuxDataTraits<T>::container_pointer_type; - auxid_t id = SG::AuxTypeRegistry::instance().getAuxID<T> (name); - auto beg = reinterpret_cast<container_pointer_type> (getDataArray (id)); - return span<T> (beg, size_v()); -} - - -/** - * @brief Return a span over an aux data item. - * @param auxid The desired aux data item. - * - * This will return a span containing the value of the requested - * auxiliary variable for all elements in the container. - * If the item doesn't exist, it will be created. - * Errors are signaled by raising an exception. - * Note that the @c value_type of the span is not necessarily @c T; - * an example is @c bool for which we return a span of @c char. - */ -template <class T> -AuxVectorData::const_span<T> -AuxVectorData::getDataSpan (const std::string& name) const -{ - using const_container_pointer_type = typename AuxDataTraits<T>::const_container_pointer_type; - auxid_t id = SG::AuxTypeRegistry::instance().getAuxID<T> (name); - auto beg = reinterpret_cast<const_container_pointer_type> (getDataArray (id)); - return const_span<T> (beg, size_v()); -} - - -/** - * @brief Return a span over an aux data item for a decoration. - * @param auxid The desired aux data item. - * - * This will return a span containing the value of the requested - * auxiliary variable for all elements in the container. - * If the item doesn't exist, it will be created. - * Errors are signaled by raising an exception. - * Note that the @c value_type of the span is not necessarily @c T; - * an example is @c bool for which we return a span of @c char. - * - * The difference between @c getDecorationSpan and @c getDataSpan is that - * @c getDecorationSpan takes a const container as input, but returns - * a span over non-const objects. This will only succeed if either the - * container is not locked or the item was first accessed - * as a decoration. - */ -template <class T> -AuxVectorData::span<T> -AuxVectorData::getDecorationSpan (const std::string& name) const -{ - using container_pointer_type = typename AuxDataTraits<T>::container_pointer_type; - auxid_t id = SG::AuxTypeRegistry::instance().getAuxID<T> (name); - auto beg = reinterpret_cast<container_pointer_type> (getDecorationArray (id)); - return span<T> (beg, size_v()); -} - - -/** - * @brief Return a span over an aux data item. - * @param auxid The desired aux data item. - * - * This will return a span containing the value of the requested - * auxiliary variable for all elements in the container. - * If the item doesn't exist, it will be created. - * Errors are signaled by raising an exception. - * Note that the @c value_type of the span is not necessarily @c T; - * an example is @c bool for which we return a span of @c char. - */ -template <class T> -AuxVectorData::const_span<T> -AuxVectorData::getConstDataSpan (const std::string& name) const -{ - using const_container_pointer_type = typename AuxDataTraits<T>::const_container_pointer_type; - auxid_t id = SG::AuxTypeRegistry::instance().getAuxID<T> (name); - auto beg = reinterpret_cast<const_container_pointer_type> (getDataArray (id)); - return const_span<T> (beg, size_v()); -} - - /** * @brief Swap this instance with another. * @param other The other instance with which to swap. diff --git a/Control/AthContainers/share/AuxVectorBase_test.ref b/Control/AthContainers/share/AuxVectorBase_test.ref index 28c342a29e7e8631bd8aa110ad4417efd98a461a..3e74b2484721b9f3110108b4e4904d2a25d2e5cd 100644 --- a/Control/AthContainers/share/AuxVectorBase_test.ref +++ b/Control/AthContainers/share/AuxVectorBase_test.ref @@ -1,6 +1,8 @@ test_set_store test_set_store2 test_get_data +test_isAvailable +test_get_span test_reserve_resize test_shift test_get_types diff --git a/Control/AthContainers/test/AuxVectorBase_test.cxx b/Control/AthContainers/test/AuxVectorBase_test.cxx index b57cf2071849dfcfeb3efca172e1f13c187d1061..023c948a39625476ae1d5f60285c1da267964f0a 100644 --- a/Control/AthContainers/test/AuxVectorBase_test.cxx +++ b/Control/AthContainers/test/AuxVectorBase_test.cxx @@ -1,8 +1,6 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ - -// $Id$ /** * @file AthContainers/test/AuxVectorBase_test.cxx * @author scott snyder <snyder@bnl.gov> @@ -522,6 +520,73 @@ void test_get_data() } +void test_isAvailable() +{ + std::cout << "test_isAvailable\n"; + SG::AuxVectorBase_test b1; + b1.initAuxVectorBase<B> (SG::OWN_ELEMENTS, SG::DEFAULT_TRACK_INDICES); + + // No store. + assert (!b1.isAvailable<int> ("anInt")); + assert (!b1.isAvailableWritable<int> ("anInt")); + assert (!b1.isAvailableWritableAsDecoration<int> ("anInt")); + + // Empty const store. + SG::AuxStoreInternal store; + SG::IConstAuxStore* cstore = &store; + b1.setStore (cstore); + assert (!b1.isAvailable<int> ("anInt")); + assert (!b1.isAvailableWritable<int> ("anInt")); + assert (!b1.isAvailableWritableAsDecoration<int> ("anInt")); + + // Mutable store with variable. + SG::auxid_t ityp = SG::AuxTypeRegistry::instance().getAuxID<int> ("anInt"); + b1.setStore (&store); + b1.getData<int> (ityp, 0) = 1; + assert (b1.isAvailable<int> ("anInt")); + assert (b1.isAvailableWritable<int> ("anInt")); + assert (b1.isAvailableWritableAsDecoration<int> ("anInt")); + + // Make store const. + b1.setStore (cstore); + assert (b1.isAvailable<int> ("anInt")); + assert (!b1.isAvailableWritable<int> ("anInt")); + assert (b1.isAvailableWritableAsDecoration<int> ("anInt")); +} + + +template <class T> +std::vector<typename T::value_type> make_vector (const T& c) +{ + return std::vector<typename T::value_type> (c.begin(), c.end()); +} + + +void test_get_span() +{ + std::cout << "test_get_span\n"; + SG::AuxVectorBase_test b1; + b1.initAuxVectorBase<B> (SG::OWN_ELEMENTS, SG::DEFAULT_TRACK_INDICES); + SG::AuxStoreInternal store; + b1.setStore (&store); + + SG::auxid_t ityp = SG::AuxTypeRegistry::instance().getAuxID<int> ("anInt"); + b1.getData<int> (ityp, 0) = 1; + b1.getData<int> (ityp, 1) = 2; + + std::vector<int> vexp {1, 2, 0, 0, 0, 0, 0, 0, 0, 0}; + assert (make_vector (b1.getDataSpan<int> ("anInt")) == vexp); + + SG::IConstAuxStore* cstore = &store; + b1.setStore (cstore); + const SG::AuxVectorBase& cb1 = b1; + assert (b1.getConstDataSpan<int> ("anInt")[0] == 1); + assert (make_vector (b1.getConstDataSpan<int> ("anInt")) == vexp); + assert (make_vector (cb1.getDataSpan<int> ("anInt")) == vexp); + assert (make_vector (cb1.getDecorationSpan<int> ("anInt")) == vexp); +} + + void test_reserve_resize() { std::cout << "test_reserve_resize\n"; @@ -993,6 +1058,8 @@ int main() test_clear_index(); test_clear_indices(); test_get_data(); + test_isAvailable(); + test_get_span(); test_reserve_resize(); test_shift(); test_get_types(); diff --git a/Control/AthContainers/test/AuxVectorData_test.cxx b/Control/AthContainers/test/AuxVectorData_test.cxx index 06cd72b701f151a015e9423981f74bb8497fd4c2..d6cdd8d382f0b51144e312daf2cff533054f7983 100644 --- a/Control/AthContainers/test/AuxVectorData_test.cxx +++ b/Control/AthContainers/test/AuxVectorData_test.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ /** * @file AthContainers/test/AuxVectorData_test.cxx @@ -50,13 +50,6 @@ using SG::AuxVectorData; using SG::AuxVectorData_test; -template <class T> -std::vector<typename T::value_type> make_vector (const T& c) -{ - return std::vector<typename T::value_type> (c.begin(), c.end()); -} - - void test_get_data() { std::cout << "test_get_data\n"; @@ -75,9 +68,6 @@ void test_get_data() assert (!b1.isAvailable (ityp)); assert (!b1.isAvailableWritable (ityp)); assert (!b1.isAvailableWritableAsDecoration (ityp)); - assert (!b1.isAvailable<int> ("anInt")); - assert (!b1.isAvailableWritable<int> ("anInt")); - assert (!b1.isAvailableWritableAsDecoration<int> ("anInt")); assert (b1.getConstStore() == 0); assert (b1.getStore() == 0); b1.setStore (cstore); @@ -88,9 +78,6 @@ void test_get_data() assert (!b1.isAvailable (ityp)); assert (!b1.isAvailableWritable (ityp)); assert (!b1.isAvailableWritableAsDecoration (ityp)); - assert (!b1.isAvailable<int> ("anInt")); - assert (!b1.isAvailableWritable<int> ("anInt")); - assert (!b1.isAvailableWritableAsDecoration<int> ("anInt")); EXPECT_EXCEPTION (SG::ExcConstAuxData, b1.getData<int> (ityp, 0)); EXPECT_EXCEPTION (SG::ExcBadAuxVar, cb1.getData<int> (ityp, 0)); EXPECT_EXCEPTION (SG::ExcBadAuxVar, cb1.getDataArray (ityp)); @@ -110,15 +97,9 @@ void test_get_data() assert (b1.isAvailable (ityp)); assert (b1.isAvailableWritable (ityp)); assert (b1.isAvailableWritableAsDecoration (ityp)); - assert (b1.isAvailable<int> ("anInt")); - assert (b1.isAvailableWritable<int> ("anInt")); - assert (b1.isAvailableWritableAsDecoration<int> ("anInt")); assert (reinterpret_cast<const int*>(cb1.getDataArray (ityp))[1] == 2); assert (reinterpret_cast<const int*>(cb1.getDataArrayAllowMissing (ityp))[1] == 2); - std::vector<int> vexp {1, 2, 0, 0, 0, 0, 0, 0, 0, 0}; - assert (make_vector (b1.getDataSpan<int> ("anInt")) == vexp); - b1.setStore (cstore); assert (!b1.hasNonConstStore()); assert (cb1.getData<int> (ityp, 0) == 1); @@ -126,9 +107,6 @@ void test_get_data() assert (b1.isAvailable (ityp)); assert (!b1.isAvailableWritable (ityp)); assert (b1.isAvailableWritableAsDecoration (ityp)); - assert (b1.isAvailable<int> ("anInt")); - assert (!b1.isAvailableWritable<int> ("anInt")); - assert (b1.isAvailableWritableAsDecoration<int> ("anInt")); SG::auxid_t ftyp = SG::AuxTypeRegistry::instance().getAuxID<float> ("aFloat"); float* ff = reinterpret_cast<float*> (store.getData (ftyp, 10, 20)); @@ -136,11 +114,6 @@ void test_get_data() ff[1] = 2.5; assert (cb1.getData<float> (ftyp, 0) == 1.5); assert (cb1.getData<float> (ftyp, 1) == 2.5); - - assert (b1.getConstDataSpan<int> ("anInt")[0] == 1); - assert (make_vector (b1.getConstDataSpan<int> ("anInt")) == vexp); - assert (make_vector (cb1.getDataSpan<int> ("anInt")) == vexp); - assert (make_vector (cb1.getDecorationSpan<int> ("anInt")) == vexp); }