Return track parameter position and momentum vectors by value
In the current implementation of the track parameters, the position and
momentum vectors are returned by reference. This is enforced at an
interface level by the ParametersBase
class. Unfortunately this is not
necessarily good interface design, for several reasons:
Firstly, this interface design forces certain design choices on the implementing classes. That is to say, the implementing classes need to store some vector internally in order for it to be possible for them to return them by reference. This robs the implementing classes of the freedom to design their internals in the most efficient possible way.
Secondly, it breaks encapsulation of the class. The internals of the track parameters class should be hidden from the outside world, and this concept of information hiding is integral to good object-oriented programming. However, returning references to members of the class breaks this rule. Returning the references as const alleviates this problem somewhat, but the implementation is still far from ideal.
Thirdly, there is a potential lifetime issue with this design, as a reference to the internal vectors of the track parameters object can outlive the parameters object which they point to, which can lead to memory unsafety. Unless a Rust-like reference lifetime is implemented on a code level (because it is not supported by the C++ language standard) there is virtually no way to go about this safely.
Finally, there are thread-safety concerns with this design, as it is possible for one thread to update the internals of the object while another thread has a seemingly const reference to its internal data. This is not supposed to happen in the Athena code, but it's hard to enforce such requirements.
The solution proposed in this commit is to move away from the return-by-reference design, towards a return-by-value design. Returning a copy instead of a reference to internal data resolves all the previously mentioned concerns with the existing design, and should not incur any significant performance hits.
At first it might seem like replacing this interface would be a Herculean effort because these methods are used in so many different places, but there is a saving grace that means that this change might be simpler than expected. Indeed, the existing implementation uses const references, which means that we can exploit the fact that temporaries (and other rvalues) can be implicitly bound to const references to extend their lifetime. That is to say, any existing code that relies on this code returning const references should be compatible on a source code level (not on an API level) with the new code returning these vectors by value.
It's pretty much impossible to properly test changes to the track parameters locally since there are so many usage sites throughout the code. So I'm relying on the CI system to give me some indication on whether this works or not. It works for me compiling a subset of the Athena code, but compiling the whole thing is difficult.
Merge request reports
Activity
added 164 commits
-
c99b6a1a...e122725b - 163 commits from branch
atlas:master
- 3e915d02 - Return track parameter vectors by value
-
c99b6a1a...e122725b - 163 commits from branch
This merge request affects 7 files:
- Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/CurvilinearParametersT.h
- Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/CurvilinearParametersT.icc
- Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/ParametersBase.h
- Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/ParametersT.h
- Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/ParametersT.icc
- Tracking/TrkEvent/TrkPatternParameters/TrkPatternParameters/PatternTrackParameters.h
- Tracking/TrkEvent/TrkPatternParameters/src/PatternTrackParameters.cxx
added JetEtmiss Tracking master review-pending-level-1 labels
CI Result FAILURE (hash 3e915d02)Athena AthSimulation AthGeneration AnalysisBase externals cmake make required tests optional tests Full details available on this CI monitor view
Athena: number of compilation errors 4, warnings 1
AthSimulation: number of compilation errors 0, warnings 0
AthGeneration: number of compilation errors 0, warnings 0
AnalysisBase: number of compilation errors 0, warnings 0
For experts only: Jenkins output [CI-MERGE-REQUEST-CC7 23226]This merge request affects 16 files:
- MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MdtDriftCircleOnTrackCreator/src/MdtDriftCircleOnTrackCreator.cxx
- MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonChamberHoleRecoveryTool.cxx
- MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSeededSegmentFinder.cxx
- MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MooTrackFitter.cxx
- Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/CurvilinearParametersT.h
- Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/CurvilinearParametersT.icc
- Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/ParametersBase.h
- Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/ParametersT.h
- Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/ParametersT.icc
- Tracking/TrkEvent/TrkPatternParameters/TrkPatternParameters/PatternTrackParameters.h
- Tracking/TrkEvent/TrkPatternParameters/src/PatternTrackParameters.cxx
- Tracking/TrkFitter/TrkGlobalChi2Fitter/TrkGlobalChi2Fitter/GXFTrackState.h
- Tracking/TrkFitter/TrkGlobalChi2Fitter/src/GXFTrackState.cxx
- graphics/VP1/VP1Systems/VP1TrackSystems/VP1TrackSystems/TrackHandleBase.h
- graphics/VP1/VP1Systems/VP1TrackSystems/src/TrackHandleBase.cxx
- graphics/VP1/VP1Systems/VP1TrackSystems/src/VP1TrackSystem.cxx
Adding @goetz ,@rosati ,@wleight ,@gavrilen ,@nkoehler ,@amorley ,@rbianchi as watchers
added EventDisplay MuonSpectrometer labels
CI Result FAILURE (hash 9371297f)Athena AthSimulation AthGeneration AnalysisBase externals cmake make required tests optional tests Full details available on this CI monitor view
Athena: number of compilation errors 1, warnings 0
AthSimulation: number of compilation errors 0, warnings 0
AthGeneration: number of compilation errors 0, warnings 0
AnalysisBase: number of compilation errors 0, warnings 0
For experts only: Jenkins output [CI-MERGE-REQUEST-CC7 23269]added review-user-action-required label and removed review-pending-level-1 label
This merge request affects 16 files:
- MuonSpectrometer/MuonReconstruction/MuonRIO_OnTrackCreators/MdtDriftCircleOnTrackCreator/src/MdtDriftCircleOnTrackCreator.cxx
- MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonChamberHoleRecoveryTool.cxx
- MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackFinderTools/src/MuonSeededSegmentFinder.cxx
- MuonSpectrometer/MuonReconstruction/MuonTrackMakers/MuonTrackMakerTools/MuonTrackSteeringTools/src/MooTrackFitter.cxx
- Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/CurvilinearParametersT.h
- Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/CurvilinearParametersT.icc
- Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/ParametersBase.h
- Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/ParametersT.h
- Tracking/TrkEvent/TrkParametersBase/TrkParametersBase/ParametersT.icc
- Tracking/TrkEvent/TrkPatternParameters/TrkPatternParameters/PatternTrackParameters.h
- Tracking/TrkEvent/TrkPatternParameters/src/PatternTrackParameters.cxx
- Tracking/TrkFitter/TrkGlobalChi2Fitter/TrkGlobalChi2Fitter/GXFTrackState.h
- Tracking/TrkFitter/TrkGlobalChi2Fitter/src/GXFTrackState.cxx
- graphics/VP1/VP1Systems/VP1TrackSystems/VP1TrackSystems/TrackHandleBase.h
- graphics/VP1/VP1Systems/VP1TrackSystems/src/TrackHandleBase.cxx
- graphics/VP1/VP1Systems/VP1TrackSystems/src/VP1TrackSystem.cxx
Adding @goetz ,@rosati ,@wleight ,@gavrilen ,@nkoehler ,@amorley ,@rbianchi as watchers
added review-pending-level-1 label and removed review-user-action-required label
- Resolved by Stephen Nicholas Swatman
CI Result SUCCESS (hash e178aba1)Athena AthSimulation AthGeneration AnalysisBase externals cmake make required tests optional tests Full details available on this CI monitor view
Athena: number of compilation errors 0, warnings 0
AthSimulation: number of compilation errors 0, warnings 0
AthGeneration: number of compilation errors 0, warnings 0
AnalysisBase: number of compilation errors 0, warnings 0
For experts only: Jenkins output [CI-MERGE-REQUEST-CC7 23280]
added review-approved label and removed review-pending-level-1 label
mentioned in commit 167c61c0
added sweep:ignore label
mentioned in merge request !38348 (merged)