Skip to content

Commit c920cca

Browse files
refactor(Base): Move FairModule::fAllSensitiveVolumes to FairRunSim
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.
1 parent 23a39ba commit c920cca

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

fairroot/base/sim/FairDetector.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "FairGeoNode.h" // for FairGeoNode
1616
#include "FairRootManager.h"
17+
#include "FairRunSim.h"
1718
#include "FairVolume.h" // for FairVolume
1819

1920
#include <TFolder.h> // for TFolder
@@ -97,7 +98,7 @@ void FairDetector::Initialize()
9798
FairGeoNode* fN;
9899
TString cutName;
99100
TString copysign = "#";
100-
for (auto aVol : fAllSensitiveVolumes) {
101+
for (auto aVol : GetRunSim().RangeAllSensitiveVolumes()) {
101102
cutName = aVol->GetName();
102103
Ssiz_t pos = cutName.Index(copysign, 1);
103104
if (pos > 1) {

fairroot/base/sim/FairMCApplication.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ void FairMCApplication::InitGeometry()
880880
fMCEventHeader->SetRunID(runId);
881881

882882
// Fill sensitive volumes in fVolMap
883-
for (auto fv : FairModule::fAllSensitiveVolumes) {
883+
for (auto fv : fRun->RangeAllSensitiveVolumes()) {
884884
if (!fv) {
885885
continue;
886886
}

fairroot/base/sim/FairModule.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
#include <memory>
5353
#include <tuple> // for std::ignore
5454

55-
thread_local std::vector<FairVolume*> FairModule::fAllSensitiveVolumes;
56-
5755
void FairModule::ConstructGeometry()
5856
{
5957
LOG(warn)
@@ -216,9 +214,10 @@ void FairModule::SetGeometryFileName(TString fname, TString)
216214

217215
void FairModule::RegisterSensitiveVolume(FairVolume& vol)
218216
{
217+
assert(fRunSim);
219218
vol.setModId(fModId);
220219
vol.SetModule(this);
221-
fAllSensitiveVolumes.push_back(&vol);
220+
fRunSim->RegisterSensitiveVolume(vol);
222221
++fNbOfSensitiveVol;
223222
}
224223

@@ -277,6 +276,7 @@ void FairModule::ProcessNodes(TList* nodes)
277276

278277
void FairModule::AddSensitiveVolume(TGeoVolume* vol)
279278
{
279+
assert(vol);
280280
auto volName = vol->GetName();
281281
LOG(debug2) << "AddSensitiveVolume " << volName;
282282

fairroot/base/sim/FairModule.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
#include <TList.h> // for TList (ptr only), TListIter
2424
#include <TNamed.h> // for TNamed
2525
#include <TObjArray.h> // for TObjArray
26-
#include <TRefArray.h> // for TRefArray
2726
#include <TString.h> // for TString, operator!=
2827
#include <TVirtualMC.h>
28+
#include <cassert>
2929
#include <fairlogger/Logger.h>
3030
#include <string>
3131
#include <type_traits>
@@ -144,10 +144,6 @@ class FairModule : public TNamed
144144
static thread_local inline FairVolumeList* vList{nullptr}; //!
145145
/**total number of volumes in a simulaion session*/
146146
static thread_local inline Int_t fNbOfVolumes{0}; //!
147-
/**
148-
* For internal use only: list of all sensitive volumes in a simulaion session
149-
*/
150-
static thread_local std::vector<FairVolume*> fAllSensitiveVolumes; //!
151147

152148
TString fMotherVolumeName{""}; //!
153149
/**
@@ -195,6 +191,16 @@ class FairModule : public TNamed
195191
*/
196192
FairRootManager& GetRootManager();
197193

194+
/**
195+
* \brief Get RunSim of this Module
196+
* \note Only valid after being added to a RunSim
197+
*/
198+
FairRunSim& GetRunSim()
199+
{
200+
assert(fRunSim);
201+
return *fRunSim;
202+
}
203+
198204
/**
199205
* \brief Get Geometry Loader
200206
* \note Only valid during ConstructGeometry

fairroot/base/steer/FairRunSim.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
#include <functional>
2222
#include <memory>
2323
#include <utility>
24+
#include <vector>
2425

2526
class FairField;
2627
class FairGeoLoader;
2728
class FairMCEventHeader;
2829
class FairMesh;
2930
class FairModule;
3031
class FairPrimaryGenerator;
32+
class FairVolume;
3133

3234
/**
3335
* \brief Configure the Simulation session
@@ -223,6 +225,15 @@ class FairRunSim : public FairRun
223225

224226
void ls(Option_t* option = "") const override;
225227

228+
/**
229+
* \brief Internal: Add Sensitive Volume
230+
*/
231+
void RegisterSensitiveVolume(FairVolume& vol) { fAllSensitiveVolumes.push_back(&vol); }
232+
/**
233+
* \brief Internal: Iterate over all sensitive Volumes
234+
*/
235+
auto const& RangeAllSensitiveVolumes() const { return fAllSensitiveVolumes; }
236+
226237
private:
227238
FairRunSim(const FairRunSim& M);
228239
FairRunSim& operator=(const FairRunSim&) { return *this; }
@@ -239,6 +250,11 @@ class FairRunSim : public FairRun
239250

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

253+
/**
254+
* For internal use only: list of all sensitive volumes in a simulaion session
255+
*/
256+
std::vector<FairVolume*> fAllSensitiveVolumes; //!
257+
242258
protected:
243259
Int_t count{0}; //!< Internal counter
244260
FairMCApplication* fApp{nullptr}; //!< Main VMC application

0 commit comments

Comments
 (0)