Skip to content

Commit 0650789

Browse files
committed
Fix initialization from Dummy IO Handler
1 parent 19571e7 commit 0650789

15 files changed

+182
-55
lines changed

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@ class ADIOS2IOHandler : public AbstractIOHandler
837837
#if openPMD_HAVE_MPI
838838

839839
ADIOS2IOHandler(
840+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
840841
std::string path,
841842
Access,
842843
MPI_Comm,
@@ -847,6 +848,7 @@ class ADIOS2IOHandler : public AbstractIOHandler
847848
#endif
848849

849850
ADIOS2IOHandler(
851+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
850852
std::string path,
851853
Access,
852854
json::TracingJSON options,

include/openPMD/IO/AbstractIOHandler.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,22 @@ class AbstractIOHandler
223223
#if openPMD_HAVE_MPI
224224
template <typename TracingJSON>
225225
AbstractIOHandler(
226-
std::string path, Access at, TracingJSON &&jsonConfig, MPI_Comm);
226+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
227+
std::string path,
228+
Access at,
229+
TracingJSON &&jsonConfig,
230+
MPI_Comm);
227231
#endif
228232

229233
template <typename TracingJSON>
230-
AbstractIOHandler(std::string path, Access at, TracingJSON &&jsonConfig);
234+
AbstractIOHandler(
235+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
236+
std::string path,
237+
Access at,
238+
TracingJSON &&jsonConfig);
239+
240+
AbstractIOHandler(std::optional<std::unique_ptr<AbstractIOHandler>>);
241+
231242
virtual ~AbstractIOHandler();
232243

233244
AbstractIOHandler(AbstractIOHandler const &) = delete;

include/openPMD/IO/AbstractIOHandlerHelper.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace openPMD
4747
*/
4848
template <typename JSON>
4949
std::unique_ptr<AbstractIOHandler> createIOHandler(
50+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
5051
std::string path,
5152
Access access,
5253
Format format,
@@ -74,6 +75,7 @@ std::unique_ptr<AbstractIOHandler> createIOHandler(
7475
*/
7576
template <typename JSON>
7677
std::unique_ptr<AbstractIOHandler> createIOHandler(
78+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
7779
std::string path,
7880
Access access,
7981
Format format,
@@ -83,6 +85,7 @@ std::unique_ptr<AbstractIOHandler> createIOHandler(
8385

8486
// version without configuration to use in AuxiliaryTest
8587
std::unique_ptr<AbstractIOHandler> createIOHandler(
88+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
8689
std::string path,
8790
Access access,
8891
Format format,

include/openPMD/IO/HDF5/HDF5IOHandler.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ class HDF5IOHandlerImpl;
3434
class HDF5IOHandler : public AbstractIOHandler
3535
{
3636
public:
37-
HDF5IOHandler(std::string path, Access, json::TracingJSON config);
37+
HDF5IOHandler(
38+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
39+
std::string path,
40+
Access,
41+
json::TracingJSON config);
3842
~HDF5IOHandler() override;
3943

4044
std::string backendName() const override

include/openPMD/IO/HDF5/ParallelHDF5IOHandler.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,17 @@ class ParallelHDF5IOHandler : public AbstractIOHandler
3737
public:
3838
#if openPMD_HAVE_MPI
3939
ParallelHDF5IOHandler(
40-
std::string path, Access, MPI_Comm, json::TracingJSON config);
40+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
41+
std::string path,
42+
Access,
43+
MPI_Comm,
44+
json::TracingJSON config);
4145
#else
4246
ParallelHDF5IOHandler(
43-
std::string const &path, Access, json::TracingJSON config);
47+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
48+
std::string const &path,
49+
Access,
50+
json::TracingJSON config);
4451
#endif
4552
~ParallelHDF5IOHandler() override;
4653

include/openPMD/IO/JSON/JSONIOHandler.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ class JSONIOHandler : public AbstractIOHandler
3535
{
3636
public:
3737
JSONIOHandler(
38+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
3839
std::string path,
3940
Access at,
4041
openPMD::json::TracingJSON config,
4142
JSONIOHandlerImpl::FileFormat,
4243
std::string originalExtension);
4344
#if openPMD_HAVE_MPI
4445
JSONIOHandler(
46+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
4547
std::string path,
4648
Access at,
4749
MPI_Comm,

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,25 +2233,33 @@ namespace detail
22332233
#if openPMD_HAVE_MPI
22342234

22352235
ADIOS2IOHandler::ADIOS2IOHandler(
2236+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
22362237
std::string path,
22372238
openPMD::Access at,
22382239
MPI_Comm comm,
22392240
json::TracingJSON options,
22402241
std::string engineType,
22412242
std::string specifiedExtension)
2242-
: AbstractIOHandler(std::move(path), at, std::move(options), comm)
2243+
: AbstractIOHandler(
2244+
std::move(initialize_from),
2245+
std::move(path),
2246+
at,
2247+
std::move(options),
2248+
comm)
22432249
, m_impl{this, comm, std::move(engineType), std::move(specifiedExtension)}
22442250
{}
22452251

22462252
#endif
22472253

22482254
ADIOS2IOHandler::ADIOS2IOHandler(
2255+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
22492256
std::string path,
22502257
Access at,
22512258
json::TracingJSON options,
22522259
std::string engineType,
22532260
std::string specifiedExtension)
2254-
: AbstractIOHandler(std::move(path), at, std::move(options))
2261+
: AbstractIOHandler(
2262+
std::move(initialize_from), std::move(path), at, std::move(options))
22552263
, m_impl{this, std::move(engineType), std::move(specifiedExtension)}
22562264
{}
22572265

@@ -2265,6 +2273,7 @@ ADIOS2IOHandler::flush(internal::ParsedFlushParams &flushParams)
22652273

22662274
#if openPMD_HAVE_MPI
22672275
ADIOS2IOHandler::ADIOS2IOHandler(
2276+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
22682277
std::string path,
22692278
Access at,
22702279
MPI_Comm comm,
@@ -2273,20 +2282,27 @@ ADIOS2IOHandler::ADIOS2IOHandler(
22732282
std::string,
22742283
// NOLINTNEXTLINE(performance-unnecessary-value-param)
22752284
std::string)
2276-
: AbstractIOHandler(std::move(path), at, std::move(config), comm)
2285+
: AbstractIOHandler(
2286+
std::move(initialize_from),
2287+
std::move(path),
2288+
at,
2289+
std::move(config),
2290+
comm)
22772291
{}
22782292

22792293
#endif // openPMD_HAVE_MPI
22802294

22812295
ADIOS2IOHandler::ADIOS2IOHandler(
2296+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
22822297
std::string path,
22832298
Access at,
22842299
json::TracingJSON config,
22852300
// NOLINTNEXTLINE(performance-unnecessary-value-param)
22862301
std::string,
22872302
// NOLINTNEXTLINE(performance-unnecessary-value-param)
22882303
std::string)
2289-
: AbstractIOHandler(std::move(path), at, std::move(config))
2304+
: AbstractIOHandler(
2305+
std::move(initialize_from), std::move(path), at, std::move(config))
22902306
{}
22912307

22922308
std::future<void> ADIOS2IOHandler::flush(internal::ParsedFlushParams &)

src/IO/AbstractIOHandler.cpp

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,42 @@ std::future<void> AbstractIOHandler::flush(internal::FlushParams const &params)
122122
#if openPMD_HAVE_MPI
123123
template <>
124124
AbstractIOHandler::AbstractIOHandler(
125-
std::string path, Access at, json::TracingJSON &&jsonConfig, MPI_Comm)
126-
: jsonMatcher(std::make_unique<json::JsonMatcher>(std::move(jsonConfig)))
127-
, directory{std::move(path)}
128-
, m_backendAccess{at}
129-
, m_frontendAccess{at}
130-
{}
125+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
126+
std::string path,
127+
Access at,
128+
json::TracingJSON &&jsonConfig,
129+
MPI_Comm)
130+
: AbstractIOHandler(std::move(initialize_from))
131+
{
132+
jsonMatcher = std::make_unique<json::JsonMatcher>(std::move(jsonConfig));
133+
directory = std::move(path);
134+
m_backendAccess = at;
135+
m_frontendAccess = at;
136+
}
131137
#endif
132138

133139
template <>
134140
AbstractIOHandler::AbstractIOHandler(
135-
std::string path, Access at, json::TracingJSON &&jsonConfig)
136-
: jsonMatcher(std::make_unique<json::JsonMatcher>(std::move(jsonConfig)))
137-
, directory{std::move(path)}
138-
, m_backendAccess{at}
139-
, m_frontendAccess{at}
140-
{}
141+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
142+
std::string path,
143+
Access at,
144+
json::TracingJSON &&jsonConfig)
145+
: AbstractIOHandler(std::move(initialize_from))
146+
{
147+
jsonMatcher = std::make_unique<json::JsonMatcher>(std::move(jsonConfig));
148+
directory = std::move(path);
149+
m_backendAccess = at;
150+
m_frontendAccess = at;
151+
}
152+
153+
AbstractIOHandler::AbstractIOHandler(
154+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from)
155+
{
156+
if (initialize_from.has_value() && *initialize_from)
157+
{
158+
this->operator=(std::move(**initialize_from));
159+
}
160+
}
141161

142162
AbstractIOHandler::~AbstractIOHandler() = default;
143163
// std::queue::queue(queue&&) is not noexcept

0 commit comments

Comments
 (0)