From 5fddba21350b4a99058d48a9e744e631d3f8d9c0 Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Thu, 25 Jul 2024 13:44:14 -0700 Subject: [PATCH] add conditional compiling for H5 object type --- src/hdf5/HDF5IO.cpp | 39 ++++++++++++++++++++------------------- src/hdf5/HDF5IO.hpp | 10 ++++++++++ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/hdf5/HDF5IO.cpp b/src/hdf5/HDF5IO.cpp index 7b2a325c..1d64255a 100644 --- a/src/hdf5/HDF5IO.cpp +++ b/src/hdf5/HDF5IO.cpp @@ -7,7 +7,6 @@ #include "HDF5IO.hpp" #include -#include #include "Utils.hpp" @@ -95,13 +94,8 @@ Status HDF5IO::createAttribute(const BaseDataType& type, if (!opened) return Status::Failure; - // get whether path is a dataset or group - H5O_info_t objInfo; // Structure to hold information about the object - H5Oget_info_by_name( - file->getId(), path.c_str(), &objInfo, H5O_INFO_BASIC, H5P_DEFAULT); - H5O_type_t objectType = objInfo.type; - // open the group or dataset + H5O_type_t objectType = getObjectType(path); switch (objectType) { case H5O_TYPE_GROUP: gloc = file->openGroup(path); @@ -178,13 +172,8 @@ Status HDF5IO::createAttribute(const std::vector& data, StrType H5type(PredType::C_S1, maxSize); H5type.setSize(H5T_VARIABLE); - // get whether path is a dataset or group - H5O_info_t objInfo; // Structure to hold information about the object - H5Oget_info_by_name( - file->getId(), path.c_str(), &objInfo, H5O_INFO_BASIC, H5P_DEFAULT); - H5O_type_t objectType = objInfo.type; - // open the group or dataset + H5O_type_t objectType = getObjectType(path); switch (objectType) { case H5O_TYPE_GROUP: gloc = file->openGroup(path); @@ -237,13 +226,8 @@ Status HDF5IO::createReferenceAttribute(const std::string& referencePath, if (!opened) return Status::Failure; - // get whether path is a dataset or group - H5O_info_t objInfo; // Structure to hold information about the object - H5Oget_info_by_name( - file->getId(), path.c_str(), &objInfo, H5O_INFO_BASIC, H5P_DEFAULT); - H5O_type_t objectType = objInfo.type; - // open the group or dataset + H5O_type_t objectType = getObjectType(path); switch (objectType) { case H5O_TYPE_GROUP: gloc = file->openGroup(path); @@ -454,6 +438,23 @@ AQNWB::BaseRecordingData* HDF5IO::createDataSet(const BaseDataType& type, return new HDF5RecordingData(data.release()); } +H5O_type_t HDF5IO::getObjectType(const std::string& path) +{ +#if H5_VERSION_GE(1, 12, 0) + // get whether path is a dataset or group + H5O_info_t objInfo; // Structure to hold information about the object + H5Oget_info_by_name( + this->file->getId(), path.c_str(), &objInfo, H5O_INFO_BASIC, H5P_DEFAULT); +#else + // get whether path is a dataset or group + H5O_info_t objInfo; // Structure to hold information about the object + H5Oget_info_by_name(this->file->getId(), path.c_str(), &objInfo, H5P_DEFAULT); +#endif + H5O_type_t objectType = objInfo.type; + + return objectType; +} + H5::DataType HDF5IO::getNativeType(BaseDataType type) { H5::DataType baseType; diff --git a/src/hdf5/HDF5IO.hpp b/src/hdf5/HDF5IO.hpp index 03ff379b..7ba58056 100644 --- a/src/hdf5/HDF5IO.hpp +++ b/src/hdf5/HDF5IO.hpp @@ -4,8 +4,11 @@ #include #include +#include + #include "BaseIO.hpp" #include "Types.hpp" + namespace H5 { class DataSet; @@ -194,6 +197,13 @@ class HDF5IO : public BaseIO */ BaseRecordingData* getDataSet(const std::string& path) override; + /** + * @brief Returns the HDF5 type of object at a given path. + * @param path The location in the file of the object. + * @return The type of object at the given path. + */ + H5O_type_t getObjectType(const std::string& path); + /** * @brief Returns the HDF5 native data type for a given base data type. * @param type The base data type.