rank of virtual parameters is 2 and not 1 as in single module, single file acquisition

This commit is contained in:
maliakal_d 2024-12-05 01:02:48 +01:00
parent e5df929a9a
commit 0b252709bd
2 changed files with 13 additions and 7 deletions

View File

@ -20,7 +20,7 @@ struct H5Handles {
std::vector<hsize_t> count;
std::vector<hsize_t> offset;
H5Handles(const std::string& fname, const std::string& dname, int rank):
H5Handles(const std::string& fname, const std::string& dname):
file_name(fname),
dataset_name(dname),
file(fname, H5F_ACC_RDONLY),
@ -28,9 +28,8 @@ struct H5Handles {
dataspace(dataset.getSpace()),
datatype(dataset.getDataType())
{
if (dataspace.getSimpleExtentNdims() != rank) {
throw std::runtime_error(LOCATION + "Expected rank of " + dname + " dataset to be " + std::to_string(rank) + ". Got " + std::to_string(dataspace.getSimpleExtentNdims()));
}
// get dimensions
int rank = dataspace.getSimpleExtentNdims();
dims.resize(rank);
dataspace.getSimpleExtentDims(dims.data(), nullptr);
@ -41,6 +40,13 @@ struct H5Handles {
// header datasets
if (rank == 1) {
memspace = std::make_unique<H5::DataSpace>(H5S_SCALAR);
}
// header virtual datasets
else if (rank == 2) {
hsize_t dimsm[1] = {dims[1]};
memspace = std::make_unique<H5::DataSpace>(1, dimsm);
count.push_back(dims[1]);
offset.push_back(0);
}
// data dataset
else {

View File

@ -87,7 +87,7 @@ DetectorHeader Hdf5File::read_header(const std::filesystem::path &fname) {
std::vector<std::unique_ptr<H5Handles>> handles;
try {
for (size_t i = 0; i != header_dataset_names.size(); ++i) {
handles.push_back(std::make_unique<H5Handles>(fname.string(), metadata_group_name+ header_dataset_names[i], 1));
handles.push_back(std::make_unique<H5Handles>(fname.string(), metadata_group_name+ header_dataset_names[i]));
}
handles[0]->get_frame_into(0, reinterpret_cast<std::byte *>(&(h.frameNumber)));
handles[1]->get_frame_into(0, reinterpret_cast<std::byte *>(&(h.expLength)));
@ -213,7 +213,7 @@ void Hdf5File::open_data_file() {
throw std::runtime_error(LOCATION +
"Unsupported mode. Can only read Hdf5 files.");
try {
m_data_file = std::make_unique<H5Handles>(m_master.master_fname().string(), metadata_group_name + "/data", 3);
m_data_file = std::make_unique<H5Handles>(m_master.master_fname().string(), metadata_group_name + "/data");
m_total_frames = m_data_file->dims[0];
m_rows = m_data_file->dims[1];
@ -235,7 +235,7 @@ void Hdf5File::open_header_files() {
"Unsupported mode. Can only read Hdf5 files.");
try {
for (size_t i = 0; i != header_dataset_names.size(); ++i) {
m_header_files.push_back(std::make_unique<H5Handles>(m_master.master_fname().string(), metadata_group_name + header_dataset_names[i], 1));
m_header_files.push_back(std::make_unique<H5Handles>(m_master.master_fname().string(), metadata_group_name + header_dataset_names[i]));
//fmt::print("{} Dataset dimensions: size = {}\n",
// header_dataset_names[i], m_header_files[i]->dims[0]);
}