From 033996f9e442f58d0329875e9a7db5a7e06761d9 Mon Sep 17 00:00:00 2001 From: Radoslaw Karabowicz Date: Fri, 22 Nov 2024 11:39:00 +0100 Subject: [PATCH] fix(sim): Clarify behaviour for same-name sensitive volumes 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 #1595. --- fairroot/base/sim/FairModule.cxx | 8 ++++---- fairroot/base/sim/FairVolumeList.cxx | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/fairroot/base/sim/FairModule.cxx b/fairroot/base/sim/FairModule.cxx index 190db6d375..11dcbd9da6 100644 --- a/fairroot/base/sim/FairModule.cxx +++ b/fairroot/base/sim/FairModule.cxx @@ -216,8 +216,6 @@ void FairModule::SetGeometryFileName(TString fname, TString) void FairModule::RegisterSensitiveVolume(FairVolume& vol) { - vol.setModId(fModId); - vol.SetModule(this); fAllSensitiveVolumes.push_back(&vol); ++fNbOfSensitiveVol; } @@ -249,7 +247,7 @@ void FairModule::ProcessNodes(TList* nodes) std::ignore = node->calcLabTransform(); auto nodeTruncName = node->getTruncName(); - auto volume = std::make_unique(nodeTruncName, fNbOfVolumes); + auto volume = std::make_unique(nodeTruncName, fNbOfVolumes, fModId, this); volume->setRealName(node->GetName()); auto addedVol = vList->addVolume(std::move(volume)); @@ -280,8 +278,10 @@ void FairModule::AddSensitiveVolume(TGeoVolume* vol) auto volName = vol->GetName(); LOG(debug2) << "AddSensitiveVolume " << volName; - auto addedVol = vList->addVolume(std::make_unique(volName, fNbOfVolumes)); + auto addedVol = vList->addVolume(std::make_unique(volName, fNbOfVolumes, fModId, this)); if (!addedVol) { + LOG(debug) << "FairModule: Trying to register element " << vol->GetName() << " for detector " << GetName() + << " failed, beacuse it was already defined"; return; } ++fNbOfVolumes; diff --git a/fairroot/base/sim/FairVolumeList.cxx b/fairroot/base/sim/FairVolumeList.cxx index 519cd9b39f..e6b8c9cb08 100644 --- a/fairroot/base/sim/FairVolumeList.cxx +++ b/fairroot/base/sim/FairVolumeList.cxx @@ -12,6 +12,9 @@ #include "FairVolumeList.h" +#include "FairDetector.h" +#include "FairVolume.h" + FairVolume* FairVolumeList::getVolume(const TString& name) { auto obj = findObject(name); @@ -35,8 +38,13 @@ FairVolume* FairVolumeList::addVolume(std::unique_ptr vol) auto vol_found = findObject(vol->GetName()); if (vol_found) { - LOG(error) << "FairVolumeList element: " << vol->GetName() << " VolId : " << vol->getVolumeId() - << " already defined " << vol_found->getVolumeId(); + // FATAL: The same volume name for different detectors + if (vol->GetDetector() != vol_found->GetDetector()) { + LOG(fatal) << "FairVolumeList Trying to register element: " << vol->GetName() + << " (VolId=" << vol->getVolumeId() << ") for detector " << vol->GetDetector()->GetName() + << ", but it was already defined (VolId=" << vol_found->getVolumeId() << ") for detector " + << vol_found->GetDetector()->GetName(); + } return nullptr; }