Skip to content

Commit

Permalink
refactor of getter methods for datasets in hdf5_core
Browse files Browse the repository at this point in the history
  • Loading branch information
jarkenau committed Dec 19, 2023
1 parent d819e8d commit 68444d5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,30 +222,43 @@ class Hdf5CoreGeneral
std::shared_ptr<HighFive::Group> getHdf5Group(const std::string& group_path, bool create = true);

/**
* @brief Get a shared pointer to a hdf5 data set specified by the hdf5DataSetPath
* @brief Returns a shared pointer to a HighFive::DataSet object for the given dataset path.
*
* @tparam T type of the dataset
* @param hdf5DataSetPath path to the dataset
* @param dataSpace the data space to specify the dimensions of the dataset
* @return std::shared_ptr<HighFive::DataSet> shared pointer to the data set
* @param dataset_path The path to the dataset.
* @return std::shared_ptr<HighFive::DataSet> A shared pointer to the dataset object. Nullptr if the dataset does not exist.
*/
std::shared_ptr<HighFive::DataSet> getHdf5DataSet(const std::string& dataset_path);

/**
* @brief Returns a shared pointer to a HighFive::DataSet object for the given dataset path and data space.
*
* A new dataset will be created if it does not already exist.
*
* @tparam T The data type of the dataset.
* @param dataset_path The path to the dataset.
* @param dataspace The data space of the dataset.
* @return std::shared_ptr<HighFive::DataSet> A shared pointer to the HighFive dataset object.
*/
template <class T>
std::shared_ptr<HighFive::DataSet> getHdf5DataSet(const std::string& hdf5DataSetPath, HighFive::DataSpace& dataSpace);
std::shared_ptr<HighFive::DataSet> getHdf5DataSet(const std::string& dataset_path,
const HighFive::DataSpace& dataspace);

/**
* @brief Get a shared pointer to a hdf5 data set specified by the hdf5DataSetPath
* @brief Get a shared pointer to a HighFive::Dataset object for the given path, dataspace, and properties.
*
* A new dataset will be created if it does not already exist.
*
* @tparam T type of the dataset
* @param hdf5DataSetPath path to the dataset
* @param dataSpace the data space to specify the dimensions of the dataset
* @param createProps properties for creation of the dataset
* @return std::shared_ptr<HighFive::DataSet> shared pointer to the data set
* @tparam T The datatype of the dataset.
* @param dataset_path The path to the dataset.
* @param dataspace The dataspace of the dataset.
* @param properties The properties of the dataset.
* @return std::shared_ptr<HighFive::DataSet> A shared pointer to the HDF5 dataset.
*/
template <class T>
std::shared_ptr<HighFive::DataSet> getHdf5DataSet(const std::string& hdf5DataSetPath, HighFive::DataSpace& dataSpace,
HighFive::DataSetCreateProps& createProps);
std::shared_ptr<HighFive::DataSet> getHdf5DataSet(const std::string& dataset_path,
const HighFive::DataSpace& dataspace,
const HighFive::DataSetCreateProps& properties);

std::shared_ptr<HighFive::DataSet> getHdf5DataSet(const std::string& hdf5DataSetPath);
/**
* @brief get the labels of a group/dataset matching the general prefix (label type) and return the labels matching
* the specified type. Also extract the category from the postfix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,21 @@ void Hdf5CoreGeneral::writeFrameId(HighFive::AnnotateTraits<C>& object, const st

template <class T>
std::shared_ptr<HighFive::DataSet> Hdf5CoreGeneral::getHdf5DataSet(const std::string& hdf5DataSetPath,
HighFive::DataSpace& dataSpace)
const HighFive::DataSpace& dataSpace)
{
HighFive::DataSetCreateProps emptyProps;
return getHdf5DataSet<T>(hdf5DataSetPath, dataSpace, emptyProps);
return getHdf5DataSet<T>(hdf5DataSetPath, dataSpace, HighFive::DataSetCreateProps());
}

template <class T>
std::shared_ptr<HighFive::DataSet> Hdf5CoreGeneral::getHdf5DataSet(const std::string& hdf5DataSetPath,
HighFive::DataSpace& dataSpace,
HighFive::DataSetCreateProps& createProps)
std::shared_ptr<HighFive::DataSet> Hdf5CoreGeneral::getHdf5DataSet(const std::string& dataset_path,
const HighFive::DataSpace& dataspace,
const HighFive::DataSetCreateProps& properties)
{
try
{
checkExists(hdf5DataSetPath);
BOOST_LOG_SEV(m_logger, boost::log::trivial::severity_level::trace)
<< "hdf5 group" << hdf5DataSetPath << " already exists!";
return std::make_shared<HighFive::DataSet>(m_file->getDataSet(hdf5DataSetPath));
}
catch (std::invalid_argument const& e)
if (exists(dataset_path))
{
BOOST_LOG_SEV(m_logger, boost::log::trivial::severity_level::trace)
<< "hdf5 group " << hdf5DataSetPath << " does not exist! Creating a new group";
return std::make_shared<HighFive::DataSet>(m_file->createDataSet<T>(hdf5DataSetPath, dataSpace, createProps));
return std::make_shared<HighFive::DataSet>(m_file->getDataSet(dataset_path));
}
return std::make_shared<HighFive::DataSet>(m_file->createDataSet<T>(dataset_path, dataspace, properties));
}

template <class T>
Expand Down
5 changes: 1 addition & 4 deletions seerep_hdf5/seerep_hdf5_core/src/hdf5_core_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,7 @@ std::shared_ptr<HighFive::DataSet> Hdf5CoreGeneral::getHdf5DataSet(const std::st
{
return std::make_shared<HighFive::DataSet>(m_file->getDataSet(hdf5DataSetPath));
}
else
{
return nullptr;
}
return nullptr;
}

void Hdf5CoreGeneral::getLabelCategories(std::string id, std::string labelType,
Expand Down

0 comments on commit 68444d5

Please sign in to comment.