Skip to content

Commit e62bc75

Browse files
committed
Revert "DPL Analysis: Extended histogram registry to use TH2 and TH3 (#4063)"
This reverts commit 7c43a8a.
1 parent 48404ce commit e62bc75

File tree

3 files changed

+18
-129
lines changed

3 files changed

+18
-129
lines changed

Framework/Core/include/Framework/HistogramRegistry.h

Lines changed: 15 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -32,66 +32,31 @@ namespace o2
3232

3333
namespace framework
3434
{
35-
// Most common histogram types
36-
enum HistogramType {
37-
kTH1D,
38-
kTH1F,
39-
kTH1I,
40-
kTH2D,
41-
kTH2F,
42-
kTH2I,
43-
kTH3D,
44-
kTH3F,
45-
kTH3I
46-
};
47-
48-
/// Description of a single histogram axis
49-
struct AxisSpec {
50-
AxisSpec(int nBins_, std::vector<double> bins_, std::string label_ = "")
51-
: nBins(nBins_),
52-
bins(bins_),
53-
binsEqual(false),
54-
label(label_)
55-
{
56-
}
57-
58-
AxisSpec(int nBins_, double binMin_, double binMax_, std::string label_ = "")
59-
: nBins(nBins_),
60-
bins({binMin_, binMax_}),
61-
binsEqual(true),
62-
label(label_)
63-
{
64-
}
65-
66-
AxisSpec() : nBins(1), binsEqual(false), bins(), label("") {}
67-
68-
int nBins;
69-
std::vector<double> bins;
70-
bool binsEqual; // if true, then bins specify min and max for equidistant binning
71-
std::string label;
72-
};
73-
7435
/// Data sctructure that will allow to construct a fully qualified TH* histogram
36+
/// Currently only supports TH1F
7537
struct HistogramConfigSpec {
76-
HistogramConfigSpec(HistogramType type_, std::vector<AxisSpec> axes_)
77-
: type(type_),
78-
axes(axes_),
79-
binsEqual(axes.size() > 0 ? axes[0].binsEqual : false)
38+
HistogramConfigSpec(char const* const kind_, unsigned int nBins_, double xmin_, double xmax_)
39+
: kind(kind_),
40+
nBins(nBins_),
41+
xmin(xmin_),
42+
xmax(xmax_)
8043
{
8144
}
8245

8346
HistogramConfigSpec()
84-
: type(HistogramType::kTH1F),
85-
axes(),
86-
binsEqual(false)
47+
: kind(""),
48+
nBins(1),
49+
xmin(0),
50+
xmax(1)
8751
{
8852
}
8953
HistogramConfigSpec(HistogramConfigSpec const& other) = default;
9054
HistogramConfigSpec(HistogramConfigSpec&& other) = default;
9155

92-
HistogramType type;
93-
std::vector<AxisSpec> axes;
94-
bool binsEqual;
56+
std::string kind;
57+
unsigned int nBins;
58+
double xmin;
59+
double xmax;
9560
};
9661

9762
/// Data structure containing histogram specification for the HistogramRegistry
@@ -121,80 +86,6 @@ struct HistogramSpec {
12186
HistogramConfigSpec config;
12287
};
12388

124-
class HistogramFactory
125-
{
126-
public:
127-
static std::unique_ptr<TH1> create(HistogramSpec& spec)
128-
{
129-
const auto& it = lookup().find(spec.config.type);
130-
if (it == lookup().end()) {
131-
return nullptr;
132-
}
133-
return std::move(it->second->createImpl(spec));
134-
}
135-
136-
protected:
137-
static std::map<HistogramType, HistogramFactory*>& lookup()
138-
{
139-
static std::map<HistogramType, HistogramFactory*> histMap;
140-
return histMap;
141-
}
142-
143-
private:
144-
virtual std::unique_ptr<TH1> createImpl(HistogramSpec const& spec) = 0;
145-
};
146-
147-
template <typename T>
148-
class HistogramFactoryImpl : public HistogramFactory
149-
{
150-
public:
151-
HistogramFactoryImpl(HistogramType type)
152-
: position(this->lookup().insert(std::make_pair(type, this)).first)
153-
{
154-
}
155-
156-
~HistogramFactoryImpl()
157-
{
158-
this->lookup().erase(position);
159-
}
160-
161-
private:
162-
std::unique_ptr<TH1> createImpl(HistogramSpec const& spec) override
163-
{
164-
if (spec.config.axes.size() == 0) {
165-
throw std::runtime_error("No arguments available in spec to create a histogram");
166-
}
167-
if constexpr (std::is_base_of_v<TH3, T>) {
168-
if (spec.config.binsEqual) {
169-
return std::make_unique<T>(spec.name.data(), spec.readableName.data(), spec.config.axes[0].nBins, spec.config.axes[0].bins[0], spec.config.axes[0].bins[1], spec.config.axes[1].nBins, spec.config.axes[1].bins[0], spec.config.axes[1].bins[1], spec.config.axes[2].nBins, spec.config.axes[2].bins[0], spec.config.axes[2].bins[1]);
170-
}
171-
return std::make_unique<T>(spec.name.data(), spec.readableName.data(), spec.config.axes[0].nBins, spec.config.axes[0].bins.data(), spec.config.axes[1].nBins, spec.config.axes[1].bins.data(), spec.config.axes[2].nBins, spec.config.axes[2].bins.data());
172-
} else if constexpr (std::is_base_of_v<TH2, T>) {
173-
if (spec.config.binsEqual) {
174-
return std::make_unique<T>(spec.name.data(), spec.readableName.data(), spec.config.axes[0].nBins, spec.config.axes[0].bins[0], spec.config.axes[0].bins[1], spec.config.axes[1].nBins, spec.config.axes[1].bins[0], spec.config.axes[1].bins[1]);
175-
}
176-
return std::make_unique<T>(spec.name.data(), spec.readableName.data(), spec.config.axes[0].nBins, spec.config.axes[0].bins.data(), spec.config.axes[1].nBins, spec.config.axes[1].bins.data());
177-
} else if constexpr (std::is_base_of_v<TH1, T>) {
178-
if (spec.config.binsEqual) {
179-
return std::make_unique<T>(spec.name.data(), spec.readableName.data(), spec.config.axes[0].nBins, spec.config.axes[0].bins[0], spec.config.axes[0].bins[1]);
180-
}
181-
return std::make_unique<T>(spec.name.data(), spec.readableName.data(), spec.config.axes[0].nBins, spec.config.axes[0].bins.data());
182-
}
183-
}
184-
185-
typename std::map<HistogramType, HistogramFactory*>::iterator position;
186-
};
187-
188-
HistogramFactoryImpl<TH1D> const hf1d(HistogramType::kTH1D);
189-
HistogramFactoryImpl<TH1F> const hf1f(HistogramType::kTH1F);
190-
HistogramFactoryImpl<TH1I> const hf1i(HistogramType::kTH1I);
191-
HistogramFactoryImpl<TH2D> const hf2d(HistogramType::kTH2D);
192-
HistogramFactoryImpl<TH2F> const hf2f(HistogramType::kTH2F);
193-
HistogramFactoryImpl<TH2I> const hf2i(HistogramType::kTH2I);
194-
HistogramFactoryImpl<TH3D> const hf3d(HistogramType::kTH3D);
195-
HistogramFactoryImpl<TH3F> const hf3f(HistogramType::kTH3F);
196-
HistogramFactoryImpl<TH3I> const hf3i(HistogramType::kTH3I);
197-
19889
/// Histogram registry for an analysis task that allows to define needed histograms
19990
/// and serves as the container/wrapper to fill them
20091
class HistogramRegistry
@@ -257,7 +148,7 @@ class HistogramRegistry
257148
for (auto j = 0u; j < MAX_REGISTRY_SIZE; ++j) {
258149
if (mRegistryValue[imask(j + i)].get() == nullptr) {
259150
mRegistryKey[imask(j + i)] = spec.id;
260-
mRegistryValue[imask(j + i)] = HistogramFactory::create(spec);
151+
mRegistryValue[imask(j + i)] = {std::make_unique<TH1F>(spec.name.data(), spec.readableName.data(), spec.config.nBins, spec.config.xmin, spec.config.xmax)};
261152
lookup += j;
262153
return;
263154
}

Framework/Core/test/benchmark_HistogramRegistry.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void BM_HashedNameLookup(benchmark::State& state)
3030
state.PauseTiming();
3131
std::vector<HistogramSpec> specs;
3232
for (auto i = 0; i < state.range(0); ++i) {
33-
specs.push_back({fmt::format("histo{}", i + 1).c_str(), fmt::format("Histo {}", i + 1).c_str(), {HistogramType::kTH1F, {{100, 0, 1}}}});
33+
specs.push_back({(boost::format("histo%1%") % (i + 1)).str().c_str(), (boost::format("Histo %1%") % (i + 1)).str().c_str(), {"TH1F", 100, 0, 1}});
3434
}
3535
HistogramRegistry registry{"registry", true, specs};
3636
state.ResumeTiming();

Framework/Core/test/test_HistogramRegistry.cxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,18 @@ using namespace o2::framework;
1919

2020
HistogramRegistry foo()
2121
{
22-
return {"r", true, {{"histo", "histo", {HistogramType::kTH1F, {{100, 0, 1}}}}}};
22+
return {"r", true, {{"histo", "histo", {"TH1F", 100, 0, 1}}}};
2323
}
2424

2525
BOOST_AUTO_TEST_CASE(HistogramRegistryLookup)
2626
{
2727
/// Construct a registry object with direct declaration
28-
HistogramRegistry registry{"registry", true, {{"eta", "#Eta", {HistogramType::kTH1F, {{100, -2.0, 2.0}}}}, {"phi", "#Phi", {HistogramType::kTH1D, {{102, 0, 2 * M_PI}}}}, {"pt", "p_{T}", {HistogramType::kTH1D, {{1002, -0.01, 50.1}}}}, {"ptToPt", "#ptToPt", {HistogramType::kTH2F, {{100, -0.01, 10.01}, {100, -0.01, 10.01}}}}}};
28+
HistogramRegistry registry{"registry", true, {{"eta", "#Eta", {"TH1F", 100, -2.0, 2.0}}, {"phi", "#Phi", {"TH1D", 102, 0, 2 * M_PI}}, {"pt", "p_{T}", {"TH1D", 1002, -0.01, 50.1}}}};
2929

3030
/// Get histograms by name
3131
BOOST_REQUIRE_EQUAL(registry.get("eta")->GetNbinsX(), 100);
3232
BOOST_REQUIRE_EQUAL(registry.get("phi")->GetNbinsX(), 102);
3333
BOOST_REQUIRE_EQUAL(registry.get("pt")->GetNbinsX(), 1002);
34-
BOOST_REQUIRE_EQUAL(registry.get("ptToPt")->GetNbinsX(), 100);
35-
BOOST_REQUIRE_EQUAL(registry.get("ptToPt")->GetNbinsY(), 100);
3634

3735
/// Get a pointer to the histogram
3836
auto histo = registry.get("pt").get();

0 commit comments

Comments
 (0)