diff --git a/Core/include/Acts/Geometry/SurfaceArrayCreator.hpp b/Core/include/Acts/Geometry/SurfaceArrayCreator.hpp index 7ac78342408..c14a3582c4b 100644 --- a/Core/include/Acts/Geometry/SurfaceArrayCreator.hpp +++ b/Core/include/Acts/Geometry/SurfaceArrayCreator.hpp @@ -20,7 +20,6 @@ #include "Acts/Utilities/BinningType.hpp" #include "Acts/Utilities/Logger.hpp" -#include #include #include #include diff --git a/Core/include/Acts/Surfaces/SurfaceArray.hpp b/Core/include/Acts/Surfaces/SurfaceArray.hpp index 16f2bd344d1..e8d6fa6ae05 100644 --- a/Core/include/Acts/Surfaces/SurfaceArray.hpp +++ b/Core/include/Acts/Surfaces/SurfaceArray.hpp @@ -13,12 +13,15 @@ #include "Acts/Surfaces/RegularSurface.hpp" #include "Acts/Surfaces/Surface.hpp" #include "Acts/Utilities/AxisDefinitions.hpp" -#include "Acts/Utilities/Diagnostics.hpp" #include "Acts/Utilities/IAxis.hpp" #include #include +namespace ActsTests { +struct SurfaceArrayCreatorFixture; +} + namespace Acts { using SurfaceVector = std::vector; @@ -30,7 +33,7 @@ using SurfaceVector = std::vector; /// and performs utility actions. This struct needs to be initialised /// externally and passed to @c SurfaceArray on construction. class SurfaceArray { - public: + private: /// Base interface for all surface lookups. struct ISurfaceGridLookup { virtual ~ISurfaceGridLookup() = default; @@ -41,44 +44,28 @@ class SurfaceArray { virtual void fill(const GeometryContext& gctx, std::span surfaces) = 0; - /// Performs lookup at @c pos and returns bin content as const reference - /// @param position Lookup position - /// @param direction Lookup direction - /// @return A vector of surfaces at given bin - [[deprecated("Use lookup with GeometryContext instead")]] - virtual const std::vector& lookup( - const Vector3& position, const Vector3& direction) const = 0; + /// Get all surfaces in bin given by the global bin index + /// @param bin the global bin index + /// @return span of surface pointers of the bin at that position + virtual std::span at(std::size_t bin) const = 0; /// Performs lookup at @c pos and returns bin content as const reference /// @param gctx The current geometry context object, e.g. alignment /// @param position Lookup position /// @param direction Lookup direction /// @return A span of surface pointers - virtual std::span lookup( + virtual std::span at( const GeometryContext& gctx, const Vector3& position, const Vector3& direction) const = 0; - /// Performs lookup at global bin and returns bin content as reference - /// @param bin Global lookup bin - /// @return A vector of surfaces at given bin - [[deprecated( - "Mutable access will be removed without replacement in the future")]] - virtual std::vector& lookup(std::size_t bin) = 0; - - /// Performs lookup at global bin and returns bin content as const reference - /// @param bin Global lookup bin - /// @return A vector of surfaces at given bin - [[deprecated("Use at(gridIndices, neighborDistance) instead")]] - virtual const std::vector& lookup( - std::size_t bin) const = 0; - - /// Performs a lookup at @c pos, but returns neighbors as well - /// @param position Lookup position - /// @param direction Lookup direction - /// @return A vector of surfaces at given bin. Copy of all bins selected - [[deprecated("Use neighbors with GeometryContext instead")]] - virtual const std::vector& neighbors( - const Vector3& position, const Vector3& direction) const = 0; + /// Get all surfaces in bin given by local grid indices and neighbor + /// distance. + /// @param gridIndices the local grid indices + /// @param neighborDistance the neighbor distance to include in the lookup + /// @return span of surface pointers of the bin at that position and its neighbors + virtual std::span neighbors( + std::array gridIndices, + std::uint8_t neighborDistance) const = 0; /// Performs a lookup at @c pos, but returns neighbors as well /// @param gctx The current geometry context object, e.g. alignment @@ -128,300 +115,9 @@ class SurfaceArray { /// is used to determine how many neighbors to include in neighbor lookups. /// @return Maximum neighbor distance virtual std::uint8_t maxNeighborDistance() const = 0; - - /// Get all surfaces in bin given by local grid indices and neighbor - /// distance. - /// @param gridIndices the local grid indices - /// @param neighborDistance the neighbor distance to include in the lookup - /// @return span of surface pointers of the bin at that position and its neighbors - virtual std::span at( - std::array gridIndices, - std::uint8_t neighborDistance) const = 0; }; - private: - /// Factory method to create a surface grid lookup for a given representative - /// surface, tolerance, and axes. This will internally create the appropriate - /// lookup class based on the axes and concrete @ref Grid. - /// @param representative The surface which is used as representative - /// @param tolerance The tolerance used for intersection checks - /// @param axes The axes used for the grid - /// @param maxNeighborDistance Maximum next neighbor distance to be included in neighbor lookups - /// @return A unique pointer to the surface grid lookup - static std::unique_ptr makeSurfaceGridLookup( - std::shared_ptr representative, double tolerance, - std::tuple axes, - std::uint8_t maxNeighborDistance = 1); - - // This is temporary until Gen1 is removed - friend class SurfaceArrayCreator; - public: - /// Lookup helper which encapsulates a @c Grid - /// @tparam Axis1 The first axis - /// @tparam Axis2 The second axis - /// @deprecated This is deprecated in favor of direct @ref SurfaceArray constructors. - template - struct [[deprecated("Use makeSurfaceGridLookup instead")]] SurfaceGridLookup - : ISurfaceGridLookup { - /// Construct a surface grid lookup - /// @param representative The surface which is used as representative - /// @param tolerance The tolerance used for intersection checks - /// @param axes The axes used for the grid - /// @param bValues Optional vector of axis directions for binning - /// @param maxNeighborDistance Maximum next neighbor distance to be included in neighbor lookups - SurfaceGridLookup(std::shared_ptr representative, - double tolerance, std::tuple axes, - const std::vector& bValues = {}, - std::uint8_t maxNeighborDistance = 1) - : m_impl(makeSurfaceGridLookup(std::move(representative), tolerance, - std::move(axes), maxNeighborDistance)) { - static_cast(bValues); - } - - /// Fill provided surfaces into the contained @c Grid. - /// @param gctx The current geometry context object, e.g. alignment - /// @param surfaces Input surface pointers - void fill(const GeometryContext& gctx, - std::span surfaces) override { - m_impl->fill(gctx, surfaces); - } - - /// Performs lookup at @c pos and returns bin content as const reference - /// @param position Lookup position - /// @param direction Lookup direction - /// @return A vector of surfaces at given bin - const std::vector& lookup( - const Vector3& position, const Vector3& direction) const override { - ACTS_PUSH_IGNORE_DEPRECATED() - return m_impl->lookup(position, direction); - ACTS_POP_IGNORE_DEPRECATED() - } - - /// Performs lookup at @c pos and returns bin content as const reference - /// @param gctx The current geometry context object, e.g. alignment - /// @param position Lookup position - /// @param direction Lookup direction - /// @return A span of surface pointers - std::span lookup( - const GeometryContext& gctx, const Vector3& position, - const Vector3& direction) const override { - return m_impl->lookup(gctx, position, direction); - } - - /// Performs lookup at global bin and returns bin content as reference - /// @param bin Global lookup bin - /// @return A vector of surfaces at given bin - std::vector& lookup(std::size_t bin) override { - ACTS_PUSH_IGNORE_DEPRECATED() - return m_impl->lookup(bin); - ACTS_POP_IGNORE_DEPRECATED() - } - - /// Performs lookup at global bin and returns bin content as const reference - /// @param bin Global lookup bin - /// @return A vector of surfaces at given bin - const std::vector& lookup(std::size_t bin) const override { - ACTS_PUSH_IGNORE_DEPRECATED() - return m_impl->lookup(bin); - ACTS_POP_IGNORE_DEPRECATED() - } - - /// Performs a lookup at @c pos, but returns neighbors as well - /// @param position Lookup position - /// @param direction Lookup direction - /// @return A vector of surfaces at given bin. Copy of all bins selected - const std::vector& neighbors( - const Vector3& position, const Vector3& direction) const override { - ACTS_PUSH_IGNORE_DEPRECATED() - return m_impl->neighbors(position, direction); - ACTS_POP_IGNORE_DEPRECATED() - } - - /// Performs a lookup at @c pos, but returns neighbors as well - /// @param gctx The current geometry context object, e.g. alignment - /// @param position Lookup position - /// @param direction Lookup direction - /// @return A span of surface pointers - std::span neighbors( - const GeometryContext& gctx, const Vector3& position, - const Vector3& direction) const override { - return m_impl->neighbors(gctx, position, direction); - } - - /// Returns the total size of the grid (including under/overflow bins) - /// @return Size of the grid data structure - std::size_t size() const override { return m_impl->size(); } - - /// Gets the center position of bin @c bin in global coordinates - /// @param bin the global bin index - /// @return The bin center - Vector3 getBinCenter(std::size_t bin) const override { - return m_impl->getBinCenter(bin); - } - - /// Returns copies of the axes used in the grid as @c AnyAxis - /// @return The axes - /// @note This returns copies. Use for introspection and querying. - std::vector getAxes() const override { - return m_impl->getAxes(); - } - - /// Get the representative surface used for this lookup - /// @return Surface pointer - const Surface* surfaceRepresentation() const override { - return m_impl->surfaceRepresentation(); - } - - /// Checks if global bin is valid - /// @param bin the global bin index - /// @return bool if the bin is valid - /// @note Valid means that the index points to a bin which is not a under - /// or overflow bin or out of range in any axis. - bool isValidBin(std::size_t bin) const override { - return m_impl->isValidBin(bin); - } - - /// The binning values described by this surface grid lookup. They are in - /// order of the axes (optional) and empty for eingle lookups - /// @return Vector of axis directions for binning - std::vector binningValues() const override { - return m_impl->binningValues(); - } - - std::array numLocalBins() const override { - return m_impl->numLocalBins(); - } - - std::uint8_t maxNeighborDistance() const override { - return m_impl->maxNeighborDistance(); - } - - std::span at( - std::array gridIndices, - std::uint8_t neighborDistance) const override { - return m_impl->at(gridIndices, neighborDistance); - } - - private: - std::unique_ptr m_impl; - }; - - /// Lookup implementation which wraps one element and always returns this - /// element when lookup is called - /// @deprecated Construct the @ref SurfaceArray directly with a single surface - struct [[deprecated( - "Construct the SurfaceArray directly with a single " - "surface")]] SingleElementLookup : ISurfaceGridLookup { - /// Default constructor. - /// @param element the one and only element. - explicit SingleElementLookup(const Surface* element) - : m_element({element}) {} - - /// Default constructor. - /// @param elements the surfaces that are provided through a single lookup - explicit SingleElementLookup(const std::vector& elements) - : m_element(elements) {} - - /// Lookup, always returns @c element - /// @return reference to vector containing only @c element - const std::vector& lookup( - const Vector3& /*position*/, - const Vector3& /*direction*/) const override { - return m_element; - } - - /// Lookup, always returns @c element - /// @return span of surface pointers containing only @c element - std::span lookup( - const GeometryContext& /*gctx*/, const Vector3& /*position*/, - const Vector3& /*direction*/) const override { - return m_element; - } - - /// Lookup, always returns @c element - /// @return reference to vector containing only @c element - std::vector& lookup(std::size_t /*bin*/) override { - return m_element; - } - - /// Lookup, always returns @c element - /// @return reference to vector containing only @c element - const std::vector& lookup( - std::size_t /*bin*/) const override { - return m_element; - } - - /// Lookup, always returns @c element - /// @return reference to vector containing only @c element - const std::vector& neighbors( - const Vector3& /*position*/, - const Vector3& /*direction*/) const override { - return m_element; - } - - /// Lookup, always returns @c element - /// @return span of surface pointers containing only @c element - std::span neighbors( - const GeometryContext& /*gctx*/, const Vector3& /*position*/, - const Vector3& /*direction*/) const override { - return m_element; - } - - /// Returns the total size of the grid (including under/overflow bins) - /// @return 1 - std::size_t size() const override { return 1; } - - /// Gets the bin center, but always returns (0, 0, 0) - /// @return (0, 0, 0) - Vector3 getBinCenter(std::size_t /*bin*/) const override { - return Vector3(0, 0, 0); - } - - /// Returns an empty vector of @c AnyAxis - /// @return empty vector - std::vector getAxes() const override { return {}; } - - const Surface* surfaceRepresentation() const override { return nullptr; } - - /// Comply with concept and provide fill method - /// @note Does nothing - void fill(const GeometryContext& /*gctx*/, - std::span /*surfaces*/) override {} - - /// Returns if the bin is valid (it is) - /// @return always true - bool isValidBin(std::size_t /*bin*/) const override { return true; } - - std::array numLocalBins() const override { return {1, 1}; } - - std::uint8_t maxNeighborDistance() const override { return 0; } - - std::span at( - std::array gridIndices, - std::uint8_t neighborDistance) const override { - if (gridIndices != std::array{0, 0} || - neighborDistance != 0) { - throw std::out_of_range( - "SingleElementLookupImpl only contains one bin with zero neighbor " - "distance"); - } - return m_element; - } - - private: - std::vector m_element; - }; - - /// Default constructor which takes a @c SurfaceLookup and a vector of surfaces - /// @param gridLookup The grid storage. @c SurfaceArray does not fill it on its own - /// @param surfaces The input vector of surfaces. This is only for bookkeeping, so we can ask - /// @param transform Optional additional transform for this SurfaceArray - [[deprecated("Use the constructor with axes instead")]] - SurfaceArray(std::unique_ptr gridLookup, - std::vector> surfaces, - const Transform3& transform = Transform3::Identity()); - /// Constructor with a single surface /// @param srf The one and only surface explicit SurfaceArray(std::shared_ptr srf); @@ -434,21 +130,18 @@ class SurfaceArray { /// @param representative The surface which is used as representative /// @param tolerance The tolerance used for intersection checks /// @param axes The axes used for the grid + /// @param maxNeighborDistance Maximum next neighbor distance to be included in neighbor lookups SurfaceArray(const GeometryContext& gctx, std::vector> surfaces, std::shared_ptr representative, double tolerance, - std::tuple axes); + std::tuple axes, + std::uint8_t maxNeighborDistance = 1); - /// Get all surfaces in bin given by position @p pos. - /// @param position the lookup position - /// @param direction the lookup direction - /// @return const reference to surface vector contained in bin at that position - [[deprecated("Use at with GeometryContext instead")]] - const std::vector& at(const Vector3& position, - const Vector3& direction) const { - ACTS_PUSH_IGNORE_DEPRECATED() - return m_gridLookup->lookup(position, direction); - ACTS_POP_IGNORE_DEPRECATED() + /// Get all surfaces in bin given by the global bin index + /// @param bin the global bin index + /// @return span of surface pointers of the bin at that position + std::span at(std::size_t bin) const { + return m_gridLookup->at(bin); } /// Get all surfaces in bin given by position @p pos. @@ -459,40 +152,18 @@ class SurfaceArray { std::span at(const GeometryContext& gctx, const Vector3& position, const Vector3& direction) const { - return m_gridLookup->lookup(gctx, position, direction); + return m_gridLookup->at(gctx, position, direction); } - /// Get all surfaces in bin given by global bin index @p bin. - /// @param bin the global bin index - /// @return mutable reference to surface vector contained in bin - [[deprecated( - "Mutable access will be removed without replacement in the future")]] - std::vector& at(std::size_t bin) { - ACTS_PUSH_IGNORE_DEPRECATED() - return m_gridLookup->lookup(bin); - ACTS_POP_IGNORE_DEPRECATED() - } - - /// Get all surfaces in bin given by global bin index. - /// @param bin the global bin index - /// @return const reference to surface vector contained in bin - [[deprecated("Use at(gridIndices, neighborDistance) instead")]] - const std::vector& at(std::size_t bin) const { - ACTS_PUSH_IGNORE_DEPRECATED() - return m_gridLookup->lookup(bin); - ACTS_POP_IGNORE_DEPRECATED() - } - - /// Get all surfaces in bin at @p pos and its neighbors - /// @param position The position to lookup - /// @param direction The direction to lookup - /// @return Merged surface vector of neighbors and nominal - [[deprecated("Use neighbors with GeometryContext instead")]] - const std::vector& neighbors(const Vector3& position, - const Vector3& direction) const { - ACTS_PUSH_IGNORE_DEPRECATED() - return m_gridLookup->neighbors(position, direction); - ACTS_POP_IGNORE_DEPRECATED() + /// Get all surfaces in bin given by local grid indices and neighbor + /// distance. + /// @param gridIndices the local grid indices + /// @param neighborDistance the neighbor distance to include in the lookup + /// @return span of surface pointers of the bin at that position and its neighbors + std::span neighbors( + std::array gridIndices, + std::uint8_t neighborDistance) const { + return m_gridLookup->neighbors(gridIndices, neighborDistance); } /// Get all surfaces in bin at @p pos and its neighbors @@ -542,14 +213,6 @@ class SurfaceArray { return m_gridLookup->isValidBin(bin); } - /// Get the transform of this surface array. - /// @return Reference to the transformation matrix - /// @deprecated This is an implementation detail and will be removed soon - [[deprecated("This is an implementation detail and will be removed soon")]] - const Transform3& transform() const { - return m_transform; - } - /// The binning values described by this surface grid lookup. They are in /// order of the axes /// @return Vector of axis directions for binning @@ -563,14 +226,6 @@ class SurfaceArray { /// @return the output stream given as @p sl std::ostream& toStream(const GeometryContext& gctx, std::ostream& sl) const; - /// Return the lookup object - /// @return Reference to the surface grid lookup interface - [[deprecated( - "Grid lookup is an implementation detail and will be removed soon")]] - const ISurfaceGridLookup& gridLookup() const { - return *m_gridLookup; - } - /// Get the representative surface used for this surface array /// @return Surface pointer const Surface* surfaceRepresentation() const { @@ -591,17 +246,11 @@ class SurfaceArray { return m_gridLookup->maxNeighborDistance(); } - /// Get all surfaces in bin given by local grid indices and neighbor - /// distance. - /// @param gridIndices the local grid indices - /// @param neighborDistance the neighbor distance to include in the lookup - /// @return span of surface pointers of the bin at that position and its neighbors - std::span at(std::array gridIndices, - std::uint8_t neighborDistance) const { - return m_gridLookup->at(gridIndices, neighborDistance); - } - private: + struct SingleElementLookupImpl; + template + struct SurfaceGridLookupImpl; + /// The actual grid lookup implementation std::unique_ptr m_gridLookup; /// this vector makes sure we have shared ownership over the surfaces @@ -609,8 +258,29 @@ class SurfaceArray { /// this vector is returned, so that (expensive) copying of the shared_ptr /// vector does not happen by default std::vector m_surfacesRawPointers; - /// this is only used to keep info on transform applied by l2g and g2l - Transform3 m_transform; + + friend class SurfaceArrayCreator; + friend struct ActsTests::SurfaceArrayCreatorFixture; + + /// Factory method to create a surface grid lookup for a given representative + /// surface, tolerance, and axes. This will internally create the appropriate + /// lookup class based on the axes and concrete @ref Grid. + /// @param representative The surface which is used as representative + /// @param tolerance The tolerance used for intersection checks + /// @param axes The axes used for the grid + /// @param maxNeighborDistance Maximum next neighbor distance to be included in neighbor lookups + /// @return A unique pointer to the surface grid lookup + static std::unique_ptr makeSurfaceGridLookup( + std::shared_ptr representative, double tolerance, + std::tuple axes, + std::uint8_t maxNeighborDistance = 1); + + /// Default constructor which takes a @c SurfaceLookup and a vector of surfaces + /// @param gridLookup The grid storage. @c SurfaceArray does not fill it on its own + /// @param surfaces The input vector of surfaces. This is only for bookkeeping, so we can ask + [[deprecated("Use the constructor with axes instead")]] + SurfaceArray(std::unique_ptr gridLookup, + std::vector> surfaces); }; } // namespace Acts diff --git a/Core/src/Geometry/SurfaceArrayCreator.cpp b/Core/src/Geometry/SurfaceArrayCreator.cpp index 0431069c13e..eaadf1266ba 100644 --- a/Core/src/Geometry/SurfaceArrayCreator.cpp +++ b/Core/src/Geometry/SurfaceArrayCreator.cpp @@ -68,7 +68,7 @@ std::unique_ptr SurfaceArrayCreator::surfaceArrayOnCylinder( sl->fill(gctx, surfacesRaw); ACTS_PUSH_IGNORE_DEPRECATED() - SurfaceArray sa(std::move(sl), std::move(surfaces), fullTransform); + SurfaceArray sa(std::move(sl), std::move(surfaces)); return std::make_unique(std::move(sa)); ACTS_POP_IGNORE_DEPRECATED() } @@ -128,7 +128,7 @@ std::unique_ptr SurfaceArrayCreator::surfaceArrayOnCylinder( << bins0 * bins1 << " bins."); ACTS_PUSH_IGNORE_DEPRECATED() - SurfaceArray sa(std::move(sl), std::move(surfaces), fullTransform); + SurfaceArray sa(std::move(sl), std::move(surfaces)); return std::make_unique(std::move(sa)); ACTS_POP_IGNORE_DEPRECATED() } @@ -188,7 +188,7 @@ std::unique_ptr SurfaceArrayCreator::surfaceArrayOnDisc( sl->fill(gctx, surfacesRaw); ACTS_PUSH_IGNORE_DEPRECATED() - SurfaceArray sa(std::move(sl), std::move(surfaces), fullTransform); + SurfaceArray sa(std::move(sl), std::move(surfaces)); return std::make_unique(std::move(sa)); ACTS_POP_IGNORE_DEPRECATED() } @@ -300,7 +300,7 @@ std::unique_ptr SurfaceArrayCreator::surfaceArrayOnDisc( sl->fill(gctx, surfacesRaw); ACTS_PUSH_IGNORE_DEPRECATED() - SurfaceArray sa(std::move(sl), std::move(surfaces), fullTransform); + SurfaceArray sa(std::move(sl), std::move(surfaces)); return std::make_unique(std::move(sa)); ACTS_POP_IGNORE_DEPRECATED() } @@ -397,7 +397,7 @@ std::unique_ptr SurfaceArrayCreator::surfaceArrayOnPlane( sl->fill(gctx, surfacesRaw); ACTS_PUSH_IGNORE_DEPRECATED() - SurfaceArray sa(std::move(sl), std::move(surfaces), fullTransform); + SurfaceArray sa(std::move(sl), std::move(surfaces)); return std::make_unique(std::move(sa)); ACTS_POP_IGNORE_DEPRECATED() } diff --git a/Core/src/Surfaces/SurfaceArray.cpp b/Core/src/Surfaces/SurfaceArray.cpp index 3f15d56dd9e..bf903bcd271 100644 --- a/Core/src/Surfaces/SurfaceArray.cpp +++ b/Core/src/Surfaces/SurfaceArray.cpp @@ -24,44 +24,34 @@ namespace Acts { -SurfaceArray::SurfaceArray(std::unique_ptr gridLookup, - std::vector> surfaces, - const Transform3& transform) - : m_gridLookup(std::move(gridLookup)), - m_surfaces(std::move(surfaces)), - m_surfacesRawPointers(unpackSmartPointers(m_surfaces)), - m_transform(transform) {} - -namespace { - -struct SingleElementLookupImpl final : SurfaceArray::ISurfaceGridLookup { +struct SurfaceArray::SingleElementLookupImpl final + : SurfaceArray::ISurfaceGridLookup { explicit SingleElementLookupImpl(const Surface* element) : m_element({element}) {} - const std::vector& lookup( - const Vector3& /*position*/, - const Vector3& /*direction*/) const override { - return m_element; - } - - std::vector& lookup(std::size_t /*bin*/) override { - return m_element; - } - - const std::vector& lookup( - std::size_t /*bin*/) const override { + std::span at(std::size_t bin) const override { + if (bin != 0) { + throw std::out_of_range( + "SingleElementLookupImpl only contains one bin with index 0"); + } return m_element; } - std::span lookup( + std::span at( const GeometryContext& /*gctx*/, const Vector3& /*position*/, const Vector3& /*direction*/) const override { return m_element; } - const std::vector& neighbors( - const Vector3& /*position*/, - const Vector3& /*direction*/) const override { + std::span neighbors( + std::array gridIndices, + std::uint8_t neighborDistance) const override { + if (gridIndices != std::array{0, 0} || + neighborDistance != 0) { + throw std::out_of_range( + "SingleElementLookupImpl only contains one bin with zero neighbor " + "distance"); + } return m_element; } @@ -84,79 +74,19 @@ struct SingleElementLookupImpl final : SurfaceArray::ISurfaceGridLookup { void fill(const GeometryContext& /*gctx*/, std::span /*surfaces*/) override {} - bool isValidBin(std::size_t /*bin*/) const override { return true; } + bool isValidBin(std::size_t bin) const override { return bin == 0; } std::array numLocalBins() const override { return {1, 1}; } std::uint8_t maxNeighborDistance() const override { return 0; } - std::span at( - std::array gridIndices, - std::uint8_t neighborDistance) const override { - if (gridIndices != std::array{0, 0} || - neighborDistance != 0) { - throw std::out_of_range( - "SingleElementLookupImpl only contains one bin with zero neighbor " - "distance"); - } - return m_element; - } - private: std::vector m_element; }; -} // namespace - -SurfaceArray::SurfaceArray(std::shared_ptr srf) - : m_gridLookup(std::make_unique(srf.get())), - m_surfaces({std::move(srf)}) { - m_surfacesRawPointers.push_back(m_surfaces.at(0).get()); -} - -std::ostream& SurfaceArray::toStream(const GeometryContext& /*gctx*/, - std::ostream& sl) const { - sl << std::fixed << std::setprecision(4); - sl << "SurfaceArray:" << std::endl; - sl << " - no surfaces: " << m_surfaces.size() << std::endl; - - const std::vector axes = m_gridLookup->getAxes(); - - for (const auto [j, axis] : enumerate(axes)) { - const AxisBoundaryType bdt = axis->getBoundaryType(); - sl << " - axis " << (j + 1) << std::endl; - sl << " - boundary type: "; - if (bdt == AxisBoundaryType::Open) { - sl << "open"; - } - if (bdt == AxisBoundaryType::Bound) { - sl << "bound"; - } - if (bdt == AxisBoundaryType::Closed) { - sl << "closed"; - } - sl << std::endl; - sl << " - type: " << (axis->isEquidistant() ? "equidistant" : "variable") - << std::endl; - sl << " - n bins: " << axis->getNBins() << std::endl; - sl << " - bin edges: [ "; - const std::vector binEdges = axis->getBinEdges(); - for (const auto [i, binEdge] : enumerate(binEdges)) { - if (i > 0) { - sl << ", "; - } - // Do not display negative zeroes - sl << ((std::abs(binEdge) >= 5e-4) ? binEdge : 0.0); - } - sl << " ]" << std::endl; - } - return sl; -} - -namespace { - template -struct SurfaceGridLookupImpl final : SurfaceArray::ISurfaceGridLookup { +struct SurfaceArray::SurfaceGridLookupImpl final + : SurfaceArray::ISurfaceGridLookup { SurfaceGridLookupImpl(std::shared_ptr representative, double tolerance, std::tuple axes, std::vector binValues = {}, @@ -193,31 +123,13 @@ struct SurfaceGridLookupImpl final : SurfaceArray::ISurfaceGridLookup { populateNeighborCache(); } - const std::vector& lookup( - const Vector3& position, const Vector3& direction) const override { - const GeometryContext gctx = GeometryContext::dangerouslyDefaultConstruct(); - const std::optional localBins = findLocalBin2D( - gctx, position, direction, std::numeric_limits::infinity()); - if (!localBins.has_value()) { - static std::vector emptyVector; - return emptyVector; - } - const std::size_t globalBin = globalBinFromLocalBins2D(*localBins); - return m_fillingGrid.at(globalBin); - } - - std::vector& lookup(std::size_t globalBin) override { + std::span at(std::size_t globalBin) const override { return m_fillingGrid.at(globalBin); } - const std::vector& lookup( - std::size_t globalBin) const override { - return m_fillingGrid.at(globalBin); - } - - std::span lookup( - const GeometryContext& gctx, const Vector3& position, - const Vector3& direction) const override { + std::span at(const GeometryContext& gctx, + const Vector3& position, + const Vector3& direction) const override { const std::optional localBins = findLocalBin2D( gctx, position, direction, std::numeric_limits::infinity()); if (!localBins.has_value()) { @@ -227,15 +139,11 @@ struct SurfaceGridLookupImpl final : SurfaceArray::ISurfaceGridLookup { return m_neighborSurfacePacks.at(globalBin); } - const std::vector& neighbors( - const Vector3& position, const Vector3& direction) const override { - // hacky temporary solution until removal due deprecation - static thread_local std::vector neighborsVector; - const GeometryContext gctx = GeometryContext::dangerouslyDefaultConstruct(); - const std::span neighborsSpan = - neighbors(gctx, position, direction); - neighborsVector.assign(neighborsSpan.begin(), neighborsSpan.end()); - return neighborsVector; + std::span neighbors( + std::array gridIndices, + std::uint8_t neighborDistance) const override { + return m_neighborSurfacePacks.at( + globalBinFromLocalBins3D(gridIndices, neighborDistance)); } std::span neighbors( @@ -303,13 +211,6 @@ struct SurfaceGridLookupImpl final : SurfaceArray::ISurfaceGridLookup { return m_maxNeighborDistance; } - std::span at( - std::array gridIndices, - std::uint8_t neighborDistance) const override { - return m_neighborSurfacePacks.at( - globalBinFromLocalBins3D(gridIndices, neighborDistance)); - } - private: using GridIndex = std::array; using GridPoint = std::array; @@ -573,7 +474,60 @@ struct SurfaceGridLookupImpl final : SurfaceArray::ISurfaceGridLookup { } }; -} // namespace +SurfaceArray::SurfaceArray(std::shared_ptr srf) + : m_gridLookup(std::make_unique(srf.get())), + m_surfaces({std::move(srf)}) { + m_surfacesRawPointers.push_back(m_surfaces.at(0).get()); +} + +SurfaceArray::SurfaceArray(std::unique_ptr gridLookup, + std::vector> surfaces) + : m_gridLookup(std::move(gridLookup)), m_surfaces(std::move(surfaces)) { + m_surfacesRawPointers = + m_surfaces | + std::views::transform( + [](const std::shared_ptr& sp) { return sp.get(); }) | + Ranges::to; +} + +std::ostream& SurfaceArray::toStream(const GeometryContext& /*gctx*/, + std::ostream& sl) const { + sl << std::fixed << std::setprecision(4); + sl << "SurfaceArray:" << std::endl; + sl << " - no surfaces: " << m_surfaces.size() << std::endl; + + const std::vector axes = m_gridLookup->getAxes(); + + for (const auto [j, axis] : enumerate(axes)) { + const AxisBoundaryType bdt = axis->getBoundaryType(); + sl << " - axis " << (j + 1) << std::endl; + sl << " - boundary type: "; + if (bdt == AxisBoundaryType::Open) { + sl << "open"; + } + if (bdt == AxisBoundaryType::Bound) { + sl << "bound"; + } + if (bdt == AxisBoundaryType::Closed) { + sl << "closed"; + } + sl << std::endl; + sl << " - type: " << (axis->isEquidistant() ? "equidistant" : "variable") + << std::endl; + sl << " - n bins: " << axis->getNBins() << std::endl; + sl << " - bin edges: [ "; + const std::vector binEdges = axis->getBinEdges(); + for (const auto [i, binEdge] : enumerate(binEdges)) { + if (i > 0) { + sl << ", "; + } + // Do not display negative zeroes + sl << ((std::abs(binEdge) >= 5e-4) ? binEdge : 0.0); + } + sl << " ]" << std::endl; + } + return sl; +} std::unique_ptr SurfaceArray::makeSurfaceGridLookup( @@ -598,10 +552,10 @@ SurfaceArray::SurfaceArray(const GeometryContext& gctx, std::vector> surfaces, std::shared_ptr representative, double tolerance, - std::tuple axes) { - m_transform = representative->localToGlobalTransform(gctx); - m_gridLookup = - makeSurfaceGridLookup(std::move(representative), tolerance, axes); + std::tuple axes, + std::uint8_t maxNeighborDistance) { + m_gridLookup = makeSurfaceGridLookup(std::move(representative), tolerance, + axes, maxNeighborDistance); m_surfaces = std::move(surfaces); m_surfacesRawPointers = m_surfaces | diff --git a/Plugins/Detray/src/DetrayNavigation.cpp b/Plugins/Detray/src/DetrayNavigation.cpp index 5512306966a..f38208084ea 100644 --- a/Plugins/Detray/src/DetrayNavigation.cpp +++ b/Plugins/Detray/src/DetrayNavigation.cpp @@ -153,7 +153,7 @@ std::optional DetrayPayloadConverter::convertSurfaceArray( const auto dj = mapj(j); const std::span surfaces = - surfaceArray.at({i, j}, 0); + surfaceArray.neighbors({i, j}, 0); std::vector surfaceIndices; diff --git a/Tests/UnitTests/Core/Geometry/LayerCreatorTests.cpp b/Tests/UnitTests/Core/Geometry/LayerCreatorTests.cpp index b053b9cdd52..7f17ffc14aa 100644 --- a/Tests/UnitTests/Core/Geometry/LayerCreatorTests.cpp +++ b/Tests/UnitTests/Core/Geometry/LayerCreatorTests.cpp @@ -25,7 +25,6 @@ #include "Acts/Surfaces/Surface.hpp" #include "Acts/Surfaces/SurfaceArray.hpp" #include "Acts/Utilities/BinningType.hpp" -#include "Acts/Utilities/Diagnostics.hpp" #include "Acts/Utilities/IAxis.hpp" #include "Acts/Utilities/Logger.hpp" #include "ActsTests/CommonHelpers/FloatComparisons.hpp" @@ -107,9 +106,7 @@ struct LayerCreatorFixture { if (!sArray->isValidBin(i)) { continue; } - ACTS_PUSH_IGNORE_DEPRECATED() - const std::vector& binContent = sArray->at(i); - ACTS_POP_IGNORE_DEPRECATED() + const std::span binContent = sArray->at(i); BOOST_TEST_INFO("Bin: " << i); BOOST_CHECK_EQUAL(binContent.size(), n); result = result && binContent.size() == n; @@ -429,15 +426,12 @@ BOOST_FIXTURE_TEST_CASE(LayerCreator_barrelStagger, LayerCreatorFixture) { // std::endl; Vector3 ctr = A->referencePosition(tgContext, AxisDirection::AxisR); - ACTS_PUSH_IGNORE_DEPRECATED() - const std::vector& binContent = - layer->surfaceArray()->at(ctr, ctr.normalized()); - ACTS_POP_IGNORE_DEPRECATED() + const std::span binContent = + layer->surfaceArray()->at(tgContext, ctr, ctr.normalized()); BOOST_CHECK_EQUAL(binContent.size(), 2u); - std::set act(binContent.begin(), binContent.end()); std::set exp({A, B}); - BOOST_CHECK(std::ranges::includes(act, exp)); + BOOST_CHECK(std::ranges::includes(binContent, exp)); } } diff --git a/Tests/UnitTests/Core/Geometry/SurfaceArrayCreatorTests.cpp b/Tests/UnitTests/Core/Geometry/SurfaceArrayCreatorTests.cpp index ed56beee139..3abac107d55 100644 --- a/Tests/UnitTests/Core/Geometry/SurfaceArrayCreatorTests.cpp +++ b/Tests/UnitTests/Core/Geometry/SurfaceArrayCreatorTests.cpp @@ -85,6 +85,14 @@ struct SurfaceArrayCreatorFixture { std::forward(args)...); } + SurfaceArray makeSurfaceArray( + std::vector> surfaces, + std::unique_ptr gridLookup) { + ACTS_PUSH_IGNORE_DEPRECATED() + return SurfaceArray(std::move(gridLookup), std::move(surfaces)); + ACTS_POP_IGNORE_DEPRECATED() + } + SrfVec fullPhiTestSurfacesEC(std::size_t n = 10, double shift = 0, double zbase = 0, double r = 10, double w = 2, double h = 1) { @@ -575,13 +583,8 @@ BOOST_FIXTURE_TEST_CASE(SurfaceArrayCreator_completeBinning, auto cylinder = Surface::makeShared(Transform3::Identity(), R, 100); - ACTS_PUSH_IGNORE_DEPRECATED() - auto sl = std::make_unique< - SurfaceArray::SurfaceGridLookup>( - cylinder, 1., std::make_tuple(std::move(phiAxis), std::move(zAxis))); - sl->fill(tgContext, brlRaw); - SurfaceArray sa(std::move(sl), brl); - ACTS_POP_IGNORE_DEPRECATED() + SurfaceArray sa(tgContext, brl, cylinder, 1., + std::tuple(std::move(phiAxis), std::move(zAxis))); // Write the surrace array with grid ObjVisualization3D objVis; @@ -653,9 +656,7 @@ BOOST_FIXTURE_TEST_CASE(SurfaceArrayCreator_barrelStagger, cylinder, 1., pAxisPhi, pAxisZ, 1); sl->fill(tgContext, brlRaw); - ACTS_PUSH_IGNORE_DEPRECATED() - SurfaceArray sa(std::move(sl), brl); - ACTS_POP_IGNORE_DEPRECATED() + SurfaceArray sa = makeSurfaceArray(brl, std::move(sl)); auto axes = sa.getAxes(); BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30u); BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7u); @@ -689,9 +690,7 @@ BOOST_FIXTURE_TEST_CASE(SurfaceArrayCreator_barrelStagger, cylinder, 1., pAxisPhiVar, pAxisZVar, 1); sl2->fill(tgContext, brlRaw); - ACTS_PUSH_IGNORE_DEPRECATED() - SurfaceArray sa2(std::move(sl2), brl); - ACTS_POP_IGNORE_DEPRECATED() + SurfaceArray sa2 = makeSurfaceArray(brl, std::move(sl2)); axes = sa2.getAxes(); BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30u); BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7u);