43#include "debug/Stats.hh"
54 for (
const auto &
s : labels) {
66 bool desc,
bool formulas)
67 : fname(file), timeChunk(chunking),
68 enableDescriptions(desc), enableFormula(formulas),
74 H5::Exception::dontPrint();
87 dumpCount > 0 ? H5F_ACC_RDWR : H5F_ACC_TRUNC);
116 }
catch (
const H5::FileIException&
e) {
118 }
catch (
const H5::GroupIException&
e) {
128 assert(!
path.empty());
138 hsize_t fdims[1] = { 0, };
153 warn_once(
"HDF5 stat files don't support distributions.\n");
159 warn_once(
"HDF5 stat files don't support vector distributions.\n");
168 hsize_t fdims[3] = { 0, info.
x, info.
y };
169 H5::DataSet data_set =
appendStat(info, 3, fdims, info.
cvec.data());
198 warn_once(
"HDF5 stat files don't support sparse histograms.\n");
208 hsize_t fdims[2] = { 0, vr.size() };
209 H5::DataSet data_set =
appendStat(info, 2, fdims, vr.data());
225 H5::Group group =
path.top();
226 H5::DataSet data_set;
227 H5::DataSpace fspace;
234 data_set = group.openDataSet(info.
name);
235 data_set.extend(dims);
236 fspace = data_set.getSpace();
240 H5::DSetCreatPropList props;
244 std::copy(dims, dims + rank, max_dims.begin());
245 max_dims[0] = H5S_UNLIMITED;
249 std::copy(dims, dims + rank, chunk_dims.begin());
251 props.setChunk(rank, chunk_dims.data());
256 fspace = H5::DataSpace(rank, dims, max_dims.data());
258 DPRINTF(Stats,
"Creating dataset %s in group %s\n",
259 info.
name, group.getObjnameByIdx(group.getId()));
260 data_set = group.createDataSet(info.
name,
261 H5::PredType::NATIVE_DOUBLE, fspace, props);
262 }
catch (
const H5::Exception &
e) {
263 std::string
err =
"Failed creating H5::DataSet " + info.
name +
"; ";
264 err +=
e.getDetailMsg() +
" in " +
e.getFuncName();
266 throw std::runtime_error(
err);
276 H5::DataSpace mspace(rank, dims);
280 fspace.selectHyperslab(H5S_SELECT_SET, dims, foffset.data());
281 data_set.write(
data, H5::PredType::NATIVE_DOUBLE, mspace, fspace);
290 H5::StrType
type(H5::PredType::C_S1, H5T_VARIABLE);
291 hsize_t dims[1] = { values.size(), };
292 H5::DataSpace space(1, dims);
293 H5::Attribute attribute = loc.createAttribute(
name,
type, space);
294 attribute.write(
type, values.data());
302 for (
int i = 0;
i < values.size(); ++
i)
303 cstrs[
i] = values[
i].c_str();
310 const std::string &value)
312 H5::StrType
type(H5::PredType::C_S1, value.length() + 1);
313 hsize_t dims[1] = { 1, };
314 H5::DataSpace space(1, dims);
315 H5::Attribute attribute = loc.createAttribute(
name,
type, space);
316 attribute.write(
type, value.c_str());
322 hsize_t dims[1] = { 1, };
323 H5::DataSpace space(1, dims);
324 H5::Attribute attribute = loc.createAttribute(
325 name, H5::PredType::NATIVE_DOUBLE, space);
326 attribute.write(H5::PredType::NATIVE_DOUBLE, &value);
330std::unique_ptr<Output>
331initHDF5(
const std::string &filename,
unsigned chunking,
332 bool desc,
bool formulas)
334 return std::unique_ptr<Output>(
std::string resolve(const std::string &name) const
Returns relative file names prepended with name of this directory.
H5::DataSet appendStat(const Info &info, int rank, hsize_t *dims, const double *data)
Helper function to append an n-dimensional double stat to the file.
bool valid() const override
const bool enableDescriptions
void addMetaData(H5::DataSet &loc, const char *name, const std::vector< const char * > &values)
Helper function to add a string vector attribute to a stat.
std::stack< H5::Group > path
H5::DataSet appendVectorInfo(const VectorInfo &info)
Helper function to append vector stats and set their metadata.
void visit(const ScalarInfo &info) override
void beginGroup(const char *name) override
std::string name
The name of the stat.
std::string desc
The description of the stat.
virtual Result result() const =0
std::vector< std::string > subdescs
std::vector< std::string > y_subnames
std::vector< std::string > subnames
Names and descriptions of subfields.
VCounter cvec
Local storage for the entry values, used for printing.
virtual const VResult & result() const =0
std::vector< std::string > subdescs
std::vector< std::string > subnames
Names and descriptions of subfields.
std::unique_ptr< Output > initHDF5(const std::string &filename, unsigned chunking, bool desc, bool formulas)
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
bool emptyStrings(const T &labels)
Check if all strings in a container are empty.
const std::string & name()