From e574e8a0b971a4225f6803de0a5837757a8aaea9 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Tue, 21 Nov 2023 12:11:09 +0100 Subject: [PATCH] feat: Introduce concepts for (Regular)Surface (#2646) This helps catching missing `using` methods to make derived classes fully comply with the base `Surface` class. C++ inheritance is strange. Blocked by: - #2340 --- Core/include/Acts/Surfaces/ConeSurface.hpp | 4 + .../include/Acts/Surfaces/CylinderSurface.hpp | 4 + Core/include/Acts/Surfaces/DiscSurface.hpp | 5 + Core/include/Acts/Surfaces/PerigeeSurface.hpp | 4 + Core/include/Acts/Surfaces/PlaneSurface.hpp | 4 + Core/include/Acts/Surfaces/StrawSurface.hpp | 4 + Core/include/Acts/Surfaces/SurfaceConcept.hpp | 133 ++++++++++++++++++ Tests/UnitTests/Core/Surfaces/SurfaceStub.hpp | 9 ++ 8 files changed, 167 insertions(+) create mode 100644 Core/include/Acts/Surfaces/SurfaceConcept.hpp diff --git a/Core/include/Acts/Surfaces/ConeSurface.hpp b/Core/include/Acts/Surfaces/ConeSurface.hpp index 0d453e106ed..3701bc7b5f7 100644 --- a/Core/include/Acts/Surfaces/ConeSurface.hpp +++ b/Core/include/Acts/Surfaces/ConeSurface.hpp @@ -18,7 +18,9 @@ #include "Acts/Surfaces/ConeBounds.hpp" #include "Acts/Surfaces/RegularSurface.hpp" #include "Acts/Surfaces/Surface.hpp" +#include "Acts/Surfaces/SurfaceConcept.hpp" #include "Acts/Utilities/BinningType.hpp" +#include "Acts/Utilities/Concepts.hpp" #include "Acts/Utilities/Result.hpp" #include "Acts/Utilities/detail/RealQuadraticEquation.hpp" @@ -278,4 +280,6 @@ class ConeSurface : public RegularSurface { const Vector3& direction) const; }; +ACTS_STATIC_CHECK_CONCEPT(RegularSurfaceConcept, ConeSurface); + } // namespace Acts diff --git a/Core/include/Acts/Surfaces/CylinderSurface.hpp b/Core/include/Acts/Surfaces/CylinderSurface.hpp index 2d1d550a5e5..717b55514c8 100644 --- a/Core/include/Acts/Surfaces/CylinderSurface.hpp +++ b/Core/include/Acts/Surfaces/CylinderSurface.hpp @@ -18,7 +18,9 @@ #include "Acts/Surfaces/CylinderBounds.hpp" #include "Acts/Surfaces/RegularSurface.hpp" #include "Acts/Surfaces/Surface.hpp" +#include "Acts/Surfaces/SurfaceConcept.hpp" #include "Acts/Utilities/BinningType.hpp" +#include "Acts/Utilities/Concepts.hpp" #include "Acts/Utilities/Result.hpp" #include "Acts/Utilities/detail/RealQuadraticEquation.hpp" @@ -285,4 +287,6 @@ class CylinderSurface : public RegularSurface { const Vector3& direction) const; }; +ACTS_STATIC_CHECK_CONCEPT(RegularSurfaceConcept, CylinderSurface); + } // namespace Acts diff --git a/Core/include/Acts/Surfaces/DiscSurface.hpp b/Core/include/Acts/Surfaces/DiscSurface.hpp index a0402ed441b..d55fc2c6181 100644 --- a/Core/include/Acts/Surfaces/DiscSurface.hpp +++ b/Core/include/Acts/Surfaces/DiscSurface.hpp @@ -18,7 +18,9 @@ #include "Acts/Surfaces/InfiniteBounds.hpp" #include "Acts/Surfaces/RegularSurface.hpp" #include "Acts/Surfaces/Surface.hpp" +#include "Acts/Surfaces/SurfaceConcept.hpp" #include "Acts/Utilities/BinningType.hpp" +#include "Acts/Utilities/Concepts.hpp" #include "Acts/Utilities/Result.hpp" #include @@ -328,4 +330,7 @@ class DiscSurface : public RegularSurface { protected: std::shared_ptr m_bounds; ///< bounds (shared) }; + +ACTS_STATIC_CHECK_CONCEPT(RegularSurfaceConcept, DiscSurface); + } // end of namespace Acts diff --git a/Core/include/Acts/Surfaces/PerigeeSurface.hpp b/Core/include/Acts/Surfaces/PerigeeSurface.hpp index e67a723160d..e8c95dba52c 100644 --- a/Core/include/Acts/Surfaces/PerigeeSurface.hpp +++ b/Core/include/Acts/Surfaces/PerigeeSurface.hpp @@ -13,6 +13,8 @@ #include "Acts/Surfaces/InfiniteBounds.hpp" #include "Acts/Surfaces/LineSurface.hpp" #include "Acts/Surfaces/Surface.hpp" +#include "Acts/Surfaces/SurfaceConcept.hpp" +#include "Acts/Utilities/Concepts.hpp" #include #include @@ -91,4 +93,6 @@ class PerigeeSurface : public LineSurface { std::size_t lseg) const final; }; +ACTS_STATIC_CHECK_CONCEPT(SurfaceConcept, PerigeeSurface); + } // namespace Acts diff --git a/Core/include/Acts/Surfaces/PlaneSurface.hpp b/Core/include/Acts/Surfaces/PlaneSurface.hpp index aeabeb9ae34..90c1441f1dd 100644 --- a/Core/include/Acts/Surfaces/PlaneSurface.hpp +++ b/Core/include/Acts/Surfaces/PlaneSurface.hpp @@ -17,7 +17,9 @@ #include "Acts/Surfaces/PlanarBounds.hpp" #include "Acts/Surfaces/RegularSurface.hpp" #include "Acts/Surfaces/Surface.hpp" +#include "Acts/Surfaces/SurfaceConcept.hpp" #include "Acts/Utilities/BinningType.hpp" +#include "Acts/Utilities/Concepts.hpp" #include "Acts/Utilities/Result.hpp" #include @@ -232,4 +234,6 @@ class PlaneSurface : public RegularSurface { private: }; +ACTS_STATIC_CHECK_CONCEPT(RegularSurfaceConcept, PlaneSurface); + } // end of namespace Acts diff --git a/Core/include/Acts/Surfaces/StrawSurface.hpp b/Core/include/Acts/Surfaces/StrawSurface.hpp index 314c2637a51..06a219ee28d 100644 --- a/Core/include/Acts/Surfaces/StrawSurface.hpp +++ b/Core/include/Acts/Surfaces/StrawSurface.hpp @@ -13,6 +13,8 @@ #include "Acts/Surfaces/LineBounds.hpp" #include "Acts/Surfaces/LineSurface.hpp" #include "Acts/Surfaces/Surface.hpp" +#include "Acts/Surfaces/SurfaceConcept.hpp" +#include "Acts/Utilities/Concepts.hpp" #include #include @@ -108,4 +110,6 @@ inline std::string Acts::StrawSurface::name() const { return "Acts::StrawSurface"; } +ACTS_STATIC_CHECK_CONCEPT(SurfaceConcept, StrawSurface); + } // namespace Acts diff --git a/Core/include/Acts/Surfaces/SurfaceConcept.hpp b/Core/include/Acts/Surfaces/SurfaceConcept.hpp new file mode 100644 index 00000000000..d510e2aa3ce --- /dev/null +++ b/Core/include/Acts/Surfaces/SurfaceConcept.hpp @@ -0,0 +1,133 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2023 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 http://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Definitions/Algebra.hpp" +#include "Acts/Definitions/Alignment.hpp" +#include "Acts/Definitions/TrackParametrization.hpp" +#include "Acts/Geometry/DetectorElementBase.hpp" +#include "Acts/Geometry/GeometryContext.hpp" +#include "Acts/Material/ISurfaceMaterial.hpp" +#include "Acts/Surfaces/BoundaryCheck.hpp" +#include "Acts/Surfaces/Surface.hpp" +#include "Acts/Surfaces/SurfaceBounds.hpp" +#include "Acts/Utilities/Result.hpp" + +#if defined(__cpp_concepts) +#include + +namespace Acts { + +template +concept SurfaceConcept = requires(S s, const S cs, S s2, const S cs2, + GeometryContext gctx) { + { cs == s2 } -> std::same_as; + + { cs.type() } -> std::same_as; + { cs.transform(gctx) } -> std::same_as; + { cs.center(gctx) } -> std::same_as; + { cs.normal(gctx, Vector3{}, Vector3{}) } -> std::same_as; + { cs.bounds() } -> std::convertible_to; + { + cs.associatedDetectorElement() + } -> std::same_as; + + { cs.associatedLayer() } -> std::same_as; + { s.associateLayer(std::declval()) } -> std::same_as; + + { cs.surfaceMaterial() } -> std::same_as; + { + cs.surfaceMaterialSharedPtr() + } -> std::same_as&>; + { + s.assignSurfaceMaterial( + std::declval>()) + } -> std::same_as; + { + cs.isOnSurface(gctx, Vector3{}, Vector3{}, + std::declval()) + } -> std::same_as; + { + cs.insideBounds(Vector2{}, std::declval()) + } -> std::same_as; + + { cs.localToGlobal(gctx, Vector2{}, Vector3{}) } -> std::same_as; + + { + cs.globalToLocal(gctx, Vector3{}, Vector3{}, double{5}) + } -> std::same_as>; + + { + cs.referenceFrame(gctx, Vector3{}, Vector3{}) + } -> std::same_as; + + { + cs.boundToFreeJacobian(gctx, BoundVector{}) + } -> std::same_as; + + { + cs.boundToFreeJacobian(gctx, BoundVector{}) + } -> std::same_as; + + { + cs.freeToBoundJacobian(gctx, FreeVector{}) + } -> std::same_as; + + { + cs.freeToPathDerivative(gctx, FreeVector{}) + } -> std::same_as; + + { cs.pathCorrection(gctx, Vector3{}, Vector3{}) } -> std::same_as; + + { + cs.intersect(gctx, Vector3{}, Vector3{}, + std::declval(), std::declval()) + } -> std::same_as; + + { + cs.toStream(gctx, std::declval()) + } -> std::same_as; + + { cs.toString(gctx) } -> std::same_as; + + { cs.name() } -> std::same_as; + + { + cs.polyhedronRepresentation(gctx, std::declval()) + } -> std::same_as; + + { + cs.alignmentToBoundDerivative(gctx, FreeVector{}, FreeVector{}) + } -> std::same_as; + + { + cs.alignmentToPathDerivative(gctx, FreeVector{}) + } -> std::same_as; + + { + cs.localCartesianToBoundLocalDerivative(gctx, Vector3{}) + } -> std::same_as>; +}; + +template +concept RegularSurfaceConcept = SurfaceConcept && + requires(S s, const S cs, GeometryContext gctx) { + { cs.normal(gctx, Vector2{}) } -> std::same_as; + + { cs.normal(gctx, Vector3{}) } -> std::same_as; + + { + cs.globalToLocal(gctx, Vector3{}, Vector3{}, std::declval()) + } -> std::same_as>; + + { cs.localToGlobal(gctx, Vector2{}) } -> std::same_as; +}; +} // namespace Acts + +#endif diff --git a/Tests/UnitTests/Core/Surfaces/SurfaceStub.hpp b/Tests/UnitTests/Core/Surfaces/SurfaceStub.hpp index 6fa2fb7036d..3363bb5d098 100644 --- a/Tests/UnitTests/Core/Surfaces/SurfaceStub.hpp +++ b/Tests/UnitTests/Core/Surfaces/SurfaceStub.hpp @@ -14,6 +14,8 @@ #include "Acts/Surfaces/PlanarBounds.hpp" #include "Acts/Surfaces/RegularSurface.hpp" #include "Acts/Surfaces/Surface.hpp" +#include "Acts/Surfaces/SurfaceConcept.hpp" +#include "Acts/Utilities/Concepts.hpp" #include "Acts/Utilities/Intersection.hpp" namespace Acts { @@ -57,6 +59,8 @@ class SurfaceStub : public RegularSurface { return Vector3(0., 0., 0.); } + using RegularSurface::localToGlobal; + /// Global to local transformation Result globalToLocal(const GeometryContext& /*cxt*/, const Vector3& /*gpos*/, @@ -64,6 +68,8 @@ class SurfaceStub : public RegularSurface { return Result::success(Vector2{20., 20.}); } + using RegularSurface::globalToLocal; + /// Calculation of the path correction for incident double pathCorrection(const GeometryContext& /*cxt*/, const Vector3& /*gpos*/, const Vector3& /*gmom*/) const final { @@ -115,4 +121,7 @@ class SurfaceStub : public RegularSurface { /// the bounds of this surface std::shared_ptr m_bounds; }; + +ACTS_STATIC_CHECK_CONCEPT(RegularSurfaceConcept, SurfaceStub); + } // namespace Acts