Describe the bug
Reading a files with mesh data with constant record components fails.
To Reproduce
I added the following sample file (constant, scalar mesh "rho"): 3_write_serial.h5.tar.gz
#include <openPMD/openPMD.hpp>
int main()
{
using openPMD;
Series series = Series(
"samples/3_write_serial.h5",
AccessType::READ_ONLY
);
return 0;
}
fails with:
HDF5-DIAG: Error detected in HDF5 (1.10.0-patch1) thread 0:
#000: ../../../src/H5A.c line 438 in H5Aopen(): unable to load attribute info from object header for attribute: 'position'
major: Attribute
minor: Unable to initialize object
#001: ../../../src/H5Oattribute.c line 530 in H5O_attr_open_by_name(): can't locate attribute: 'position'
major: Attribute
minor: Object not found
terminate called after throwing an instance of 'std::runtime_error'
what(): Internal error: Failed to open HDF5 attribute during attribute read
Expected behavior
Should be able to read the position attribute from a constant record component.
Also, if position is indeed missing, we should handle the backend (e..g HDF5) error gracefully and throw ourselves. The read should not crash in the HDF5 layer.
Software Environment:
cc @C0nsultant any idea what's wrong here? Looks to me like the attribute is properly written in const and non-constant records but the logic for reading might be off in the constant record component case?
@ax3l will look into it when I have some spare time on my hands today.
Without much digging: The reference file looks fine.
This is probably easier than expected.
The code of interest for reading constant scalar meshes is in Iteration::read(), Mesh::read() and MeshRecordComponent::read().
It looks mostly correct, but lacks a call to open the path for the RecordComponent (the same path that has already been opened for the Record, analogous to the flow for the non-constant scalar mesh).
As the underlying Writable does not know its corresponding location in the HDF5 file, the attribute read for position fails.
I can only test this later today, but my first shot will be to replace code in Iteration::read() with
if( value != end && shape != end )
{
MeshRecordComponent& mrc = m[MeshRecordComponent::SCALAR];
mrc.parent = m.parent;
IOHandler->enqueue(IOTask(&mrc, pOpen));
IOHandler->flush();
*mrc.m_isConstant = true;
}
Most helpful comment
This is probably easier than expected.
The code of interest for reading constant scalar meshes is in
Iteration::read(),Mesh::read()andMeshRecordComponent::read().It looks mostly correct, but lacks a call to open the path for the
RecordComponent(the same path that has already been opened for theRecord, analogous to the flow for the non-constant scalar mesh).As the underlying
Writabledoes not know its corresponding location in the HDF5 file, the attribute read forpositionfails.I can only test this later today, but my first shot will be to replace code in
Iteration::read()with