Skip to content

Commit 4d35a43

Browse files
committed
Works
1 parent 49f3b7f commit 4d35a43

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
@@ -159,6 +159,7 @@ struct OPENPMDAPI_EXPORT Parameter<Operation::CREATE_FILE>
159159
new Parameter<Operation::CREATE_FILE>(std::move(*this)));
160160
}
161161

162+
Writable *storageLocation = nullptr;
162163
std::string name = "";
163164
};
164165

@@ -218,6 +219,7 @@ struct OPENPMDAPI_EXPORT Parameter<Operation::OPEN_FILE>
218219
NoReopen
219220
};
220221

222+
Writable *storageLocation = nullptr;
221223
std::string name = "";
222224
Reopen reopen = Reopen::NoReopen;
223225
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
@@ -679,8 +679,11 @@ void ADIOS2IOHandlerImpl::createFile(
679679
{
680680
std::string name = parameters.name + fileSuffix();
681681

682+
auto storageLocation =
683+
parameters.storageLocation ? parameters.storageLocation : writable;
682684
auto &file =
683-
makeFile(writable, name, /* consider_open_files = */ false);
685+
makeFile(storageLocation, name, /* consider_open_files = */ false);
686+
propagateFilestateToRoot(storageLocation);
684687
auto &file_state = **file;
685688
if (m_handler->m_backendAccess != Access::CREATE &&
686689
m_handler->m_backendAccess != Access::APPEND &&
@@ -954,9 +957,11 @@ void ADIOS2IOHandlerImpl::openFile(
954957

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

957-
auto &file = makeFile(writable, name, /* consider_open_files = */ true);
958-
959-
associateWithFile(writable, file);
960+
auto storageLocation =
961+
parameters.storageLocation ? parameters.storageLocation : writable;
962+
auto &file =
963+
makeFile(storageLocation, name, /* consider_open_files = */ true);
964+
propagateFilestateToRoot(storageLocation);
960965

961966
writable->written = true;
962967
writable->abstractFilePosition = std::make_shared<ADIOS2FilePosition>();

src/IO/AbstractIOHandlerImpl.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,19 @@ std::future<void> AbstractIOHandlerImpl::flush()
130130
"->",
131131
i.writable,
132132
"] CREATE_FILE: ",
133-
parameter.name);
133+
parameter.name,
134+
[ptr = parameter.storageLocation]() {
135+
if (ptr)
136+
{
137+
std::stringstream s;
138+
s << " into " << ptr;
139+
return s.str();
140+
}
141+
else
142+
{
143+
return std::string();
144+
}
145+
});
134146
createFile(i.writable, parameter);
135147
break;
136148
}
@@ -198,7 +210,19 @@ std::future<void> AbstractIOHandlerImpl::flush()
198210
"->",
199211
i.writable,
200212
"] OPEN_FILE: ",
201-
parameter.name);
213+
parameter.name,
214+
[ptr = parameter.storageLocation]() {
215+
if (ptr)
216+
{
217+
std::stringstream s;
218+
s << " into " << ptr;
219+
return s.str();
220+
}
221+
else
222+
{
223+
return std::string();
224+
}
225+
});
202226
openFile(i.writable, parameter);
203227
break;
204228
}

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

@@ -1005,7 +1008,11 @@ void JSONIOHandlerImpl::openFile(
10051008

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

1008-
auto &file = makeFile(writable, name, /* consider_open_files = */ true);
1011+
auto storageLocation =
1012+
parameter.storageLocation ? parameter.storageLocation : writable;
1013+
auto &file =
1014+
makeFile(storageLocation, name, /* consider_open_files = */ true);
1015+
propagateFilestateToRoot(storageLocation);
10091016

10101017
associateWithFile(writable, file);
10111018

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
@@ -1552,7 +1552,6 @@ void Series::readFileBased(
15521552
std::optional<IterationIndex_t> read_only_this_single_iteration)
15531553
{
15541554
auto &series = get();
1555-
Parameter<Operation::OPEN_FILE> fOpen;
15561555
Parameter<Operation::READ_ATT> aRead;
15571556

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

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

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

17811781
fOpen.name = filePath;
1782+
fOpen.storageLocation = &it.writable();
17821783
IOHandler()->enqueue(IOTask(this, fOpen));
17831784
IOHandler()->flush(internal::defaultFlushParams);
17841785
series.iterations.parent() = getWritable(this);
@@ -2866,6 +2867,7 @@ void Series::openIteration(IterationIndex_t index, Iteration &iteration)
28662867
{
28672868
fOpen.reopen = R::WasFoundOnDisk;
28682869
}
2870+
fOpen.storageLocation = &iteration.writable();
28692871
IOHandler()->enqueue(IOTask(this, fOpen));
28702872

28712873
/* open base path */

0 commit comments

Comments
 (0)