Skip to content

Commit

Permalink
add conditional compiling for H5 object type
Browse files Browse the repository at this point in the history
  • Loading branch information
stephprince committed Jul 25, 2024
1 parent b3c1110 commit 5fddba2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/hdf5/HDF5IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "HDF5IO.hpp"

#include <H5Cpp.h>
#include <H5Opublic.h>

#include "Utils.hpp"

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -178,13 +172,8 @@ Status HDF5IO::createAttribute(const std::vector<const char*>& 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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/hdf5/HDF5IO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
#include <memory>
#include <string>

#include <H5Opublic.h>

#include "BaseIO.hpp"
#include "Types.hpp"

namespace H5
{
class DataSet;
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 5fddba2

Please sign in to comment.