Robowflex  v0.1
Making MoveIt Easy
robowflex::IO::HDF5Data Class Reference

A container class for HDF5 DataSets loaded by an HDF5File. More...

#include <hdf5.h>

Public Member Functions

template<typename T >
 HDF5Data (const T &location, const std::string &name)
 Constructor. Loads reads DataSet from file. More...
 
 ~HDF5Data ()
 Destructor. Cleans up all read data. More...
 
const std::vector< hsize_t > getDims () const
 Gets the dimensions of the data. Can be used to create the array necessary to store results. More...
 
const void * getData () const
 Get a pointer to the underlying data array. It is of size type[dim0][dim1]... More...
 
const std::string getStatus () const
 Get a string describing the data. More...
 
template<typename T >
const T & get (const std::vector< hsize_t > &index) const
 Get the value at an index. More...
 

Private Member Functions

std::tuple< H5::PredType, unsigned int, std::stringgetDataProperties () const
 Return information about the data type of the data. More...
 

Private Attributes

const H5::DataSet dataset_
 Dataset being read from. More...
 
const H5::DataSpace space_
 Size of the dataset. More...
 
const H5T_class_t type_
 Type of the dataset. More...
 
const int rank_
 Rank of the dataset. More...
 
const hsize_t * dims_
 Dimensions of the dataset (rank_ dimensions) More...
 
const void * data_
 Data itself. More...
 

Detailed Description

A container class for HDF5 DataSets loaded by an HDF5File.

Definition at line 32 of file hdf5.h.

Constructor & Destructor Documentation

◆ HDF5Data()

template<typename T >
template IO::HDF5Data::HDF5Data ( const T &  location,
const std::string name 
)

Constructor. Loads reads DataSet from file.

Parameters
[in]locationLocation to read data from.
[in]nameName of object to read.
Template Parameters
H5type to read.

IO::HDF5Data

Definition at line 18 of file hdf5.cpp.

