diff --git a/fairroot/base/sim/FairModule.cxx b/fairroot/base/sim/FairModule.cxx index 397a72157f..b4389662fc 100644 --- a/fairroot/base/sim/FairModule.cxx +++ b/fairroot/base/sim/FairModule.cxx @@ -246,18 +246,19 @@ void FairModule::ProcessNodes(TList* aList) void FairModule::AddSensitiveVolume(TGeoVolume* v) { - LOG(debug2) << "AddSensitiveVolume " << v->GetName(); + auto vol_name = v->GetName(); + LOG(debug2) << "AddSensitiveVolume " << vol_name; + + auto volume = std::make_unique(vol_name, fNbOfVolumes); // Only register volumes which are not already registered // Otherwise the stepping will be slowed down - if (!vList->findObject(v->GetName())) { - auto volume = std::make_unique(v->GetName(), fNbOfVolumes++); - auto volume_ptr = volume.get(); - vList->addVolume(std::move(volume)); - volume_ptr->setModId(fModId); - volume_ptr->SetModule(this); - fAllSensitiveVolumes.push_back(volume_ptr); - fNbOfSensitiveVol++; + if (auto vol_added = vList->addVolume(std::move(volume)); vol_added) { + ++fNbOfVolumes; + vol_added->setModId(fModId); + vol_added->SetModule(this); + fAllSensitiveVolumes.push_back(vol_added); + ++fNbOfSensitiveVol; } } diff --git a/fairroot/base/sim/FairModule.h b/fairroot/base/sim/FairModule.h index 7ca7b11ea4..0e1ca2d3e1 100644 --- a/fairroot/base/sim/FairModule.h +++ b/fairroot/base/sim/FairModule.h @@ -147,6 +147,7 @@ class FairModule : public TNamed * \deprecated Not used anywhere, will be removed in a future release */ [[deprecated]] FairVolume* getFairVolume(FairGeoNode* fNode); + /** Takes ownership of passed volume **/ void AddSensitiveVolume(TGeoVolume* v); private: