Skip to content

refactor: Surface takes shared ownership of SurfacePlacementBase#5305

Draft
paulgessinger wants to merge 3 commits intoacts-project:mainfrom
paulgessinger:refactor/surface-shared-placement
Draft

refactor: Surface takes shared ownership of SurfacePlacementBase#5305
paulgessinger wants to merge 3 commits intoacts-project:mainfrom
paulgessinger:refactor/surface-shared-placement

Conversation

@paulgessinger
Copy link
Copy Markdown
Member

Summary

  • Surface::m_placement is now a std::variant holding either a raw const SurfacePlacementBase* (old backward-compat path) or a std::shared_ptr<const SurfacePlacementBase> (new owning path)
  • Detector element classes (GenericDetectorElement, TGeoDetectorElement, DetectorElementStub) gain a createSurface() factory that uses shared_from_this() to pass shared ownership into the surface
  • The old surface() accessor on SurfacePlacementBase is deprecated ([[deprecated]]) but kept for 1–2 releases; a m_legacySurface member keeps the surface alive for callers still using unique_ptr-managed elements
  • SurfacePlacementBase now inherits std::enable_shared_from_this
  • All four concrete surface types (PlaneSurface, DiscSurface, CylinderSurface, LineSurface) gain a parallel constructor taking shared_ptr<const SurfacePlacementBase>
  • Call sites in DD4hep and TGeo plugins migrated to createSurface()

Not migrated in this PR (use deprecated path, compiler warnings only)

  • PortalPlacement.cpp, Geant4DetectorElement.cpp, GeoModelDetectorElement, JsonDetectorElement — need factory-pattern refactor, separate PR
  • Python bindings, various test files using assignSurfacePlacement(*element)

Test plan

  • All 51 surface/detector-element/navigator/TGeo/DD4hep/alignment tests pass
  • CI green

🤖 Generated with Claude Code

Add a new ownership model where Surface can hold a shared_ptr to its
SurfacePlacementBase (detector element), replacing the raw pointer.
A std::variant in Surface::m_placement carries either the old raw
pointer (backward compat) or the new shared_ptr path.

Detector element classes (GenericDetectorElement, TGeoDetectorElement,
DetectorElementStub) gain a createSurface() factory that calls
shared_from_this() to hand shared ownership to the surface. The old
surface() accessor is deprecated but kept for 1-2 releases via a
m_legacySurface member that keeps the surface alive for code still
using unique_ptr-managed elements.

Call sites in DD4hep and TGeo plugins updated to use createSurface().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added Component - Core Affects the Core module Component - Examples Affects the Examples module Component - Plugins Affects one or more Plugins labels Mar 31, 2026
@github-actions github-actions bot added this to the next milestone Mar 31, 2026
paulgessinger and others added 2 commits March 31, 2026 18:40
…IGNORE_DEPRECATED

Add a static PortalPlacement::create() factory that constructs the
placement via make_shared and then calls the non-deprecated
assignSurfacePlacement(shared_ptr) overload (shared_from_this() is
valid post-construction). Remove the #pragma GCC diagnostic workaround
from PortalPlacement.cpp.

Change VolumePlacementBase::m_portalPlacements from unique_ptr to
shared_ptr and update portalPlacement() return types accordingly.

Replace the raw #pragma GCC diagnostic in TGeoCylinderDiscSplitter.cpp
with the central ACTS_PUSH_IGNORE_DEPRECATED / ACTS_POP_IGNORE_DEPRECATED
macros from Acts/Utilities/Diagnostics.hpp.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace the sequential std::get_if checks with a std::visit call using
the overloaded visitor helper from Acts/Utilities/Helpers.hpp.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component - Core Affects the Core module Component - Examples Affects the Examples module Component - Plugins Affects one or more Plugins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant