Skip to content

Cppcheck 2.20#4268

Merged
pinkenburg merged 15 commits into
sPHENIX-Collaboration:masterfrom
pinkenburg:cppcheck-2.20
May 19, 2026
Merged

Cppcheck 2.20#4268
pinkenburg merged 15 commits into
sPHENIX-Collaboration:masterfrom
pinkenburg:cppcheck-2.20

Conversation

@pinkenburg
Copy link
Copy Markdown
Contributor

@pinkenburg pinkenburg commented May 18, 2026

Types of changes

  • [X ] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work for users)
  • Requiring change in macros repository (Please provide links to the macros pull request in the last section)
  • I am a member of GitHub organization of sPHENIX Collaboration, EIC, or ECCE (contact Chris Pinkenburg to join)

What kind of change does this PR introduce? (Bug fix, feature, ...)

This PR fixes the warnings from the new cppcheck version before we switch

TODOs (if applicable)

Links to other PRs in macros and calibration repositories (if applicable)

Summary

This PR applies targeted fixes across the codebase to address warnings raised by cppcheck 2.20 and to modernize some C++ usage. Changes are intended as non-breaking quality/maintenance fixes (casts, formatting, small refactors, safer initializations) rather than new features or algorithmic changes.

Motivation / context

Prepare the repository for adoption of cppcheck 2.20 and reduce static-analysis noise by correcting or silencing flagged issues. The edits adopt safer, well-defined C++ idioms (C++20 where used) and improve code clarity for future maintenance.

Key changes

  • Modernized formatting and casts:
    • Replaced boost::format with C++20 std::format for histogram name construction (ClusterCDFCalculator).
    • Replaced C-style casts with static_cast and std::bit_cast where appropriate (examples: PHSimpleKFProp, JetProbeMaker, PixelData, PHG4GDMLWrite Xerces-LS calls).
  • Logging and string streaming:
    • Many log/error messages now stream std::string objects directly instead of using .c_str().
  • Initialization and safety:
    • Value-initialized GBTWord::data8 byte array to zeros to avoid uninitialized memory.
    • Replaced C-style cast of a vector reference with static_cast in mvtx::ChipPixelData::getData().
  • API/implementation cleanups:
    • Move/inline small implementations (MvtxEventInfov2 getter moved inline in header).
    • Change trivial destructor to = default (JetProbeMaker).
    • Remove End(PHCompositeNode*) override from PHSimpleKFProp and corresponding declaration.
    • Several local-variable changes in PHSimpleKFProp: pointer vs value bindings, passing index/distance buffers via .data(), use of std::bit_cast for cluster key extraction.
  • Minor refactors and whitespace/formatting changes across multiple files.

Potential risk areas

  • Build/toolchain:
    • std::format and std::bit_cast require C++20; CI/toolchains must support C++20 (libstdc++/libc++ and compiler). Verify build configurations and packaging.
  • Semantic/behavior risks:
    • GBTWord::data8 zero-initialization changes default content of previously uninitialized memory. This is generally safer but could alter behavior of low-level decoding or code that (incorrectly) depended on indeterminate values—careful testing recommended.
    • Replacing pointer-reinterpretation with std::bit_cast is well-defined in C++20, but reviewers should confirm bit-level compatibility with prior behavior (endian/size assumptions).
    • Moving the MvtxEventInfov2 getter inline or changing copy/reference semantics should be checked for ABI/caller expectations.
    • Removing the PHSimpleKFProp::End override may affect code relying on that override to run cleanup—verify higher-level control flow.
  • Thread-safety/performance:
    • No deliberate threading or algorithmic changes were made, but small changes (e.g., copying vs moving finalchain in PHSimpleKFProp) could impact performance or memory behavior in hot code paths—spot-check performance-critical paths.
  • IO/reconstruction:
    • No intentional IO format or reconstruction-algorithm changes, but reviewers should validate histograms/name lookups (ClusterCDFCalculator) and KD-tree/cluster-key reconstruction codepaths.

Suggested follow-ups / possible future improvements

  • Enable cppcheck 2.20 in CI and run it repository-wide to catch remaining issues early.
  • Add unit/integration tests for low-level decoding and KD-tree/cluster-key reconstruction to detect regressions from initialization or reinterpretation changes.
  • Verify and document C++20 requirement in build/CI configs; consider feature-gating if older toolchains must be supported.
  • Audit any remaining cppcheck suppressions and document rationale for future maintainers.

