سؤال

I am using the HDF5 C++ API. I have a program that very occasionally has to write attributes larger than 64 kB. It throws an H5::AttributeIException when trying to write such a large attribute.

The HDF5 documentation mentions two ways of storing large attributes. The first option is dense storage (available since version 1.8.8, I think), while the second option is offloading the data in the attribute to an additional dataset, and storing a reference to that dataset inside the attribute. This second option is supposed to be backwards compatible, while the first option breaks compatibility with HDF5 versions before 1.8.8.

Unfortunately, there doesn't seem to be any documentation on how to implement either of these options in C++. I've tried to hack the first option by combining the C API with the C++ API. Here was my attempt, based on the dense storage example here:

hid_t dID = dataset->getId();
herr_t res = H5Pset_attr_phase_change(dID, 0, 0);
if(res < 0) {
    std::cerr << "Failed to specify dense storage." << std::endl;
}

Here, dataset is an H5::DataSet object. This code fails to set dense storage, as indicated by res always being negative. I think this may be due to the fact that I'm not specifying something like H5F_LIBVER_LATEST, as done in the C example of dense storage:

fpid = H5Pcreate (H5P_FILE_ACCESS);
status = H5Pset_libver_bounds (fpid, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
fid = H5Fcreate("adense.h5", H5F_ACC_TRUNC, H5P_DEFAULT, fpid);

I can't find any way in the C++ API to specify H5F_LIBVER_LATEST. The H5::FileAccPropList class doesn't have any member function akin to set_libver_bounds, as far as I can tell from the documentation.

As for the second option, that of storing the attribute as a reference to an auxiliary dataset, I don't know where to begin, since there's no example of this in the C++ documentation.

Does anyone know how to implement either dense storage, or storing attributes as references to datasets in C++?

هل كانت مفيدة؟

المحلول 2

For future references:

There is a method to set the lib version (with the C++ API):

void H5::FileAccPropList::setLibverBounds   (H5F_libver_t   libver_low,
                                             H5F_libver_t   libver_high 
                                            ) const

LINK:

نصائح أخرى

H5::FileAccPropList has an overloaded constructor that allows the object to inherit (or rather to wrap) an existing file access property list, created using the C API. So you should be able to do something like:

hid_t fapl = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
H5::FileAccPropList faplObj(fapl);
...

(not enough rep for commenting on the question).

The dense storage feature for attributes was introduced in release HDF5 1.8.0 according to https://support.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetAttrPhaseChange.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top