Skip to content

Commit

Permalink
refactor data group accessor method in hdf5-core-general
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Arkenau committed Oct 20, 2022
1 parent 1b155b8 commit f077a9f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,13 @@ class Hdf5CoreGeneral
// Hdf5
//################
/**
* @brief Get a shared pointer to a hdf5 group specified by the hdf5GroupPath.
*
* If a group with the path already exists we use that, otherwise a new one is created.
* @brief Get a shared pointer to a hdf5 group
*
* @param hdf5GroupPath path to the data group
* @param create create a new group if the group path can't be found?
* @return std::shared_ptr<HighFive::Group> shared pointer to the group
*/
std::shared_ptr<HighFive::Group> getHdf5Group(const std::string& hdf5GroupPath);
std::shared_ptr<HighFive::Group> getHdf5Group(const std::string& hdf5GroupPath, bool create = true);
/**
* @brief Get a shared pointer to a hdf5 data set specified by the hdf5DataSetPath
*
Expand Down
11 changes: 9 additions & 2 deletions seerep-hdf5/seerep-hdf5-core/src/hdf5-core-general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void Hdf5CoreGeneral::readInstances(const std::string& id, const std::string ins
datasetInstances.read(instances);
}

std::shared_ptr<HighFive::Group> Hdf5CoreGeneral::getHdf5Group(const std::string& hdf5GroupPath)
std::shared_ptr<HighFive::Group> Hdf5CoreGeneral::getHdf5Group(const std::string& hdf5GroupPath, bool create)
{
try
{
Expand All @@ -379,7 +379,14 @@ std::shared_ptr<HighFive::Group> Hdf5CoreGeneral::getHdf5Group(const std::string
{
BOOST_LOG_SEV(m_logger, boost::log::trivial::severity_level::trace)
<< "hdf5 group " << hdf5GroupPath << " does not exist! Creating a new group";
return std::make_shared<HighFive::Group>(m_file->createGroup(hdf5GroupPath));
if (create)
{
return std::make_shared<HighFive::Group>(m_file->createGroup(hdf5GroupPath));
}
else
{
return nullptr;
}
}
}

Expand Down
11 changes: 2 additions & 9 deletions seerep-hdf5/seerep-hdf5-fb/src/hdf5-fb-pointcloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,10 @@ Hdf5FbPointCloud::readPointCloud2(const std::string& id, const bool withoutData)
BOOST_LOG_SEV(m_logger, boost::log::trivial::severity_level::debug)
<< "loading flatbuffers point cloud from: " << hdf5GroupPath;

std::shared_ptr<HighFive::Group> dataGroupPtr;
std::shared_ptr<HighFive::Group> dataGroupPtr = getHdf5Group(hdf5GroupPath, false);

try
{
checkExists(hdf5GroupPath);
dataGroupPtr = std::make_shared<HighFive::Group>(m_file->getGroup(hdf5GroupPath));
}
catch (std::invalid_argument const& e)
if (!dataGroupPtr)
{
BOOST_LOG_SEV(m_logger, boost::log::trivial::severity_level::warning)
<< "hdf5 group " << hdf5GroupPath << " does not exist!";
return std::nullopt;
}

Expand Down

0 comments on commit f077a9f

Please sign in to comment.