Skip to content

Commit 0ff85c5

Browse files
committed
Works
1 parent ba8e7f0 commit 0ff85c5

8 files changed

Lines changed: 70 additions & 14 deletions

File tree

include/openPMD/IO/AbstractIOHandlerImplCommon.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class AbstractIOHandlerImplCommon : public AbstractIOHandlerImpl
103103
FilePositionType *
104104
setAndGetFilePosition(Writable *writable, std::string extend);
105105

106+
void propagateFilestateToRoot(Writable *writable);
107+
106108
/*
107109
* The "virtual" methods here must be implemented by the child class,
108110
* but the references are resolved at compile time, hence not really
@@ -138,8 +140,9 @@ AbstractIOHandlerImplCommon<IOHandler_t, FilePositionType>::makeFile(
138140
Writable *writable, std::string file, bool consider_open_files)
139141
{
140142
auto make_new = [&]() {
141-
new (&writable->fileState)
142-
internal::SharedFileState(std::in_place, file);
143+
using SharedFileState = internal::SharedFileState;
144+
writable->fileState.~SharedFileState();
145+
new (&writable->fileState) SharedFileState(std::in_place, file);
143146
m_files[std::move(file)].derive_from(writable->fileState);
144147
};
145148
if (consider_open_files)
@@ -311,4 +314,16 @@ auto AbstractIOHandlerImplCommon<IOHandlerImpl_t, FilePositionType>::
311314
writable->abstractFilePosition = std::move(new_pos);
312315
return dynamic_cast<FilePositionType *>(res);
313316
}
317+
318+
template <typename IOHandlerImpl_t, typename FilePositionType>
319+
void AbstractIOHandlerImplCommon<IOHandlerImpl_t, FilePositionType>::
320+
propagateFilestateToRoot(Writable *const writable)
321+
{
322+
auto ancestor = writable;
323+
while (ancestor->parent)
324+
{
325+
ancestor = ancestor->parent;
326+
ancestor->fileState.derive_from(writable->fileState);
327+
}
328+
}
314329
} // namespace openPMD

include/openPMD/IO/IOTask.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ struct OPENPMDAPI_EXPORT
166166
new Parameter<Operation::CREATE_FILE>(std::move(*this)));
167167
}
168168

169+
Writable *storageLocation = nullptr;
169170
std::string name = "";
170171
};
171172

@@ -225,6 +226,7 @@ struct OPENPMDAPI_EXPORT
225226
NoReopen
226227
};
227228

229+
Writable *storageLocation = nullptr;
228230
std::string name = "";
229231
Reopen reopen = Reopen::NoReopen;
230232
using ParsePreference = internal::ParsePreference;

include/openPMD/Series.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ OPENPMD_private
907907
*/
908908
void readFileBased(
909909
std::optional<IterationIndex_t> read_only_this_single_iteration);
910-
void readOneIterationFileBased(std::string const &filePath);
910+
void readOneIterationFileBased(std::string const &filePath, Iteration &it);
911911
/**
912912
* Note on re-parsing of a Series:
913913
* If init == false, the parsing process will seek for new

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,11 @@ void ADIOS2IOHandlerImpl::createFile(
680680
{
681681
std::string name = parameters.name + fileSuffix();
682682

683+
auto storageLocation =
684+
parameters.storageLocation ? parameters.storageLocation : writable;
683685
auto &file =
684-
makeFile(writable, name, /* consider_open_files = */ false);
686+
makeFile(storageLocation, name, /* consider_open_files = */ false);
687+
propagateFilestateToRoot(storageLocation);
685688
auto &file_state = **file;
686689
if (m_handler->m_backendAccess != Access::CREATE &&
687690
m_handler->m_backendAccess != Access::APPEND &&
@@ -1015,9 +1018,11 @@ void ADIOS2IOHandlerImpl::openFile(
10151018

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

1018-
auto &file = makeFile(writable, name, /* consider_open_files = */ true);
1019-
1020-
associateWithFile(writable, file);
1021+
auto storageLocation =
1022+
parameters.storageLocation ? parameters.storageLocation : writable;
1023+
auto &file =
1024+
makeFile(storageLocation, name, /* consider_open_files = */ true);
1025+
propagateFilestateToRoot(storageLocation);
10211026

10221027
writable->written = true;
10231028
writable->abstractFilePosition = std::make_shared<ADIOS2FilePosition>();

src/IO/AbstractIOHandlerImpl.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,19 @@ std::future<void> AbstractIOHandlerImpl::flush()
107107
"->",
108108
i.writable,
109109
"] CREATE_FILE: ",
110-
parameter.name);
110+
parameter.name,
111+
[ptr = parameter.storageLocation]() {
112+
if (ptr)
113+
{
114+
std::stringstream s;
115+
s << " into " << ptr;
116+
return s.str();
117+
}
118+
else
119+
{
120+
return std::string();
121+
}
122+
});
111123
createFile(i.writable, parameter);
112124
break;
113125
}
@@ -175,7 +187,19 @@ std::future<void> AbstractIOHandlerImpl::flush()
175187
"->",
176188
i.writable,
177189
"] OPEN_FILE: ",
178-
parameter.name);
190+
parameter.name,
191+
[ptr = parameter.storageLocation]() {
192+
if (ptr)
193+
{
194+
std::stringstream s;
195+
s << " into " << ptr;
196+
return s.str();
197+
}
198+
else
199+
{
200+
return std::string();
201+
}
202+
});
179203
openFile(i.writable, parameter);
180204
break;
181205
}

