Skip to content

Commit

Permalink
Don't leak unitSI into free datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Nov 20, 2023
1 parent 2c1b50c commit 7aa1fa3
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion include/openPMD/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class Mesh : public BaseRecord<MeshRecordComponent>

void
flush_impl(std::string const &, internal::FlushParams const &) override;
void read() override;
void read();
}; // Mesh

template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion include/openPMD/Record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Record : public BaseRecord<RecordComponent>

void
flush_impl(std::string const &, internal::FlushParams const &) override;
void read() override;
void read();
}; // Record

template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions include/openPMD/RecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -486,7 +486,7 @@ OPENPMD_protected
BaseRecordComponent::setData(m_recordComponentData);
}

void readBase();
void readBase(bool read_defaults);
}; // RecordComponent

} // namespace openPMD
Expand Down
2 changes: 1 addition & 1 deletion include/openPMD/backend/MeshRecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/CustomHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -160,7 +160,7 @@ void Record::read()
rc.written() = true;
try
{
rc.read();
rc.read(/* read_defaults = */ true);
}
catch (error::ReadError const &err)
{
Expand Down
37 changes: 20 additions & 17 deletions src/RecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ void RecordComponent::flush(
}
}

void RecordComponent::read()
void RecordComponent::read(bool read_defaults)
{
readBase();
readBase(read_defaults);
}

namespace
Expand All @@ -369,7 +369,7 @@ namespace
};
} // namespace

void RecordComponent::readBase()
void RecordComponent::readBase(bool read_defaults)
{
using DT = Datatype;
// auto & rc = get();
Expand Down Expand Up @@ -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<double>();
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<double>();
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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/MeshRecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 7aa1fa3

Please sign in to comment.