diff --git a/Core/include/Acts/Geometry/TrackingVolume.hpp b/Core/include/Acts/Geometry/TrackingVolume.hpp index 7d99da344ff..f47f8b440fc 100644 --- a/Core/include/Acts/Geometry/TrackingVolume.hpp +++ b/Core/include/Acts/Geometry/TrackingVolume.hpp @@ -19,6 +19,7 @@ #include "Acts/Geometry/Volume.hpp" #include "Acts/Material/IVolumeMaterial.hpp" #include "Acts/Navigation/NavigationDelegate.hpp" +#include "Acts/Navigation/NavigationStream.hpp" #include "Acts/Surfaces/Surface.hpp" #include "Acts/Surfaces/SurfaceArray.hpp" #include "Acts/Surfaces/SurfaceVisitorConcept.hpp" @@ -501,10 +502,15 @@ class TrackingVolume : public Volume { /// @param policy is the navigation policy to be registered void setNavigationPolicy(std::unique_ptr policy); - /// Update the navigation state for this volume. Internally, this consults the - /// registered navigation policy, where the default is a noop. + /// Populate the navigation stream with navigation candidates from this + /// volume. Internally, this consults the registered navigation policy, where + /// the default is a noop. /// @param args are the navigation arguments - void updateNavigationState(const NavigationArguments& args) const; + /// @param stream is the navigation stream to be updated + /// @param logger is the logger + void initializeNavigationCandidates(const NavigationArguments& args, + AppendOnlyNavigationStream& stream, + const Logger& logger) const; private: void connectDenseBoundarySurfaces( diff --git a/Core/include/Acts/Navigation/INavigationPolicy.hpp b/Core/include/Acts/Navigation/INavigationPolicy.hpp index 27a11c3a543..6794dbdea09 100644 --- a/Core/include/Acts/Navigation/INavigationPolicy.hpp +++ b/Core/include/Acts/Navigation/INavigationPolicy.hpp @@ -9,6 +9,7 @@ #pragma once #include "Acts/Navigation/NavigationDelegate.hpp" +#include "Acts/Navigation/NavigationStream.hpp" #include "Acts/Utilities/DelegateChainBuilder.hpp" #include @@ -26,7 +27,9 @@ concept NavigationPolicyConcept = requires { requires std::is_base_of_v; // Has a conforming update method requires requires(T policy, const NavigationArguments& args) { - { policy.updateState(args) }; + policy.initializeCandidates(args, + std::declval(), + std::declval()); }; }; @@ -39,7 +42,9 @@ class INavigationPolicy { public: /// Noop update function that is suitable as a default for default navigation /// delegates. - static void noopUpdate(const NavigationArguments& /*unused*/) {} + static void noopInitializeCandidates(const NavigationArguments& /*unused*/, + AppendOnlyNavigationStream& /*unused*/, + const Logger& /*unused*/) {} /// Virtual destructor so policies can be held through this base class. virtual ~INavigationPolicy() = default; @@ -60,7 +65,8 @@ class INavigationPolicy { void connectDefault(NavigationDelegate& delegate) const { // This cannot be a concept because we use it in CRTP below const auto* self = static_cast(this); - DelegateChainBuilder{delegate}.add<&T::updateState>(self).store(delegate); + DelegateChainBuilder{delegate}.add<&T::initializeCandidates>(self).store( + delegate); } }; diff --git a/Core/include/Acts/Navigation/MultiNavigationPolicy.hpp b/Core/include/Acts/Navigation/MultiNavigationPolicy.hpp index d733435d69f..67c1af6bde4 100644 --- a/Core/include/Acts/Navigation/MultiNavigationPolicy.hpp +++ b/Core/include/Acts/Navigation/MultiNavigationPolicy.hpp @@ -63,7 +63,8 @@ class MultiNavigationPolicy final : public MultiNavigationPolicyBase { using policy_type = std::tuple_element_t; auto* policy = &std::get(m_policies); - auto added = factory.template add<&policy_type::updateState>(policy); + auto added = + factory.template add<&policy_type::initializeCandidates>(policy); if constexpr (sizeof...(Is) > 0) { return add(added); diff --git a/Core/include/Acts/Navigation/NavigationDelegate.hpp b/Core/include/Acts/Navigation/NavigationDelegate.hpp index 4a9944ea1a1..8e243818d30 100644 --- a/Core/include/Acts/Navigation/NavigationDelegate.hpp +++ b/Core/include/Acts/Navigation/NavigationDelegate.hpp @@ -9,6 +9,7 @@ #pragma once #include "Acts/Definitions/Algebra.hpp" +#include "Acts/Navigation/NavigationStream.hpp" #include "Acts/Surfaces/BoundaryTolerance.hpp" #include "Acts/Utilities/Delegate.hpp" @@ -20,17 +21,15 @@ class Logger; /// Struct that serves as the argument to the navigation delegate. /// It is not supposed to be used as an lvalue. struct NavigationArguments { - NavigationStream& main; Vector3 position; Vector3 direction; BoundaryTolerance tolerance = BoundaryTolerance::None(); - - const Logger& logger; }; /// Central alias for the navigation delegate. This type is owning to support /// (type-erased) navigation delegate chains (i.e. multiple policies). -using NavigationDelegate = OwningDelegate; +using NavigationDelegate = OwningDelegate; } // namespace Acts diff --git a/Core/include/Acts/Navigation/NavigationStream.hpp b/Core/include/Acts/Navigation/NavigationStream.hpp index 7e9c51dc7f9..97e154214d7 100644 --- a/Core/include/Acts/Navigation/NavigationStream.hpp +++ b/Core/include/Acts/Navigation/NavigationStream.hpp @@ -179,4 +179,14 @@ class NavigationStream { std::size_t m_currentIndex = 0u; }; +struct AppendOnlyNavigationStream { + explicit AppendOnlyNavigationStream(NavigationStream& stream); + void addSurfaceCandidate(const Surface& surface, + const BoundaryTolerance& bTolerance); + void addPortalCandidate(const Portal& portal); + + private: + NavigationStream* m_stream; +}; + } // namespace Acts diff --git a/Core/include/Acts/Navigation/SurfaceArrayNavigationPolicy.hpp b/Core/include/Acts/Navigation/SurfaceArrayNavigationPolicy.hpp index db788fce9c9..9143cf0087d 100644 --- a/Core/include/Acts/Navigation/SurfaceArrayNavigationPolicy.hpp +++ b/Core/include/Acts/Navigation/SurfaceArrayNavigationPolicy.hpp @@ -6,14 +6,14 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -#include "Acts/Geometry/SurfaceArrayCreator.hpp" #include "Acts/Navigation/INavigationPolicy.hpp" -#include "Acts/Surfaces/SurfaceArray.hpp" #pragma once namespace Acts { +class SurfaceArray; + /// A navigation policy that internally uses the Gen1 @c SurfaceArray class class SurfaceArrayNavigationPolicy : public INavigationPolicy { public: @@ -44,7 +44,11 @@ class SurfaceArrayNavigationPolicy : public INavigationPolicy { /// Update the navigation state from the surface array /// @param args The navigation arguments - void updateState(const NavigationArguments& args) const; + /// @param stream The navigation stream to update + /// @param logger The logger + void initializeCandidates(const NavigationArguments& args, + AppendOnlyNavigationStream& stream, + const Logger& logger) const; /// Connect this policy with a navigation delegate /// @param delegate The navigation delegate to connect to @@ -74,4 +78,6 @@ class SurfaceArrayNavigationPolicy : public INavigationPolicy { const TrackingVolume& m_volume; }; +static_assert(NavigationPolicyConcept); + } // namespace Acts diff --git a/Core/include/Acts/Navigation/TryAllNavigationPolicies.hpp b/Core/include/Acts/Navigation/TryAllNavigationPolicies.hpp deleted file mode 100644 index 876d9210ad7..00000000000 --- a/Core/include/Acts/Navigation/TryAllNavigationPolicies.hpp +++ /dev/null @@ -1,72 +0,0 @@ -// This file is part of the ACTS project. -// -// Copyright (C) 2016 CERN for the benefit of the ACTS project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#pragma once - -#include "Acts/Navigation/INavigationPolicy.hpp" - -namespace Acts { - -class TrackingVolume; -class GeometryContext; -class Logger; - -/// Policy which adds **all** portals of the volume to the main navigation -/// stream -class TryAllPortalNavigationPolicy final : public INavigationPolicy { - public: - /// Constructor from a volume - /// @param gctx is the geometry context - /// @param volume is the volume to navigate - /// @param logger is the logger - explicit TryAllPortalNavigationPolicy(const GeometryContext& gctx, - const TrackingVolume& volume, - const Logger& logger); - - /// Update the navigation state with all volume portals. - /// @param args are the navigation arguments - void updateState(const NavigationArguments& args) const; - - /// Connect the policy to a navigation delegate - /// @param delegate is the navigation delegate - void connect(NavigationDelegate& delegate) const override; - - private: - const TrackingVolume* m_volume; -}; - -static_assert(NavigationPolicyConcept); - -/// Policy which adds **all** surfaces of the volume to the main navigation -/// @note This does **not** include portal surfaces, but does not make any distinction -/// between sensitive and other surfaces in the volume. -class TryAllSurfaceNavigationPolicy final : public INavigationPolicy { - public: - /// Constructor from a volume - /// @param gctx is the geometry context - /// @param volume is the volume to navigate - /// @param logger is the logger - explicit TryAllSurfaceNavigationPolicy(const GeometryContext& gctx, - const TrackingVolume& volume, - const Logger& logger); - - /// Update the navigation state with all volume surfaces. - /// @param args are the navigation arguments - void updateState(const NavigationArguments& args) const; - - /// Connect the policy to a navigation delegate - /// @param delegate is the navigation delegate - void connect(NavigationDelegate& delegate) const override; - - private: - const TrackingVolume* m_volume; -}; - -static_assert(NavigationPolicyConcept); - -} // namespace Acts diff --git a/Core/include/Acts/Navigation/TryAllNavigationPolicy.hpp b/Core/include/Acts/Navigation/TryAllNavigationPolicy.hpp new file mode 100644 index 00000000000..bef9dab6e0d --- /dev/null +++ b/Core/include/Acts/Navigation/TryAllNavigationPolicy.hpp @@ -0,0 +1,57 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Navigation/INavigationPolicy.hpp" +#include "Acts/Navigation/NavigationStream.hpp" + +namespace Acts { + +class TrackingVolume; +class GeometryContext; +class Logger; + +/// Policy which adds **all** candidates of the configured type to the +/// stream +class TryAllNavigationPolicy final : public INavigationPolicy { + public: + struct Config { + bool portals = true; + bool sensitives = true; + }; + + /// Constructor from a volume + /// @param config The configuration for the policy + /// @param gctx is the geometry context + /// @param volume is the volume to navigate + /// @param logger is the logger + TryAllNavigationPolicy(const Config& config, const GeometryContext& gctx, + const TrackingVolume& volume, const Logger& logger); + + TryAllNavigationPolicy(const GeometryContext& gctx, + const TrackingVolume& volume, const Logger& logger); + + /// Update the navigation state with all volume portals. + /// @param args are the navigation arguments + void initializeCandidates(const NavigationArguments& args, + AppendOnlyNavigationStream& stream, + const Logger& logger) const; + + /// Connect the policy to a navigation delegate + /// @param delegate is the navigation delegate + void connect(NavigationDelegate& delegate) const override; + + private: + Config m_cfg; + const TrackingVolume* m_volume; +}; + +static_assert(NavigationPolicyConcept); + +} // namespace Acts diff --git a/Core/src/Geometry/TrackingVolume.cpp b/Core/src/Geometry/TrackingVolume.cpp index 8fc7366abdb..611904537f0 100644 --- a/Core/src/Geometry/TrackingVolume.cpp +++ b/Core/src/Geometry/TrackingVolume.cpp @@ -17,6 +17,7 @@ #include "Acts/Material/IVolumeMaterial.hpp" #include "Acts/Material/ProtoVolumeMaterial.hpp" #include "Acts/Navigation/INavigationPolicy.hpp" +#include "Acts/Navigation/NavigationStream.hpp" #include "Acts/Propagator/Navigator.hpp" #include "Acts/Surfaces/RegularSurface.hpp" #include "Acts/Surfaces/Surface.hpp" @@ -52,7 +53,7 @@ TrackingVolume::TrackingVolume( connectDenseBoundarySurfaces(denseVolumeVector); DelegateChainBuilder{m_navigationDelegate} - .add<&INavigationPolicy::noopUpdate>() + .add<&INavigationPolicy::noopInitializeCandidates>() .store(m_navigationDelegate); } @@ -754,9 +755,10 @@ void TrackingVolume::setNavigationPolicy( m_navigationPolicy->connect(m_navigationDelegate); } -void TrackingVolume::updateNavigationState( - const NavigationArguments& args) const { - m_navigationDelegate(args); +void TrackingVolume::initializeNavigationCandidates( + const NavigationArguments& args, AppendOnlyNavigationStream& stream, + const Logger& logger) const { + m_navigationDelegate(args, stream, logger); } } // namespace Acts diff --git a/Core/src/Navigation/CMakeLists.txt b/Core/src/Navigation/CMakeLists.txt index afd09ce5484..72bbf65b853 100644 --- a/Core/src/Navigation/CMakeLists.txt +++ b/Core/src/Navigation/CMakeLists.txt @@ -2,6 +2,6 @@ target_sources( ActsCore PRIVATE NavigationStream.cpp - TryAllNavigationPolicies.cpp + TryAllNavigationPolicy.cpp SurfaceArrayNavigationPolicy.cpp ) diff --git a/Core/src/Navigation/NavigationStream.cpp b/Core/src/Navigation/NavigationStream.cpp index 62ec7eb11eb..c36eed12bbe 100644 --- a/Core/src/Navigation/NavigationStream.cpp +++ b/Core/src/Navigation/NavigationStream.cpp @@ -13,10 +13,12 @@ #include -bool Acts::NavigationStream::initialize(const GeometryContext& gctx, - const QueryPoint& queryPoint, - const BoundaryTolerance& cTolerance, - ActsScalar onSurfaceTolerance) { +namespace Acts { + +bool NavigationStream::initialize(const GeometryContext& gctx, + const QueryPoint& queryPoint, + const BoundaryTolerance& cTolerance, + ActsScalar onSurfaceTolerance) { // Position and direction from the query point const Vector3& position = queryPoint.position; const Vector3& direction = queryPoint.direction; @@ -91,9 +93,9 @@ bool Acts::NavigationStream::initialize(const GeometryContext& gctx, return true; } -bool Acts::NavigationStream::update(const GeometryContext& gctx, - const QueryPoint& queryPoint, - ActsScalar onSurfaceTolerance) { +bool NavigationStream::update(const GeometryContext& gctx, + const QueryPoint& queryPoint, + ActsScalar onSurfaceTolerance) { // Loop over the (currently valid) candidates and update for (; m_currentIndex < m_candidates.size(); ++m_currentIndex) { // Get the candidate, and resolve the tuple @@ -121,14 +123,14 @@ bool Acts::NavigationStream::update(const GeometryContext& gctx, return false; } -void Acts::NavigationStream::addSurfaceCandidate( +void NavigationStream::addSurfaceCandidate( const Surface& surface, const BoundaryTolerance& bTolerance) { m_candidates.emplace_back( Candidate{.intersection = ObjectIntersection::invalid(&surface), .bTolerance = bTolerance}); } -void Acts::NavigationStream::addSurfaceCandidates( +void NavigationStream::addSurfaceCandidates( std::span surfaces, const BoundaryTolerance& bTolerance) { std::ranges::for_each(surfaces, [&](const auto* surface) { m_candidates.emplace_back( @@ -137,22 +139,21 @@ void Acts::NavigationStream::addSurfaceCandidates( }); } -void Acts::NavigationStream::addPortalCandidate( - const Experimental::Portal& portal) { +void NavigationStream::addPortalCandidate(const Experimental::Portal& portal) { m_candidates.emplace_back(Candidate{ .intersection = ObjectIntersection::invalid(&portal.surface()), .gen2Portal = &portal, .bTolerance = BoundaryTolerance::None()}); } -void Acts::NavigationStream::addPortalCandidate(const Portal& portal) { +void NavigationStream::addPortalCandidate(const Portal& portal) { m_candidates.emplace_back(Candidate{ .intersection = ObjectIntersection::invalid(&portal.surface()), .portal = &portal, .bTolerance = BoundaryTolerance::None()}); } -void Acts::NavigationStream::addPortalCandidates( +void NavigationStream::addPortalCandidates( std::span portals) { std::ranges::for_each(portals, [&](const auto& portal) { m_candidates.emplace_back(Candidate{ @@ -162,3 +163,17 @@ void Acts::NavigationStream::addPortalCandidates( .bTolerance = BoundaryTolerance::None()}); }); } + +AppendOnlyNavigationStream::AppendOnlyNavigationStream(NavigationStream& stream) + : m_stream{&stream} {} + +void AppendOnlyNavigationStream::addPortalCandidate(const Portal& portal) { + m_stream->addPortalCandidate(portal); +} + +void AppendOnlyNavigationStream::addSurfaceCandidate( + const Surface& surface, const BoundaryTolerance& bTolerance) { + m_stream->addSurfaceCandidate(surface, bTolerance); +} + +} // namespace Acts diff --git a/Core/src/Navigation/SurfaceArrayNavigationPolicy.cpp b/Core/src/Navigation/SurfaceArrayNavigationPolicy.cpp index e2eb4d88eed..f40621fdd06 100644 --- a/Core/src/Navigation/SurfaceArrayNavigationPolicy.cpp +++ b/Core/src/Navigation/SurfaceArrayNavigationPolicy.cpp @@ -8,9 +8,9 @@ #include "Acts/Navigation/SurfaceArrayNavigationPolicy.hpp" +#include "Acts/Geometry/SurfaceArrayCreator.hpp" #include "Acts/Geometry/TrackingVolume.hpp" #include "Acts/Navigation/NavigationStream.hpp" -#include "Acts/Utilities/BinningType.hpp" #include @@ -60,9 +60,9 @@ SurfaceArrayNavigationPolicy::SurfaceArrayNavigationPolicy( } } -void SurfaceArrayNavigationPolicy::updateState( - const NavigationArguments& args) const { - const Logger& logger = args.logger; +void SurfaceArrayNavigationPolicy::initializeCandidates( + const NavigationArguments& args, AppendOnlyNavigationStream& stream, + const Logger& logger) const { ACTS_VERBOSE("SrfArrNavPol (volume=" << m_volume.volumeName() << ")"); ACTS_VERBOSE("Querying sensitive surfaces at " << args.position.transpose()); @@ -72,7 +72,7 @@ void SurfaceArrayNavigationPolicy::updateState( << " sensitive surfaces"); for (const auto* surface : sensitiveSurfaces) { - args.main.addSurfaceCandidate(*surface, args.tolerance); + stream.addSurfaceCandidate(*surface, args.tolerance); }; } diff --git a/Core/src/Navigation/TryAllNavigationPolicies.cpp b/Core/src/Navigation/TryAllNavigationPolicies.cpp deleted file mode 100644 index 3c3d71f72dc..00000000000 --- a/Core/src/Navigation/TryAllNavigationPolicies.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// This file is part of the ACTS project. -// -// Copyright (C) 2016 CERN for the benefit of the ACTS project -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -#include "Acts/Navigation/TryAllNavigationPolicies.hpp" - -#include "Acts/Geometry/TrackingVolume.hpp" -#include "Acts/Navigation/NavigationStream.hpp" - -namespace Acts { - -TryAllPortalNavigationPolicy::TryAllPortalNavigationPolicy( - const GeometryContext& /*gctx*/, const TrackingVolume& volume, - const Logger& logger) - : m_volume(&volume) { - assert(m_volume != nullptr); - ACTS_VERBOSE("TryAllPortalNavigationPolicy created for volume " - << m_volume->volumeName()); -} - -void TryAllPortalNavigationPolicy::updateState( - const NavigationArguments& args) const { - const Logger& logger = args.logger; - ACTS_VERBOSE("TryAllPortalNavigationPolicy"); - assert(m_volume != nullptr); - - for (const auto& portal : m_volume->portals()) { - args.main.addPortalCandidate(portal); - }; -} - -void TryAllPortalNavigationPolicy::connect(NavigationDelegate& delegate) const { - connectDefault(delegate); -} - -TryAllSurfaceNavigationPolicy::TryAllSurfaceNavigationPolicy( - const GeometryContext& /*gctx*/, const TrackingVolume& volume, - const Logger& logger) - : m_volume(&volume) { - ACTS_VERBOSE("TryAllSurfaceNavigationPolicy created for volume " - << m_volume->volumeName()); -} - -void TryAllSurfaceNavigationPolicy::updateState( - const NavigationArguments& args) const { - const Logger& logger = args.logger; - ACTS_VERBOSE("TryAllSurfaceNavigationPolicy"); - assert(m_volume != nullptr); - - for (const auto& surface : m_volume->surfaces()) { - args.main.addSurfaceCandidate(surface, args.tolerance); - }; -} - -void TryAllSurfaceNavigationPolicy::connect( - NavigationDelegate& delegate) const { - connectDefault(delegate); -} - -} // namespace Acts diff --git a/Core/src/Navigation/TryAllNavigationPolicy.cpp b/Core/src/Navigation/TryAllNavigationPolicy.cpp new file mode 100644 index 00000000000..df423bfc9b8 --- /dev/null +++ b/Core/src/Navigation/TryAllNavigationPolicy.cpp @@ -0,0 +1,53 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 CERN for the benefit of the ACTS project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#include "Acts/Navigation/TryAllNavigationPolicy.hpp" + +#include "Acts/Geometry/TrackingVolume.hpp" +#include "Acts/Navigation/NavigationStream.hpp" + +namespace Acts { + +TryAllNavigationPolicy::TryAllNavigationPolicy(const Config& config, + const GeometryContext& /*gctx*/, + const TrackingVolume& volume, + const Logger& logger) + : m_cfg{config}, m_volume(&volume) { + assert(m_volume != nullptr); + ACTS_VERBOSE("TryAllPortalNavigationPolicy created for volume " + << m_volume->volumeName()); +} + +TryAllNavigationPolicy::TryAllNavigationPolicy(const GeometryContext& gctx, + const TrackingVolume& volume, + const Logger& logger) + : TryAllNavigationPolicy({}, gctx, volume, logger) {} + +void TryAllNavigationPolicy::initializeCandidates( + const NavigationArguments& args, AppendOnlyNavigationStream& stream, + const Logger& logger) const { + ACTS_VERBOSE("TryAllPortalNavigationPolicy"); + assert(m_volume != nullptr); + + if (m_cfg.portals) { + for (const auto& portal : m_volume->portals()) { + stream.addPortalCandidate(portal); + } + } + + if (m_cfg.sensitives) + for (const auto& surface : m_volume->surfaces()) { + stream.addSurfaceCandidate(surface, args.tolerance); + }; +} + +void TryAllNavigationPolicy::connect(NavigationDelegate& delegate) const { + connectDefault(delegate); +} + +} // namespace Acts diff --git a/Examples/Python/src/Navigation.cpp b/Examples/Python/src/Navigation.cpp index 57dd62b2ae1..32153cccaf6 100644 --- a/Examples/Python/src/Navigation.cpp +++ b/Examples/Python/src/Navigation.cpp @@ -10,7 +10,7 @@ #include "Acts/Geometry/NavigationPolicyFactory.hpp" #include "Acts/Geometry/TrackingVolume.hpp" #include "Acts/Navigation/SurfaceArrayNavigationPolicy.hpp" -#include "Acts/Navigation/TryAllNavigationPolicies.hpp" +#include "Acts/Navigation/TryAllNavigationPolicy.hpp" #include "Acts/Plugins/Python/Utilities.hpp" #include "Acts/Utilities/Logger.hpp" #include "Acts/Utilities/TypeTag.hpp" @@ -30,10 +30,7 @@ namespace Acts::Python { struct AnyNavigationPolicyFactory : public Acts::NavigationPolicyFactory { virtual std::unique_ptr add( - TypeTag /*type*/) = 0; - - virtual std::unique_ptr add( - TypeTag /*type*/) = 0; + TypeTag /*type*/) = 0; virtual std::unique_ptr add( TypeTag /*type*/, @@ -52,13 +49,8 @@ struct NavigationPolicyFactoryT : public AnyNavigationPolicyFactory { : m_impl{} {} std::unique_ptr add( - TypeTag /*type*/) override { - return add(); - } - - std::unique_ptr add( - TypeTag /*type*/) override { - return add(); + TypeTag /*type*/) override { + return add(); } std::unique_ptr add( @@ -101,11 +93,9 @@ class NavigationPolicyFactory : public Acts::NavigationPolicyFactory { NavigationPolicyFactory& addNoArguments(const py::object& cls) { auto m = py::module_::import("acts"); if (py::object o = m.attr("TryAllPortalNavigationPolicy"); cls.is(o)) { - m_impl = m_impl->add(Type); - } else if (o = m.attr("TryAllSurfaceNavigationPolicy"); cls.is(o)) { - m_impl = m_impl->add(Type); - } else { + m_impl = m_impl->add(Type); } + // Add other policies here return *this; } @@ -134,8 +124,7 @@ void addNavigation(Context& ctx) { std::shared_ptr>( m, "_NavigationPolicyFactory"); - py::class_(m, "TryAllPortalNavigationPolicy"); - py::class_(m, "TryAllSurfaceNavigationPolicy"); + py::class_(m, "TryAllNavigationPolicy"); py::class_>( diff --git a/Examples/Python/tests/test_navigation.py b/Examples/Python/tests/test_navigation.py index 9178cad6854..8723049b061 100644 --- a/Examples/Python/tests/test_navigation.py +++ b/Examples/Python/tests/test_navigation.py @@ -9,8 +9,7 @@ def test_navigation_policy_factory(): policy = ( acts.NavigationPolicyFactory.make() - .add(acts.TryAllPortalNavigationPolicy) - .add(acts.TryAllSurfaceNavigationPolicy) + .add(acts.TryAllNavigationPolicy) .add( acts.SurfaceArrayNavigationPolicy, acts.SurfaceArrayNavigationPolicy.Config( @@ -22,11 +21,7 @@ def test_navigation_policy_factory(): policy._buildTest() - policy = ( - acts.NavigationPolicyFactory.make() - .add(acts.TryAllPortalNavigationPolicy) - .add(acts.TryAllSurfaceNavigationPolicy) - ) + policy = acts.NavigationPolicyFactory.make().add(acts.TryAllNavigationPolicy) policy._buildTest() @@ -42,7 +37,6 @@ def test_navigation_policy_factory_add_multiple(): with pytest.raises(ValueError): ( acts.NavigationPolicyFactory.make() - .add(acts.TryAllPortalNavigationPolicy) - .add(acts.TryAllSurfaceNavigationPolicy) - .add(acts.TryAllPortalNavigationPolicy) + .add(acts.TryAllNavigationPolicy) + .add(acts.TryAllNavigationPolicy) ) diff --git a/Tests/UnitTests/Core/Navigation/NavigationPolicyTests.cpp b/Tests/UnitTests/Core/Navigation/NavigationPolicyTests.cpp index febec7031f9..e98b5703410 100644 --- a/Tests/UnitTests/Core/Navigation/NavigationPolicyTests.cpp +++ b/Tests/UnitTests/Core/Navigation/NavigationPolicyTests.cpp @@ -16,7 +16,7 @@ #include "Acts/Navigation/MultiNavigationPolicy.hpp" #include "Acts/Navigation/NavigationDelegate.hpp" #include "Acts/Navigation/NavigationStream.hpp" -#include "Acts/Navigation/TryAllNavigationPolicies.hpp" +#include "Acts/Navigation/TryAllNavigationPolicy.hpp" using namespace Acts; using namespace Acts::UnitLiterals; @@ -30,12 +30,14 @@ struct APolicy : public INavigationPolicy { APolicy(const GeometryContext& /*gctx*/, const TrackingVolume& /*volume*/, const Logger& /*logger*/) {} - void updateState(const NavigationArguments& /*unused*/) const { + void initializeCandidates(const NavigationArguments& /*unused*/, + AppendOnlyNavigationStream& /*unused*/, + const Logger& /*unused*/) const { const_cast(this)->executed = true; } void connect(NavigationDelegate& delegate) const override { - connectDefault(delegate); + connectDefault(delegate); } bool executed = false; @@ -51,10 +53,12 @@ struct BPolicy : public INavigationPolicy { : m_config(config) {} void connect(NavigationDelegate& delegate) const override { - connectDefault(delegate); + connectDefault(delegate); } - void updateState(const NavigationArguments& /*unused*/) const { + void initializeCandidates(const NavigationArguments& /*unused*/, + AppendOnlyNavigationStream& /*unused*/, + const Logger& /*unused*/) const { const_cast(this)->executed = true; const_cast(this)->value = m_config.value; } @@ -78,10 +82,10 @@ BOOST_AUTO_TEST_CASE(DirectTest) { policy.connect(delegate); NavigationStream main; - delegate(NavigationArguments{.main = main, - .position = Vector3::Zero(), - .direction = Vector3::Zero(), - .logger = *logger}); + AppendOnlyNavigationStream stream{main}; + delegate(NavigationArguments{.position = Vector3::Zero(), + .direction = Vector3::Zero()}, + stream, *logger); BOOST_CHECK(std::get(policy.policies()).executed); BOOST_CHECK(std::get(policy.policies()).executed); @@ -112,10 +116,10 @@ BOOST_AUTO_TEST_CASE(FactoryTest) { policy.connect(delegate); NavigationStream main; - delegate(NavigationArguments{.main = main, - .position = Vector3::Zero(), - .direction = Vector3::Zero(), - .logger = *logger}); + AppendOnlyNavigationStream stream{main}; + delegate(NavigationArguments{.position = Vector3::Zero(), + .direction = Vector3::Zero()}, + stream, *logger); BOOST_CHECK(std::get(policy.policies()).executed); BOOST_CHECK(std::get(policy.policies()).executed); @@ -127,10 +131,9 @@ BOOST_AUTO_TEST_CASE(FactoryTest) { NavigationDelegate delegate2; policyBase2->connect(delegate2); - delegate2(NavigationArguments{.main = main, - .position = Vector3::Zero(), - .direction = Vector3::Zero(), - .logger = *logger}); + delegate(NavigationArguments{.position = Vector3::Zero(), + .direction = Vector3::Zero()}, + stream, *logger); BOOST_CHECK(std::get(policy2.policies()).executed); BOOST_CHECK(std::get(policy2.policies()).executed); @@ -153,10 +156,10 @@ BOOST_AUTO_TEST_CASE(AsUniquePtrTest) { policyBase->connect(delegate); NavigationStream main; - delegate(NavigationArguments{.main = main, - .position = Vector3::Zero(), - .direction = Vector3::Zero(), - .logger = *logger}); + AppendOnlyNavigationStream stream{main}; + delegate(NavigationArguments{.position = Vector3::Zero(), + .direction = Vector3::Zero()}, + stream, *logger); BOOST_CHECK(std::get(policy.policies()).executed); } @@ -173,10 +176,12 @@ struct CPolicySpecialized : public CPolicy { : m_config(config) {} void connect(NavigationDelegate& delegate) const override { - connectDefault(delegate); + connectDefault>(delegate); } - void updateState(const NavigationArguments& /*unused*/) const { + void initializeCandidates(const NavigationArguments& /*unused*/, + AppendOnlyNavigationStream& /*stream*/, + const Logger& /*logger*/) const { auto* self = const_cast*>(this); self->executed = true; self->value = m_config.value; @@ -221,10 +226,10 @@ BOOST_AUTO_TEST_CASE(IsolatedFactory) { policyBase->connect(delegate); NavigationStream main; - delegate(NavigationArguments{.main = main, - .position = Vector3::Zero(), - .direction = Vector3::Zero(), - .logger = *logger}); + AppendOnlyNavigationStream stream{main}; + delegate(NavigationArguments{.position = Vector3::Zero(), + .direction = Vector3::Zero()}, + stream, *logger); BOOST_CHECK(std::get(policy.policies()).executed); BOOST_CHECK(std::get>(policy.policies()).executed);