Change element name to fix ROOT parser#51
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughElement keys in ChangesElement Key Renaming Fix
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
❌ prek hooks failed |
There was a problem hiding this comment.
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 `@src/SHiPMaterials.cpp`:
- Around line 39-83: `createElements()` in `SHiPMaterials` now registers only
the suffixed `_E` keys, but `getElement()` is still documented and likely used
with unsuffixed names such as “Nitrogen” and “Oxygen”. Add compatibility aliases
in `createElements()` (or otherwise normalize lookups in `getElement()`) so both
the old documented names and the new `_E` names resolve to the same
`GeoElement`, and keep the public contract consistent with existing consumers.
🪄 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: aeed46f5-a5ea-42b4-9507-3b275bb34718
📒 Files selected for processing (2)
CHANGELOG.mdsrc/SHiPMaterials.cpp
| m_elements["Hydrogen_E"] = new GeoElement( | ||
| "Hydrogen_E", "H", 1, 1.008 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Helium_E"] = new GeoElement( | ||
| "Helium_E", "He", 2, 4.003 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Carbon_E"] = new GeoElement( | ||
| "Carbon_E", "C", 6, 12.011 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Nitrogen_E"] = new GeoElement( | ||
| "Nitrogen_E", "N", 7, 14.007 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Oxygen_E"] = new GeoElement( | ||
| "Oxygen_E", "O", 8, 15.999 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Silicon_E"] = new GeoElement( | ||
| "Silicon_E", "Si", 14, 28.085 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Argon_E"] = new GeoElement( | ||
| "Argon_E", "Ar", 18, 39.948 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Calcium_E"] = new GeoElement( | ||
| "Calcium_E", "Ca", 20, 40.078 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Titanium_E"] = new GeoElement( | ||
| "Titanium_E", "Ti", 22, 47.867 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Chromium_E"] = new GeoElement( | ||
| "Chromium_E", "Cr", 24, 51.996 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Manganese_E"] = new GeoElement( | ||
| "Manganese_E", "Mn", 25, 54.938 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Iron_E"] = new GeoElement( | ||
| "Iron_E", "Fe", 26, 55.845 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Nickel_E"] = new GeoElement( | ||
| "Nickel_E", "Ni", 28, 58.693 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Copper_E"] = new GeoElement( | ||
| "Copper_E", "Cu", 29, 63.546 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Niobium_E"] = new GeoElement( | ||
| "Niobium_E", "Nb", 41, 92.906 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Molybdenum_E"] = new GeoElement( | ||
| "Molybdenum_E", "Mo", 42, 95.95 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Tantalum_E"] = new GeoElement( | ||
| "Tantalum_E", "Ta", 73, 180.948 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Tungsten_E"] = new GeoElement( | ||
| "Tungsten_E", "W", 74, 183.84 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
|
|
||
| // Aluminium | ||
| m_elements["Aluminium"] = new GeoElement( | ||
| "Aluminium", "Al", 13.0, 26.982 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| m_elements["Aluminium_E"] = new GeoElement( | ||
| "Aluminium_E", "Al", 13.0, 26.982 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
|
|
||
| // Lead | ||
| m_elements["Lead"] = new GeoElement("Lead", "Pb", 82.0, | ||
| m_elements["Lead_E"] = new GeoElement("Lead_E", "Pb", 82.0, | ||
| 207.2 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole); | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Verify direct callers still using documented unsuffixed element names.
rg -n -P '\bgetElement\s*\(\s*"(Hydrogen|Helium|Carbon|Nitrogen|Oxygen|Silicon|Argon|Calcium|Titanium|Chromium|Manganese|Iron|Nickel|Copper|Niobium|Molybdenum|Tantalum|Tungsten|Aluminium|Lead)"\s*\)' . || true
# Verify public docs/examples were updated with the new element naming contract.
rg -n 'Element name \(e\.g\., "Nitrogen", "Oxygen"\)|getElement\(.*Nitrogen' include/SHiPGeometry/SHiPMaterials.h || trueRepository: ShipSoft/Geometry
Length of output: 219
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the public API and nearby implementation.
ast-grep outline include/SHiPGeometry/SHiPMaterials.h --view expanded || true
ast-grep outline src/SHiPMaterials.cpp --view expanded || true
# Find all getElement call sites and the element keys used in this module.
rg -n '\bgetElement\s*\(' . || true
rg -n '"[A-Za-z]+(_E)?"' src/SHiPMaterials.cpp include/SHiPGeometry/SHiPMaterials.h || trueRepository: ShipSoft/Geometry
Length of output: 10584
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Find explicit unsuffixed element lookups and any compatibility layer.
rg -n '"(Hydrogen|Helium|Carbon|Nitrogen|Oxygen|Silicon|Argon|Calcium|Titanium|Chromium|Manganese|Iron|Nickel|Copper|Niobium|Molybdenum|Tantalum|Tungsten|Aluminium|Lead)"' . || true
rg -n 'm_elements\.find|m_elements\[' src/SHiPMaterials.cpp include/SHiPGeometry/SHiPMaterials.h || trueRepository: ShipSoft/Geometry
Length of output: 9667
Keep getElement() compatible with the documented names
createElements() now stores only _E keys, but include/SHiPGeometry/SHiPMaterials.h still documents unsuffixed lookups like getElement("Nitrogen") and getElement("Oxygen"). Keep aliases for the old names or update the contract and all consumers together.
🧰 Tools
🪛 GitHub Actions: Lint / 0_prek _ prek.txt
[error] 78-80: Prek hook 'clang-format' failed. Files were modified by this hook. Run 'prek run --all-files' locally to apply clang-format changes.
🪛 GitHub Actions: Lint / prek _ prek
[error] 78-81: pre-commit hook 'clang-format' failed: files were modified by this hook. The CI run did not include formatted changes. Diff indicates clang-format reflowed the GeoElement construction for m_elements["Lead_E"].
🤖 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 `@src/SHiPMaterials.cpp` around lines 39 - 83, `createElements()` in
`SHiPMaterials` now registers only the suffixed `_E` keys, but `getElement()` is
still documented and likely used with unsuffixed names such as “Nitrogen” and
“Oxygen”. Add compatibility aliases in `createElements()` (or otherwise
normalize lookups in `getElement()`) so both the old documented names and the
new `_E` names resolve to the same `GeoElement`, and keep the public contract
consistent with existing consumers.
|
No need to update the change log manually, for all the new repos we generate the change log automatically from the commit messages (which is why it's even more important to write proper commit messages!) |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
This will be fixed upstream: root-project/root#22834 We have at least two documented workarounds, I'd prefer not to change our software here. |
Hello,
The ROOT GDML parser does not read correctly the materials having the same names as the elements. I see empty mixtures, without any element.
This makes the material transparent when gevgen_fnal uses ROOT to import our geometry.
By changing the element name (here I just added a _E to all elements, but any naming convention can be used), the issue is fixed:
I link also the reference to GDML parser used in ROOT, since it may guide us in understanding what causes the issue in the first place: https://root.cern/doc/master/classTGDMLParse.html#a0cc936290c83a556baf53f0478bbf794
All the best,
Antonio
Summary by CodeRabbit
Bug Fixes
Documentation