diff --git a/seerep-hdf5/seerep-hdf5-core/include/seerep-hdf5-core/hdf5-core-general.h b/seerep-hdf5/seerep-hdf5-core/include/seerep-hdf5-core/hdf5-core-general.h index 3d15e4917..80fbbbf87 100644 --- a/seerep-hdf5/seerep-hdf5-core/include/seerep-hdf5-core/hdf5-core-general.h +++ b/seerep-hdf5/seerep-hdf5-core/include/seerep-hdf5-core/hdf5-core-general.h @@ -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 shared pointer to the group */ - std::shared_ptr getHdf5Group(const std::string& hdf5GroupPath); + std::shared_ptr getHdf5Group(const std::string& hdf5GroupPath, bool create = true); /** * @brief Get a shared pointer to a hdf5 data set specified by the hdf5DataSetPath * diff --git a/seerep-hdf5/seerep-hdf5-core/src/hdf5-core-general.cpp b/seerep-hdf5/seerep-hdf5-core/src/hdf5-core-general.cpp index 3e0815289..c047a3577 100644 --- a/seerep-hdf5/seerep-hdf5-core/src/hdf5-core-general.cpp +++ b/seerep-hdf5/seerep-hdf5-core/src/hdf5-core-general.cpp @@ -366,7 +366,7 @@ void Hdf5CoreGeneral::readInstances(const std::string& id, const std::string ins datasetInstances.read(instances); } -std::shared_ptr Hdf5CoreGeneral::getHdf5Group(const std::string& hdf5GroupPath) +std::shared_ptr Hdf5CoreGeneral::getHdf5Group(const std::string& hdf5GroupPath, bool create) { try { @@ -379,7 +379,14 @@ std::shared_ptr 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(m_file->createGroup(hdf5GroupPath)); + if (create) + { + return std::make_shared(m_file->createGroup(hdf5GroupPath)); + } + else + { + return nullptr; + } } } diff --git a/seerep-hdf5/seerep-hdf5-fb/src/hdf5-fb-pointcloud.cpp b/seerep-hdf5/seerep-hdf5-fb/src/hdf5-fb-pointcloud.cpp index 001329c9e..3103827bb 100644 --- a/seerep-hdf5/seerep-hdf5-fb/src/hdf5-fb-pointcloud.cpp +++ b/seerep-hdf5/seerep-hdf5-fb/src/hdf5-fb-pointcloud.cpp @@ -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 dataGroupPtr; + std::shared_ptr dataGroupPtr = getHdf5Group(hdf5GroupPath, false); - try - { - checkExists(hdf5GroupPath); - dataGroupPtr = std::make_shared(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; }