Skip to content

Commit

Permalink
chore: Move FairModule::fAllSensitiveVolumes to FairRunSim
Browse files Browse the repository at this point in the history
Instead of using a thread local, let's use something that
is tied to the "simulaion session" (as noted in some places).

FairRunSim has all the Modules anyway, so let it also have
the list of sensitive Volumes.
  • Loading branch information
ChristianTackeGSI committed Jun 10, 2024
1 parent 32bb52f commit 1d4a1e4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion fairroot/base/sim/FairDetector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "FairGeoNode.h" // for FairGeoNode
#include "FairRootManager.h"
#include "FairRunSim.h"
#include "FairVolume.h" // for FairVolume

#include <TFolder.h> // for TFolder
Expand Down Expand Up @@ -97,7 +98,7 @@ void FairDetector::Initialize()
FairGeoNode* fN;
TString cutName;
TString copysign = "#";
for (auto aVol : fAllSensitiveVolumes) {
for (auto aVol : FairRunSim::Instance()->fAllSensitiveVolumes) {
cutName = aVol->GetName();
Ssiz_t pos = cutName.Index(copysign, 1);
if (pos > 1) {
Expand Down
2 changes: 1 addition & 1 deletion fairroot/base/sim/FairMCApplication.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ void FairMCApplication::InitGeometry()
fMCEventHeader->SetRunID(runId);

// Fill sensitive volumes in fVolMap
for (auto fv : FairModule::fAllSensitiveVolumes) {
for (auto fv : fRun->fAllSensitiveVolumes) {
if (!fv) {
continue;
}
Expand Down
15 changes: 7 additions & 8 deletions fairroot/base/sim/FairModule.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "FairGeoNode.h" // for FairGeoNode
#include "FairGeoParSet.h" // for FairBaseParSet
#include "FairMCApplication.h"
#include "FairRun.h" // for FairRun
#include "FairRunSim.h" // for FairRun, FairRunSim
#include "FairRuntimeDb.h" // for FairRuntimeDb
#include "FairVolume.h" // for FairVolume
#include "FairVolumeList.h" // for FairVolumeList
Expand Down Expand Up @@ -50,8 +50,6 @@
#include <memory>
#include <tuple> // for std::ignore

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

void FairModule::ConstructGeometry()
{
LOG(warn)
Expand Down Expand Up @@ -200,11 +198,11 @@ void FairModule::SetGeometryFileName(TString fname, TString)
fgeoName = "";
}

void FairModule::RegisterSensitiveVolume(FairVolume& vol)
void FairModule::RegisterSensitiveVolume(FairRunSim& run, FairVolume& vol)
{
vol.setModId(fModId);
vol.SetModule(this);
fAllSensitiveVolumes.push_back(&vol);
run.fAllSensitiveVolumes.push_back(&vol);
++fNbOfSensitiveVol;
}

Expand All @@ -221,7 +219,8 @@ void FairModule::ProcessNodes(TList* nodes)
vList = new FairVolumeList();
}

auto rtdb = FairRun::Instance()->GetRuntimeDb();
auto& run = *(FairRunSim::Instance());
auto rtdb = run.GetRuntimeDb();
auto par = static_cast<FairGeoParSet*>(rtdb->getContainer("FairGeoParSet"));
TSeqCollection* parNodes = par->GetGeoNodes();
for (auto node : TRangeDynCast<FairGeoNode>(nodes)) {
Expand Down Expand Up @@ -251,7 +250,7 @@ void FairModule::ProcessNodes(TList* nodes)
}

if (node->isSensitive() && fActive) {
RegisterSensitiveVolume(*addedVol);
RegisterSensitiveVolume(run, *addedVol);
parNodes->AddLast(node);
}
}
Expand All @@ -267,7 +266,7 @@ void FairModule::AddSensitiveVolume(TGeoVolume* vol)
return;
}
++fNbOfVolumes;
RegisterSensitiveVolume(*addedVol);
RegisterSensitiveVolume(*FairRunSim::Instance(), *addedVol);
}

FairVolume* FairModule::getFairVolume(FairGeoNode* fN)
Expand Down
7 changes: 2 additions & 5 deletions fairroot/base/sim/FairModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
#include <TList.h> // for TList (ptr only), TListIter
#include <TNamed.h> // for TNamed
#include <TObjArray.h> // for TObjArray
#include <TRefArray.h> // for TRefArray
#include <TString.h> // for TString, operator!=
#include <TVirtualMC.h>
#include <string>
#include <vector>

class FairRunSim;
class FairVolumeList;
class FairVolume;

Expand Down Expand Up @@ -140,8 +139,6 @@ class FairModule : public TNamed
static thread_local inline FairVolumeList* vList{nullptr}; //!
/**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 std::vector<FairVolume*> fAllSensitiveVolumes; //!

TString fMotherVolumeName{""}; //!
/**
Expand All @@ -159,7 +156,7 @@ class FairModule : public TNamed
void ReAssignMediaId();
void swap(FairModule& other) throw();

void RegisterSensitiveVolume(FairVolume&);
void RegisterSensitiveVolume(FairRunSim& run, FairVolume&);

protected:
FairModule(const FairModule&);
Expand Down
9 changes: 9 additions & 0 deletions fairroot/base/steer/FairRunSim.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
#include <functional>
#include <memory>
#include <utility>
#include <vector>

class FairField;
class FairGeoLoader;
class FairMCEventHeader;
class FairMesh;
class FairModule;
class FairPrimaryGenerator;
class FairVolume;

/**
* \brief Configure the Simulation session
Expand All @@ -38,6 +40,10 @@ class FairPrimaryGenerator;
*/
class FairRunSim : public FairRun
{
friend class FairModule;
friend class FairDetector;
friend class FairMCApplication;

public:
/** default ctor*/
FairRunSim(Bool_t isMaster = kTRUE);
Expand Down Expand Up @@ -226,6 +232,9 @@ class FairRunSim : public FairRun

std::unique_ptr<FairGeoLoader> fGeoLoader; //!

/**list of all sensitive volumes in a simulaion session*/
std::vector<FairVolume*> fAllSensitiveVolumes; //!

protected:
Int_t count{0}; //!< Internal counter
FairMCApplication* fApp{nullptr}; //!< Main VMC application
Expand Down

0 comments on commit 1d4a1e4

Please sign in to comment.