Skip to content

Commit

Permalink
Upon parsing, store each iteration's filename
Browse files Browse the repository at this point in the history
If the padding is inconsistent, a later Iteration::open() needs the
original filename. Trying to compute the filename from the expansion
pattern will lead to wrong filenames.
  • Loading branch information
franzpoeschel authored and ax3l committed May 26, 2022
1 parent 6cb783f commit 67e8d8b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions include/openPMD/Iteration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ class Iteration : public LegacyAttributable
std::make_shared<auxiliary::Option<DeferredParseAccess> >(
auxiliary::Option<DeferredParseAccess>());

std::shared_ptr<auxiliary::Option<std::string> >
m_overrideFilebasedFilename =
std::make_shared<auxiliary::Option<std::string> >(
auxiliary::Option<std::string>());

/**
* @brief Begin an IO step on the IO file (or file-like object)
* containing this iteration. In case of group-based iteration
Expand Down
2 changes: 2 additions & 0 deletions src/Iteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ void Iteration::readFileBased(
auto &series = retrieveSeries();

series.readOneIterationFileBased(filePath);
*m_overrideFilebasedFilename =
auxiliary::makeOption<std::string>(std::move(filePath));

read_impl(groupPath);
}
Expand Down
27 changes: 24 additions & 3 deletions src/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <iostream>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>

Expand Down Expand Up @@ -1142,14 +1143,34 @@ void SeriesInterface::readBase()

std::string SeriesInterface::iterationFilename(uint64_t i)
{
/*
* The filename might have been overridden at the Series level or at the
* Iteration level. See the struct members' documentation for the reasons.
*/
auto &series = get();
auto iteration = series.iterations.find(i);
if (series.m_overrideFilebasedFilename.has_value())
{
return series.m_overrideFilebasedFilename.get();
}
std::stringstream iteration("");
iteration << std::setw(series.m_filenamePadding) << std::setfill('0') << i;
return series.m_filenamePrefix + iteration.str() + series.m_filenamePostfix;
else if (
iteration != series.iterations.end() &&
iteration->second.m_overrideFilebasedFilename->has_value())
{
return iteration->second.m_overrideFilebasedFilename->get();
}
else
{
/*
* If no filename has been explicitly stored, we use the filename
* pattern to compute it.
*/
std::stringstream iterationNr("");
iterationNr << std::setw(series.m_filenamePadding) << std::setfill('0')
<< i;
return series.m_filenamePrefix + iterationNr.str() +
series.m_filenamePostfix;
}
}

SeriesInterface::iterations_iterator
Expand Down

0 comments on commit 67e8d8b

Please sign in to comment.