src/IO/JSON/JSONIOHandlerImpl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,11 @@ void JSONIOHandlerImpl::createFile(
516516
{
517517
std::string name = parameters.name + m_originalExtension;
518518

519+
auto storageLocation =
520+
parameters.storageLocation ? parameters.storageLocation : writable;
519521
auto &file =
520-
makeFile(writable, name, /* consider_open_files = */ false);
522+
makeFile(storageLocation, name, /* consider_open_files = */ false);
523+
propagateFilestateToRoot(storageLocation);
521524
auto &file_state = **file;
522525
auto file_exists = auxiliary::file_exists(fullPath(file_state));
523526

@@ -1012,7 +1015,11 @@ void JSONIOHandlerImpl::openFile(
10121015

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

1015-
auto &file = makeFile(writable, name, /* consider_open_files = */ true);
1018+
auto storageLocation =
1019+
parameter.storageLocation ? parameter.storageLocation : writable;
1020+
auto &file =
1021+
makeFile(storageLocation, name, /* consider_open_files = */ true);
1022+
propagateFilestateToRoot(storageLocation);
10161023

10171024
associateWithFile(writable, file);
10181025

src/Iteration.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ void Iteration::flushFileBased(
229229
/* create file */
230230
Parameter<Operation::CREATE_FILE> fCreate;
231231
fCreate.name = filename;
232+
fCreate.storageLocation = &this->writable();
232233
IOHandler()->enqueue(IOTask(&s.writable(), fCreate));
233234

234235
/*
@@ -428,7 +429,7 @@ void Iteration::readFileBased(
428429
}
429430
auto series = retrieveSeries();
430431

431-
series.readOneIterationFileBased(filePath);
432+
series.readOneIterationFileBased(filePath, *this);
432433

433434
auto &series_data = series.get();
434435
if (series_data.m_iterationFilenames.find(idx) ==

src/Series.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,6 @@ void Series::readFileBased(
15531553
std::optional<IterationIndex_t> read_only_this_single_iteration)
15541554
{
15551555
auto &series = get();
1556-
Parameter<Operation::OPEN_FILE> fOpen;
15571556
Parameter<Operation::READ_ATT> aRead;
15581557

15591558
// Tell the backend that we are parsing file-based iteration encoding.
@@ -1766,7 +1765,8 @@ void Series::readFileBased(
17661765
"Please specify '%0<N>T' or open as read-only.");
17671766
}
17681767

1769-
void Series::readOneIterationFileBased(std::string const &filePath)
1768+
void Series::readOneIterationFileBased(
1769+
std::string const &filePath, Iteration &it)
17701770
{
17711771
auto &series = get();
17721772

@@ -1780,6 +1780,7 @@ void Series::readOneIterationFileBased(std::string const &filePath)
17801780
Parameter<Operation::READ_ATT> aRead;
17811781

17821782
fOpen.name = filePath;
1783+
fOpen.storageLocation = &it.writable();
17831784
IOHandler()->enqueue(IOTask(this, fOpen));
17841785
IOHandler()->flush(internal::defaultFlushParams);
17851786
series.iterations.parent() = getWritable(this);
@@ -2867,6 +2868,7 @@ void Series::openIteration(IterationIndex_t index, Iteration &iteration)
28672868
{
28682869
fOpen.reopen = R::WasFoundOnDisk;
28692870
}
2871+
fOpen.storageLocation = &iteration.writable();
28702872
IOHandler()->enqueue(IOTask(this, fOpen));
28712873

28722874
/* open base path */

0 commit comments

Comments
 (0)