Skip to content

fix(shipgen): make tPythia6Generator concrete again (#1272)#1274

Merged
olantwin merged 1 commit into
masterfrom
fix/1272-tpythia6-abstract
Jun 22, 2026
Merged

fix(shipgen): make tPythia6Generator concrete again (#1272)#1274
olantwin merged 1 commit into
masterfrom
fix/1272-tpythia6-abstract

Conversation

@olantwin

@olantwin olantwin commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • tPythia6Generator became abstract in 26.02 when it was reparented onto SHiP::Generator (which has pure-virtual file-based Init overloads) without stub overrides; cppyy correctly refuses to instantiate it, breaking makeCascade.py and the Pythia6 branch of run_simScript.py. Add the stub Init(const char*) / Init(const char*, int) pair that the other generators use.
  • Closes tpythia6Generator error in makeCascade.py #1272.

Test plan

  • pixi run build succeeds
  • python -c "import ROOT; ROOT.gSystem.Load('libShipGen'); ROOT.tPythia6Generator()" constructs cleanly (was TypeError: cannot instantiate abstract class)
  • makeCascade.py-style sequence (TDatabasePDG, TPythia6, tPythia6Generator, SetMom, SetTarget) runs past the reported failure site
  • Reporter confirmation on a real makeCascade.py run

Follow-up

The sibling class Pythia6Generator (no t) had the same latent abstract-class bug but is unused (zero callsites anywhere in the tree, no substantive commit since 2008). A separate PR will remove it rather than fix it.

Summary by CodeRabbit

Bug Fixes

  • Restored Pythia6Generator instantiation from Python, which was broken following a previous refactor.
  • Added file-based initialization method overloads accepting input filenames and optional event indices; methods currently unsupported but prevent crashes.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4006aef7-df3e-41f1-82fc-aae21412692c

📥 Commits

Reviewing files that changed from the base of the PR and between 5980486 and 7b1c64a.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • shipgen/tPythia6Generator.h
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • shipgen/tPythia6Generator.h

📝 Walkthrough

Walkthrough

Adds two inline Init overrides (Init(const char*) and Init(const char*, int)) to tPythia6Generator in shipgen/tPythia6Generator.h, along with a FairLogger.h include. Both overloads log a warning and delegate to the parameterless Init(). A changelog entry records the fix.

Changes

tPythia6Generator Python instantiation fix

Layer / File(s) Summary
Inline Init overrides and changelog
shipgen/tPythia6Generator.h, CHANGELOG.md
Adds FairLogger.h include and two inline Init overrides to tPythia6Generator: the single-argument form calls the two-argument form with startEvent=0, and the two-argument form emits a warning then falls back to parameterless Init(), making the class concrete and instantiable from Python. The changelog records the fix under Unreleased → Fixed.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested reviewers

  • mesmith75
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing tPythia6Generator to be concrete again by addressing issue #1272.
Description check ✅ Passed The PR description is well-structured, explains the root cause, test plan, and follow-up work. It aligns with the provided template requirements.
Linked Issues check ✅ Passed The PR successfully addresses issue #1272 by implementing stub Init overloads to make tPythia6Generator concrete, allowing instantiation from Python as required.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the abstract class issue in tPythia6Generator. The CHANGELOG and header file modifications are appropriately scoped to address the linked issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1272-tpythia6-abstract

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@shipgen/Pythia6Generator.h`:
- Around line 100-105: The Init method with startEvent parameter in
Pythia6Generator class is using FairGenerator::Init() as the fallback, but this
differs from the established pattern in Pythia8Generator and other related
generator classes which use Init() instead. Change the return statement in the
Pythia6Generator::Init(const char* inFile, int startEvent) override method to
call Init() directly rather than FairGenerator::Init() to maintain consistency
with the pattern established in Pythia8Generator, tPythia6Generator,
ParticleGunGenerator, HNLPythia8Generator, FixedTargetGenerator, and
DPPythia8Generator.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 61061471-9f44-4b3e-8de6-036a9588bb39

📥 Commits

Reviewing files that changed from the base of the PR and between 9b50035 and 5980486.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • shipgen/Pythia6Generator.h
  • shipgen/tPythia6Generator.h

Comment thread shipgen/Pythia6Generator.h Outdated
Comment on lines +100 to +105
Bool_t Init(const char* inFile) override { return Init(inFile, 0); };
Bool_t Init(const char* inFile, int startEvent) override {
LOG(warning) << "Init with files not implemented for Pythia6Generator. "
"Using default Init() instead";
return FairGenerator::Init();
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check Init override pattern in Pythia8Generator and similar classes

# Search for Init overrides with file parameters in generator classes
rg -nP -A5 'Bool_t\s+Init\s*\(\s*const\s+char\*.*\)\s*override' --glob '*.h' --glob '*.cxx'

# Specifically look for Pythia8Generator Init implementation
rg -nP -A10 'class\s+Pythia8Generator' --glob '*.h' | rg -A10 'Init'

Repository: ShipSoft/FairShip

Length of output: 7263


Fallback Init call differs from Pythia8Generator pattern.

The PR claims to match Pythia8Generator's pattern, but there's a key difference: Pythia6Generator calls FairGenerator::Init() while Pythia8Generator (and most other generators like tPythia6Generator, ParticleGunGenerator, HNLPythia8Generator, FixedTargetGenerator, and DPPythia8Generator) call Init(). Both approaches have identical warning messages and delegation strategies, but the fallback is inconsistent. Verify whether FairGenerator::Init() is intentional for Pythia6Generator or if it should align with the established Init() pattern used by Pythia8Generator and related classes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shipgen/Pythia6Generator.h` around lines 100 - 105, The Init method with
startEvent parameter in Pythia6Generator class is using FairGenerator::Init() as
the fallback, but this differs from the established pattern in Pythia8Generator
and other related generator classes which use Init() instead. Change the return
statement in the Pythia6Generator::Init(const char* inFile, int startEvent)
override method to call Init() directly rather than FairGenerator::Init() to
maintain consistency with the pattern established in Pythia8Generator,
tPythia6Generator, ParticleGunGenerator, HNLPythia8Generator,
FixedTargetGenerator, and DPPythia8Generator.

@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

CI Plots

View all plots

fixed-target

pixi

PlaneHA20011 PlaneHA21011 PlaneHA22011 PlaneHA10011 PlaneHA11011 PlaneHA12011 PlaneHA20012 PlaneHA21012 PlaneHA22012 PlaneHA10012 PlaneHA11012 PlaneHA12012 PlaneHA20013 PlaneHA21013 PlaneHA22013 PlaneHA10013 PlaneHA11013 PlaneHA12013 PlaneHA20014 PlaneHA21014 PlaneHA22014 PlaneHA10014 PlaneHA11014 PlaneHA12014 PlaneHA20015 PlaneHA21015 PlaneHA22015 PlaneHA10015 PlaneHA11015 PlaneHA12015 PlaneHA20016 PlaneHA21016 PlaneHA22016 PlaneHA10016 PlaneHA11016 PlaneHA12016 PlaneHA20017 PlaneHA21017 PlaneHA22017 PlaneHA10017 PlaneHA11017 PlaneHA12017 PlaneHA10022 PlaneHA11022 PlaneHA12022 PlaneHA10111 PlaneHA11111 PlaneHA12111 PlaneHA10221 PlaneHA11221 PlaneHA12221 PlaneHA10223 PlaneHA11223 PlaneHA12223 PlaneHA10331 PlaneHA11331 PlaneHA12331

sim-chain

helium-all-TRY_2025

distu distv disty nmeas chi2 delPOverP pullPOverPx pullPOverPy pullPOverPz delPOverP2 delPOverPz delPOverP2z chi2 prob IP Vzresol Vxresol Vyresol Vzpull Vxpull Vypull Doca IP0 HNL IP0_pi0 HNL_pi0 HNLw meas meas2 measVSchi2 distu distv disty meanhits extrapTimeDetX extrapTimeDetY oa nrtracks nrSBT pi0Mass delPOverPz_py delPOverP2z_py pullPOverPx_py pullPOverPy_py pullPOverPz_py

vacuums-all-TRY_2025

distu distv disty nmeas chi2 delPOverP pullPOverPx pullPOverPy pullPOverPz delPOverP2 delPOverPz delPOverP2z chi2 prob IP Vzresol Vxresol Vyresol Vzpull Vxpull Vypull Doca IP0 HNL IP0_pi0 HNL_pi0 HNLw meas meas2 measVSchi2 distu distv disty meanhits extrapTimeDetX extrapTimeDetY oa nrtracks nrSBT pi0Mass delPOverPz_py delPOverP2z_py pullPOverPx_py pullPOverPy_py pullPOverPz_py

tracking-benchmark

pixi

h_dp_over_p h_dp_vs_p h_dx h_dy h_dtx h_dty h_hit_residual h_hit_pull h_chi2ndf h_p_truth h_p_matched

The SHiP::Generator base class introduced in #1047 declares two
file-based Init overloads as pure virtual. tPythia6Generator only
overrides the no-arg Init() and brings the other overloads into scope
with `using SHiP::Generator::Init;`, which is not an implementation.
The class is therefore abstract and Python (cppyy) correctly refuses
to instantiate it, breaking macro/makeCascade.py and the Pythia6
branch of macro/run_simScript.py.

Add stub overrides on tPythia6Generator that warn and fall back to
Init(), matching the pattern used by Pythia8Generator and friends.

Closes #1272
@olantwin olantwin force-pushed the fix/1272-tpythia6-abstract branch from 5980486 to 7b1c64a Compare June 22, 2026 12:43
@olantwin

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@antonioiuliano2 antonioiuliano2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perfect!
Thank you very much Oliver for this fix.
I confirm it works, the code still crashes but it's for a different reason, not related to this PR.
It looks for PDG particle -130 which does not exist, and the if _p is not None condition is not working as expected. I am now opening a new dedicated PR.
For this one, everything ok.

@olantwin olantwin merged commit bce2906 into master Jun 22, 2026
15 checks passed
@olantwin olantwin deleted the fix/1272-tpythia6-abstract branch June 22, 2026 15:32
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.

tpythia6Generator error in makeCascade.py

2 participants