Commit 613aa2e0 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron
Browse files

[PROC][SMX] Use HDF5 wrapper to read the kernel params from files

parent 41bf10ab
Pipeline #74559 passed with stages
in 9 minutes and 40 seconds
......@@ -24,28 +24,22 @@ namespace processing::pipelines
lima::frame read_h5_file(lima::pixel_enum pixel, int dataset_dims, std::filesystem::path file_path,
lima::io::h5::path const& data_path = "/data")
{
namespace h5 = lima::io::h5;
LIMA_LOG(trace, proc) << "Loading file: " << file_path << " [" << data_path.c_str() << "] ...";
// load data from H5 file
hid_t file_id = H5Fopen(file_path.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
if (file_id < 0)
LIMA_THROW_EXCEPTION(lima::runtime_error("Failed to open HDF5 file"));
auto file = h5::file::open(file_path);
// Open an existing dataset
hid_t dataset_id = H5Dopen2(file_id, data_path.c_str(), H5P_DEFAULT);
if (dataset_id < 0)
LIMA_THROW_EXCEPTION(lima::runtime_error("Failed to open HDF5 dataset"));
auto dataset = h5::dataset::open(file, data_path);
// Check the dimensions
assert((dataset_dims > 0) && (dataset_dims <= 3));
hid_t dataspace_id = H5Dget_space(dataset_id);
const int ndims = H5Sget_simple_extent_ndims(dataspace_id);
if (ndims != dataset_dims)
LIMA_THROW_EXCEPTION(
lima::invalid_argument("Invalid dataset number of dimensions: " + std::to_string(ndims)));
auto dataspace = dataset.space();
const int ndims = dataspace.ndims();
hsize_t dims[ndims];
H5Sget_simple_extent_dims(dataspace_id, dims, NULL);
dataspace.dims(dims, nullptr);
// Last dimension defines the nb of colums
const int last_dim = dataset_dims - 1;
......@@ -59,26 +53,8 @@ namespace processing::pipelines
auto ptr = boost::gil::apply_operation(view, [&](auto&& v) { return static_cast<void*>(&v(0, 0)); });
// Read the dataset
hid_t dtype_id = lima::io::h5::datatype(view);
herr_t res;
res = H5Dread(dataset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, ptr);
if (res < 0)
LIMA_THROW_EXCEPTION(lima::hdf5_error("H5Dread error") << boost::errinfo_errno(res));
// Close the dataspace
res = H5Sclose(dataspace_id);
if (res < 0)
LIMA_THROW_EXCEPTION(lima::hdf5_error("H5Sclose error") << boost::errinfo_errno(res));
// Close the dataset
res = H5Dclose(dataset_id);
if (res < 0)
LIMA_THROW_EXCEPTION(lima::hdf5_error("H5Dclose error") << boost::errinfo_errno(res));
// Close the file
res = H5Fclose(file_id);
if (res < 0)
LIMA_THROW_EXCEPTION(lima::hdf5_error("H5Fclose error") << boost::errinfo_errno(res));
auto dtype = h5::datatype(view);
dataset.read(ptr, dtype);
LIMA_LOG(trace, proc) << "File loaded with " << dims[1] << "x" << dims[0] << " pixels";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment