Skip to content

Commit 48ec4e3

Browse files
committed
Fix initialization from Dummy IO Handler
1 parent 9607c83 commit 48ec4e3

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
@@ -844,6 +844,7 @@ class ADIOS2IOHandler : public AbstractIOHandler
844844
#if openPMD_HAVE_MPI
845845

846846
ADIOS2IOHandler(
847+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
847848
std::string path,
848849
Access,
849850
MPI_Comm,
@@ -854,6 +855,7 @@ class ADIOS2IOHandler : public AbstractIOHandler
854855
#endif
855856

856857
ADIOS2IOHandler(
858+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
857859
std::string path,
858860
Access,
859861
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
@@ -2471,25 +2471,33 @@ ERROR: Variable ')"[1] + varName +
24712471
#if openPMD_HAVE_MPI
24722472

24732473
ADIOS2IOHandler::ADIOS2IOHandler(
2474+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
24742475
std::string path,
24752476
openPMD::Access at,
24762477
MPI_Comm comm,
24772478
json::TracingJSON options,
24782479
std::string engineType,
24792480
std::string specifiedExtension)
2480-
: AbstractIOHandler(std::move(path), at, std::move(options), comm)
2481+
: AbstractIOHandler(
2482+
std::move(initialize_from),
2483+
std::move(path),
2484+
at,
2485+
std::move(options),
2486+
comm)
24812487
, m_impl{this, comm, std::move(engineType), std::move(specifiedExtension)}
24822488
{}
24832489

24842490
#endif
24852491

24862492
ADIOS2IOHandler::ADIOS2IOHandler(
2493+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
24872494
std::string path,
24882495
Access at,
24892496
json::TracingJSON options,
24902497
std::string engineType,
24912498
std::string specifiedExtension)
2492-
: AbstractIOHandler(std::move(path), at, std::move(options))
2499+
: AbstractIOHandler(
2500+
std::move(initialize_from), std::move(path), at, std::move(options))
24932501
, m_impl{this, std::move(engineType), std::move(specifiedExtension)}
24942502
{}
24952503

@@ -2503,6 +2511,7 @@ ADIOS2IOHandler::flush(internal::ParsedFlushParams &flushParams)
25032511

25042512
#if openPMD_HAVE_MPI
25052513
ADIOS2IOHandler::ADIOS2IOHandler(
2514+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
25062515
std::string path,
25072516
Access at,
25082517
MPI_Comm comm,
@@ -2511,20 +2520,27 @@ ADIOS2IOHandler::ADIOS2IOHandler(
25112520
std::string,
25122521
// NOLINTNEXTLINE(performance-unnecessary-value-param)
25132522
std::string)
2514-
: AbstractIOHandler(std::move(path), at, std::move(config), comm)
2523+
: AbstractIOHandler(
2524+
std::move(initialize_from),
2525+
std::move(path),
2526+
at,
2527+
std::move(config),
2528+
comm)
25152529
{}
25162530

25172531
#endif // openPMD_HAVE_MPI
25182532

25192533
ADIOS2IOHandler::ADIOS2IOHandler(
2534+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
25202535
std::string path,
25212536
Access at,
25222537
json::TracingJSON config,
25232538
// NOLINTNEXTLINE(performance-unnecessary-value-param)
25242539
std::string,
25252540
// NOLINTNEXTLINE(performance-unnecessary-value-param)
25262541
std::string)
2527-
: AbstractIOHandler(std::move(path), at, std::move(config))
2542+
: AbstractIOHandler(
2543+
std::move(initialize_from), std::move(path), at, std::move(config))
25282544
{}
25292545

25302546
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
@@ -127,22 +127,42 @@ bool AbstractIOHandler::fullSupportForVariableBasedEncoding() const
127127
#if openPMD_HAVE_MPI
128128
template <>
129129
AbstractIOHandler::AbstractIOHandler(
130-
std::string path, Access at, json::TracingJSON &&jsonConfig, MPI_Comm)
131-
: jsonMatcher(std::make_unique<json::JsonMatcher>(std::move(jsonConfig)))
132-
, directory{std::move(path)}
133-
, m_backendAccess{at}
134-
, m_frontendAccess{at}
135-
{}
130+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
131+
std::string path,
132+
Access at,
133+
json::TracingJSON &&jsonConfig,
134+
MPI_Comm)
135+
: AbstractIOHandler(std::move(initialize_from))
136+
{
137+
jsonMatcher = std::make_unique<json::JsonMatcher>(std::move(jsonConfig));
138+
directory = std::move(path);
139+
m_backendAccess = at;
140+
m_frontendAccess = at;
141+
}
136142
#endif
137143

138144
template <>
139145
AbstractIOHandler::AbstractIOHandler(
140-
std::string path, Access at, json::TracingJSON &&jsonConfig)
141-
: jsonMatcher(std::make_unique<json::JsonMatcher>(std::move(jsonConfig)))
142-
, directory{std::move(path)}
143-
, m_backendAccess{at}
144-
, m_frontendAccess{at}
145-
{}
146+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from,
147+
std::string path,
148+
Access at,
149+
json::TracingJSON &&jsonConfig)
150+
: AbstractIOHandler(std::move(initialize_from))
151+
{
152+
jsonMatcher = std::make_unique<json::JsonMatcher>(std::move(jsonConfig));
153+
directory = std::move(path);
154+
m_backendAccess = at;
155+
m_frontendAccess = at;
156+
}
157+
158+
AbstractIOHandler::AbstractIOHandler(
159+
std::optional<std::unique_ptr<AbstractIOHandler>> initialize_from)
160+
{
161+
if (initialize_from.has_value() && *initialize_from)
162+
{
163+
this->operator=(std::move(**initialize_from));
164+
}
165+
}
146166

147167
AbstractIOHandler::~AbstractIOHandler() = default;
148168
// std::queue::queue(queue&&) is not noexcept

0 commit comments

Comments
 (0)