Skip to content

Commit

Permalink
Without Cleanup: todos from previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Jan 10, 2024
1 parent efe2814 commit e964232
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 13 deletions.
12 changes: 9 additions & 3 deletions include/openPMD/IO/AbstractIOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ class AbstractIOHandler
{}
virtual ~AbstractIOHandler() = default;

AbstractIOHandler(AbstractIOHandler const &) = default;
AbstractIOHandler(AbstractIOHandler &&) = default;

AbstractIOHandler &operator=(AbstractIOHandler const &) = default;
AbstractIOHandler &operator=(AbstractIOHandler &&) = default;

/** Add provided task to queue according to FIFO.
*
* @param iotask Task to be executed after all previously enqueued
Expand Down Expand Up @@ -245,7 +251,7 @@ class AbstractIOHandler
/** The currently used backend */
virtual std::string backendName() const = 0;

std::string const directory;
std::string directory;
/*
* Originally, the reason for distinguishing these two was that during
* parsing in reading access modes, the access type would be temporarily
Expand All @@ -261,8 +267,8 @@ class AbstractIOHandler
* which is entirely implemented by the frontend, which internally uses
* the backend in CREATE mode.
*/
Access const m_backendAccess;
Access const m_frontendAccess;
Access m_backendAccess;
Access m_frontendAccess;
internal::SeriesStatus m_seriesStatus = internal::SeriesStatus::Default;
std::queue<IOTask> m_work;
/**
Expand Down
1 change: 1 addition & 0 deletions include/openPMD/IO/DummyIOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ class DummyIOHandler : public AbstractIOHandler
* without IO.
*/
std::future<void> flush(internal::ParsedFlushParams &) override;
std::string backendName() const override;
}; // DummyIOHandler
} // namespace openPMD
27 changes: 20 additions & 7 deletions include/openPMD/Series.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,7 @@ OPENPMD_private
{
if (m_series->m_deferred_initialization.has_value())
{
decltype(m_series->m_deferred_initialization) steal_the_goods =
std::nullopt;
m_series->m_deferred_initialization.swap(steal_the_goods);
steal_the_goods->operator()();
return *m_series;
}
return *m_series;
}
Expand Down Expand Up @@ -791,19 +788,35 @@ OPENPMD_private
*/
std::optional<std::vector<IterationIndex_t>> currentSnapshot() const;

static std::string debug(AbstractIOHandler const *ptr)
{
std::stringstream res;
res << ptr;
if (ptr)
res << '(' << ptr->directory << ')';
return res.str();
}

AbstractIOHandler *IOHandler()
{
auto res = Attributable::IOHandler();
if (!res)
if ((!res || res->backendName() == "Dummy") &&
m_series->m_deferred_initialization.has_value())
{
get();
decltype(m_series->m_deferred_initialization) steal_the_goods =
std::nullopt;
m_series->m_deferred_initialization.swap(steal_the_goods);
steal_the_goods->operator()();
res = Attributable::IOHandler();
}
// std::cout << "Returning " << debug(res) << std::endl;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
return res;
}
AbstractIOHandler const *IOHandler() const
{
return Attributable::IOHandler();
auto res = Attributable::IOHandler();
// std::cout << "Returning " << debug(res) << std::endl;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
return res;
}
}; // Series
} // namespace openPMD
Expand Down
5 changes: 5 additions & 0 deletions src/IO/DummyIOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ std::future<void> DummyIOHandler::flush(internal::ParsedFlushParams &)
{
return std::future<void>();
}

std::string DummyIOHandler::backendName() const
{
return "Dummy";
}
} // namespace openPMD
51 changes: 48 additions & 3 deletions src/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "openPMD/IO/AbstractIOHandler.hpp"
#include "openPMD/IO/AbstractIOHandlerHelper.hpp"
#include "openPMD/IO/Access.hpp"
#include "openPMD/IO/DummyIOHandler.hpp"
#include "openPMD/IO/Format.hpp"
#include "openPMD/IterationEncoding.hpp"
#include "openPMD/ReadIterations.hpp"
Expand All @@ -37,6 +38,7 @@
#include <exception>
#include <iomanip>
#include <iostream>
#include <memory>
#include <optional>
#include <regex>
#include <set>
Expand Down Expand Up @@ -289,6 +291,10 @@ IterationEncoding Series::iterationEncoding() const
Series &Series::setIterationEncoding(IterationEncoding ie)
{
auto &series = get();
if (series.m_deferred_initialization)
{
IOHandler();
}
if (written())
throw std::runtime_error(
"A files iterationEncoding can not (yet) be changed after it has "
Expand Down Expand Up @@ -670,10 +676,45 @@ void Series::initSeries(
std::unique_ptr<Series::ParsedInput> input)
{
auto &series = get();
writable().IOHandler =
std::make_shared<std::optional<std::unique_ptr<AbstractIOHandler>>>(
auto &writable = series.m_writable;

// auto print = [&](auto const &info) {
// std::cout << "[" << info << "] "
// << debug(writable.IOHandler ? (**writable.IOHandler).get()
// : nullptr)
// << " <- " << debug(ioHandler.get()) << std::endl;
// };
// print("begin");

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

std::string directory = ioHandler->directory;

if (writable.IOHandler)
{
if (writable.IOHandler->has_value())
{
ioHandler->operator=(***writable.IOHandler);
ioHandler->directory = std::move(directory);
}
}
else
{
writable.IOHandler = std::make_shared<
std::optional<std::unique_ptr<AbstractIOHandler>>>();
}
{
std::optional<std::unique_ptr<AbstractIOHandler>> *ptr =
writable.IOHandler.get();
*ptr = std::nullopt;
*ptr = std::make_optional<std::unique_ptr<AbstractIOHandler>>(
std::move(ioHandler));
series.iterations.linkHierarchy(writable());
}
// print("after");
// *writable.IOHandler = std::nullopt;
// *writable.IOHandler =
// std::make_optional<std::unique_ptr<AbstractIOHandler>>(
// std::move(ioHandler));

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.

series.iterations.linkHierarchy(writable);
series.iterations.writable().ownKeyWithinParent = "iterations";

series.m_name = input->name;
Expand Down Expand Up @@ -2475,6 +2516,10 @@ Series::Series(
case Access::READ_LINEAR:
case Access::APPEND: {
auto &series = get();
writable().IOHandler =
std::make_shared<std::optional<std::unique_ptr<AbstractIOHandler>>>(
std::make_unique<DummyIOHandler>("dummy", at));
get().iterations.linkHierarchy(writable());
series.m_deferred_initialization = [this, filepath, at, options]() {
return init(filepath, at, options);
};
Expand Down

0 comments on commit e964232

Please sign in to comment.