ATLAS Offline Software
Loading...
Searching...
No Matches
H5Utils::hist::detail Namespace Reference

Classes

struct  regular_axis_t
struct  Axis

Functions

void chkerr (herr_t code, std::string_view error)
void write_str_attr (H5::H5Object &obj, const std::string &key, const std::string &val)
void write_bool_attr (H5::H5Object &obj, const char *key, bool val)
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)
void write_axes (H5::Group &hist_grp, const std::vector< Axis > &axes)
size_t n_bins (const regular_axis_t &r)
size_t n_bins (const std::vector< double > &edges)
size_t n_bins (const std::vector< int64_t > &vals)
size_t n_bins (const std::vector< std::string > &labels)
size_t n_bins (const std::pair< int64_t, int64_t > &range)
void write_str_dataset (H5::Group &parent, const std::string &name, const std::vector< std::string > &values)
void write_axis_edges (H5::Group &ax_grp, const regular_axis_t &r)
void write_axis_edges (H5::Group &ax_grp, const std::vector< double > &edges)
void write_axis_edges (H5::Group &ax_grp, const std::pair< int64_t, int64_t > &range)
void write_axis_edges (H5::Group &ax_grp, const std::vector< int64_t > &vals)
void write_axis_edges (H5::Group &ax_grp, const std::vector< std::string > &labels)

Variables

template<typename T>
const H5::DataType hdf5_t
template<>
const H5::DataType hdf5_t< double > = H5::PredType::NATIVE_DOUBLE
template<>
const H5::DataType hdf5_t< float > = H5::PredType::NATIVE_FLOAT
template<>
const H5::DataType hdf5_t< int > = H5::PredType::NATIVE_INT
template<>
const H5::DataType hdf5_t< long > = H5::PredType::NATIVE_LONG
template<>
const H5::DataType hdf5_t< long long > = H5::PredType::NATIVE_LLONG
template<>
const H5::DataType hdf5_t< unsigned long > = H5::PredType::NATIVE_ULONG
template<>
const H5::DataType hdf5_t< unsigned long long > = H5::PredType::NATIVE_ULLONG
template<>
const H5::DataType hdf5_t< unsigned char > = H5::PredType::NATIVE_UCHAR
template<>
const H5::DataType hdf5_t< unsigned short > = H5::PredType::NATIVE_USHORT

Function Documentation

◆ chkerr()

void H5Utils::hist::detail::chkerr ( herr_t code,
std::string_view error )

Definition at line 13 of file HistCommon.cxx.

13 {
14 if (code < 0) throw std::runtime_error(std::format("error setting {}",error));
15}

◆ n_bins() [1/5]

size_t H5Utils::hist::detail::n_bins ( const regular_axis_t & r)

Definition at line 59 of file HistCommon.cxx.

59{ return r.n_bins; }
int r
Definition globals.cxx:22

◆ n_bins() [2/5]

size_t H5Utils::hist::detail::n_bins ( const std::pair< int64_t, int64_t > & range)

Definition at line 63 of file HistCommon.cxx.

63{ return static_cast<size_t>(r.second - r.first + 1); }

◆ n_bins() [3/5]

size_t H5Utils::hist::detail::n_bins ( const std::vector< double > & edges)

Definition at line 60 of file HistCommon.cxx.

60{ return e.size() - 1; }

◆ n_bins() [4/5]

size_t H5Utils::hist::detail::n_bins ( const std::vector< int64_t > & vals)

Definition at line 61 of file HistCommon.cxx.

61{ return e.size(); }

◆ n_bins() [5/5]

size_t H5Utils::hist::detail::n_bins ( const std::vector< std::string > & labels)

Definition at line 62 of file HistCommon.cxx.

62{ return e.size(); }

◆ write_axes()

void H5Utils::hist::detail::write_axes ( H5::Group & hist_grp,
const std::vector< Axis > & axes )

Definition at line 131 of file HistCommon.cxx.