19  : dataset_(location.openDataSet(name))
20  , space_(dataset_.getSpace())
21  , type_(dataset_.getTypeClass())
22  , rank_(space_.getSimpleExtentNdims())
23  , dims_([&] {
24  auto *dims = new hsize_t[rank_];
25  space_.getSimpleExtentDims(dims);
26  return dims;
27  }())
28  , data_([&] {
29  const auto &properties = getDataProperties();
30  void *data = std::malloc(std::get<1>(properties) * //
32 
33  dataset_.read(data, std::get<0>(properties), space_, space_);
34  return data;
35  }())
36 {
37 }
T accumulate(T... args)
const hsize_t * dims_
Dimensions of the dataset (rank_ dimensions)
Definition: hdf5.h:82
const void * data_
Data itself.
Definition: hdf5.h:84
const H5::DataSet dataset_
Dataset being read from.
Definition: hdf5.h:77
const int rank_
Rank of the dataset.
Definition: hdf5.h:81
const H5T_class_t type_
Type of the dataset.
Definition: hdf5.h:80
const H5::DataSpace space_
Size of the dataset.
Definition: hdf5.h:78
std::tuple< H5::PredType, unsigned int, std::string > getDataProperties() const
Return information about the data type of the data.
Definition: hdf5.cpp:116
T malloc(T... args)

◆ ~HDF5Data()

IO::HDF5Data::~HDF5Data ( )

Destructor. Cleans up all read data.

Definition at line 42 of file hdf5.cpp.

43 {
44  delete dims_;
45 
46  // clang-format off
48  // clang-format on
49 
50  std::free((void *)data_);
52 }
T free(T... args)
#define ROBOWFLEX_PUSH_DISABLE_GCC_WARNING(warning)
Definition: macros.h:77
#define ROBOWFLEX_POP_GCC
Definition: macros.h:80

Member Function Documentation

◆ get()

template<typename T >
template const double & IO::HDF5Data::get ( const std::vector< hsize_t > &  index) const

Get the value at an index.

Parameters
[in]indexThe indices at each dimension.
Template Parameters
Thereturn type of the data.
Returns
The value at the index in the data.

Definition at line 99 of file hdf5.cpp.

100 {
101  if (index.size() != (unsigned int)rank_)
102  throw Exception(1, "Index size must be the same as data rank!");
103 
104  const T *data = reinterpret_cast<const T *>(data_);
105  unsigned int offset = 0;
106 
107  for (int i = 0; i < rank_; ++i)
108  offset += hpow(dims_[i], i) * index[rank_ - (i + 1)];
109 
110  return data[offset];
111 }
Exception that contains a message and an error code.
Definition: util.h:15
T size(T... args)

◆ getData()

const void * IO::HDF5Data::getData ( ) const

Get a pointer to the underlying data array. It is of size type[dim0][dim1]...

Returns
A pointer to the data array.

Definition at line 59 of file hdf5.cpp.

60 {
61  return data_;
62 }

◆ getDataProperties()

std::tuple< H5::PredType, unsigned int, std::string > IO::HDF5Data::getDataProperties ( ) const
private

Return information about the data type of the data.

Returns
The H5 type, the size of, and the name of the data type.

Definition at line 116 of file hdf5.cpp.

117 {
118  switch (type_)
119  {
120  case H5T_INTEGER:
121  return std::make_tuple(H5::PredType::NATIVE_INT, sizeof(int), "integer");
122  case H5T_FLOAT:
123  return std::make_tuple(H5::PredType::NATIVE_DOUBLE, sizeof(double), "double");
124  // case H5T_TIME:
125  // case H5T_STRING:
126  // case H5T_BITFIELD:
127  // case H5T_OPAQUE:
128  // case H5T_COMPOUND:
129  // case H5T_REFERENCE:
130  // case H5T_ENUM:
131  // case H5T_VLEN:
132  // case H5T_ARRAY:
133  default:
134  return std::make_tuple(H5::PredType::NATIVE_OPAQUE, 0, "unknown");
135  break;
136  }
137 }
T make_tuple(T... args)

◆ getDims()

const std::vector< hsize_t > IO::HDF5Data::getDims ( ) const

Gets the dimensions of the data. Can be used to create the array necessary to store results.

Returns
The dimensions of the data.

Definition at line 54 of file hdf5.cpp.

55 {
57 }

◆ getStatus()

const std::string IO::HDF5Data::getStatus ( ) const

Get a string describing the data.

Returns
A string describing the data.

Definition at line 64 of file hdf5.cpp.

65 {
67  ss << "HDF5DataSet ";
68  ss << "Rank: " << rank_ << ", ";
69  ss << "Type: " << std::get<2>(getDataProperties()) << ", ";
70  ss << "Dimensions: ";
71  for (int i = 0; i < rank_; ++i)
72  {
73  if (i > 0)
74  ss << " x ";
75  ss << dims_[i];
76  }
77 
78  return ss.str();
79 }
T str(T... args)

Member Data Documentation

◆ data_

const void* robowflex::IO::HDF5Data::data_
private

Data itself.

Definition at line 84 of file hdf5.h.

◆ dataset_

const H5::DataSet robowflex::IO::HDF5Data::dataset_
private

Dataset being read from.

Definition at line 77 of file hdf5.h.

◆ dims_

const hsize_t* robowflex::IO::HDF5Data::dims_
private

Dimensions of the dataset (rank_ dimensions)

Definition at line 82 of file hdf5.h.

◆ rank_

const int robowflex::IO::HDF5Data::rank_
private

Rank of the dataset.

Definition at line 81 of file hdf5.h.

◆ space_

const H5::DataSpace robowflex::IO::HDF5Data::space_
private

Size of the dataset.

Definition at line 78 of file hdf5.h.

◆ type_

const H5T_class_t robowflex::IO::HDF5Data::type_
private

Type of the dataset.

Definition at line 80 of file hdf5.h.


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