Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adapt visitor concept #2901

Merged
merged 12 commits into from
Jan 29, 2024
57 changes: 56 additions & 1 deletion Core/include/Acts/Detector/Detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Definitions/Common.hpp"
#include "Acts/Detector/DetectorVolume.hpp"
#include "Acts/Detector/DetectorVolumeVisitorConcept.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/GeometryHierarchyMap.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Geometry/SurfaceVisitorConcept.hpp"
#include "Acts/Navigation/NavigationDelegates.hpp"
#include "Acts/Surfaces/SurfaceVisitorConcept.hpp"
#include "Acts/Utilities/Concepts.hpp"
#include "Acts/Utilities/Delegate.hpp"

Expand Down Expand Up @@ -109,13 +110,67 @@ class Detector : public std::enable_shared_from_this<Detector> {
/// @param visitor will be handed to each root volume,
/// eventually contained volumes within the root volumes are
/// handled by the root volume
///
/// @note if a context is needed for the visit, the vistitor has to provide
/// it, e.g. as a private member
template <ACTS_CONCEPT(SurfaceVisitor) visitor_t>
void visitSurfaces(visitor_t&& visitor) const {
for (const auto& v : rootVolumes()) {
v->template visitSurfaces<visitor_t>(std::forward<visitor_t>(visitor));
}
}

/// @brief Visit all reachable surfaces of the detector - non-const
///
/// @tparam visitor_t Type of the callable visitor
///
/// @param visitor will be handed to each root volume,
/// eventually contained volumes within the root volumes are
/// handled by the root volume
///
/// @note if a context is needed for the visit, the vistitor has to provide
/// it, e.g. as a private member
template <ACTS_CONCEPT(SurfacePtrVisitor) visitor_t>
void visitSurfacePtrs(visitor_t&& visitor) {
for (auto& v : volumePtrs()) {
v->template visitSurfacePtrs<visitor_t>(std::forward<visitor_t>(visitor));
}
}

/// @brief Visit all reachable detector volumes of the detector
///
/// @tparam visitor_t Type of the callable visitor
///
/// @param visitor will be handed to each root volume,
/// eventually contained volumes within the root volumes are
/// handled by the root volume
///
/// @note if a context is needed for the visit, the vistitor has to provide
/// it, e.g. as a private member
template <ACTS_CONCEPT(DetectorVolumeVisitor) visitor_t>
void visitVolumes(visitor_t&& visitor) const {
for (const auto& v : rootVolumes()) {
v->template visitVolumes<visitor_t>(std::forward<visitor_t>(visitor));
}
}

/// @brief Visit all reachable detector volumes of the detector - non-const
///
/// @tparam visitor_t Type of the callable visitor
///
/// @param visitor will be handed to each root volume,
/// eventually contained volumes within the root volumes are
/// handled by the root volume
///
/// @note if a context is needed for the visit, the vistitor has to provide
/// it, e.g. as a private member
template <ACTS_CONCEPT(DetectorVolumePtrVisitor) visitor_t>
void visitVolumePtrs(visitor_t&& visitor) {
for (const auto& v : volumePtrs()) {
v->template visitVolumePtrs<visitor_t>(std::forward<visitor_t>(visitor));
}
}

/// Update the current volume of a given navigation state
///
/// @param gctx is the Geometry context of the call
Expand Down
59 changes: 57 additions & 2 deletions Core/include/Acts/Detector/DetectorVolume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
#include "Acts/Geometry/Extent.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Geometry/SurfaceVisitorConcept.hpp"
#include "Acts/Geometry/VolumeBounds.hpp"
#include "Acts/Material/IVolumeMaterial.hpp"
#include "Acts/Navigation/NavigationDelegates.hpp"
#include "Acts/Navigation/NavigationState.hpp"
#include "Acts/Surfaces/BoundaryCheck.hpp"
#include "Acts/Surfaces/SurfaceVisitorConcept.hpp"
#include "Acts/Utilities/BoundingBox.hpp"
#include "Acts/Utilities/Concepts.hpp"
#include "Acts/Utilities/Delegate.hpp"
Expand Down Expand Up @@ -296,13 +296,68 @@ class DetectorVolume : public std::enable_shared_from_this<DetectorVolume> {
visitor(s);
}
for (const auto& p : portals()) {
p->visitSurfaces(std::forward<visitor_t>(visitor));
p->visitSurface(std::forward<visitor_t>(visitor));
}
for (const auto& v : volumes()) {
v->visitSurfaces(std::forward<visitor_t>(visitor));
}
}

