Skip to content

Commit 54ad232

Browse files
ChristianTackeGSIdennisklein
authored andcommitted
Use std containers for FairModule::svList
FairModule::svList can very well be implemented using std::vector without all the casting. And rename to `fAllSensitiveVolumes`.
1 parent a3dbb00 commit 54ad232

8 files changed

Lines changed: 16 additions & 41 deletions

File tree

fairroot/base/sim/FairDetector.cxx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
2+
* Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
33
* *
44
* This software is distributed under the terms of the *
55
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -13,7 +13,6 @@
1313
#include "FairDetector.h"
1414

1515
#include "FairGeoNode.h" // for FairGeoNode
16-
#include "FairModule.h" // for FairModule::svList, etc
1716
#include "FairRootManager.h"
1817
#include "FairVolume.h" // for FairVolume
1918

@@ -94,13 +93,11 @@ void FairDetector::Initialize()
9493
DefineSensitiveVolumes();
9594
}
9695

97-
Int_t NoOfEntries = svList->GetEntries();
9896
Int_t fMCid;
9997
FairGeoNode* fN;
10098
TString cutName;
10199
TString copysign = "#";
102-
for (Int_t i = 0; i < NoOfEntries; i++) {
103-
FairVolume* aVol = static_cast<FairVolume*>(svList->At(i));
100+
for (auto aVol : fAllSensitiveVolumes) {
104101
cutName = aVol->GetName();
105102
Ssiz_t pos = cutName.Index(copysign, 1);
106103
if (pos > 1) {

fairroot/base/sim/FairMCApplication.cxx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
2+
* Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
33
* *
44
* This software is distributed under the terms of the *
55
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -885,13 +885,9 @@ void FairMCApplication::InitGeometry()
885885
}
886886
fMCEventHeader->SetRunID(runId);
887887

888-
// Get static thread local svList
889-
auto sen_volumes = FairModule::svList;
890-
891888
// Fill sensitive volumes in fVolMap
892-
for (auto fv : TRangeDynCast<FairVolume>(sen_volumes)) {
889+
for (auto fv : FairModule::fAllSensitiveVolumes) {
893890
if (!fv) {
894-
LOG(error) << "Not a FairVolume in FairModule::svList";
895891
continue;
896892
}
897893
auto id = fv->getMCid();

fairroot/base/sim/FairModule.cxx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
2+
* Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
33
* *
44
* This software is distributed under the terms of the *
55
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -47,6 +47,8 @@
4747
#include <map>
4848
#include <memory>
4949

50+
thread_local std::vector<FairVolume*> FairModule::fAllSensitiveVolumes;
51+
5052
void FairModule::ConstructGeometry()
5153
{
5254
LOG(warn)
@@ -65,9 +67,6 @@ FairModule::FairModule(const char* Name, const char* title, Bool_t Active)
6567
: TNamed(Name, title)
6668
, fActive(Active)
6769
{
68-
if (!svList) {
69-
svList = new TRefArray();
70-
}
7170
if (!vList) {
7271
vList = new FairVolumeList();
7372
}
@@ -84,13 +83,6 @@ FairModule::FairModule(const FairModule& rhs)
8483
, fVerboseLevel(rhs.fVerboseLevel)
8584
, fGeoSaved(rhs.fGeoSaved)
8685
{
87-
if (!svList) {
88-
svList = new TRefArray();
89-
for (Int_t i = 0; i < rhs.svList->GetEntries(); i++) {
90-
svList->Add(rhs.svList->At(i));
91-
}
92-
}
93-
9486
if (!vList) {
9587
vList = new FairVolumeList();
9688
for (Int_t i = 0; i < rhs.vList->getEntries(); i++) {
@@ -218,9 +210,6 @@ void FairModule::ProcessNodes(TList* aList)
218210
from ConstructGeometry() of your detector class. Aborting...";
219211
}
220212

221-
if (!svList) {
222-
svList = new TRefArray();
223-
}
224213
if (!vList) {
225214
vList = new FairVolumeList();
226215
}
@@ -251,7 +240,7 @@ void FairModule::ProcessNodes(TList* aList)
251240
if (node->isSensitive() && fActive) {
252241
volume->setModId(fModId);
253242
volume->SetModule(this);
254-
svList->Add(volume);
243+
fAllSensitiveVolumes.push_back(volume);
255244
aVol = dynamic_cast<FairGeoVolume*>(node);
256245
fNodes->AddLast(aVol);
257246
fNbOfSensitiveVol++;
@@ -271,7 +260,7 @@ void FairModule::AddSensitiveVolume(TGeoVolume* v)
271260
vList->addVolume(volume);
272261
volume->setModId(fModId);
273262
volume->SetModule(this);
274-
svList->Add(volume);
263+
fAllSensitiveVolumes.push_back(volume);
275264
fNbOfSensitiveVol++;
276265
}
277266
}

fairroot/base/sim/FairModule.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
2+
* Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
33
* *
44
* This software is distributed under the terms of the *
55
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -26,6 +26,7 @@
2626
#include <TString.h> // for TString, operator!=
2727
#include <TVirtualMC.h>
2828
#include <string>
29+
#include <vector>
2930

3031
class FairVolumeList;
3132
class FairVolume;
@@ -139,7 +140,7 @@ class FairModule : public TNamed
139140
/**total number of volumes in a simulaion session*/
140141
static thread_local inline Int_t fNbOfVolumes{0}; //!
141142
/**list of all sensitive volumes in a simulaion session*/
142-
static thread_local inline TRefArray* svList{nullptr}; //!
143+
static thread_local std::vector<FairVolume*> fAllSensitiveVolumes; //!
143144

144145
TString fMotherVolumeName{""}; //!
145146
FairVolume* getFairVolume(FairGeoNode* fNode);

templates/NewDetector_root_containers/NewDetector.cxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
2+
* Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
33
* *
44
* This software is distributed under the terms of the *
55
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -81,8 +81,6 @@ void NewDetector::Initialize()
8181
{
8282
/**
8383
* WORKAROUND needed for Geant4 in MT mode
84-
* Call AddSensitiveVolume for sensitive volumes in order to fill
85-
* thread-local FairModule::svList.
8684
*/
8785
DefineSensitiveVolumes();
8886

templates/NewDetector_stl_containers/NewDetector.cxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
2+
* Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
33
* *
44
* This software is distributed under the terms of the *
55
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -80,8 +80,6 @@ void NewDetector::Initialize()
8080
{
8181
/**
8282
* WORKAROUND needed for Geant4 in MT mode
83-
* Call AddSensitiveVolume for sensitive volumes in order to fill
84-
* thread-local FairModule::svList.
8583
*/
8684
DefineSensitiveVolumes();
8785

templates/project_root_containers/NewDetector/NewDetector.cxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
2+
* Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
33
* *
44
* This software is distributed under the terms of the *
55
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -81,8 +81,6 @@ void NewDetector::Initialize()
8181
{
8282
/**
8383
* WORKAROUND needed for Geant4 in MT mode
84-
* Call AddSensitiveVolume for sensitive volumes in order to fill
85-
* thread-local FairModule::svList.
8684
*/
8785
DefineSensitiveVolumes();
8886

templates/project_stl_containers/NewDetector/NewDetector.cxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/********************************************************************************
2-
* Copyright (C) 2014-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
2+
* Copyright (C) 2014-2024 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
33
* *
44
* This software is distributed under the terms of the *
55
* GNU Lesser General Public Licence (LGPL) version 3, *
@@ -80,8 +80,6 @@ void NewDetector::Initialize()
8080
{
8181
/**
8282
* WORKAROUND needed for Geant4 in MT mode
83-
* Call AddSensitiveVolume for sensitive volumes in order to fill
84-
* thread-local FairModule::svList.
8583
*/
8684
DefineSensitiveVolumes();
8785

0 commit comments

Comments
 (0)