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

An HDF5 File loaded into memory. More...

#include <hdf5.h>

Public Types

typedef boost::make_recursive_variant< HDF5DataPtr, std::map< std::string, boost::recursive_variant_ > >::type Node
 A recursive map that has a dictionary-like structure to store HDF5 datasets. More...
 
typedef std::map< std::string, NodeNodeMap
 A specific map in the recursive set. More...
 

Public Member Functions

 HDF5File (const std::string &filename)
 Constructor. Opens filename. More...
 
const HDF5DataPtr getData (const std::vector< std::string > &keys) const
 Get the dataset under the set of keys. Each key is applied successively. More...
 
const std::vector< std::vector< std::string > > getKeys () const
 Gets all valid keys in the file. More...
 

Private Member Functions

template<typename T >
std::vector< std::stringlistObjects (const T &location) const
 List the objects at the HDF5 location. More...
 
template<typename T >
void loadData (Node &node, const T &location, const std::string &name)
 Loads the data in the object name at the HDF5 location. Recursive. More...
 

Private Attributes

const H5::H5File file_
 The loaded HDF5 file. More...
 
Node data_
 A recursive map of loaded data. More...
 

Detailed Description

An HDF5 File loaded into memory.

Definition at line 89 of file hdf5.h.

Member Typedef Documentation

◆ Node

typedef boost::make_recursive_variant< HDF5DataPtr, std::map<std::string, boost::recursive_variant_> >::type robowflex::IO::HDF5File::Node

A recursive map that has a dictionary-like structure to store HDF5 datasets.

Definition at line 95 of file hdf5.h.

◆ NodeMap

A specific map in the recursive set.

Definition at line 98 of file hdf5.h.

Constructor & Destructor Documentation

◆ HDF5File()

IO::HDF5File::HDF5File ( const std::string filename)

Constructor. Opens filename.

Parameters
[in]filenameFile to open.

IO::HDF5File

Definition at line 143 of file hdf5.cpp.

144  : file_(IO::resolvePath(filename), H5F_ACC_RDONLY), data_(NodeMap())
145 {
146  for (const auto &obj : listObjects(file_))
147  loadData(data_, file_, obj);
148 }
Node data_
A recursive map of loaded data.
Definition: hdf5.h:134
std::vector< std::string > listObjects(const T &location) const
List the objects at the HDF5 location.
Definition: hdf5.cpp:238
void loadData(Node &node, const T &location, const std::string &name)
Loads the data in the object name at the HDF5 location. Recursive.
Definition: hdf5.cpp:251
const H5::H5File file_
The loaded HDF5 file.
Definition: hdf5.h:133
std::map< std::string, Node > NodeMap
A specific map in the recursive set.
Definition: hdf5.h:98
std::string resolvePath(const std::string &path)
Resolves package:// URLs and relative file paths to their canonical form.

Member Function Documentation

◆ getData()

const IO::HDF5DataPtr IO::HDF5File::getData ( const std::vector< std::string > &  keys) const

Get the dataset under the set of keys. Each key is applied successively.

Parameters
[in]keysThe keys for the dataset to access.
Returns
The loaded HDF5 dataset.

Definition at line 220 of file hdf5.cpp.

221 {
222  const NodeMap &node = boost::get<NodeMap>(data_);
223  return getDataHelper(keys, node);
224 }

◆ getKeys()

const std::vector< std::vector< std::string > > IO::HDF5File::getKeys ( ) const

Gets all valid keys in the file.

Returns
All keys in the file. Keys are vectors of strings.

Definition at line 226 of file hdf5.cpp.

227 {
228  const NodeMap &node = boost::get<NodeMap>(data_);
231 
232  getKeysHelper(keys, key, node);
233 
234  return keys;
235 }

◆ listObjects()

template<typename T >
template std::vector< std::string > IO::HDF5File::listObjects ( const T &  location) const
private

List the objects at the HDF5 location.

Parameters
[in]locationThe location to search
Template Parameters
TA HDF5 object.

Definition at line 238 of file hdf5.cpp.

239 {
241  for (hsize_t i = 0; i < location.getNumObjs(); ++i)
242  names.emplace_back(location.getObjnameByIdx(i));
243 
244  return names;
245 }
T emplace_back(T... args)

◆ loadData()

template<typename T >
template void IO::HDF5File::loadData ( Node node,
const T &  location,
const std::string name 
)
private

Loads the data in the object name at the HDF5 location. Recursive.

Parameters
[in]nodeThe node to add data to.
[in]locationThe location to search
[in]nameThe name to search for.
Template Parameters
TA HDF5 object.

Definition at line 251 of file hdf5.cpp.

252 {
253  auto &map = boost::get<NodeMap>(node);
254 
255 #if ROBOWFLEX_AT_LEAST_KINETIC
256  H5O_type_t type = location.childObjType(name);
257 #else
258  H5O_type_t type = childObjType(location, name);
259 #endif
260 
261  switch (type)
262  {
263  case H5O_TYPE_GROUP:
264  {
265  map[name] = NodeMap();
266 
267  H5::Group group = location.openGroup(name);
268  for (const auto &obj : listObjects(group))
269  loadData(map[name], group, obj);
270 
271  break;
272  }
273  case H5O_TYPE_DATASET:
274  {
275  map[name] = std::make_shared<HDF5Data>(location, name);
276  break;
277  }
278 
279  // case H5O_TYPE_NAMED_DATATYPE:
280  // case H5O_TYPE_NTYPES:
281  default:
282  break;
283  };
284 }

Member Data Documentation

◆ data_

Node robowflex::IO::HDF5File::data_
private

A recursive map of loaded data.

Definition at line 134 of file hdf5.h.

◆ file_

const H5::H5File robowflex::IO::HDF5File::file_
private

The loaded HDF5 file.

Definition at line 133 of file hdf5.h.


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