/// @brief Visit all reachable surfaces of the detector - non-const
///
/// @tparam visitor_t Type of the callable visitor
///
/// @param visitor will be called for each found surface,
/// it will be handed down to contained volumes and portals
template <ACTS_CONCEPT(SurfacePtrVisitor) visitor_t>
void visitSurfacePtrs(visitor_t&& visitor) {
for (auto& s : surfacePtrs()) {
visitor(s);
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
}
for (auto& p : portalPtrs()) {
p->visitSurfacePtr(std::forward<visitor_t>(visitor));
}
for (auto& v : volumePtrs()) {
v->visitSurfacePtrs(std::forward<visitor_t>(visitor));
}
}

/// @brief Visit all reachable detector volumes of the detector
///
/// @tparam visitor_t Type of the callable visitor
///
/// @param visitor will be handed to each root volume,
/// eventually contained volumes within the root volumes are
/// handled by the root volume
///
/// @note if a context is needed for the visit, the vistitor has to provide
/// it, e.g. as a private member
template <ACTS_CONCEPT(DetectorVolumeVisitor) visitor_t>
void visitVolumes(visitor_t&& visitor) const {
visitor(this);
for (const auto& v : volumes()) {
v->visitVolumes(std::forward<visitor_t>(visitor));
}
}

/// @brief Visit all reachable detector volumes of the detector - non-const
///
/// @tparam visitor_t Type of the callable visitor
///
/// @param visitor will be handed to each root volume,
/// eventually contained volumes within the root volumes are
/// handled by the root volume
///
/// @note if a context is needed for the visit, the vistitor has to provide
/// it, e.g. as a private member
template <ACTS_CONCEPT(DetectorVolumeVisitor) visitor_t>
void visitVolumePtrs(visitor_t&& visitor) {
visitor(this);
for (auto& v : volumePtrs()) {
v->visitVolumePtrs(std::forward<visitor_t>(visitor));
}
}

/// This method allows to udate the navigation state updator
/// module.
///
Expand Down
34 changes: 34 additions & 0 deletions Core/include/Acts/Detector/DetectorVolumeVisitorConcept.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// This file is part of the Acts project.
//
// Copyright (C) 2024 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 <memory>

#if defined(__cpp_concepts)
#include <concepts>

namespace Acts {

class DetectorVolume;

template <typename T>
concept DetectorVolumeVisitor = requires(T v) {
{v(std::declval<const DetectorVolume*>())};
};

template <typename T>
concept DetectorVolumePtrVisitor = requires(T v) {
{v(std::declval<std::shared_ptr<DetectorVolume>>())};
};



} // namespace Acts

#endif
14 changes: 12 additions & 2 deletions Core/include/Acts/Detector/Portal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
#include "Acts/Definitions/Direction.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Geometry/SurfaceVisitorConcept.hpp"
#include "Acts/Navigation/NavigationDelegates.hpp"
#include "Acts/Navigation/NavigationState.hpp"
#include "Acts/Surfaces/BoundaryCheck.hpp"
#include "Acts/Surfaces/RegularSurface.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Surfaces/SurfaceVisitorConcept.hpp"
#include "Acts/Utilities/Concepts.hpp"

