Skip to content

Format network values as Athena does for C++26, and use C++23 ranges, views and deducing this - #215

Merged
jbeirer merged 3 commits into
mainfrom
athena-backport-cxx23
Nov 24, 2026
Merged

jbeirer merged 3 commits into
mainfrom
athena-backport-cxx23

Conversation

@jbeirer

@jbeirer jbeirer commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Athena changes not yet in this library

I compared every non-merge commit on Athena main since March 2024 (the classes were copied in #4, April 2024) that touches Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimEvent, ISF_FastCaloSimParametrization or G4CaloTransportTool, 127 commits listed through the GitLab API, against this library. The local Athena clone is shallow, so the API was used for the older history.

All functional fixes are already here, mostly through #106 and the later reviews:

  • the ATLASSIM-7031 series up to 0ab6c22 (fixHists: SetDirectory(nullptr) and kIsOnHeap cleared on the GAN binning histograms, called from the chain streamer; MarkTObjectAsNotOnHeap from 85dd89c),
  • the TFile and libxml2 leak fixes, the GAN mutex, the robust TFCSGANXMLParameters parsing (ff06de0, 27589b8),
  • the TFCSHitCellMappingWiggle re-initialisation (ae5455f),
  • the division-by-zero guards (1fb7cc5), the null element check in the chain streamer (a7be9da),
  • the transport stop on a failed LocateGlobalPointAndSetup (f11ba0f, f7545f8).

The remaining Athena commits are cppcheck/coverity/style changes that the modernisation PRs here already cover or supersede, Athena-only code (FastCaloSimCaloTransportation, the SDs, XMLCoreParser, DataVector constructors, configuration), or the Athena geometry and extrapolation, which this library replaced.

Not yet here: b3077d3 ("c++26 compatibility"). VNetworkBase formats the network inputs and outputs with std::to_string(double), whose output changes in C++26 (shortest representation instead of %f). Athena now uses std::format("{:f}", ...). This PR does the same, so the output stays identical with C++23 and keeps it identical in C++26.

C++23

All of the following is available in the oldest standard library of the CI (GCC 14 in the Alma 10 and Ubuntu 24 images). Range formatting (std::format("{}", vector)) is not, so it is not used.

  • Deducing this replaces the const/non-const accessor pairs with one accessor each, auto name(this auto&& self) -> auto& { return self.member; } (const or not as the object; std::forward_like is not used because clang-tidy 18 of the Ubuntu 24 image cannot parse it): TFCS1DFunctionInt32Histogram and TFCS1DFunctionTemplateHistogram (get_HistoBordersx, and get_HistoContents of the template), TFCS2DFunctionHistogram (get_HistoBordersx/y), TFCSHistoLateralShapeParametrization::histogram, the chain() of TFCSParametrizationChain and TFCSLateralShapeParametrizationHitChain, Cell::raw. Call sites do not change (Athena main-FCSExternal uses none of them). The ROOT dictionary and the interpreter (C++23, as required by CMakeLists.txt) accept them.
  • std::views::pairwise for the track segments in CylinderExtrapolation.cxx (crossCylinder, extrapolateWithClosestApproach): the consecutive track points instead of track[i - 1], track[i]; the last segment is &end == &track.back().
  • std::views::zip for parallel containers instead of a shared index: the input and output nodes of TFCSONNXHandler (names, shapes, values, tensors, sizes), layer energies and scale factors in TFCSEnergyRenormalization, the PCA layer fractions with their layers, the nearest R-tree entries with their distances, wiggle histograms with their functions, duplicate mothers with their indices in RemoveDuplicates (which also no longer copies each map entry with its vectors).
  • std::ranges::to and std::views::transform/take/keys: log(Ekin) in the energy interpolations, the scaled PCA layer fractions.
  • std::ranges::contains in LayerRoles::is_strip_layer.

Index loops that need a std::size_t index were kept: std::views::enumerate gives a signed index, which would need casts. Not used: std::mdspan (not in the GCC 14 standard library of the CI), std::expected (an error-handling change of the loader interfaces, for a separate PR), monadic std::optional and fold_left (the candidates are short and clearer as they are).

Two print fixes found on the way (log output only):

  • TFCSSimulationState::Print looped i < m_E.size() over the layer energies, which are stored by layer ID. It now prints all of them in order, and with the = that was missing (E2=123 instead of E2123).
  • TFCSExtrapolationState::Print labelled every sub-position MID.

No persistent member, class version or simulation result changes.

Checks

Against main (73c5cc7):

  • GCC 15 (LCG_110, developer build, incl. dictionary): 0 warnings; ctest 128/128 passed, incl. the unchanged AtlasTransportTests and AtlasSimTests references
  • AtlasBenchmark dump (BENCH_N=50): byte-identical to main
  • SliceCheck on the MC23 file TFCSparam_dev_Hybrid_Ha_v5_all_baryons_0_500.root (BENCH_N=20): byte-identical to main, max RSS 4.75 GB on both
  • Timing, AtlasBenchmark pinned to one core each, 3 runs with the cores swapped: 1.0042 of main (runs 1.0024, 1.0059, 1.0044), within the core-to-core noise seen before; the first version without the extrapolation and ONNX loops measured 0.9998
  • clang-format 20.1.8, codespell
  • GCC 16 and Clang 22 with the CI flags: 0 warnings
  • Alma 10 ci-linux (GCC 14 standard library, clang-tidy 21, cppcheck): 0 warnings; its ctest 128/128 passed
  • Ubuntu 24 ci-linux (clang-tidy 18): 0 warnings; its ctest 128/128 passed (the first version failed here on std::forward_like, fixed)

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PR replaces several const and mutable accessor overloads with forwarding accessors, updates indexed loops to use C++ ranges, and changes selected simulation and network output formatting.

Changes: C++ accessor and range updates

Layer / File(s) Summary
Forwarding member accessors
include/FastCaloSim/Core/TFCS1DFunctionInt32Histogram.h, include/FastCaloSim/Core/TFCS1DFunctionTemplateHistogram.h, include/FastCaloSim/Core/TFCS2DFunctionHistogram.h, include/FastCaloSim/Core/TFCSHistoLateralShapeParametrization.h, include/FastCaloSim/Core/TFCSLateralShapeParametrizationHitChain.h, include/FastCaloSim/Core/TFCSParametrizationChain.h, include/FastCaloSim/Geometry/Cell.h
These accessors now use explicit-object parameters and preserve the receiver’s constness and value category when returning members.
Range-based energy processing
source/Core/TFCSEnergyInterpolationPiecewiseLinear.cxx, source/Core/TFCSEnergyInterpolationSpline.cxx, source/Core/TFCSEnergyRenormalization.cxx, source/Core/TFCSPCAEnergyParametrization.cxx
Energy conversions and parametrization loops use spans, transforms, structured bindings, and zipped traversal.
Range-based geometry and parametrization traversal
include/FastCaloSim/Geometry/LayerRoles.h, source/Core/TFCSHitCellMappingWiggle.cxx, source/Core/TFCSParametrizationBase.cxx, source/Geometry/RTree.cxx
Layer membership and loops for histogram mapping, duplicate replacement, and nearest-entry selection use ranges-based operations.
Simulation and network output
source/Core/TFCSExtrapolationState.cxx, source/Core/TFCSSimulationState.cxx, source/Core/VNetworkBase.cxx
Simulation-state printing sorts actual layer IDs. Network values use floating-point formatting, and extrapolation output removes the MID label.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Merge Risk: Minimal · up to 6cfd8

This change modernizes accessors and loops, and makes network-value formatting stable under C++26. It also fixes two log-output issues. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two main parts of the change: network-value formatting changed to std::format("{:f}") for C++26 compatibility, and the adoption of C++23 ranges, views, and deducing this. The raw s…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the two main parts of the change: network-value formatting changed to std::format("{:f}") for C++26 compatibility, and the adoption of C++23 ranges, views, and deducing this. The raw summary confirms both parts: VNetworkBase.cxx switches to std::format, and many accessors move to deducing this and ranges/views. The title is long, but it describes real, primary changes and is not misleading.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f5899c61-c1b3-40a0-b35e-134815d33410
Commits

Reviewing files that changed from the base of the PR and between 73c5cc7 and 6cfd8be.

Files selected for processing: 18

  • include/FastCaloSim/Core/TFCS1DFunctionInt32Histogram.h
  • include/FastCaloSim/Core/TFCS1DFunctionTemplateHistogram.h
  • include/FastCaloSim/Core/TFCS2DFunctionHistogram.h
  • include/FastCaloSim/Core/TFCSHistoLateralShapeParametrization.h
  • include/FastCaloSim/Core/TFCSLateralShapeParametrizationHitChain.h
  • include/FastCaloSim/Core/TFCSParametrizationChain.h
  • include/FastCaloSim/Geometry/Cell.h
  • include/FastCaloSim/Geometry/LayerRoles.h
  • source/Core/TFCSEnergyInterpolationPiecewiseLinear.cxx
  • source/Core/TFCSEnergyInterpolationSpline.cxx
  • source/Core/TFCSEnergyRenormalization.cxx
  • source/Core/TFCSExtrapolationState.cxx
  • source/Core/TFCSHitCellMappingWiggle.cxx
  • source/Core/TFCSPCAEnergyParametrization.cxx
  • source/Core/TFCSParametrizationBase.cxx
  • source/Core/TFCSSimulationState.cxx
  • source/Core/VNetworkBase.cxx
  • source/Geometry/RTree.cxx

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@jbeirer
jbeirer merged commit d7859da into main Nov 24, 2026
16 checks passed
@jbeirer
jbeirer deleted the athena-backport-cxx23 branch November 24, 2026 10:35
@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 37.80488% with 51 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
source/Core/TFCSONNXHandler.cxx 0.00% 20 Missing ⚠️
source/Core/TFCSHitCellMappingWiggle.cxx 0.00% 8 Missing ⚠️
source/Core/TFCSSimulationState.cxx 0.00% 5 Missing ⚠️
...ce/Core/TFCSEnergyInterpolationPiecewiseLinear.cxx 0.00% 4 Missing ⚠️
source/Core/TFCSEnergyInterpolationSpline.cxx 0.00% 4 Missing ⚠️
source/Core/TFCSParametrizationBase.cxx 0.00% 4 Missing ⚠️
source/Core/TFCSEnergyRenormalization.cxx 66.66% 3 Missing ⚠️
source/Core/VNetworkBase.cxx 0.00% 2 Missing ⚠️
...Sim/Core/TFCSLateralShapeParametrizationHitChain.h 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
...de/FastCaloSim/Core/TFCS1DFunctionInt32Histogram.h 92.30% <100.00%> (-0.55%) ⬇️
...FastCaloSim/Core/TFCS1DFunctionTemplateHistogram.h 0.00% <ø> (ø)
include/FastCaloSim/Core/TFCS2DFunctionHistogram.h 93.33% <100.00%> (-0.79%) ⬇️
...aloSim/Core/TFCSHistoLateralShapeParametrization.h 80.00% <100.00%> (-3.34%) ⬇️
...nclude/FastCaloSim/Core/TFCSParametrizationChain.h 84.21% <100.00%> (-0.79%) ⬇️
include/FastCaloSim/Geometry/Cell.h 95.00% <100.00%> (-0.07%) ⬇️
include/FastCaloSim/Geometry/LayerRoles.h 100.00% <100.00%> (ø)
source/Core/TFCSExtrapolationState.cxx 64.70% <ø> (ø)
source/Core/TFCSPCAEnergyParametrization.cxx 46.66% <100.00%> (ø)
source/Extrapolation/CylinderExtrapolation.cxx 71.80% <100.00%> (-0.74%) ⬇️
... and 10 more

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant