Skip to content

Fix Tracker copy semantics: re-point panels and planes at the copy - #1972

Open
oksuzian wants to merge 1 commit into
mainfrom
fix-tracker-copy-semantics
Open

Fix Tracker copy semantics: re-point panels and planes at the copy#1972
oksuzian wants to merge 1 commit into
mainfrom
fix-tracker-copy-semantics

Conversation

@oksuzian

@oksuzian oksuzian commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

Intent

Panel holds std::array<const Straw*, 96> pointing into the Tracker's own straw array, and Plane holds std::array<const Panel*, 6> pointing into its panel array. Tracker declares no copy constructor, so the compiler-generated one gives the copy fresh straw and panel storage while every Panel and Plane inside it still points at the original object's storage.

The only copy site in Offline today, AlignedTrackerMaker::fromFcl/fromDb (TrackerConditions/src/AlignedTrackerMaker.cc:93,123), is correct only because alignTracker subsequently rebuilds every panel and plane from the copy's own straws. Nothing in TrackerGeom makes that requirement discoverable, so any other copy would silently read another tracker's geometry, and a copy outliving its source would dangle.

Change

  • Tracker gets a copy constructor that copies the members and then re-points the constituents at its own content.
  • New private helpers Panel::rebindStraws and Plane::rebindPanels do the re-pointing. The two Panel constructors and the Plane constructor now call them instead of repeating the fill loop, so that logic has a single home.
  • Tracker is a friend of Panel and Plane for those two helpers; nothing else gains access.

No behavior changes for existing callers: ProditionsEntity deletes assignment, so Tracker stays copy constructible and non-assignable, and the only std::move involving a tracker (TrackerMaker::getTrackerPtr) moves a unique_ptr, not a Tracker.

Deliberately not changed: the TrackerG4Info shared_ptr is still shared with the original rather than deep copied. It describes the nominal G4 model and does not depend on the (possibly aligned) straw positions.

Validation

Compiled the changed translation units, plus the three main consumers, with the Muse spack toolchain (gcc 13.3, -std=c++20 -Wall -Werror): all of TrackerGeom/src/*.cc, TrackerConditions/src/AlignedTrackerMaker.cc, GeometryService/src/TrackerMaker.cc and Mu2eG4/src/ConstructTrackerDetail5.cc pass.

Wrote a throwaway program that builds a Tracker from a synthetic straw set, copies it, and counts constituent pointers that do not fall inside the copy's own arrays. Against main:

straw pointers not owned by the copy: 20736 / 20736
panel pointers not owned by the copy: 216 / 216

With this branch:

straw pointers not owned by the copy: 0 / 20736
panel pointers not owned by the copy: 0 / 216

The program is not included here; TrackerGeom has no test directory and I did not want to add one in this PR. Happy to contribute it wherever the collaboration would want such a check to live.

I have not run a full build or the physics validation jobs locally; leaving that to CI.

Related, not addressed here

While reading the package I noticed a few adjacent items that are separate topics and are deliberately left out to keep this PR to one thing: the Panel/Plane pointer arrays are not value initialised in the value constructors and no check catches an unfilled slot; Panel.cc hardcodes straws 47/48 as the panel middle while Plane.cc divides by a literal 6; Tracker::_origin is never assigned; and Manifold/ManifoldId appear to be dead but are still built. I can open follow-ups if they are wanted.

🤖 Generated with Claude Code

https://claude.ai/code/session_0138sWPyeSCDFbbn2cB9JBDy

Panel holds an array of pointers into the Tracker's straw array and Plane
holds an array of pointers into its panel array, so the compiler-generated
copy constructor produced a Tracker whose panels and planes still referred
to the straws and panels of the original.  The only copy site today,
AlignedTrackerMaker, is correct only because alignTracker afterwards
rebuilds every panel and plane from the copy's own content.

Add a Tracker copy constructor that re-points the constituents at the copy,
using new private Panel::rebindStraws and Plane::rebindPanels helpers.  The
two Panel constructors and the Plane constructor now call those helpers
instead of repeating the fill loop, so the pointer-filling logic has one
home.  The TrackerG4Info is still shared with the original: it describes the
nominal G4 model and does not depend on the straw positions.

ProditionsEntity deletes assignment, so Tracker remains copy constructible
but not assignable, and no behavior changes for existing callers.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0138sWPyeSCDFbbn2cB9JBDy
@FNALbuild

Copy link
Copy Markdown
Collaborator

Hi @oksuzian,
You have proposed changes to files in these packages:

  • TrackerGeom

which require these tests: build.

@Mu2e/fnalbuild-users, @Mu2e/write have access to CI actions on main.

⌛ The following tests have been triggered for c350c73: build (Build queue - API unavailable)

About FNALbuild. Code review on Mu2e/Offline.

@FNALbuild

Copy link
Copy Markdown
Collaborator

☀️ The build tests passed at c350c73.

Test Result Details
test with Command did not list any other PRs to include
merge Merged c350c73 at c4b2bc6
build (prof) Log file. Build time: 04 min 22 sec
ceSimReco Log file.
g4test_03MT Log file.
transportOnly Log file.
POT Log file.
g4study Log file.
cosmicSimReco Log file.
cosmicOffSpill Log file.
ceSteps Log file.
ceDigi Log file.
muDauSteps Log file.
ceMix Log file.
rootOverlaps Log file.
g4surfaceCheck Log file.
trigger Log file. Return Code 1.
check_cmake Log file.
FIXME, TODO ➡️ TODO (2) FIXME (4) in 6 files
clang-tidy ➡️ 2 errors 17 warnings
whitespace check no whitespace errors found

N.B. These results were obtained from a build of this Pull Request at c350c73 after being merged into the base branch at c4b2bc6.

For more information, please check the job page here.
Build artifacts are deleted after 5 days. If this is not desired, select Keep this build forever on the job page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants