Skip to content

Commit

Permalink
Use std containers for FairModule::svList
Browse files Browse the repository at this point in the history
FairModule::svList can very well be implemented using
std::vector without all the casting.

And rename to `fAllSensitiveVolumes`.
  • Loading branch information
ChristianTackeGSI committed Mar 8, 2024
1 parent a3dbb00 commit 5b24a7e
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 41 deletions.
7 changes: 2 additions & 5 deletions fairroot/base/sim/FairDetector.cxx
Original file line number Diff line number Diff line change
@@ -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, *
Expand All @@ -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

Expand Down Expand Up @@ -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<FairVolume*>(svList->At(i));
for (auto aVol : fAllSensitiveVolumes) {
cutName = aVol->GetName();
Ssiz_t pos = cutName.Index(copysign, 1);
if (pos > 1) {
Expand Down
8 changes: 2 additions & 6 deletions fairroot/base/sim/FairMCApplication.cxx
Original file line number Diff line number Diff line change
@@ -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, *
Expand Down Expand Up @@ -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<FairVolume>(sen_volumes)) {
for (auto fv : FairModule::fAllSensitiveVolumes) {
if (!fv) {
LOG(error) << "Not a FairVolume in FairModule::svList";
continue;
}
auto id = fv->getMCid();
Expand Down
21 changes: 5 additions & 16 deletions fairroot/base/sim/FairModule.cxx
Original file line number Diff line number Diff line change
@@ -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, *
Expand Down Expand Up @@ -47,6 +47,8 @@
#include <map>
#include <memory>

thread_local std::vector<FairVolume*> FairModule::fAllSensitiveVolumes;

void FairModule::ConstructGeometry()
{
LOG(warn)
Expand All @@ -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();
}
Expand All @@ -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++) {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<FairGeoVolume*>(node);
fNodes->AddLast(aVol);
fNbOfSensitiveVol++;
Expand All @@ -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++;
}
}
Expand Down
5 changes: 3 additions & 2 deletions fairroot/base/sim/FairModule.h
Original file line number Diff line number Diff line change
@@ -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, *
Expand All @@ -26,6 +26,7 @@
#include <TString.h> // for TString, operator!=
#include <TVirtualMC.h>
#include <string>
#include <vector>

class FairVolumeList;
class FairVolume;
Expand Down Expand Up @@ -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<FairVolume*> fAllSensitiveVolumes; //!

TString fMotherVolumeName{""}; //!
FairVolume* getFairVolume(FairGeoNode* fNode);
Expand Down
4 changes: 1 addition & 3 deletions templates/NewDetector_root_containers/NewDetector.cxx
Original file line number Diff line number Diff line change
@@ -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, *
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 1 addition & 3 deletions templates/NewDetector_stl_containers/NewDetector.cxx
Original file line number Diff line number Diff line change
@@ -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, *
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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, *
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 1 addition & 3 deletions templates/project_stl_containers/NewDetector/NewDetector.cxx
Original file line number Diff line number Diff line change
@@ -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, *
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 5b24a7e

Please sign in to comment.