diff --git a/include/openPMD/Mesh.hpp b/include/openPMD/Mesh.hpp index 38db4df2e9..1c255e3910 100644 --- a/include/openPMD/Mesh.hpp +++ b/include/openPMD/Mesh.hpp @@ -231,7 +231,7 @@ class Mesh : public BaseRecord void flush_impl(std::string const &, internal::FlushParams const &) override; - void read() override; + void read(); }; // Mesh template diff --git a/include/openPMD/Record.hpp b/include/openPMD/Record.hpp index 4f7ee51c28..c875389db5 100644 --- a/include/openPMD/Record.hpp +++ b/include/openPMD/Record.hpp @@ -52,7 +52,7 @@ class Record : public BaseRecord void flush_impl(std::string const &, internal::FlushParams const &) override; - void read() override; + void read(); }; // Record template diff --git a/include/openPMD/RecordComponent.hpp b/include/openPMD/RecordComponent.hpp index 40e4723db1..597e47c4cc 100644 --- a/include/openPMD/RecordComponent.hpp +++ b/include/openPMD/RecordComponent.hpp @@ -434,7 +434,7 @@ class RecordComponent : public BaseRecordComponent private: void flush( std::string const &, internal::FlushParams const &, bool set_defaults); - virtual void read(); + void read(bool read_defaults); /** * Internal method to be called by all methods that create an empty dataset. @@ -486,7 +486,7 @@ OPENPMD_protected BaseRecordComponent::setData(m_recordComponentData); } - void readBase(); + void readBase(bool read_defaults); }; // RecordComponent } // namespace openPMD diff --git a/include/openPMD/backend/MeshRecordComponent.hpp b/include/openPMD/backend/MeshRecordComponent.hpp index 3d10cedacd..d05163d754 100644 --- a/include/openPMD/backend/MeshRecordComponent.hpp +++ b/include/openPMD/backend/MeshRecordComponent.hpp @@ -46,7 +46,7 @@ class MeshRecordComponent : public RecordComponent private: MeshRecordComponent(); MeshRecordComponent(NoInit); - void read() override; + void read(); void flush(std::string const &, internal::FlushParams const &); public: diff --git a/src/CustomHierarchy.cpp b/src/CustomHierarchy.cpp index 86970e5437..0708c91e4c 100644 --- a/src/CustomHierarchy.cpp +++ b/src/CustomHierarchy.cpp @@ -487,7 +487,7 @@ void CustomHierarchy::read( rc.written() = false; rc.resetDataset(Dataset(*dOpen.dtype, *dOpen.extent)); rc.written() = true; - rc.read(); + rc.read(/* read_defaults = */ false); } catch (error::ReadError const &err) { @@ -533,7 +533,7 @@ void CustomHierarchy::read( pOpen.path = path; IOHandler()->enqueue(IOTask(&rc, pOpen)); rc.get().m_isConstant = true; - rc.read(); + rc.read(/* read_defaults = */ false); } catch (error::ReadError const &err) { diff --git a/src/Record.cpp b/src/Record.cpp index 568d66be46..07c4f1fa8a 100644 --- a/src/Record.cpp +++ b/src/Record.cpp @@ -109,7 +109,7 @@ void Record::read() /* using operator[] will incorrectly update parent */ try { - T_RecordComponent::read(); + T_RecordComponent::read(/* read_defaults = */ true); } catch (error::ReadError const &err) { @@ -133,7 +133,7 @@ void Record::read() rc.get().m_isConstant = true; try { - rc.read(); + rc.read(/* read_defaults = */ true); } catch (error::ReadError const &err) { @@ -160,7 +160,7 @@ void Record::read() rc.written() = true; try { - rc.read(); + rc.read(/* read_defaults = */ true); } catch (error::ReadError const &err) { diff --git a/src/RecordComponent.cpp b/src/RecordComponent.cpp index 0293fea89d..87ccf6c3ad 100644 --- a/src/RecordComponent.cpp +++ b/src/RecordComponent.cpp @@ -342,9 +342,9 @@ void RecordComponent::flush( } } -void RecordComponent::read() +void RecordComponent::read(bool read_defaults) { - readBase(); + readBase(read_defaults); } namespace @@ -369,7 +369,7 @@ namespace }; } // namespace -void RecordComponent::readBase() +void RecordComponent::readBase(bool read_defaults) { using DT = Datatype; // auto & rc = get(); @@ -415,20 +415,23 @@ void RecordComponent::readBase() written() = true; } - aRead.name = "unitSI"; - IOHandler()->enqueue(IOTask(this, aRead)); - IOHandler()->flush(internal::defaultFlushParams); - if (auto val = Attribute(*aRead.resource).getOptional(); - val.has_value()) - setUnitSI(val.value()); - else - throw error::ReadError( - error::AffectedObject::Attribute, - error::Reason::UnexpectedContent, - {}, - "Unexpected Attribute datatype for 'unitSI' (expected double, " - "found " + - datatypeToString(Attribute(*aRead.resource).dtype) + ")"); + if (read_defaults) + { + aRead.name = "unitSI"; + IOHandler()->enqueue(IOTask(this, aRead)); + IOHandler()->flush(internal::defaultFlushParams); + if (auto val = Attribute(*aRead.resource).getOptional(); + val.has_value()) + setUnitSI(val.value()); + else + throw error::ReadError( + error::AffectedObject::Attribute, + error::Reason::UnexpectedContent, + {}, + "Unexpected Attribute datatype for 'unitSI' (expected double, " + "found " + + datatypeToString(Attribute(*aRead.resource).dtype) + ")"); + } readAttributes(ReadMode::FullyReread); } diff --git a/src/backend/MeshRecordComponent.cpp b/src/backend/MeshRecordComponent.cpp index 8bf617ef3e..10bee1cf45 100644 --- a/src/backend/MeshRecordComponent.cpp +++ b/src/backend/MeshRecordComponent.cpp @@ -64,7 +64,7 @@ void MeshRecordComponent::read() "of any floating point type, found " + datatypeToString(Attribute(*aRead.resource).dtype) + ")"); - readBase(); + readBase(/* read_defaults = */ true); } void MeshRecordComponent::flush(