Skip to content

Commit 8baefd9

Browse files
authored
DPL Analysis: out of line HistogramRegistry population methods (#13906)
1 parent f2e7956 commit 8baefd9

File tree

2 files changed

+101
-41
lines changed

2 files changed

+101
-41
lines changed

Framework/Core/include/Framework/HistogramRegistry.h

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
#include "Framework/SerializationMethods.h"
2323
#include "Framework/TableBuilder.h"
2424
#include "Framework/RuntimeError.h"
25+
#include "StepTHn.h"
2526

2627
#include <TDataMember.h>
2728
#include <TDataType.h>
2829
#include <TArrayL.h>
30+
#include <THnSparse.h>
2931
#include <TProfile2D.h>
3032
#include <fmt/core.h>
3133

@@ -403,28 +405,6 @@ constexpr HistogramRegistry::HistName::HistName(const ConstStr<chars...>& hashed
403405
{
404406
}
405407

406-
template <typename T>
407-
std::shared_ptr<T> HistogramRegistry::add(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2)
408-
{
409-
auto histVariant = add(name, title, histConfigSpec, callSumw2);
410-
if (auto histPtr = std::get_if<std::shared_ptr<T>>(&histVariant)) {
411-
return *histPtr;
412-
} else {
413-
throw runtime_error_f(R"(Histogram type specified in add<>("%s") does not match the actual type of the histogram!)", name);
414-
}
415-
}
416-
417-
template <typename T>
418-
std::shared_ptr<T> HistogramRegistry::add(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2)
419-
{
420-
auto histVariant = add(name, title, histType, axes, callSumw2);
421-
if (auto histPtr = std::get_if<std::shared_ptr<T>>(&histVariant)) {
422-
return *histPtr;
423-
} else {
424-
throw runtime_error_f(R"(Histogram type specified in add<>("%s") does not match the actual type of the histogram!)", name);
425-
}
426-
}
427-
428408
template <typename T>
429409
std::shared_ptr<T> HistogramRegistry::add(const std::string& name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2)
430410
{
@@ -447,25 +427,6 @@ std::shared_ptr<T> HistogramRegistry::operator()(const HistName& histName)
447427
return get<T>(histName);
448428
}
449429

450-
template <typename T>
451-
HistPtr HistogramRegistry::insertClone(const HistName& histName, const std::shared_ptr<T> originalHist)
452-
{
453-
validateHistName(histName.str, histName.hash);
454-
for (auto i = 0u; i < MAX_REGISTRY_SIZE; ++i) {
455-
TObject* rawPtr = nullptr;
456-
std::visit([&](const auto& sharedPtr) { rawPtr = sharedPtr.get(); }, mRegistryValue[imask(histName.idx + i)]);
457-
if (!rawPtr) {
458-
registerName(histName.str);
459-
mRegistryKey[imask(histName.idx + i)] = histName.hash;
460-
mRegistryValue[imask(histName.idx + i)] = std::shared_ptr<T>(static_cast<T*>(originalHist->Clone(histName.str)));
461-
lookup += i;
462-
return mRegistryValue[imask(histName.idx + i)];
463-
}
464-
}
465-
LOGF(fatal, R"(Internal array of HistogramRegistry "%s" is full.)", mName);
466-
return HistPtr();
467-
}
468-
469430
template <typename T>
470431
uint32_t HistogramRegistry::getHistIndex(const T& histName)
471432
{
@@ -491,6 +452,35 @@ extern template void HistogramRegistry::fill(const HistName& histName, double);
491452
extern template void HistogramRegistry::fill(const HistName& histName, float);
492453
extern template void HistogramRegistry::fill(const HistName& histName, int);
493454

455+
extern template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<TH1>);
456+
extern template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<TH2>);
457+
extern template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<TH3>);
458+
extern template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<TProfile>);
459+
extern template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<TProfile2D>);
460+
extern template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<TProfile3D>);
461+
extern template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<THnSparse>);
462+
extern template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<THn>);
463+
extern template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<StepTHn>);
464+
465+
extern template std::shared_ptr<TH1> HistogramRegistry::add<TH1>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
466+
extern template std::shared_ptr<TH1> HistogramRegistry::add<TH1>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
467+
extern template std::shared_ptr<TH2> HistogramRegistry::add<TH2>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
468+
extern template std::shared_ptr<TH2> HistogramRegistry::add<TH2>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
469+
extern template std::shared_ptr<TH3> HistogramRegistry::add<TH3>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
470+
extern template std::shared_ptr<TH3> HistogramRegistry::add<TH3>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
471+
extern template std::shared_ptr<TProfile> HistogramRegistry::add<TProfile>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
472+
extern template std::shared_ptr<TProfile> HistogramRegistry::add<TProfile>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
473+
extern template std::shared_ptr<TProfile2D> HistogramRegistry::add<TProfile2D>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
474+
extern template std::shared_ptr<TProfile2D> HistogramRegistry::add<TProfile2D>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
475+
extern template std::shared_ptr<TProfile3D> HistogramRegistry::add<TProfile3D>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
476+
extern template std::shared_ptr<TProfile3D> HistogramRegistry::add<TProfile3D>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
477+
extern template std::shared_ptr<THn> HistogramRegistry::add<THn>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
478+
extern template std::shared_ptr<THn> HistogramRegistry::add<THn>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
479+
extern template std::shared_ptr<THnSparse> HistogramRegistry::add<THnSparse>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
480+
extern template std::shared_ptr<THnSparse> HistogramRegistry::add<THnSparse>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
481+
extern template std::shared_ptr<StepTHn> HistogramRegistry::add<StepTHn>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
482+
extern template std::shared_ptr<StepTHn> HistogramRegistry::add<StepTHn>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
483+
494484
template <typename... Cs, typename T>
495485
void HistogramRegistry::fill(const HistName& histName, const T& table, const o2::framework::expressions::Filter& filter)
496486
{

Framework/Core/src/HistogramRegistry.cxx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,74 @@ void HistFiller::badHistogramFill(char const* name)
414414
LOGF(fatal, "The number of arguments in fill function called for histogram %s is incompatible with histogram dimensions.", name);
415415
}
416416

