Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std containers for FairModule::svList #1499

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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