ATLAS Offline Software
Loading...
Searching...
No Matches
HistCommon.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef HDF5Utils_HistCommon_H
6#define HDF5Utils_HistCommon_H
7
9
10#include "H5Cpp.h"
11
12#include <cstdint>
13#include <string>
14#include <vector>
15
16namespace H5Utils::hist::detail {
17
18 // Error check helper
19 void chkerr(herr_t code, const std::string& error);
20
21 // Attribute write helpers
22 void write_str_attr(H5::H5Object& obj,
23 const std::string& key,
24 const std::string& val);
25 void write_bool_attr(H5::H5Object& obj,
26 const std::string& key,
27 bool val);
28 void write_int_attr(H5::H5Object& obj,
29 const std::string& key,
30 int64_t val);
31 void write_double_attr(H5::H5Object& obj,
32 const std::string& key,
33 double val);
34
35 // Write the ref_axes group and the "axes" object-reference dataset.
36 // The histogram group hist_grp must already exist.
37 void write_axes(H5::Group& hist_grp, const std::vector<Axis>& axes);
38
39 // n_bins overloads: number of data bins (excluding underflow/overflow) for
40 // each variant alternative of Axis::edges_t.
41 size_t n_bins(const regular_axis_t& r); // r.n_bins
42 size_t n_bins(const std::vector<double>& edges); // edges.size() - 1
43 size_t n_bins(const std::vector<int64_t>& vals); // vals.size()
44 size_t n_bins(const std::vector<std::string>& labels); // labels.size()
45 size_t n_bins(const std::pair<int64_t,int64_t>& range); // range.second - range.first + 1
46
47 // Write a 1-D dataset of variable-length strings.
48 void write_str_dataset(H5::Group& parent,
49 const std::string& name,
50 const std::vector<std::string>& values);
51
52 // H5 type mapping — must be inline to avoid ODR violations when this
53 // header is included in multiple translation units.
54 template <typename T>
55 extern const H5::DataType hdf5_t;
56
57 template<> inline const H5::DataType hdf5_t<double>
58 = H5::PredType::NATIVE_DOUBLE;
59 template<> inline const H5::DataType hdf5_t<float>
60 = H5::PredType::NATIVE_FLOAT;
61 template<> inline const H5::DataType hdf5_t<int>
62 = H5::PredType::NATIVE_INT;
63 template<> inline const H5::DataType hdf5_t<long>
64 = H5::PredType::NATIVE_LONG;
65 template<> inline const H5::DataType hdf5_t<long long>
66 = H5::PredType::NATIVE_LLONG;
67 template<> inline const H5::DataType hdf5_t<unsigned long>
68 = H5::PredType::NATIVE_ULONG;
69 template<> inline const H5::DataType hdf5_t<unsigned long long>
70 = H5::PredType::NATIVE_ULLONG;
71 template<> inline const H5::DataType hdf5_t<unsigned char>
72 = H5::PredType::NATIVE_UCHAR;
73 template<> inline const H5::DataType hdf5_t<unsigned short>
74 = H5::PredType::NATIVE_USHORT;
75
76} //> end namespace H5Utils::hist::detail
77
78#endif //> !HDF5Utils_HistCommon_H
int r
Definition globals.cxx:22
void chkerr(herr_t code, const std::string &error)
size_t n_bins(const regular_axis_t &r)
void write_bool_attr(H5::H5Object &obj, const std::string &key, bool val)
void write_axes(H5::Group &hist_grp, const std::vector< Axis > &axes)
void write_str_attr(H5::H5Object &obj, const std::string &key, const std::string &val)
void write_str_dataset(H5::Group &parent, const std::string &name, const std::vector< std::string > &values)
const H5::DataType hdf5_t
void write_int_attr(H5::H5Object &obj, const std::string &key, int64_t val)
void write_double_attr(H5::H5Object &obj, const std::string &key, double val)