-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(sim): Add check for multiple sensitive volumes with same name #1596
base: dev
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe changes in this pull request involve modifications to the Changes
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
fairroot/base/sim/FairModule.cxx (1)
283-289
: Consider adding debug logging for duplicate volumes.Adding debug logging when a duplicate volume is found would help with troubleshooting without impacting performance.
if (!vList->findObject(volName)) { auto addedVol = vList->addVolume(std::make_unique<FairVolume>(volName, fNbOfVolumes)); if (!addedVol) { + LOG(debug2) << "Failed to add volume " << volName << " to the volume list"; return; } ++fNbOfVolumes; RegisterSensitiveVolume(*addedVol); +} else { + LOG(debug2) << "Skipping duplicate volume " << volName; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
fairroot/base/sim/FairModule.cxx
(1 hunks)
🔇 Additional comments (2)
fairroot/base/sim/FairModule.cxx (2)
283-289
: LGTM! The implementation effectively prevents duplicate volume registration.
The changes correctly address the issue by:
- Checking for existing volumes before adding
- Using modern C++ practices with smart pointers
- Properly handling the failure case
283-289
: Verify impact on existing detector configurations.
Let's analyze the usage patterns of AddSensitiveVolume
across detectors to ensure this change doesn't break existing configurations.
✅ Verification successful
Change is safe for existing detector configurations
The analysis of AddSensitiveVolume
usage patterns shows that the change is safe because:
- All detector implementations follow a consistent pattern where volumes are first created and added to the geometry tree, then registered as sensitive volumes via
AddSensitiveVolume
. - No detector implementation attempts to register the same volume multiple times, which is the scenario this change protects against.
- The change maintains backward compatibility by:
- Still allowing registration of new volumes
- Only preventing duplicate registrations
- Incrementing volume counter only for successful additions
The usage patterns in template detectors and examples confirm that the new duplicate-prevention logic aligns with existing detector implementation practices.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Analyze AddSensitiveVolume usage patterns across detectors
# Find all detector implementations
echo "=== Detector implementations ==="
rg -l "class.*:.*public.*FairDetector"
# Find AddSensitiveVolume calls
echo -e "\n=== AddSensitiveVolume usage patterns ==="
rg -B 2 -A 2 "AddSensitiveVolume\("
# Look for potential duplicate volume registrations
echo -e "\n=== Potential duplicate volume patterns ==="
ast-grep --pattern 'AddSensitiveVolume($VOLUME)'
Length of output: 12575
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strong veto.
e351b22
to
43fc099
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
fairroot/base/sim/FairVolumeList.cxx (1)
Line range hint
26-45
: Consider improving error handling for duplicate volumesThe current implementation silently returns
nullptr
for duplicate volumes, which could lead to subtle runtime issues if the caller doesn't properly handle the null case. Consider:
- Making the duplicate volume case more explicit in the method's signature
- Adding documentation about the nullptr return case
- Considering whether debug level is appropriate for duplicate volumes, as this might indicate a configuration issue
Here's a suggested improvement:
+ /** + * Add a volume to the list. + * @param vol The volume to add (takes ownership) + * @return Pointer to the added volume, or nullptr if a volume with the same name already exists + */ FairVolume* FairVolumeList::addVolume(std::unique_ptr<FairVolume> vol) { auto vol_found = findObject(vol->GetName()); if (vol_found) { - LOG(debug) << "FairVolumeList element: " << vol->GetName() << " VolId : " << vol->getVolumeId() - << " already defined " << vol_found->getVolumeId(); + LOG(warning) << "Duplicate volume name detected: " << vol->GetName() + << " (new_id=" << vol->getVolumeId() + << ", existing_id=" << vol_found->getVolumeId() << ")"; return nullptr; }
Note: All current users of If the current behaviour is okay, then please rephrase your commit message. |
43fc099
to
ee84b67
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
fairroot/base/sim/FairModule.cxx (1)
285-286
: Consider adding documentation about volume name handling.Since both transport engines and FairRoot allow multiple nodes with the same volume name, it would be helpful to add a comment explaining this behavior above the debug message. This would help future maintainers understand why duplicate volumes are logged at debug level rather than being treated as errors.
Consider adding a comment like this:
void FairModule::AddSensitiveVolume(TGeoVolume* vol) { auto volName = vol->GetName(); LOG(debug2) << "AddSensitiveVolume " << volName; auto addedVol = vList->addVolume(std::make_unique<FairVolume>(volName, fNbOfVolumes)); if (!addedVol) { + // Both transport engines and FairRoot allow multiple nodes with same volume name + // as part of copy mechanism, so we log duplicates at debug level LOG(debug) << "FairVolumeList element: " << vol->GetName() << " VolId : " << vol->getVolumeId() << " already defined " << vol_found->getVolumeId() << "// vol = " << vol; return; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
fairroot/base/sim/FairModule.cxx
(1 hunks)fairroot/base/sim/FairVolumeList.cxx
(0 hunks)
💤 Files with no reviewable changes (1)
- fairroot/base/sim/FairVolumeList.cxx
🔇 Additional comments (1)
fairroot/base/sim/FairModule.cxx (1)
285-286
: LGTM! The debug logging aligns with the PR objectives.
The change to use LOG(debug)
for duplicate volume names is appropriate and matches the discussed approach. This maintains the functionality while making the logging less intrusive.
Let's verify the impact on simulation workflows by checking for any existing error handling patterns:
✅ Verification successful
Let me gather more information about the volume handling and logging patterns to verify this change thoroughly.
Let me check the test file and related volume handling code to make a final determination.
Based on the test implementation and FairVolumeList code, I can now make a definitive assessment:
The debug logging for duplicate volumes is appropriate and safe
The code change is verified to be correct because:
- The test suite explicitly verifies that duplicate volumes are handled gracefully by returning nullptr
- FairVolumeList's implementation shows that duplicate volumes are intentionally rejected
- The debug log message provides valuable diagnostic information without affecting the control flow
- This aligns with the existing pattern where volume-related logging is done at debug level in detector implementations
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check how duplicate volumes are handled in simulation workflows
rg -A 3 "FairVolumeList.*addVolume"
Length of output: 308
Script:
#!/bin/bash
# Check for volume-related error handling and logging patterns
rg -A 5 "LOG\((debug|info|warn|error).*volume" --type cpp
# Check the FairVolumeList implementation
ast-grep --pattern 'class FairVolumeList {
$$$
addVolume($$$) {
$$$
}
$$$
}'
# Check for volume-related tests
fd "test.*volume" --type f
Length of output: 4175
Script:
#!/bin/bash
# Check the volume list test implementation
cat tests/base/sim/test_FairVolumeList.cxx
# Check the actual implementation of volume handling
cat fairroot/base/sim/FairVolumeList.cxx
# Look for any related error handling patterns
rg -A 3 "duplicate.*volume|volume.*duplicate" --type cpp
Length of output: 3408
ee84b67
to
3fcd915
Compare
I have changed the behavior of the check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some ideas.
3fcd915
to
718e712
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now.
Maybe one could move the LOG(debug) as an else branch of the LOG(fatal), but really, I don't care much.
Please take a look at the clang-format messages from the CI.
@dennisklein might have some ideas?
The transport engines allow registering of multiple nodes with the same volume/same volume name (copy mechanism). In `FairRoot` this mechanism works provided unique volume name over the whole geometry setup of different detectors. The commit clarifies the situtation: 1. for same volume names in one detector, it quenches the log message by moving `LOG` and changing it severity from `LOG(error)` in `FairVolumeList::addVolume()` to `LOG(debug)` in `FairModule::AddSensitiveVolume()`. 2. for same volume names accross different detectors, the program prints appropriate `LOG(fatal)`. Fixes the issue FairRootGroup#1595.
718e712
to
033996f
Compare
Both the transport engines and FairRoot allow registering of multiple nodes with the same volume/same volume name (copy mechanism). However currently such workflow logs errors from
FairVolumeList::addVolume()
.The commit reintroduces the check for same volume names into the
FairModule::AddSensitiveVolume()
function thus preventing registration of copy volumes.Fixes the issue #1595.
Checklist: