19 : dataset_(location.openDataSet(name))
20 , space_(dataset_.getSpace())
21 , type_(dataset_.getTypeClass())
22 , rank_(space_.getSimpleExtentNdims())
24 auto *dims =
new hsize_t[
rank_];
25 space_.getSimpleExtentDims(dims);
29 const auto &properties = getDataProperties();
33 dataset_.read(data, std::get<0>(properties), space_, space_);
68 ss <<
"Rank: " << rank_ <<
", ";
69 ss <<
"Type: " << std::get<2>(getDataProperties()) <<
", ";
71 for (
int i = 0; i < rank_; ++i)
83 hsize_t hpow(hsize_t base, hsize_t exp)
101 if (index.
size() != (
unsigned int)rank_)
102 throw Exception(1,
"Index size must be the same as data rank!");
104 const T *data =
reinterpret_cast<const T *
>(data_);
105 unsigned int offset = 0;
107 for (
int i = 0; i < rank_; ++i)
108 offset += hpow(dims_[i], i) * index[rank_ - (i + 1)];
121 return std::make_tuple(H5::PredType::NATIVE_INT,
sizeof(
int),
"integer");
123 return std::make_tuple(H5::PredType::NATIVE_DOUBLE,
sizeof(
double),
"double");
155 for (
const auto &element : node)
162 const auto &next = boost::get<IO::HDF5File::NodeMap>(element.second);
163 getKeysHelper(keys, next_key, next);
167 keys.push_back(next_key);
177 const auto &element = node.
find(keys.
front());
178 if (element == node.
end())
183 const auto &
next = boost::get<IO::HDF5File::NodeMap>(element->second);
185 return getDataHelper(copy, next);
189 return boost::get<IO::HDF5DataPtr>(element->second);
195 template <
typename T>
196 H5O_type_t childObjType(
const T &location,
const std::string &name)
199 H5O_type_t type = H5O_TYPE_UNKNOWN;
201 herr_t r = H5Oget_info_by_name(location.getId(), name.
c_str(), &info, H5P_DEFAULT);
209 case H5O_TYPE_DATASET:
210 case H5O_TYPE_NAMED_DATATYPE:
222 const NodeMap &node = boost::get<NodeMap>(data_);
223 return getDataHelper(keys, node);
228 const NodeMap &node = boost::get<NodeMap>(data_);
232 getKeysHelper(keys, key, node);
237 template <
typename T>
241 for (hsize_t i = 0; i < location.getNumObjs(); ++i)
250 template <
typename T>
253 auto &map = boost::get<NodeMap>(node);
255 #if ROBOWFLEX_AT_LEAST_KINETIC
256 H5O_type_t type = location.childObjType(name);
258 H5O_type_t type = childObjType(location, name);
267 H5::Group group = location.openGroup(name);
268 for (
const auto &obj : listObjects(group))
269 loadData(map[name], group, obj);
273 case H5O_TYPE_DATASET:
275 map[name] = std::make_shared<HDF5Data>(location, name);
Exception that contains a message and an error code.
const void * getData() const
Get a pointer to the underlying data array. It is of size type[dim0][dim1]...
const std::string getStatus() const
Get a string describing the data.
~HDF5Data()
Destructor. Cleans up all read data.
const int rank_
Rank of the dataset.
HDF5Data(const T &location, const std::string &name)
Constructor. Loads reads DataSet from file.
const T & get(const std::vector< hsize_t > &index) const
Get the value at an index.
const std::vector< hsize_t > getDims() const
Gets the dimensions of the data. Can be used to create the array necessary to store results.
const H5::DataSpace space_
Size of the dataset.
std::tuple< H5::PredType, unsigned int, std::string > getDataProperties() const
Return information about the data type of the data.
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.
Node data_
A recursive map of loaded data.
std::vector< std::string > listObjects(const T &location) const
List the objects at the HDF5 location.
void loadData(Node &node, const T &location, const std::string &name)
Loads the data in the object name at the HDF5 location. Recursive.
const std::vector< std::vector< std::string > > getKeys() const
Gets all valid keys in the file.
const H5::H5File file_
The loaded HDF5 file.
HDF5File(const std::string &filename)
Constructor. Opens filename.
const HDF5DataPtr getData(const std::vector< std::string > &keys) const
Get the dataset under the set of keys. Each key is applied successively.
T emplace_back(T... args)
#define ROBOWFLEX_PUSH_DISABLE_GCC_WARNING(warning)
#define ROBOWFLEX_POP_GCC
std::string resolvePath(const std::string &path)
Resolves package:// URLs and relative file paths to their canonical form.
Main namespace. Contains all library classes and functions.