Skip to content

Commit 91fa856

Browse files
DPL Analysis: store created histograms in unique_ptrs (#6159)
1 parent e398192 commit 91fa856

4 files changed

Lines changed: 17 additions & 17 deletions

File tree

Analysis/Core/src/CorrelationContainer.cxx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030

3131
using namespace o2::framework;
3232

33-
ClassImp(CorrelationContainer)
33+
ClassImp(CorrelationContainer);
3434

35-
const Int_t CorrelationContainer::fgkCFSteps = 11;
35+
const Int_t CorrelationContainer::fgkCFSteps = 11;
3636

3737
CorrelationContainer::CorrelationContainer() : TNamed(),
3838
mPairHist(nullptr),
@@ -94,11 +94,10 @@ CorrelationContainer::CorrelationContainer(const char* name, const char* objTitl
9494

9595
LOGF(info, "Creating CorrelationContainer");
9696

97-
// TODO Remove Clone() pending change in HistogramRegistry
98-
mPairHist = (StepTHnF*)HistFactory::createHist<StepTHnF>({"mPairHist", "d^{2}N_{ch}/d#varphid#eta", {HistType::kStepTHnF, {axisList[0], axisList[1], axisList[2], axisList[3], axisList[4], axisList[5]}, fgkCFSteps}})->Clone();
99-
mTriggerHist = (StepTHnF*)HistFactory::createHist<StepTHnF>({"mTriggerHist", "d^{2}N_{ch}/d#varphid#eta", {HistType::kStepTHnF, {axisList[2], axisList[3], axisList[5]}, fgkCFSteps}})->Clone();
100-
mTrackHistEfficiency = (StepTHnD*)HistFactory::createHist<StepTHnD>({"mTrackHistEfficiency", "Tracking efficiency", {HistType::kStepTHnD, {axisList[6], axisList[7], {4, -0.5, 3.5, "species"}, axisList[3], axisList[8]}, fgkCFSteps}})->Clone();
101-
mEventCount = (TH2F*)(HistFactory::createHist<TH2F>({"mEventCount", ";step;centrality;count", {HistType::kTH2F, {{fgkCFSteps + 2, -2.5, -0.5 + fgkCFSteps, "step"}, axisList[3]}}})->Clone());
97+
mPairHist = HistFactory::createHist<StepTHnF>({"mPairHist", "d^{2}N_{ch}/d#varphid#eta", {HistType::kStepTHnF, {axisList[0], axisList[1], axisList[2], axisList[3], axisList[4], axisList[5]}, fgkCFSteps}}).release();
98+
mTriggerHist = HistFactory::createHist<StepTHnF>({"mTriggerHist", "d^{2}N_{ch}/d#varphid#eta", {HistType::kStepTHnF, {axisList[2], axisList[3], axisList[5]}, fgkCFSteps}}).release();
99+
mTrackHistEfficiency = HistFactory::createHist<StepTHnD>({"mTrackHistEfficiency", "Tracking efficiency", {HistType::kStepTHnD, {axisList[6], axisList[7], {4, -0.5, 3.5, "species"}, axisList[3], axisList[8]}, fgkCFSteps}}).release();
100+
mEventCount = HistFactory::createHist<TH2F>({"mEventCount", ";step;centrality;count", {HistType::kTH2F, {{fgkCFSteps + 2, -2.5, -0.5 + fgkCFSteps, "step"}, axisList[3]}}}).release();
102101
}
103102

104103
//_____________________________________________________________________________

Framework/Core/include/Framework/HistogramRegistry.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
#include "Framework/OutputSpec.h"
2121
#include "Framework/SerializationMethods.h"
2222
#include "Framework/TableBuilder.h"
23-
#include "Framework/RuntimeError.h"
2423

2524
#define HIST(name) CONST_STR(name)
2625

2726
namespace o2::framework
2827
{
28+
2929
//**************************************************************************************************
3030
/**
3131
* Static helper class to generate histograms from the specifications.
@@ -36,7 +36,7 @@ struct HistFactory {
3636

3737
// create histogram of type T with the axes defined in HistogramSpec
3838
template <typename T>
39-
static std::shared_ptr<T> createHist(const HistogramSpec& histSpec)
39+
static std::unique_ptr<T> createHist(const HistogramSpec& histSpec)
4040
{
4141
constexpr std::size_t MAX_DIM{10};
4242
const std::size_t nAxes{histSpec.config.axes.size()};
@@ -57,15 +57,15 @@ struct HistFactory {
5757
}
5858

5959
// create histogram
60-
std::shared_ptr<T> hist{generateHist<T>(histSpec.name, histSpec.title, nAxes, nBins, lowerBounds, upperBounds, histSpec.config.nSteps)};
60+
std::unique_ptr<T> hist{generateHist<T>(histSpec.name, histSpec.title, nAxes, nBins, lowerBounds, upperBounds, histSpec.config.nSteps)};
6161
if (!hist) {
6262
LOGF(FATAL, "The number of dimensions specified for histogram %s does not match the type.", histSpec.name);
6363
return nullptr;
6464
}
6565

6666
// set axis properties
6767
for (std::size_t i = 0; i < nAxes; i++) {
68-
TAxis* axis{getAxis(i, hist)};
68+
TAxis* axis{getAxis(i, hist.get())};
6969
if (axis) {
7070
if (histSpec.config.axes[i].title) {
7171
axis->SetTitle((*histSpec.config.axes[i].title).data());
@@ -117,7 +117,7 @@ struct HistFactory {
117117

118118
// helper function to get the axis via index for any type of root histogram
119119
template <typename T>
120-
static TAxis* getAxis(const int i, std::shared_ptr<T>& hist)
120+
static TAxis* getAxis(const int i, T* hist)
121121
{
122122
if constexpr (std::is_base_of_v<THnBase, T> || std::is_base_of_v<StepTHn, T>) {
123123
return hist->GetAxis(i);

Framework/Core/include/Framework/HistogramSpec.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#ifndef FRAMEWORK_HISTOGRAMSPEC_H_
1212
#define FRAMEWORK_HISTOGRAMSPEC_H_
1313

14+
#include <string>
15+
#include <variant>
16+
#include <deque>
17+
1418
#include <TH1.h>
1519
#include <TH2.h>
1620
#include <TH3.h>
@@ -23,13 +27,10 @@
2327
#include <TDataMember.h>
2428
#include <TDataType.h>
2529

26-
#include <string>
27-
#include <variant>
28-
#include <deque>
29-
3030
#include "Framework/StepTHn.h"
3131
#include "Framework/Configurable.h"
3232
#include "Framework/StringHelpers.h"
33+
#include "Framework/RuntimeError.h"
3334

3435
namespace o2::framework
3536
{

Framework/Core/src/HistogramRegistry.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ void HistogramRegistry::print(bool showAxisDetails)
194194
nDim = hist->GetDimension();
195195
}
196196
for (int d = 0; d < nDim; ++d) {
197-
TAxis* axis = HistFactory::getAxis(d, hist);
197+
TAxis* axis = HistFactory::getAxis(d, hist.get());
198198
LOGF(INFO, "- Axis %d: %-20s (%d bins)", d, axis->GetTitle(), axis->GetNbins());
199199
}
200200
}

0 commit comments

Comments
 (0)