Note: This summary was produced with AI assistance. While file-level patterns and risks are reported based on the provided diffs and repository listing, automated analysis can make mistakes—please validate changes in code review (especially zero-initialization and bit-cast/reinterpretation areas).

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4c168ce1-3f76-4091-9cb6-b54f9d68bef5

📥 Commits

Reviewing files that changed from the base of the PR and between ccda0f6 and 9fbf5e3.

📒 Files selected for processing (2)
  • offline/packages/trackreco/PHSimpleKFProp.cc
  • offline/packages/trackreco/PHSimpleKFProp.h

📝 Walkthrough

Walkthrough

This PR modernizes C++ usage across the codebase: swaps minimal ROOT includes for Rtypes.h, removes redundant .c_str() calls in logging, migrates boost::format to std::format, replaces unsafe C-style casts with static_cast/std::bit_cast, and value-initializes MVTX word storage.

Changes

C++ Modernization and Cleanup

Layer / File(s) Summary
ROOT header include updates
calibrations/calorimeter/calo_tower_slope/LiteCaloEval.cc, calibrations/framework/fun4cal/Fun4CalServer.cc
RtypesCore.h is replaced with Rtypes.h to use the full ROOT numeric type header.
String output modernization in logging statements
calibrations/calorimeter/calo_tower_slope/LiteCaloEval.cc, calibrations/framework/fun4cal/Fun4CalServer.cc, offline/QA/SimulationModules/QAG4SimulationKFParticle.cc, offline/framework/fun4all/Fun4AllHistoManager.cc, offline/framework/fun4allraw/mvtx_decoder/GBTLink.h, offline/packages/CaloReco/CaloTowerStatus.cc, offline/packages/trackreco/PHTrackPruner.cc, simulation/g4simulation/g4main/PHG4ProcessMap.cc
Log and error messages now stream std::string objects directly instead of calling .c_str().
ClusterCDFCalculator: std::format migration
offline/packages/CaloReco/ClusterCDFCalculator.cc
Replace boost::format with C++20 std::format for histogram name construction and use those strings with ROOT GetObject and error messages.
MVTX decoder: value-init and safer casts
offline/framework/fun4allraw/mvtx_decoder/GBTWord.h, offline/framework/fun4allraw/mvtx_decoder/PixelData.h
GBTWord::data8 is value-initialized (zeroed) and ChipPixelData::getData() uses static_cast to return a mutable reference to mPixels.
Cast modernizations and bit_cast usage
offline/packages/jetbase/JetProbeMaker.cc, offline/packages/trackreco/PHSimpleKFProp.cc, simulation/g4simulation/g4gdml/PHG4GDMLWrite.cc
Replace C-style casts with static_cast; use std::bit_cast to reinterpret KD-tree payload to int64_t; update Xerces DOM casts to static_cast.
PHSimpleKFProp: refactors and API adjustments
offline/packages/trackreco/PHSimpleKFProp.{h,cc}
Internal refactors: include <bit>, change local bindings to pointer/reference where appropriate, adjust thread-local insertion from move to copy, update knnSearch argument passing, remove End(PHCompositeNode*) definition, and update method parameter names in the header.
JetProbeMaker, MvtxEventInfov2, and small tidyups
offline/packages/jetbase/JetProbeMaker.h, offline/packages/jetbase/JetProbeMaker.cc, offline/packages/trackbase/MvtxEventInfov2.{h,cc}
Default JetProbeMaker destructor, minor include/formatting adjustments, and move get_strobe_BCOs() implementation inline in the header.

Possibly related PRs:


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
offline/QA/SimulationModules/QAG4SimulationKFParticle.cc (1)

79-79: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Critical bug: checking wrong variable in error path.

Line 79 checks !m_trackMap but should check !m_truthInfo. The m_truthInfo pointer was just assigned at line 78, and m_trackMap was already validated at lines 72-76. This causes incorrect error reporting and prevents proper validation of the G4TruthInfo node.

🐛 Proposed fix
   m_truthInfo = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