417+
template <typename T>
418+
HistPtr HistogramRegistry::insertClone(const HistName& histName, const std::shared_ptr<T> originalHist)
419+
{
420+
validateHistName(histName.str, histName.hash);
421+
for (auto i = 0u; i < MAX_REGISTRY_SIZE; ++i) {
422+
TObject* rawPtr = nullptr;
423+
std::visit([&](const auto& sharedPtr) { rawPtr = sharedPtr.get(); }, mRegistryValue[imask(histName.idx + i)]);
424+
if (!rawPtr) {
425+
registerName(histName.str);
426+
mRegistryKey[imask(histName.idx + i)] = histName.hash;
427+
mRegistryValue[imask(histName.idx + i)] = std::shared_ptr<T>(static_cast<T*>(originalHist->Clone(histName.str)));
428+
lookup += i;
429+
return mRegistryValue[imask(histName.idx + i)];
430+
}
431+
}
432+
LOGF(fatal, R"(Internal array of HistogramRegistry "%s" is full.)", mName);
433+
return HistPtr();
434+
}
435+
436+
template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<TH1>);
437+
template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<TH2>);
438+
template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<TH3>);
439+
template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<TProfile>);
440+
template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<TProfile2D>);
441+
template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<TProfile3D>);
442+
template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<THnSparse>);
443+
template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<THn>);
444+
template HistPtr HistogramRegistry::insertClone(const HistName&, const std::shared_ptr<StepTHn>);
445+
446+
template <typename T>
447+
std::shared_ptr<T> HistogramRegistry::add(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2)
448+
{
449+
auto histVariant = add(name, title, histConfigSpec, callSumw2);
450+
if (auto histPtr = std::get_if<std::shared_ptr<T>>(&histVariant)) {
451+
return *histPtr;
452+
} else {
453+
throw runtime_error_f(R"(Histogram type specified in add<>("%s") does not match the actual type of the histogram!)", name);
454+
}
455+
}
456+
457+
template <typename T>
458+
std::shared_ptr<T> HistogramRegistry::add(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2)
459+
{
460+
auto histVariant = add(name, title, histType, axes, callSumw2);
461+
if (auto histPtr = std::get_if<std::shared_ptr<T>>(&histVariant)) {
462+
return *histPtr;
463+
} else {
464+
throw runtime_error_f(R"(Histogram type specified in add<>("%s") does not match the actual type of the histogram!)", name);
465+
}
466+
}
467+
468+
template std::shared_ptr<TH1> HistogramRegistry::add<TH1>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
469+
template std::shared_ptr<TH1> HistogramRegistry::add<TH1>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
470+
template std::shared_ptr<TH2> HistogramRegistry::add<TH2>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
471+
template std::shared_ptr<TH2> HistogramRegistry::add<TH2>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
472+
template std::shared_ptr<TH3> HistogramRegistry::add<TH3>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
473+
template std::shared_ptr<TH3> HistogramRegistry::add<TH3>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
474+
template std::shared_ptr<TProfile> HistogramRegistry::add<TProfile>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
475+
template std::shared_ptr<TProfile> HistogramRegistry::add<TProfile>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
476+
template std::shared_ptr<TProfile2D> HistogramRegistry::add<TProfile2D>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
477+
template std::shared_ptr<TProfile2D> HistogramRegistry::add<TProfile2D>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
478+
template std::shared_ptr<TProfile3D> HistogramRegistry::add<TProfile3D>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
479+
template std::shared_ptr<TProfile3D> HistogramRegistry::add<TProfile3D>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
480+
template std::shared_ptr<THn> HistogramRegistry::add<THn>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
481+
template std::shared_ptr<THn> HistogramRegistry::add<THn>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
482+
template std::shared_ptr<THnSparse> HistogramRegistry::add<THnSparse>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
483+
template std::shared_ptr<THnSparse> HistogramRegistry::add<THnSparse>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
484+
template std::shared_ptr<StepTHn> HistogramRegistry::add<StepTHn>(char const* const name, char const* const title, const HistogramConfigSpec& histConfigSpec, bool callSumw2);
485+
template std::shared_ptr<StepTHn> HistogramRegistry::add<StepTHn>(char const* const name, char const* const title, HistType histType, const std::vector<AxisSpec>& axes, bool callSumw2);
486+
417487
} // namespace o2::framework

0 commit comments

Comments
 (0)