Fix Tracker copy semantics: re-point panels and planes at the copy - #1972
Open
oksuzian wants to merge 1 commit into
Open
Fix Tracker copy semantics: re-point panels and planes at the copy#1972oksuzian wants to merge 1 commit into
oksuzian wants to merge 1 commit into
Conversation
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
Collaborator
|
☀️ The build tests passed at c350c73.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Panelholdsstd::array<const Straw*, 96>pointing into theTracker's own straw array, andPlaneholdsstd::array<const Panel*, 6>pointing into its panel array.Trackerdeclares no copy constructor, so the compiler-generated one gives the copy fresh straw and panel storage while everyPanelandPlaneinside 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 becausealignTrackersubsequently rebuilds every panel and plane from the copy's own straws. Nothing inTrackerGeommakes that requirement discoverable, so any other copy would silently read another tracker's geometry, and a copy outliving its source would dangle.Change
Trackergets a copy constructor that copies the members and then re-points the constituents at its own content.Panel::rebindStrawsandPlane::rebindPanelsdo the re-pointing. The twoPanelconstructors and thePlaneconstructor now call them instead of repeating the fill loop, so that logic has a single home.Trackeris afriendofPanelandPlanefor those two helpers; nothing else gains access.No behavior changes for existing callers:
ProditionsEntitydeletes assignment, soTrackerstays copy constructible and non-assignable, and the onlystd::moveinvolving a tracker (TrackerMaker::getTrackerPtr) moves aunique_ptr, not aTracker.Deliberately not changed: the
TrackerG4Infoshared_ptris 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 ofTrackerGeom/src/*.cc,TrackerConditions/src/AlignedTrackerMaker.cc,GeometryService/src/TrackerMaker.ccandMu2eG4/src/ConstructTrackerDetail5.ccpass.Wrote a throwaway program that builds a
Trackerfrom a synthetic straw set, copies it, and counts constituent pointers that do not fall inside the copy's own arrays. Againstmain:With this branch:
The program is not included here;
TrackerGeomhas 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/Planepointer arrays are not value initialised in the value constructors and no check catches an unfilled slot;Panel.cchardcodes straws 47/48 as the panel middle whilePlane.ccdivides by a literal 6;Tracker::_originis never assigned; andManifold/ManifoldIdappear 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