-  if (!m_trackMap)
+  if (!m_truthInfo)
   {
     std::cout << __PRETTY_FUNCTION__ << " Fatal Error : missing G4TruthInfo" << std::endl;
     return Fun4AllReturnCodes::ABORTRUN;

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0797d61c-6193-41bd-9fe7-05e5f446712d

📥 Commits

Reviewing files that changed from the base of the PR and between 3381348 and e3be839.

📒 Files selected for processing (7)
  • calibrations/calorimeter/calo_tower_slope/LiteCaloEval.cc
  • calibrations/framework/fun4cal/Fun4CalServer.cc
  • offline/QA/SimulationModules/QAG4SimulationKFParticle.cc
  • offline/framework/fun4all/Fun4AllHistoManager.cc
  • offline/framework/fun4allraw/mvtx_decoder/GBTLink.h
  • offline/framework/fun4allraw/mvtx_decoder/GBTWord.h
  • offline/framework/fun4allraw/mvtx_decoder/PixelData.h

Comment thread offline/framework/fun4allraw/mvtx_decoder/GBTWord.h Outdated
Comment thread offline/framework/fun4allraw/mvtx_decoder/PixelData.h Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
offline/packages/trackreco/PHSimpleKFProp.cc (1)

52-57: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add the required <bit> header for std::bit_cast.

std::bit_cast at line 916 is used without the <bit> include, which will fail on stricter/non-transitive builds. The header is missing from the standard library includes at lines 52–57.

Proposed fix
 `#include` <cmath>
+#include <bit>
 `#include` <filesystem>
 `#include` <iostream>
 `#include` <syncstream>
 `#include` <vector>

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2c672798-02c8-47fd-82c2-f1746db0b791

📥 Commits

Reviewing files that changed from the base of the PR and between e3be839 and ccda0f6.

📒 Files selected for processing (12)
  • offline/framework/fun4allraw/mvtx_decoder/GBTWord.h
  • offline/framework/fun4allraw/mvtx_decoder/PixelData.h
  • offline/packages/CaloReco/CaloTowerStatus.cc
  • offline/packages/CaloReco/ClusterCDFCalculator.cc
  • offline/packages/jetbase/JetProbeMaker.cc
  • offline/packages/jetbase/JetProbeMaker.h
  • offline/packages/trackbase/MvtxEventInfov2.cc
  • offline/packages/trackbase/MvtxEventInfov2.h
  • offline/packages/trackreco/PHSimpleKFProp.cc
  • offline/packages/trackreco/PHTrackPruner.cc
  • simulation/g4simulation/g4gdml/PHG4GDMLWrite.cc
  • simulation/g4simulation/g4main/PHG4ProcessMap.cc
💤 Files with no reviewable changes (1)
  • offline/packages/trackbase/MvtxEventInfov2.cc
✅ Files skipped from review due to trivial changes (5)
  • offline/packages/jetbase/JetProbeMaker.h
  • offline/packages/trackreco/PHTrackPruner.cc
  • offline/packages/CaloReco/CaloTowerStatus.cc
  • simulation/g4simulation/g4gdml/PHG4GDMLWrite.cc
  • simulation/g4simulation/g4main/PHG4ProcessMap.cc
🚧 Files skipped from review as they are similar to previous changes (1)
  • offline/framework/fun4allraw/mvtx_decoder/PixelData.h

Comment thread offline/packages/CaloReco/ClusterCDFCalculator.cc
@sphenix-jenkins-ci
Copy link
Copy Markdown

Build & test report

Report for commit e3be83949f9af91f12fe0dd878c3db838ba392a4:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@sphenix-jenkins-ci
Copy link
Copy Markdown

Build & test report

Report for commit ccda0f6ebb2aea7e38355a162d7ae24543b5270b:
Jenkins passed


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@sphenix-jenkins-ci
Copy link
Copy Markdown

Build & test report

Report for commit 9fbf5e37b658f86de3704f5423b508d0aef0cef3:
Jenkins on fire


Automatically generated by sPHENIX Jenkins continuous integration
sPHENIX             jenkins.io

@pinkenburg
Copy link
Copy Markdown
Contributor Author

pinkenburg commented May 19, 2026

the valgrind error is from a cdb failure (not from this PR but in general not good, let's see if this happens more frequently)

@pinkenburg pinkenburg merged commit b4822c3 into sPHENIX-Collaboration:master May 19, 2026
18 of 22 checks passed
@pinkenburg pinkenburg deleted the cppcheck-2.20 branch May 19, 2026 01:11
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