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

Classes

struct  Axis

Functions

void chkerr (herr_t code, const std::string &error)
void write_str_attr (H5::H5Object &obj, const std::string &key, const std::string &val)
void write_bool_attr (H5::H5Object &obj, const std::string &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)

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,
const std::string & error )

Definition at line 14 of file HistCommon.cxx.

14 {
15 if (code < 0) throw std::runtime_error("error setting " + error);
16}

◆ write_axes()

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

Definition at line 60 of file HistCommon.cxx.

61{
62 H5::Group ref_axes_grp = hist_grp.createGroup("ref_axes");
63
64 for (size_t ax_n = 0; ax_n < axes.size(); ++ax_n) {
65 const auto& ax = axes.at(ax_n);
66 H5::Group ax_grp = ref_axes_grp.createGroup("axis_" + std::to_string(ax_n));
67
68 if (ax.n_regular_bins) {
69 write_str_attr(ax_grp, "type", "regular");
70 write_double_attr(ax_grp, "lower",
71 static_cast<double>(ax.edges.front()));
72 write_double_attr(ax_grp, "upper",
73 static_cast<double>(ax.edges.back()));
74 write_int_attr(ax_grp, "bins", *ax.n_regular_bins);
75 } else {
76 write_str_attr(ax_grp, "type", "variable");
77 hsize_t nedges = ax.edges.size();
78 H5::DataSpace edge_space(1, &nedges);
79 H5::DSetCreatPropList edge_props;
80 edge_props.setChunk(1, &nedges);
81 edge_props.setDeflate(7);
82 H5::DataSet edge_ds = ax_grp.createDataSet(
83 "edges", H5::PredType::NATIVE_FLOAT, edge_space, edge_props);
84 edge_ds.write(ax.edges.data(), H5::PredType::NATIVE_FLOAT);
85 }
86
87 write_bool_attr(ax_grp, "underflow", ax.underflow);
88 write_bool_attr(ax_grp, "overflow", ax.overflow);
89 write_bool_attr(ax_grp, "circular", false);
90
91 H5::Group ax_meta = ax_grp.createGroup("metadata");
92 if (!ax.name.empty()) {
93 write_str_attr(ax_meta, "metadata", ax.name);
94 }
95 ax_grp.createGroup("writer_info");
96 }
97
98 // Write object-reference dataset "axes"
99 std::vector<hobj_ref_t> axis_refs(axes.size());
100 for (size_t ax_n = 0; ax_n < axes.size(); ++ax_n) {
101 std::string ax_path = "ref_axes/axis_" + std::to_string(ax_n);
102 chkerr(H5Rcreate(&axis_refs.at(ax_n), hist_grp.getId(),
103 ax_path.c_str(), H5R_OBJECT, -1),
104 "axis object reference");
105 }
106 hsize_t ref_dim = axes.size();
107 H5::DataSpace ref_space(1, &ref_dim);
108 hist_grp.createDataSet("axes", H5::PredType::STD_REF_OBJ, ref_space)
109 .write(axis_refs.data(), H5::PredType::STD_REF_OBJ);
110}
void chkerr(herr_t code, const std::string &error)
void write_bool_attr(H5::H5Object &obj, const std::string &key, bool val)
void write_str_attr(H5::H5Object &obj, const std::string &key, const std::string &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)

◆ write_bool_attr()

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

Definition at line 29 of file HistCommon.cxx.

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

◆ write_double_attr()

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

Definition at line 50 of file HistCommon.cxx.

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

◆ write_int_attr()

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

Definition at line 40 of file HistCommon.cxx.

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

◆ write_str_attr()

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

Definition at line 18 of file HistCommon.cxx.

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

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 44 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 46 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 48 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 50 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 52 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 58 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 54 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 56 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 60 of file HistCommon.h.