#include <array>
Expand Down Expand Up @@ -75,10 +75,20 @@ class Portal {
///
/// @param visitor will be called with the represented surface
template <ACTS_CONCEPT(SurfaceVisitor) visitor_t>
void visitSurfaces(visitor_t&& visitor) const {
void visitSurface(visitor_t&& visitor) const {
visitor(m_surface.get());
}

/// @brief Visit all reachable surfaces of the detector - non-const
///
/// @tparam visitor_t Type of the callable visitor
///
/// @param visitor will be called with the represented surface
template <ACTS_CONCEPT(SurfacePtrVisitor) visitor_t>
void visitSurfacePtr(visitor_t&& visitor) {
visitor(m_surface);
}

/// Update the current volume
///
/// @param gctx is the Geometry context of this call
Expand Down
27 changes: 23 additions & 4 deletions Core/include/Acts/Geometry/TrackingGeometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Geometry/SurfaceVisitorConcept.hpp"
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/Geometry/TrackingVolumeVisitorConcept.hpp"
#include "Acts/Surfaces/SurfaceVisitorConcept.hpp"
#include "Acts/Utilities/Concepts.hpp"
#include "Acts/Utilities/Logger.hpp"

Expand Down Expand Up @@ -100,18 +101,36 @@ class TrackingGeometry {
/// (could be a null pointer)
const Surface* getBeamline() const;

/// @brief Visit all sensitive surfaces
/// @brief Visit all reachable surfaces
///
/// @tparam visitor_t Type of the callable visitor
///
/// @param visitor The callable. Will be called for each sensitive surface
/// that is found
/// @param visitor The callable. Will be called for each reachable surface
/// that is found, a selection of the surfaces can be done in the visitor
///
/// @note If a context is needed for the visit, the vistitor has to provide
/// this, e.g. as a private member
template <ACTS_CONCEPT(SurfaceVisitor) visitor_t>
void visitSurfaces(visitor_t&& visitor) const {
highestTrackingVolume()->template visitSurfaces<visitor_t>(
std::forward<visitor_t>(visitor));
}

/// @brief Visit all reachable tracking volumes
///
/// @tparam visitor_t Type of the callable visitor
///
/// @param visitor The callable. Will be called for each reachable volume
/// that is found, a selection of the volumes can be done in the visitor
///
/// @note If a context is needed for the visit, the vistitor has to provide
/// this, e.g. as a private member
template <ACTS_CONCEPT(TrackingVolumeVisitor) visitor_t>
void visitVolumes(visitor_t&& visitor) const {
highestTrackingVolume()->template visitVolumes<visitor_t>(
std::forward<visitor_t>(visitor));
}

/// Search for a volume with the given identifier.
///
/// @param id is the geometry identifier of the volume
Expand Down
62 changes: 49 additions & 13 deletions Core/include/Acts/Geometry/TrackingVolume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Geometry/Layer.hpp"
#include "Acts/Geometry/SurfaceVisitorConcept.hpp"
#include "Acts/Geometry/TrackingVolumeVisitorConcept.hpp"
#include "Acts/Geometry/Volume.hpp"
#include "Acts/Material/IVolumeMaterial.hpp"
#include "Acts/Surfaces/BoundaryCheck.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Surfaces/SurfaceArray.hpp"
#include "Acts/Surfaces/SurfaceVisitorConcept.hpp"
#include "Acts/Utilities/BinnedArray.hpp"
#include "Acts/Utilities/BoundingBox.hpp"
#include "Acts/Utilities/Concepts.hpp"
Expand Down Expand Up @@ -259,27 +260,42 @@ class TrackingVolume : public Volume {
/// Return the confined dense volumes
const MutableTrackingVolumeVector denseVolumes() const;

/// @brief Visit all sensitive surfaces
/// @brief Visit all reachable surfaces
///
/// @tparam visitor_t Type of the callable visitor
///
/// @param visitor The callable. Will be called for each sensitive surface
/// that is found
/// @param visitor The callable. Will be called for each reachable surface
/// that is found, a selection of the surfaces can be done in the visitor
///
/// If a context is needed for the visit, the vistitor has to provide this
/// e.g. as a private member
/// @note If a context is needed for the visit, the vistitor has to provide
/// this, e.g. as a private member
template <ACTS_CONCEPT(SurfaceVisitor) visitor_t>
void visitSurfaces(visitor_t&& visitor) const {
if (!m_confinedVolumes) {
// Visit the boundary surfaces
for (const auto& bs : m_boundarySurfaces) {
visitor(&(bs->surfaceRepresentation()));
}

// Internal structure
if (m_confinedVolumes == nullptr) {
// no sub volumes => loop over the confined layers
if (m_confinedLayers) {
if (m_confinedLayers != nullptr) {
for (const auto& layer : m_confinedLayers->arrayObjects()) {
if (layer->surfaceArray() == nullptr) {
// no surface array (?)
continue;
// Surfaces contained in the surface array
if (layer->surfaceArray() != nullptr) {
for (const auto& srf : layer->surfaceArray()->surfaces()) {
visitor(srf);
continue;
}
}
for (const auto& srf : layer->surfaceArray()->surfaces()) {
visitor(srf);
// Surfaces of the layer
visitor(&layer->surfaceRepresentation());
// Approach surfaces of the layer
if (layer->approachDescriptor() != nullptr) {
for (const auto& srf :
layer->approachDescriptor()->containedSurfaces()) {
visitor(srf);
}
}
}
}
Expand All @@ -291,6 +307,26 @@ class TrackingVolume : public Volume {
}
}

/// @brief Visit all reachable tracking volumes
///
/// @tparam visitor_t Type of the callable visitor
///
/// @param visitor The callable. Will be called for each reachable volume
/// that is found, a selection of the volumes can be done in the visitor
///
/// @note If a context is needed for the visit, the vistitor has to provide
/// this, e.g. as a private member
template <ACTS_CONCEPT(TrackingVolumeVisitor) visitor_t>
void visitVolumes(visitor_t&& visitor) const {
visitor(this);
if (m_confinedVolumes != nullptr) {
// contains sub volumes
for (const auto& volume : m_confinedVolumes->arrayObjects()) {
volume->visitVolumes(visitor);
}
}
}

/// Returns the VolumeName - for debug reason, might be depreciated later
const std::string& volumeName() const;

Expand Down
Loading
Loading