From 5b24a7eb9919c8a7b9ce9f1a60fa9892cf82fcf7 Mon Sep 17 00:00:00 2001 From: Christian Tacke <58549698+ChristianTackeGSI@users.noreply.github.com> Date: Fri, 8 Mar 2024 14:14:47 +0100 Subject: [PATCH] Use std containers for FairModule::svList FairModule::svList can very well be implemented using std::vector without all the casting. And rename to `fAllSensitiveVolumes`. --- fairroot/base/sim/FairDetector.cxx | 7 ++----- fairroot/base/sim/FairMCApplication.cxx | 8 ++----- fairroot/base/sim/FairModule.cxx | 21 +++++-------------- fairroot/base/sim/FairModule.h | 5 +++-- .../NewDetector.cxx | 4 +--- .../NewDetector.cxx | 4 +--- .../NewDetector/NewDetector.cxx | 4 +--- .../NewDetector/NewDetector.cxx | 4 +--- 8 files changed, 16 insertions(+), 41 deletions(-) diff --git a/fairroot/base/sim/FairDetector.cxx b/fairroot/base/sim/FairDetector.cxx index 0cb1f07184..e8642ca45d 100644 --- a/fairroot/base/sim/FairDetector.cxx +++ b/fairroot/base/sim/FairDetector.cxx @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -13,7 +13,6 @@ #include "FairDetector.h" #include "FairGeoNode.h" // for FairGeoNode -#include "FairModule.h" // for FairModule::svList, etc #include "FairRootManager.h" #include "FairVolume.h" // for FairVolume @@ -94,13 +93,11 @@ void FairDetector::Initialize() DefineSensitiveVolumes(); } - Int_t NoOfEntries = svList->GetEntries(); Int_t fMCid; FairGeoNode* fN; TString cutName; TString copysign = "#"; - for (Int_t i = 0; i < NoOfEntries; i++) { - FairVolume* aVol = static_cast(svList->At(i)); + for (auto aVol : fAllSensitiveVolumes) { cutName = aVol->GetName(); Ssiz_t pos = cutName.Index(copysign, 1); if (pos > 1) { diff --git a/fairroot/base/sim/FairMCApplication.cxx b/fairroot/base/sim/FairMCApplication.cxx index bf6a673a7c..fdd412b698 100644 --- a/fairroot/base/sim/FairMCApplication.cxx +++ b/fairroot/base/sim/FairMCApplication.cxx @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -885,13 +885,9 @@ void FairMCApplication::InitGeometry() } fMCEventHeader->SetRunID(runId); - // Get static thread local svList - auto sen_volumes = FairModule::svList; - // Fill sensitive volumes in fVolMap - for (auto fv : TRangeDynCast(sen_volumes)) { + for (auto fv : FairModule::fAllSensitiveVolumes) { if (!fv) { - LOG(error) << "Not a FairVolume in FairModule::svList"; continue; } auto id = fv->getMCid(); diff --git a/fairroot/base/sim/FairModule.cxx b/fairroot/base/sim/FairModule.cxx index a8c19e334d..b741f547fe 100644 --- a/fairroot/base/sim/FairModule.cxx +++ b/fairroot/base/sim/FairModule.cxx @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -47,6 +47,8 @@ #include #include +thread_local std::vector FairModule::fAllSensitiveVolumes; + void FairModule::ConstructGeometry() { LOG(warn) @@ -65,9 +67,6 @@ FairModule::FairModule(const char* Name, const char* title, Bool_t Active) : TNamed(Name, title) , fActive(Active) { - if (!svList) { - svList = new TRefArray(); - } if (!vList) { vList = new FairVolumeList(); } @@ -84,13 +83,6 @@ FairModule::FairModule(const FairModule& rhs) , fVerboseLevel(rhs.fVerboseLevel) , fGeoSaved(rhs.fGeoSaved) { - if (!svList) { - svList = new TRefArray(); - for (Int_t i = 0; i < rhs.svList->GetEntries(); i++) { - svList->Add(rhs.svList->At(i)); - } - } - if (!vList) { vList = new FairVolumeList(); for (Int_t i = 0; i < rhs.vList->getEntries(); i++) { @@ -218,9 +210,6 @@ void FairModule::ProcessNodes(TList* aList) from ConstructGeometry() of your detector class. Aborting..."; } - if (!svList) { - svList = new TRefArray(); - } if (!vList) { vList = new FairVolumeList(); } @@ -251,7 +240,7 @@ void FairModule::ProcessNodes(TList* aList) if (node->isSensitive() && fActive) { volume->setModId(fModId); volume->SetModule(this); - svList->Add(volume); + fAllSensitiveVolumes.push_back(volume); aVol = dynamic_cast(node); fNodes->AddLast(aVol); fNbOfSensitiveVol++; @@ -271,7 +260,7 @@ void FairModule::AddSensitiveVolume(TGeoVolume* v) vList->addVolume(volume); volume->setModId(fModId); volume->SetModule(this); - svList->Add(volume); + fAllSensitiveVolumes.push_back(volume); fNbOfSensitiveVol++; } } diff --git a/fairroot/base/sim/FairModule.h b/fairroot/base/sim/FairModule.h index 1d968eaed7..cb129bebb1 100644 --- a/fairroot/base/sim/FairModule.h +++ b/fairroot/base/sim/FairModule.h @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -26,6 +26,7 @@ #include // for TString, operator!= #include #include +#include class FairVolumeList; class FairVolume; @@ -139,7 +140,7 @@ class FairModule : public TNamed /**total number of volumes in a simulaion session*/ static thread_local inline Int_t fNbOfVolumes{0}; //! /**list of all sensitive volumes in a simulaion session*/ - static thread_local inline TRefArray* svList{nullptr}; //! + static thread_local std::vector fAllSensitiveVolumes; //! TString fMotherVolumeName{""}; //! FairVolume* getFairVolume(FairGeoNode* fNode); diff --git a/templates/NewDetector_root_containers/NewDetector.cxx b/templates/NewDetector_root_containers/NewDetector.cxx index 8a4df885b8..2cad86e1ba 100644 --- a/templates/NewDetector_root_containers/NewDetector.cxx +++ b/templates/NewDetector_root_containers/NewDetector.cxx @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -81,8 +81,6 @@ void NewDetector::Initialize() { /** * WORKAROUND needed for Geant4 in MT mode - * Call AddSensitiveVolume for sensitive volumes in order to fill - * thread-local FairModule::svList. */ DefineSensitiveVolumes(); diff --git a/templates/NewDetector_stl_containers/NewDetector.cxx b/templates/NewDetector_stl_containers/NewDetector.cxx index f3dea85cd7..19d3ad6cba 100644 --- a/templates/NewDetector_stl_containers/NewDetector.cxx +++ b/templates/NewDetector_stl_containers/NewDetector.cxx @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -80,8 +80,6 @@ void NewDetector::Initialize() { /** * WORKAROUND needed for Geant4 in MT mode - * Call AddSensitiveVolume for sensitive volumes in order to fill - * thread-local FairModule::svList. */ DefineSensitiveVolumes(); diff --git a/templates/project_root_containers/NewDetector/NewDetector.cxx b/templates/project_root_containers/NewDetector/NewDetector.cxx index 4e6acd2b02..1d5189e052 100644 --- a/templates/project_root_containers/NewDetector/NewDetector.cxx +++ b/templates/project_root_containers/NewDetector/NewDetector.cxx @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -81,8 +81,6 @@ void NewDetector::Initialize() { /** * WORKAROUND needed for Geant4 in MT mode - * Call AddSensitiveVolume for sensitive volumes in order to fill - * thread-local FairModule::svList. */ DefineSensitiveVolumes(); diff --git a/templates/project_stl_containers/NewDetector/NewDetector.cxx b/templates/project_stl_containers/NewDetector/NewDetector.cxx index 9f498aebae..fcd48dbb5d 100644 --- a/templates/project_stl_containers/NewDetector/NewDetector.cxx +++ b/templates/project_stl_containers/NewDetector/NewDetector.cxx @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -80,8 +80,6 @@ void NewDetector::Initialize() { /** * WORKAROUND needed for Geant4 in MT mode - * Call AddSensitiveVolume for sensitive volumes in order to fill - * thread-local FairModule::svList. */ DefineSensitiveVolumes();