Skip to content

Commit 3680dc4

Browse files
committed
Works
1 parent a35ed4b commit 3680dc4

File tree

8 files changed

+70
-14
lines changed

8 files changed

+70
-14
lines changed

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
@@ -893,7 +893,7 @@ OPENPMD_private
893893
*/
894894
void readFileBased(
895895
std::optional<IterationIndex_t> read_only_this_single_iteration);
896-
void readOneIterationFileBased(std::string const &filePath);
896+
void readOneIterationFileBased(std::string const &filePath, Iteration &it);
897897
/**
898898
* Note on re-parsing of a Series:
899899
* 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
@@ -713,8 +713,11 @@ void ADIOS2IOHandlerImpl::createFile(
713713
{
714714
std::string name = parameters.name + fileSuffix();
715715

716+
auto storageLocation =
717+
parameters.storageLocation ? parameters.storageLocation : writable;
716718
auto &file =
717-
makeFile(writable, name, /* consider_open_files = */ false);
719+
makeFile(storageLocation, name, /* consider_open_files = */ false);
720+
propagateFilestateToRoot(storageLocation);
718721
auto &file_state = **file;
719722
if (access::read(m_handler->m_backendAccess) &&
720723
(auxiliary::file_exists(fullPath(file_state)) ||
@@ -1046,9 +1049,11 @@ void ADIOS2IOHandlerImpl::openFile(
10461049

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

1049-
auto &file = makeFile(writable, name, /* consider_open_files = */ true);
1050-
1051-
associateWithFile(writable, file);
1052+
auto storageLocation =
1053+
parameters.storageLocation ? parameters.storageLocation : writable;
1054+
auto &file =
1055+
makeFile(storageLocation, name, /* consider_open_files = */ true);
1056+
propagateFilestateToRoot(storageLocation);
10521057

10531058
writable->written = true;
10541059
writable->abstractFilePosition = std::make_shared<ADIOS2FilePosition>();

src/IO/AbstractIOHandlerImpl.cpp

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

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

@@ -909,7 +912,11 @@ void JSONIOHandlerImpl::openFile(
909912

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

912-
auto &file = makeFile(writable, name, /* consider_open_files = */ true);
915+
auto storageLocation =
916+
parameter.storageLocation ? parameter.storageLocation : writable;
917+
auto &file =
918+
makeFile(storageLocation, name, /* consider_open_files = */ true);
919+
propagateFilestateToRoot(storageLocation);
913920

914921
associateWithFile(writable, file);
915922

src/Iteration.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ void Iteration::flushFileBased(
239239
/* create file */
240240
Parameter<Operation::CREATE_FILE> fCreate;
241241
fCreate.name = filename;
242+
fCreate.storageLocation = &this->writable();
242243
IOHandler()->enqueue(IOTask(&s.writable(), fCreate));
243244

244245
/*
@@ -448,7 +449,7 @@ void Iteration::readFileBased(
448449
}
449450
auto series = retrieveSeries();
450451

451-
series.readOneIterationFileBased(filePath);
452+
series.readOneIterationFileBased(filePath, *this);
452453

453454
auto &series_data = series.get();
454455
if (series_data.m_iterationFilenames.find(idx) ==

src/Series.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,6 @@ void Series::readFileBased(
15881588
std::optional<IterationIndex_t> read_only_this_single_iteration)
15891589
{
15901590
auto &series = get();
1591-
Parameter<Operation::OPEN_FILE> fOpen;
15921591
Parameter<Operation::READ_ATT> aRead;
15931592

15941593
// Tell the backend that we are parsing file-based iteration encoding.
@@ -1802,7 +1801,8 @@ void Series::readFileBased(
18021801
"Please specify '%0<N>T' or open as read-only.");
18031802
}
18041803

1805-
void Series::readOneIterationFileBased(std::string const &filePath)
1804+
void Series::readOneIterationFileBased(
1805+
std::string const &filePath, Iteration &it)
18061806
{
18071807
auto &series = get();
18081808

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

18181818
fOpen.name = filePath;
1819+
fOpen.storageLocation = &it.writable();
18191820
IOHandler()->enqueue(IOTask(this, fOpen));
18201821
IOHandler()->flush(internal::defaultFlushParams);
18211822
series.iterations.parent() = getWritable(this);
@@ -2935,6 +2936,7 @@ void Series::openIteration(IterationIndex_t index, Iteration &iteration)
29352936
{
29362937
fOpen.reopen = R::WasFoundOnDisk;
29372938
}
2939+
fOpen.storageLocation = &iteration.writable();
29382940
IOHandler()->enqueue(IOTask(this, fOpen));
29392941

29402942
/* open base path */

0 commit comments

Comments
 (0)