From a1dbcc98ab48b4811d092620bb71772d4953580c Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Wed, 6 Nov 2024 16:28:52 +0100 Subject: [PATCH] fix: TryAllNavigationPolicy config exposed to python --- .../Navigation/TryAllNavigationPolicy.hpp | 7 +++-- .../src/Navigation/TryAllNavigationPolicy.cpp | 8 +++--- Examples/Python/src/Navigation.cpp | 28 ++++++++++++++++++- Examples/Python/tests/test_navigation.py | 6 ++++ 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Core/include/Acts/Navigation/TryAllNavigationPolicy.hpp b/Core/include/Acts/Navigation/TryAllNavigationPolicy.hpp index e7dc4bb3ddc..677a1dbd6dc 100644 --- a/Core/include/Acts/Navigation/TryAllNavigationPolicy.hpp +++ b/Core/include/Acts/Navigation/TryAllNavigationPolicy.hpp @@ -27,12 +27,13 @@ class TryAllNavigationPolicy final : public INavigationPolicy { }; /// 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); + /// @param config The configuration for the policy + TryAllNavigationPolicy(const GeometryContext& gctx, + const TrackingVolume& volume, const Logger& logger, + const Config& config); /// Constructor from a volume /// @param gctx is the geometry context diff --git a/Core/src/Navigation/TryAllNavigationPolicy.cpp b/Core/src/Navigation/TryAllNavigationPolicy.cpp index 40ca70c4079..4423c7d62a8 100644 --- a/Core/src/Navigation/TryAllNavigationPolicy.cpp +++ b/Core/src/Navigation/TryAllNavigationPolicy.cpp @@ -13,10 +13,10 @@ namespace Acts { -TryAllNavigationPolicy::TryAllNavigationPolicy(const Config& config, - const GeometryContext& /*gctx*/, +TryAllNavigationPolicy::TryAllNavigationPolicy(const GeometryContext& /*gctx*/, const TrackingVolume& volume, - const Logger& logger) + const Logger& logger, + const Config& config) : m_cfg{config}, m_volume(&volume) { assert(m_volume != nullptr); ACTS_VERBOSE("TryAllNavigationPolicy created for volume " @@ -26,7 +26,7 @@ TryAllNavigationPolicy::TryAllNavigationPolicy(const Config& config, TryAllNavigationPolicy::TryAllNavigationPolicy(const GeometryContext& gctx, const TrackingVolume& volume, const Logger& logger) - : TryAllNavigationPolicy({}, gctx, volume, logger) {} + : TryAllNavigationPolicy(gctx, volume, logger, {}) {} void TryAllNavigationPolicy::initializeCandidates( const NavigationArguments& args, AppendOnlyNavigationStream& stream, diff --git a/Examples/Python/src/Navigation.cpp b/Examples/Python/src/Navigation.cpp index 733bbe1a151..a4f55a532ac 100644 --- a/Examples/Python/src/Navigation.cpp +++ b/Examples/Python/src/Navigation.cpp @@ -37,6 +37,10 @@ struct AnyNavigationPolicyFactory : public Acts::NavigationPolicyFactory { virtual std::unique_ptr add( TypeTag /*type*/, SurfaceArrayNavigationPolicy::Config config) = 0; + + virtual std::unique_ptr add( + TypeTag /*type*/, + TryAllNavigationPolicy::Config config) = 0; }; template , @@ -61,6 +65,12 @@ struct NavigationPolicyFactoryT : public AnyNavigationPolicyFactory { return add(std::move(config)); } + std::unique_ptr add( + TypeTag /*type*/, + TryAllNavigationPolicy::Config config) override { + return add(config); + } + std::unique_ptr build( const GeometryContext& gctx, const TrackingVolume& volume, const Logger& logger) const override { @@ -108,6 +118,12 @@ class NavigationPolicyFactory : public Acts::NavigationPolicyFactory { return *this; } + NavigationPolicyFactory& addTryAll( + const py::object& /*cls*/, const TryAllNavigationPolicy::Config& config) { + m_impl = m_impl->add(Type, config); + return *this; + } + std::unique_ptr build( const GeometryContext& gctx, const TrackingVolume& volume, const Logger& logger) const override { @@ -153,7 +169,16 @@ void addNavigation(Context& ctx) { std::shared_ptr>( m, "_NavigationPolicyFactory"); - py::class_(m, "TryAllNavigationPolicy"); + { + auto tryAll = + py::class_(m, "TryAllNavigationPolicy"); + using Config = TryAllNavigationPolicy::Config; + auto c = py::class_(tryAll, "Config").def(py::init<>()); + ACTS_PYTHON_STRUCT_BEGIN(c, Config); + ACTS_PYTHON_MEMBER(portals); + ACTS_PYTHON_MEMBER(sensitives); + ACTS_PYTHON_STRUCT_END(); + } py::class_>( @@ -162,6 +187,7 @@ void addNavigation(Context& ctx) { .def_static("make", []() { return NavigationPolicyFactory{}; }) .def("add", &NavigationPolicyFactory::addNoArguments) .def("add", &NavigationPolicyFactory::addSurfaceArray) + .def("add", &NavigationPolicyFactory::addTryAll) .def("_buildTest", [](NavigationPolicyFactory& self) { auto vol1 = std::make_shared( Transform3::Identity(), diff --git a/Examples/Python/tests/test_navigation.py b/Examples/Python/tests/test_navigation.py index 55ec8ac9540..56c908f7911 100644 --- a/Examples/Python/tests/test_navigation.py +++ b/Examples/Python/tests/test_navigation.py @@ -40,3 +40,9 @@ def test_navigation_policy_factory_add_multiple(): .add(acts.TryAllNavigationPolicy) .add(acts.TryAllNavigationPolicy) ) + + +def test_try_all_arguments(): + acts.NavigationPolicyFactory.make().add( + acts.TryAllNavigationPolicy, acts.TryAllNavigationPolicy.Config(sensitives=True) + )