132{
133 H5::Group ref_axes_grp = hist_grp.createGroup("ref_axes");
134 for (size_t ax_n = 0; ax_n < axes.size(); ++ax_n) {
135 const auto& ax = axes.at(ax_n);
136 H5::Group ax_grp = ref_axes_grp.createGroup("axis_" + std::to_string(ax_n));
137
138 std::visit([&ax_grp](const auto& e) {
139 write_axis_edges(ax_grp, e);
140 }, ax.edges);
141
142 write_bool_attr(ax_grp, "underflow", ax.underflow);
143 write_bool_attr(ax_grp, "overflow", ax.overflow);
144 write_bool_attr(ax_grp, "circular", false);
145
146 H5::Group ax_meta = ax_grp.createGroup("metadata");
147 if (!ax.name.empty()) {
148 write_str_attr(ax_meta, "metadata", ax.name);
149 }
150 ax_grp.createGroup("writer_info");
151 }
152
153 // Write object-reference dataset "axes"
154 std::vector<hobj_ref_t> axis_refs(axes.size());
155 for (size_t ax_n = 0; ax_n < axes.size(); ++ax_n) {
156 std::string ax_path = "ref_axes/axis_" + std::to_string(ax_n);
157 chkerr(H5Rcreate(&axis_refs.at(ax_n), hist_grp.getId(),
158 ax_path.c_str(), H5R_OBJECT, -1),
159 "axis object reference");
160 }
161 hsize_t ref_dim = axes.size();
162 H5::DataSpace ref_space(1, &ref_dim);
163 hist_grp.createDataSet("axes", H5::PredType::STD_REF_OBJ, ref_space)
164 .write(axis_refs.data(), H5::PredType::STD_REF_OBJ);
165}
void write_str_attr(H5::H5Object &obj, const std::string &key, const std::string &val)
void chkerr(herr_t code, std::string_view error)
void write_axis_edges(H5::Group &ax_grp, const regular_axis_t &r)
void write_bool_attr(H5::H5Object &obj, const char *key, bool val)

◆ write_axis_edges() [1/5]

void H5Utils::hist::detail::write_axis_edges ( H5::Group & ax_grp,
const regular_axis_t & r )

Definition at line 83 of file HistCommon.cxx.

84{
85 write_str_attr (ax_grp, "type", "regular");
86 write_double_attr(ax_grp, "lower", r.lower);
87 write_double_attr(ax_grp, "upper", r.upper);
88 write_int_attr (ax_grp, "bins", r.n_bins);
89}
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)

◆ write_axis_edges() [2/5]

void H5Utils::hist::detail::write_axis_edges ( H5::Group & ax_grp,
const std::pair< int64_t, int64_t > & range )

Definition at line 105 of file HistCommon.cxx.

106{
107 write_str_attr(ax_grp, "type", "integer");
108 write_int_attr(ax_grp, "start", range.first);
109 write_int_attr(ax_grp, "stop", range.second);
110}

◆ write_axis_edges() [3/5]

void H5Utils::hist::detail::write_axis_edges ( H5::Group & ax_grp,
const std::vector< double > & edges )

Definition at line 92 of file HistCommon.cxx.

93{
94 write_str_attr(ax_grp, "type", "variable");
95 hsize_t nedges = edges.size();
96 H5::DataSpace edge_space(1, &nedges);
97 H5::DSetCreatPropList props;
98 props.setChunk(1, &nedges);
99 props.setDeflate(7);
100 ax_grp.createDataSet("edges",
101 H5::PredType::NATIVE_DOUBLE, edge_space, props)
102 .write(edges.data(), H5::PredType::NATIVE_DOUBLE);
103}

◆ write_axis_edges() [4/5]

void H5Utils::hist::detail::write_axis_edges ( H5::Group & ax_grp,
const std::vector< int64_t > & vals )

Definition at line 112 of file HistCommon.cxx.

113{
114 write_str_attr(ax_grp, "type", "category");
115 hsize_t n = vals.size();
116 H5::DataSpace space(1, &n);
117 H5::DSetCreatPropList props;
118 props.setChunk(1, &n);
119 props.setDeflate(7);
120 ax_grp.createDataSet("categories",
121 H5::PredType::NATIVE_INT64, space, props)
122 .write(vals.data(), H5::PredType::NATIVE_INT64);
123}

◆ write_axis_edges() [5/5]

void H5Utils::hist::detail::write_axis_edges ( H5::Group & ax_grp,
const std::vector< std::string > & labels )

Definition at line 125 of file HistCommon.cxx.

126{
127 write_str_attr(ax_grp, "type", "category");
128 write_str_dataset(ax_grp, "categories", labels);
129}
void write_str_dataset(H5::Group &parent, const std::string &name, const std::vector< std::string > &values)

◆ write_bool_attr()

void H5Utils::hist::detail::write_bool_attr ( H5::H5Object & obj,
const char * key,
bool val )

Definition at line 28 of file HistCommon.cxx.

31{
32 H5::DataSpace scalar(H5S_SCALAR);
33 uint8_t v = val ? 1 : 0;
34 H5::Attribute attr = obj.createAttribute(
35 key, H5::PredType::NATIVE_UINT8, scalar);
36 attr.write(H5::PredType::NATIVE_UINT8, &v);
37}

