ATLAS Offline Software
Loading...
Searching...
No Matches
H5Utils::hist::HistogramMerger Class Reference

Accumulates UHI histogram groups from multiple source files and writes the merged result once all inputs have been consumed. More...

#include <HistogramMerger.h>

Collaboration diagram for H5Utils::hist::HistogramMerger:

Public Member Functions

 ~HistogramMerger ()
void add (const std::string &path, const H5::Group &src)
 Accumulate one UHI histogram group.
void write (H5::Group &root) const
 Write every accumulated histogram into the output file.

Private Member Functions

std::unique_ptr< IHistogrammake (const H5::Group &src)
 Factory: read the storage type from src and return a zero-initialised concrete IHistogram of the appropriate type.

Private Attributes

std::map< std::string, std::unique_ptr< IHistogram > > m_hists

Detailed Description

Accumulates UHI histogram groups from multiple source files and writes the merged result once all inputs have been consumed.

Usage: HistogramMerger hm; for each source file: hm.add("/path/to/hist", src_group); hm.write(output_root_group);

Definition at line 30 of file HistogramMerger.h.

Constructor & Destructor Documentation

◆ ~HistogramMerger()

H5Utils::hist::HistogramMerger::~HistogramMerger ( )
default

Member Function Documentation

◆ add()

void H5Utils::hist::HistogramMerger::add ( const std::string & path,
const H5::Group & src )

Accumulate one UHI histogram group.

Parameters
pathFull HDF5 object path, e.g. "/jets/mass" (same in all files).
srcThe UHI histogram group from a source file.

Definition at line 548 of file HistogramMerger.cxx.

548 {
549 if (!m_hists.count(path)) {
550 m_hists.emplace(path, make(src));
551 }
552 m_hists.at(path)->add(src);
553}
std::unique_ptr< IHistogram > make(const H5::Group &src)
Factory: read the storage type from src and return a zero-initialised concrete IHistogram of the appr...
std::map< std::string, std::unique_ptr< IHistogram > > m_hists

◆ make()

std::unique_ptr< IHistogram > H5Utils::hist::HistogramMerger::make ( const H5::Group & src)
private

Factory: read the storage type from src and return a zero-initialised concrete IHistogram of the appropriate type.

Definition at line 518 of file HistogramMerger.cxx.

518 {
519 std::vector<Axis> axes = read_axes(src);
520 std::vector<hsize_t> dims = read_dims(src);
521
522 H5::Group storage = src.openGroup("storage");
523 std::string type = read_str_attr(storage, "type");
524
525 if (type == "double") {
526 return std::make_unique<SimpleHistogram<double>>(
527 std::move(axes), std::move(dims));
528 }
529 if (type == "int") {
530 return std::make_unique<SimpleHistogram<int64_t>>(
531 std::move(axes), std::move(dims));
532 }
533 if (type == "weighted") {
534 return std::make_unique<WeightedHistogram>(
535 std::move(axes), std::move(dims));
536 }
537 if (type == "mean") {
538 return std::make_unique<MeanHistogram>(
539 std::move(axes), std::move(dims));
540 }
541 if (type == "weighted_mean") {
542 return std::make_unique<WeightedMeanHistogram>(
543 std::move(axes), std::move(dims));
544 }
545 throw std::runtime_error("HistogramMerger: unknown UHI storage type: " + type);
546}

◆ write()

void H5Utils::hist::HistogramMerger::write ( H5::Group & root) const

Write every accumulated histogram into the output file.

Parameters
rootThe root group of the output file (or any common ancestor).

Definition at line 555 of file HistogramMerger.cxx.

555 {
556 for (const auto& [path, hist] : m_hists) {
557 // Split the absolute HDF5 path (e.g. "/a/b/c") into components.
558 std::vector<std::string> parts;
559 std::istringstream ss(path);
560 std::string token;
561 while (std::getline(ss, token, '/')) {
562 if (!token.empty()) parts.push_back(token);
563 }
564 if (parts.empty()) continue;
565
566 // Navigate/create intermediate groups, then write the histogram.
567 H5::Group parent = root;
568 for (size_t i = 0; i + 1 < parts.size(); ++i) {
569 parent = open_or_create_group(parent, parts[i]);
570 }
571 hist->write(parent, parts.back());
572 }
573}
static Double_t ss

Member Data Documentation

◆ m_hists

std::map<std::string, std::unique_ptr<IHistogram> > H5Utils::hist::HistogramMerger::m_hists
private

Definition at line 48 of file HistogramMerger.h.


The documentation for this class was generated from the following files: