Skip to content

Commit ccb32e5

Browse files
committed
GPU DPL Display: Avoid using global variables through shared ptr and move files to proper folders
1 parent d14d640 commit ccb32e5

4 files changed

Lines changed: 46 additions & 34 deletions

File tree

GPU/GPUTracking/Interface/GPUO2InterfaceQA.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ struct ClusterNativeAccess;
4646
namespace o2::gpu
4747
{
4848
class GPUQA;
49-
class GPUParam;
50-
class GPUO2InterfaceConfiguration;
49+
struct GPUParam;
50+
struct GPUO2InterfaceConfiguration;
5151
class GPUO2InterfaceQA
5252
{
5353
public:

GPU/Workflow/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
o2_add_executable(display
1212
COMPONENT_NAME gpu
1313
TARGETVARNAME targetName
14-
SOURCES O2GPUDPLDisplay.cxx
14+
SOURCES src/O2GPUDPLDisplay.cxx
1515
PUBLIC_LINK_LIBRARIES O2::GPUO2Interface
1616
O2::DataFormatsGlobalTracking
1717
O2::TPCFastTransformation
1818
O2::TRDBase
1919
O2::TPCReconstruction
2020
O2::GlobalTrackingWorkflowHelpers)
21+
target_include_directories(${targetName} PUBLIC "include")

GPU/Workflow/O2GPUDPLDisplay.h renamed to GPU/Workflow/include/GPUWorkflow/O2GPUDPLDisplay.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,29 @@
1111
#ifndef O2_GPU_DPL_DISPLAY_H
1212
#define O2_GPU_DPL_DISPLAY_H
1313

14-
#include "Framework/DataProcessorSpec.h"
1514
#include "ReconstructionDataFormats/GlobalTrackID.h"
1615
#include "Framework/Task.h"
16+
#include <memory>
17+
18+
namespace o2::trd
19+
{
20+
class GeometryFlat;
21+
}
22+
namespace o2::globaltracking
23+
{
24+
struct DataRequest;
25+
}
1726

1827
namespace o2::gpu
1928
{
29+
class GPUO2InterfaceDisplay;
30+
struct GPUO2InterfaceConfiguration;
31+
class TPCFastTransform;
32+
2033
class O2GPUDPLDisplaySpec : public o2::framework::Task
2134
{
2235
public:
23-
O2GPUDPLDisplaySpec(bool useMC, o2::dataformats::GlobalTrackID::mask_t trkMask, o2::dataformats::GlobalTrackID::mask_t clMask) : mUseMC(useMC), mTrkMask(trkMask), mClMask(clMask) {}
36+
O2GPUDPLDisplaySpec(bool useMC, o2::dataformats::GlobalTrackID::mask_t trkMask, o2::dataformats::GlobalTrackID::mask_t clMask, std::shared_ptr<o2::globaltracking::DataRequest> dataRequest) : mUseMC(useMC), mTrkMask(trkMask), mClMask(clMask), mDataRequest(dataRequest) {}
2437
~O2GPUDPLDisplaySpec() override = default;
2538
void init(o2::framework::InitContext& ic) final;
2639
void run(o2::framework::ProcessingContext& pc) final;
@@ -30,6 +43,11 @@ class O2GPUDPLDisplaySpec : public o2::framework::Task
3043
bool mUseMC = false;
3144
o2::dataformats::GlobalTrackID::mask_t mTrkMask;
3245
o2::dataformats::GlobalTrackID::mask_t mClMask;
46+
std::unique_ptr<GPUO2InterfaceDisplay> mDisplay;
47+
std::unique_ptr<GPUO2InterfaceConfiguration> mConfig;
48+
std::unique_ptr<TPCFastTransform> mFastTransform;
49+
std::unique_ptr<o2::trd::GeometryFlat> mTrdGeo;
50+
std::shared_ptr<o2::globaltracking::DataRequest> mDataRequest;
3351
};
3452

3553
} // namespace o2::gpu
Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// granted to it by virtue of its status as an Intergovernmental Organization
99
// or submit itself to any jurisdiction.
1010

11-
#include "O2GPUDPLDisplay.h"
11+
#include "GPUWorkflow/O2GPUDPLDisplay.h"
1212
#include "Framework/ConfigParamSpec.h"
1313
#include "DataFormatsParameters/GRPObject.h"
1414
#include "DataFormatsGlobalTracking/RecoContainer.h"
@@ -25,15 +25,11 @@
2525

2626
using namespace o2::framework;
2727
using namespace o2::dataformats;
28+
using namespace o2::globaltracking;
2829
using namespace o2::gpu;
2930
using namespace o2::tpc;
3031
using namespace o2::trd;
3132

32-
static std::unique_ptr<GPUO2InterfaceDisplay> display;
33-
std::unique_ptr<GPUO2InterfaceConfiguration> config;
34-
std::unique_ptr<TPCFastTransform> fastTransform;
35-
std::unique_ptr<o2::trd::GeometryFlat> trdGeo;
36-
3733
void customize(std::vector<ConfigParamSpec>& workflowOptions)
3834
{
3935
std::vector<o2::framework::ConfigParamSpec> options{
@@ -47,45 +43,41 @@ void customize(std::vector<ConfigParamSpec>& workflowOptions)
4743
std::swap(workflowOptions, options);
4844
}
4945

50-
// ------------------------------------------------------------------
51-
5246
#include "Framework/runDataProcessing.h"
5347

54-
static o2::globaltracking::DataRequest dataRequest;
55-
5648
void O2GPUDPLDisplaySpec::init(InitContext& ic)
5749
{
5850
const auto grp = o2::parameters::GRPObject::loadFrom(o2::base::NameConf::getGRPFileName());
5951
o2::base::GeometryManager::loadGeometry();
6052
o2::base::Propagator::initFieldFromGRP(o2::base::NameConf::getGRPFileName());
61-
config.reset(new GPUO2InterfaceConfiguration);
62-
config->configGRP.solenoidBz = 5.00668f * grp->getL3Current() / 30000.;
63-
config->configGRP.continuousMaxTimeBin = grp->isDetContinuousReadOut(o2::detectors::DetID::TPC) ? -1 : 0; // Number of timebins in timeframe if continuous, 0 otherwise
64-
config->ReadConfigurableParam();
53+
mConfig.reset(new GPUO2InterfaceConfiguration);
54+
mConfig->configGRP.solenoidBz = 5.00668f * grp->getL3Current() / 30000.;
55+
mConfig->configGRP.continuousMaxTimeBin = grp->isDetContinuousReadOut(o2::detectors::DetID::TPC) ? -1 : 0; // Number of timebins in timeframe if continuous, 0 otherwise
56+
mConfig->ReadConfigurableParam();
6557

66-
fastTransform = std::move(TPCFastTransformHelperO2::instance()->create(0));
67-
config->configCalib.fastTransform = fastTransform.get();
58+
mFastTransform = std::move(TPCFastTransformHelperO2::instance()->create(0));
59+
mConfig->configCalib.fastTransform = mFastTransform.get();
6860

6961
auto gm = o2::trd::Geometry::instance();
7062
gm->createPadPlaneArray();
7163
gm->createClusterMatrixArray();
72-
trdGeo.reset(new o2::trd::GeometryFlat(*gm));
73-
config->configCalib.trdGeometry = trdGeo.get();
64+
mTrdGeo.reset(new o2::trd::GeometryFlat(*gm));
65+
mConfig->configCalib.trdGeometry = mTrdGeo.get();
7466

75-
display.reset(new GPUO2InterfaceDisplay(config.get()));
67+
mDisplay.reset(new GPUO2InterfaceDisplay(mConfig.get()));
7668
}
7769

7870
void O2GPUDPLDisplaySpec::run(ProcessingContext& pc)
7971
{
8072
o2::globaltracking::RecoContainer recoData;
81-
recoData.collectData(pc, dataRequest);
73+
recoData.collectData(pc, *mDataRequest);
8274
static bool first = false;
8375
if (first == false) {
84-
if (display->startDisplay()) {
76+
if (mDisplay->startDisplay()) {
8577
throw std::runtime_error("Error starting event display");
8678
}
8779
}
88-
80+
8981
GPUTrackingInOutPointers ptrs;
9082
recoData.addTPCClusters(pc, false);
9183
recoData.addTPCTracks(pc, mUseMC);
@@ -100,13 +92,13 @@ void O2GPUDPLDisplaySpec::run(ProcessingContext& pc)
10092
const auto& tpcTracksMC = recoData.getTPCTracksMCLabels();
10193
ptrs.outputTracksTPCO2MC = tpcTracksMC.data();
10294
}
103-
104-
display->show(&ptrs);
95+
96+
mDisplay->show(&ptrs);
10597
}
10698

10799
void O2GPUDPLDisplaySpec::endOfStream(EndOfStreamContext& ec)
108100
{
109-
display->endDisplay();
101+
mDisplay->endDisplay();
110102
}
111103

112104
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
@@ -116,18 +108,19 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
116108
bool useMC = cfgc.options().get<bool>("enable-mc");
117109
GlobalTrackID::mask_t srcTrk = GlobalTrackID::getSourcesMask(cfgc.options().get<std::string>("display-tracks"));
118110
GlobalTrackID::mask_t srcCl = GlobalTrackID::getSourcesMask(cfgc.options().get<std::string>("display-clusters"));
119-
dataRequest.requestTracks(srcTrk, useMC);
120-
dataRequest.requestClusters(srcCl, useMC);
111+
std::shared_ptr<DataRequest> dataRequest = std::make_shared<DataRequest>();
112+
dataRequest->requestTracks(srcTrk, useMC);
113+
dataRequest->requestClusters(srcCl, useMC);
121114

122115
if (cfgc.options().get<bool>("read-from-files")) {
123116
InputHelper::addInputSpecs(cfgc, specs, srcCl, srcTrk, srcTrk, useMC);
124117
}
125118

126119
specs.emplace_back(DataProcessorSpec{
127120
"o2-gpu-display",
128-
dataRequest.inputs,
121+
dataRequest->inputs,
129122
{},
130-
AlgorithmSpec{adaptFromTask<O2GPUDPLDisplaySpec>(useMC, srcTrk, srcCl)}});
123+
AlgorithmSpec{adaptFromTask<O2GPUDPLDisplaySpec>(useMC, srcTrk, srcCl, dataRequest)}});
131124

132125
return std::move(specs);
133126
}

0 commit comments

Comments
 (0)