Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 14 additions & 39 deletions Framework/Core/include/Framework/HistogramSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,41 +84,20 @@ using HistPtr = std::variant<std::shared_ptr<THn>, std::shared_ptr<THnSparse>, s
constexpr double VARIABLE_WIDTH = 0.;

struct AxisSpec {
AxisSpec(std::vector<double> binEdges_, std::optional<std::string> title_ = std::nullopt, std::optional<std::string> name_ = std::nullopt)
: nBins(std::nullopt),
binEdges(std::move(binEdges_)),
title(std::move(title_)),
name(std::move(name_))
{
}

AxisSpec(int nBins_, double binMin_, double binMax_, std::optional<std::string> title_ = std::nullopt, std::optional<std::string> name_ = std::nullopt)
: nBins(nBins_),
binEdges({binMin_, binMax_}),
title(std::move(title_)),
name(std::move(name_))
{
if (binMin_ > binMax_) {
LOG(fatal) << "Defined ill-defined axis";
}
}
// Defined out of line in HistogramSpec.cxx on purpose. These run once per
// histogram at init() time, so inlining them buys nothing at runtime, while
// a task that books a few hundred histograms in one init() pays for every
// expansion: each one materialises a std::vector<double> and two
// std::optional<std::string> at the call site, with the matching destructor
// and exception-unwind paths. Under -g that also means a debug record per
// temporary, which is what makes the register allocator's rewrite pass go
// superlinear on such functions.
AxisSpec(std::vector<double> binEdges_, std::optional<std::string> title_ = std::nullopt, std::optional<std::string> name_ = std::nullopt);

AxisSpec(int nBins_, double binMin_, double binMax_, std::optional<std::string> title_ = std::nullopt, std::optional<std::string> name_ = std::nullopt);

// first entry is assumed to be the number of bins; in case of variable size binning it must be set to zero
AxisSpec(ConfigurableAxis binEdges_, std::optional<std::string> title_ = std::nullopt, std::optional<std::string> name_ = std::nullopt)
: nBins(std::nullopt),
binEdges(std::vector<double>(binEdges_)),
title(std::move(title_)),
name(std::move(name_))
{
if (binEdges.empty()) {
return;
}
if (binEdges[0] != VARIABLE_WIDTH) {
nBins = static_cast<int>(binEdges[0]);
binEdges.resize(3); // nBins, lowerBound, upperBound, disregard whatever else is stored in vecotr
}
binEdges.erase(binEdges.begin()); // remove first entry that we assume to be number of bins
}
AxisSpec(ConfigurableAxis binEdges_, std::optional<std::string> title_ = std::nullopt, std::optional<std::string> name_ = std::nullopt);

[[nodiscard]] long getNbins() const;

Expand All @@ -138,12 +117,8 @@ struct AxisSpec {
*/
//**************************************************************************************************
struct HistogramConfigSpec {
HistogramConfigSpec(HistType type_, std::vector<AxisSpec> axes_, uint8_t nSteps_ = 1)
: type(type_),
axes(std::move(axes_)),
nSteps(nSteps_)
{
}
// Out of line for the same reason as the AxisSpec constructors above.
HistogramConfigSpec(HistType type_, std::vector<AxisSpec> axes_, uint8_t nSteps_ = 1);
HistogramConfigSpec() = default;
HistogramConfigSpec(HistogramConfigSpec const& other) = default;
HistogramConfigSpec(HistogramConfigSpec&& other) = default;
Expand Down
43 changes: 43 additions & 0 deletions Framework/Core/src/HistogramSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,49 @@
namespace o2::framework
{

// Out of line: see the comment on the declarations in HistogramSpec.h.
AxisSpec::AxisSpec(std::vector<double> binEdges_, std::optional<std::string> title_, std::optional<std::string> name_)
: nBins(std::nullopt),
binEdges(std::move(binEdges_)),
title(std::move(title_)),
name(std::move(name_))
{
}

AxisSpec::AxisSpec(int nBins_, double binMin_, double binMax_, std::optional<std::string> title_, std::optional<std::string> name_)
: nBins(nBins_),
binEdges({binMin_, binMax_}),
title(std::move(title_)),
name(std::move(name_))
{
if (binMin_ > binMax_) {
LOG(fatal) << "Defined ill-defined axis";
}
}

AxisSpec::AxisSpec(ConfigurableAxis binEdges_, std::optional<std::string> title_, std::optional<std::string> name_)
: nBins(std::nullopt),
binEdges(std::vector<double>(binEdges_)),
title(std::move(title_)),
name(std::move(name_))
{
if (binEdges.empty()) {
return;
}
if (binEdges[0] != VARIABLE_WIDTH) {
nBins = static_cast<int>(binEdges[0]);
binEdges.resize(3); // nBins, lowerBound, upperBound, disregard whatever else is stored in vecotr
}
binEdges.erase(binEdges.begin()); // remove first entry that we assume to be number of bins
}

HistogramConfigSpec::HistogramConfigSpec(HistType type_, std::vector<AxisSpec> axes_, uint8_t nSteps_)
: type(type_),
axes(std::move(axes_)),
nSteps(nSteps_)
{
}

void AxisSpec::makeLogarithmic()
{
if (binEdges.size() > 2) {
Expand Down
Loading