◆ write_double_attr()

void H5Utils::hist::detail::write_double_attr ( H5::H5Object & obj,
const std::string & key,
double val )

Definition at line 49 of file HistCommon.cxx.

52{
53 H5::DataSpace scalar(H5S_SCALAR);
54 H5::Attribute attr = obj.createAttribute(
55 key, H5::PredType::NATIVE_DOUBLE, scalar);
56 attr.write(H5::PredType::NATIVE_DOUBLE, &val);
57}

◆ write_int_attr()

void H5Utils::hist::detail::write_int_attr ( H5::H5Object & obj,
const std::string & key,
int64_t val )

Definition at line 39 of file HistCommon.cxx.

42{
43 H5::DataSpace scalar(H5S_SCALAR);
44 H5::Attribute attr = obj.createAttribute(
45 key, H5::PredType::NATIVE_INT64, scalar);
46 attr.write(H5::PredType::NATIVE_INT64, &val);
47}

◆ write_str_attr()

void H5Utils::hist::detail::write_str_attr ( H5::H5Object & obj,
const std::string & key,
const std::string & val )

Definition at line 17 of file HistCommon.cxx.

20{
21 H5::StrType strtype(H5::PredType::C_S1, H5T_VARIABLE);
22 H5::DataSpace scalar(H5S_SCALAR);
23 H5::Attribute attr = obj.createAttribute(key, strtype, scalar);
24 const char* cstr = val.c_str();
25 attr.write(strtype, &cstr);
26}

◆ write_str_dataset()

void H5Utils::hist::detail::write_str_dataset ( H5::Group & parent,
const std::string & name,
const std::vector< std::string > & values )

Definition at line 65 of file HistCommon.cxx.

68{
69 H5::StrType strtype(H5::PredType::C_S1, H5T_VARIABLE);
70 hsize_t n = values.size();
71 H5::DataSpace space(1, &n);
72 H5::DSetCreatPropList props;
73 props.setChunk(1, &n);
74 props.setDeflate(7);
75 std::vector<const char*> cstrs;
76 cstrs.reserve(n);
77 for (const auto& s : values) cstrs.push_back(s.c_str());
78 parent.createDataSet(name, strtype, space, props)
79 .write(cstrs.data(), strtype);
80}

Variable Documentation

◆ hdf5_t

template<typename T>
const H5::DataType H5Utils::hist::detail::hdf5_t
extern

◆ hdf5_t< double >

template<>
const H5::DataType H5Utils::hist::detail::hdf5_t< double > = H5::PredType::NATIVE_DOUBLE
inline

Definition at line 59 of file HistCommon.h.

◆ hdf5_t< float >

template<>
const H5::DataType H5Utils::hist::detail::hdf5_t< float > = H5::PredType::NATIVE_FLOAT
inline

Definition at line 61 of file HistCommon.h.

◆ hdf5_t< int >

template<>
const H5::DataType H5Utils::hist::detail::hdf5_t< int > = H5::PredType::NATIVE_INT
inline

Definition at line 63 of file HistCommon.h.

◆ hdf5_t< long >

template<>
const H5::DataType H5Utils::hist::detail::hdf5_t< long > = H5::PredType::NATIVE_LONG
inline

Definition at line 65 of file HistCommon.h.

◆ hdf5_t< long long >

template<>
const H5::DataType H5Utils::hist::detail::hdf5_t< long long > = H5::PredType::NATIVE_LLONG
inline

Definition at line 67 of file HistCommon.h.

◆ hdf5_t< unsigned char >

template<>
const H5::DataType H5Utils::hist::detail::hdf5_t< unsigned char > = H5::PredType::NATIVE_UCHAR
inline

Definition at line 73 of file HistCommon.h.

◆ hdf5_t< unsigned long >

template<>
const H5::DataType H5Utils::hist::detail::hdf5_t< unsigned long > = H5::PredType::NATIVE_ULONG
inline

Definition at line 69 of file HistCommon.h.

◆ hdf5_t< unsigned long long >

template<>
const H5::DataType H5Utils::hist::detail::hdf5_t< unsigned long long > = H5::PredType::NATIVE_ULLONG
inline

Definition at line 71 of file HistCommon.h.

◆ hdf5_t< unsigned short >

template<>
const H5::DataType H5Utils::hist::detail::hdf5_t< unsigned short > = H5::PredType::NATIVE_USHORT
inline

Definition at line 75 of file HistCommon.h.