Skip to content

Commit

Permalink
Works
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Aug 5, 2024
1 parent d054d74 commit 71cb6e0
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 14 deletions.
19 changes: 17 additions & 2 deletions include/openPMD/IO/AbstractIOHandlerImplCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class AbstractIOHandlerImplCommon : public AbstractIOHandlerImpl
FilePositionType *
setAndGetFilePosition(Writable *writable, std::string extend);

void propagateFilestateToRoot(Writable *writable);

/*
* The "virtual" methods here must be implemented by the child class,
* but the references are resolved at compile time, hence not really
Expand Down Expand Up @@ -138,8 +140,9 @@ AbstractIOHandlerImplCommon<IOHandler_t, FilePositionType>::makeFile(
Writable *writable, std::string file, bool consider_open_files)
{
auto make_new = [&]() {
new (&writable->fileState)
internal::SharedFileState(std::in_place, file);
using SharedFileState = internal::SharedFileState;
writable->fileState.~SharedFileState();
new (&writable->fileState) SharedFileState(std::in_place, file);
m_files[std::move(file)].derive_from(writable->fileState);
};
if (consider_open_files)
Expand Down Expand Up @@ -311,4 +314,16 @@ auto AbstractIOHandlerImplCommon<IOHandlerImpl_t, FilePositionType>::
writable->abstractFilePosition = std::move(new_pos);
return dynamic_cast<FilePositionType *>(res);
}

template <typename IOHandlerImpl_t, typename FilePositionType>
void AbstractIOHandlerImplCommon<IOHandlerImpl_t, FilePositionType>::
propagateFilestateToRoot(Writable *const writable)
{
auto ancestor = writable;
while (ancestor->parent)
{
ancestor = ancestor->parent;
ancestor->fileState.derive_from(writable->fileState);
}
}
} // namespace openPMD
2 changes: 2 additions & 0 deletions include/openPMD/IO/IOTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ struct OPENPMDAPI_EXPORT Parameter<Operation::CREATE_FILE>
new Parameter<Operation::CREATE_FILE>(std::move(*this)));
}

Writable *storageLocation = nullptr;
std::string name = "";
};

Expand Down Expand Up @@ -187,6 +188,7 @@ struct OPENPMDAPI_EXPORT Parameter<Operation::OPEN_FILE>
new Parameter<Operation::OPEN_FILE>(std::move(*this)));
}

Writable *storageLocation = nullptr;
std::string name = "";
using ParsePreference = internal::ParsePreference;
std::shared_ptr<ParsePreference> out_parsePreference =
Expand Down
2 changes: 1 addition & 1 deletion include/openPMD/Series.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ OPENPMD_private
void flushParticlesPath();
void flushRankTable();
void readFileBased();
void readOneIterationFileBased(std::string const &filePath);
void readOneIterationFileBased(std::string const &filePath, Iteration &it);
/**
* Note on re-parsing of a Series:
* If init == false, the parsing process will seek for new
Expand Down
13 changes: 9 additions & 4 deletions src/IO/ADIOS/ADIOS2IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,11 @@ void ADIOS2IOHandlerImpl::createFile(
{
std::string name = parameters.name + fileSuffix();

auto storageLocation =
parameters.storageLocation ? parameters.storageLocation : writable;
auto &file =
makeFile(writable, name, /* consider_open_files = */ false);
makeFile(storageLocation, name, /* consider_open_files = */ false);
propagateFilestateToRoot(storageLocation);
auto &file_state = **file;
if (m_handler->m_backendAccess != Access::CREATE &&
m_handler->m_backendAccess != Access::APPEND &&
Expand Down Expand Up @@ -945,9 +948,11 @@ void ADIOS2IOHandlerImpl::openFile(

std::string name = parameters.name + fileSuffix();

auto &file = makeFile(writable, name, /* consider_open_files = */ true);

associateWithFile(writable, file);
auto storageLocation =
parameters.storageLocation ? parameters.storageLocation : writable;
auto &file =
makeFile(storageLocation, name, /* consider_open_files = */ true);
propagateFilestateToRoot(storageLocation);

writable->written = true;
writable->abstractFilePosition = std::make_shared<ADIOS2FilePosition>();
Expand Down
28 changes: 26 additions & 2 deletions src/IO/AbstractIOHandlerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,19 @@ std::future<void> AbstractIOHandlerImpl::flush()
"->",
i.writable,
"] CREATE_FILE: ",
parameter.name);
parameter.name,
[ptr = parameter.storageLocation]() {
if (ptr)
{
std::stringstream s;
s << " into " << ptr;
return s.str();
}
else
{
return std::string();
}
});
createFile(i.writable, parameter);
break;
}
Expand Down Expand Up @@ -193,7 +205,19 @@ std::future<void> AbstractIOHandlerImpl::flush()
"->",
i.writable,
"] OPEN_FILE: ",
parameter.name);
parameter.name,
[ptr = parameter.storageLocation]() {
if (ptr)
{
std::stringstream s;
s << " into " << ptr;
return s.str();
}
else
{
return std::string();
}
});
openFile(i.writable, parameter);
break;
}
Expand Down
11 changes: 9 additions & 2 deletions src/IO/JSON/JSONIOHandlerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,11 @@ void JSONIOHandlerImpl::createFile(
{
std::string name = parameters.name + m_originalExtension;

auto storageLocation =
parameters.storageLocation ? parameters.storageLocation : writable;
auto &file =
makeFile(writable, name, /* consider_open_files = */ false);
makeFile(storageLocation, name, /* consider_open_files = */ false);
propagateFilestateToRoot(storageLocation);
auto &file_state = **file;
auto file_exists = auxiliary::file_exists(fullPath(file_state));

Expand Down Expand Up @@ -984,7 +987,11 @@ void JSONIOHandlerImpl::openFile(

std::string name = parameter.name + m_originalExtension;

auto &file = makeFile(writable, name, /* consider_open_files = */ true);
auto storageLocation =
parameter.storageLocation ? parameter.storageLocation : writable;
auto &file =
makeFile(storageLocation, name, /* consider_open_files = */ true);
propagateFilestateToRoot(storageLocation);

associateWithFile(writable, file);

Expand Down
3 changes: 2 additions & 1 deletion src/Iteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ void Iteration::flushFileBased(
/* create file */
Parameter<Operation::CREATE_FILE> fCreate;
fCreate.name = filename;
fCreate.storageLocation = &this->writable();
IOHandler()->enqueue(IOTask(&s.writable(), fCreate));

/*
Expand Down Expand Up @@ -403,7 +404,7 @@ void Iteration::readFileBased(
}
auto series = retrieveSeries();

series.readOneIterationFileBased(filePath);
series.readOneIterationFileBased(filePath, *this);
get().m_overrideFilebasedFilename = filePath;

read_impl(groupPath);
Expand Down
6 changes: 4 additions & 2 deletions src/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,6 @@ void Series::flushParticlesPath()
void Series::readFileBased()
{
auto &series = get();
Parameter<Operation::OPEN_FILE> fOpen;
Parameter<Operation::READ_ATT> aRead;

// Tell the backend that we are parsing file-based iteration encoding.
Expand Down Expand Up @@ -1752,14 +1751,16 @@ void Series::readFileBased()
"Please specify '%0<N>T' or open as read-only.");
}

void Series::readOneIterationFileBased(std::string const &filePath)
void Series::readOneIterationFileBased(
std::string const &filePath, Iteration &it)
{
auto &series = get();

Parameter<Operation::OPEN_FILE> fOpen;
Parameter<Operation::READ_ATT> aRead;

fOpen.name = filePath;
fOpen.storageLocation = &it.writable();
IOHandler()->enqueue(IOTask(this, fOpen));
IOHandler()->flush(internal::defaultFlushParams);
series.iterations.parent() = getWritable(this);
Expand Down Expand Up @@ -2678,6 +2679,7 @@ void Series::openIteration(IterationIndex_t index, Iteration iteration)
// open the iteration's file again
Parameter<Operation::OPEN_FILE> fOpen;
fOpen.name = iterationFilename(index);
fOpen.storageLocation = &iteration.writable();
IOHandler()->enqueue(IOTask(this, fOpen));

/* open base path */
Expand Down

0 comments on commit 71cb6e0

Please sign in to comment.