Skip to content

Commit

Permalink
WIP: Alternative way of checking for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Mar 6, 2024
1 parent bc7fca8 commit 3344e9d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions include/openPMD/RecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ namespace internal
* Chunk reading/writing requests on the contained dataset.
*/
std::queue<IOTask> m_chunks;

auto push_chunk(IOTask &&task) -> void;
/**
* Stores the value for constant record components.
* Ignored otherwise.
Expand Down Expand Up @@ -507,6 +509,8 @@ class RecordComponent : public BaseRecordComponent
*/
bool dirtyRecursive() const;

bool containingIterationClosed() const;

// clang-format off
OPENPMD_protected
// clang-format on
Expand Down
7 changes: 6 additions & 1 deletion include/openPMD/RecordComponent.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ RecordComponent::loadChunk(std::shared_ptr<T> data, Offset o, Extent e)
dRead.extent = extent;
dRead.dtype = getDatatype();
dRead.data = std::static_pointer_cast<void>(data);
rc.m_chunks.push(IOTask(this, dRead));
rc.push_chunk(IOTask(this, dRead));
}
}

Expand Down Expand Up @@ -287,6 +287,11 @@ template <typename T, typename F>
inline DynamicMemoryView<T>
RecordComponent::storeChunk(Offset o, Extent e, F &&createBuffer)
{
if (containingIterationClosed())
{
throw error::WrongAPIUsage("Cannot write chunks to closed Iterations.");
}

verifyChunk<T>(o, e);

/*
Expand Down
3 changes: 3 additions & 0 deletions include/openPMD/backend/Attributable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ namespace internal

template <typename, typename>
class BaseRecordData;

class RecordComponentData;
} // namespace internal

/** @brief Layer to manage storage of attributes associated with file objects.
Expand All @@ -109,6 +111,7 @@ class Attributable
friend class Series;
friend class Writable;
friend class WriteIterations;
friend class internal::RecordComponentData;

protected:
// tag for internal constructor
Expand Down
20 changes: 19 additions & 1 deletion src/RecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "openPMD/IO/Format.hpp"
#include "openPMD/Series.hpp"
#include "openPMD/auxiliary/Memory.hpp"
#include "openPMD/backend/Attributable.hpp"
#include "openPMD/backend/BaseRecord.hpp"

#include <algorithm>
Expand All @@ -39,6 +40,17 @@ namespace openPMD
namespace internal
{
RecordComponentData::RecordComponentData() = default;
auto RecordComponentData::push_chunk(IOTask &&task) -> void
{
Attributable a;
a.setData(std::shared_ptr<AttributableData>{this, [](auto const &) {}});
if (a.containingIteration().closed())
{
throw error::WrongAPIUsage(
"Cannot write/read chunks to/from closed Iterations.");
}
m_chunks.push(std::move(task));
}
} // namespace internal

RecordComponent::RecordComponent() : BaseRecordComponent(NoInit())
Expand Down Expand Up @@ -448,6 +460,12 @@ bool RecordComponent::dirtyRecursive() const
return !get().m_chunks.empty();
}

// need to define this in a cpp due to inclusion order
bool RecordComponent::containingIterationClosed() const
{
return containingIteration().closed();
}

void RecordComponent::storeChunk(
auxiliary::WriteBuffer buffer, Datatype dtype, Offset o, Extent e)
{
Expand All @@ -460,7 +478,7 @@ void RecordComponent::storeChunk(
/* std::static_pointer_cast correctly reference-counts the pointer */
dWrite.data = std::move(buffer);
auto &rc = get();
rc.m_chunks.push(IOTask(this, std::move(dWrite)));
rc.push_chunk(IOTask(this, std::move(dWrite)));
}

void RecordComponent::verifyChunk(
Expand Down

0 comments on commit 3344e9d

Please sign in to comment.