Skip to content

Commit dcea2eb

Browse files
committed
Embed JSONMatcher into the backends
1 parent fa4aa62 commit dcea2eb

14 files changed

Lines changed: 96 additions & 62 deletions

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,13 @@ class ADIOS2IOHandlerImpl
120120
ADIOS2IOHandlerImpl(
121121
AbstractIOHandler *,
122122
MPI_Comm,
123-
json::TracingJSON config,
124123
std::string engineType,
125124
std::string specifiedExtension);
126125

127126
#endif // openPMD_HAVE_MPI
128127

129128
explicit ADIOS2IOHandlerImpl(
130129
AbstractIOHandler *,
131-
json::TracingJSON config,
132130
std::string engineType,
133131
std::string specifiedExtension);
134132

include/openPMD/IO/AbstractIOHandler.hpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939

4040
namespace openPMD
4141
{
42+
namespace json
43+
{
44+
class JsonMatcher;
45+
}
46+
4247
/**
4348
* @brief Determine what items should be flushed upon Series::flush()
4449
*
@@ -186,6 +191,8 @@ class AbstractIOHandler
186191
{
187192
friend class Series;
188193
friend class ADIOS2IOHandlerImpl;
194+
friend class JSONIOHandlerImpl;
195+
friend class HDF5IOHandlerImpl;
189196
friend class detail::ADIOS2File;
190197

191198
private:
@@ -207,22 +214,28 @@ class AbstractIOHandler
207214
m_encoding = encoding;
208215
}
209216

217+
protected:
218+
// Needs to be a pointer due to include structure, this header is
219+
// transitively included in user code, but we don't reexport the JSON
220+
// library
221+
std::unique_ptr<json::JsonMatcher> jsonMatcher;
222+
210223
public:
211224
#if openPMD_HAVE_MPI
212-
AbstractIOHandler(std::string path, Access at, MPI_Comm)
213-
: directory{std::move(path)}, m_backendAccess{at}, m_frontendAccess{at}
214-
{}
225+
template <typename TracingJSON>
226+
AbstractIOHandler(
227+
std::string path, Access at, TracingJSON &&jsonConfig, MPI_Comm);
215228
#endif
216-
AbstractIOHandler(std::string path, Access at)
217-
: directory{std::move(path)}, m_backendAccess{at}, m_frontendAccess{at}
218-
{}
219-
virtual ~AbstractIOHandler() = default;
220229

221-
AbstractIOHandler(AbstractIOHandler const &) = default;
222-
AbstractIOHandler(AbstractIOHandler &&) = default;
230+
template <typename TracingJSON>
231+
AbstractIOHandler(std::string path, Access at, TracingJSON &&jsonConfig);
232+
virtual ~AbstractIOHandler();
233+
234+
AbstractIOHandler(AbstractIOHandler const &) = delete;
235+
AbstractIOHandler(AbstractIOHandler &&) noexcept;
223236

224-
AbstractIOHandler &operator=(AbstractIOHandler const &) = default;
225-
AbstractIOHandler &operator=(AbstractIOHandler &&) = default;
237+
AbstractIOHandler &operator=(AbstractIOHandler const &) = delete;
238+
AbstractIOHandler &operator=(AbstractIOHandler &&) noexcept;
226239

227240
/** Add provided task to queue according to FIFO.
228241
*

include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ namespace openPMD
3838
class HDF5IOHandlerImpl : public AbstractIOHandlerImpl
3939
{
4040
public:
41-
HDF5IOHandlerImpl(
42-
AbstractIOHandler *,
43-
json::TracingJSON config,
44-
bool do_warn_unused_params = true);
41+
HDF5IOHandlerImpl(AbstractIOHandler *, bool do_warn_unused_params = true);
4542
~HDF5IOHandlerImpl() override;
4643

4744
void

include/openPMD/IO/HDF5/ParallelHDF5IOHandlerImpl.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ namespace openPMD
3737
class ParallelHDF5IOHandlerImpl : public HDF5IOHandlerImpl
3838
{
3939
public:
40-
ParallelHDF5IOHandlerImpl(
41-
AbstractIOHandler *, MPI_Comm, json::TracingJSON config);
40+
ParallelHDF5IOHandlerImpl(AbstractIOHandler *, MPI_Comm);
4241
~ParallelHDF5IOHandlerImpl() override;
4342

4443
MPI_Comm m_mpiComm;

include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,12 @@ class JSONIOHandlerImpl : public AbstractIOHandlerImpl
166166
};
167167

168168
explicit JSONIOHandlerImpl(
169-
AbstractIOHandler *,
170-
openPMD::json::TracingJSON config,
171-
FileFormat,
172-
std::string originalExtension);
169+
AbstractIOHandler *, FileFormat, std::string originalExtension);
173170

174171
#if openPMD_HAVE_MPI
175172
JSONIOHandlerImpl(
176173
AbstractIOHandler *,
177174
MPI_Comm,
178-
openPMD::json::TracingJSON config,
179175
FileFormat,
180176
std::string originalExtension);
181177
#endif

include/openPMD/auxiliary/JSON_internal.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace json
4747

4848
struct ParsedConfig
4949
{
50-
nlohmann::json config;
50+
nlohmann::json config = nlohmann::json::object();
5151
SupportedLanguages originallySpecifiedAs{SupportedLanguages::JSON};
5252
};
5353

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "openPMD/IterationEncoding.hpp"
3131
#include "openPMD/auxiliary/Environment.hpp"
3232
#include "openPMD/auxiliary/Filesystem.hpp"
33+
#include "openPMD/auxiliary/JSONMatcher.hpp"
3334
#include "openPMD/auxiliary/Mpi.hpp"
3435
#include "openPMD/auxiliary/StringManip.hpp"
3536
#include "openPMD/auxiliary/TypeTraits.hpp"
@@ -85,7 +86,6 @@ std::optional<size_t> joinedDimension(adios2::Dims const &dims)
8586
ADIOS2IOHandlerImpl::ADIOS2IOHandlerImpl(
8687
AbstractIOHandler *handler,
8788
MPI_Comm communicator,
88-
json::TracingJSON cfg,
8989
std::string engineType,
9090
std::string specifiedExtension)
9191
: AbstractIOHandlerImplCommon(handler)
@@ -95,7 +95,7 @@ ADIOS2IOHandlerImpl::ADIOS2IOHandlerImpl(
9595
, m_userSpecifiedExtension{std::move(specifiedExtension)}
9696
{
9797
init(
98-
std::move(cfg),
98+
handler->jsonMatcher->getDefault(),
9999
/* callbackWriteAttributesFromRank = */
100100
[communicator, this](nlohmann::json const &attribute_writing_ranks) {
101101
int rank = 0;
@@ -137,15 +137,14 @@ ADIOS2IOHandlerImpl::ADIOS2IOHandlerImpl(
137137

138138
ADIOS2IOHandlerImpl::ADIOS2IOHandlerImpl(
139139
AbstractIOHandler *handler,
140-
json::TracingJSON cfg,
141140
std::string engineType,
142141
std::string specifiedExtension)
143142
: AbstractIOHandlerImplCommon(handler)
144143
, m_ADIOS{}
145144
, m_engineType(std::move(engineType))
146145
, m_userSpecifiedExtension(std::move(specifiedExtension))
147146
{
148-
init(std::move(cfg), [](auto const &...) {});
147+
init(handler->jsonMatcher->getDefault(), [](auto const &...) {});
149148
}
150149

151150
ADIOS2IOHandlerImpl::~ADIOS2IOHandlerImpl()
@@ -2076,13 +2075,8 @@ ADIOS2IOHandler::ADIOS2IOHandler(
20762075
json::TracingJSON options,
20772076
std::string engineType,
20782077
std::string specifiedExtension)
2079-
: AbstractIOHandler(std::move(path), at, comm)
2080-
, m_impl{
2081-
this,
2082-
comm,
2083-
std::move(options),
2084-
std::move(engineType),
2085-
std::move(specifiedExtension)}
2078+
: AbstractIOHandler(std::move(path), at, std::move(options), comm)
2079+
, m_impl{this, comm, std::move(engineType), std::move(specifiedExtension)}
20862080
{}
20872081

20882082
#endif
@@ -2093,12 +2087,8 @@ ADIOS2IOHandler::ADIOS2IOHandler(
20932087
json::TracingJSON options,
20942088
std::string engineType,
20952089
std::string specifiedExtension)
2096-
: AbstractIOHandler(std::move(path), at)
2097-
, m_impl{
2098-
this,
2099-
std::move(options),
2100-
std::move(engineType),
2101-
std::move(specifiedExtension)}
2090+
: AbstractIOHandler(std::move(path), at, std::move(options))
2091+
, m_impl{this, std::move(engineType), std::move(specifiedExtension)}
21022092
{}
21032093

21042094
std::future<void>

src/IO/AbstractIOHandler.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "openPMD/IO/AbstractIOHandler.hpp"
2323

2424
#include "openPMD/IO/FlushParametersInternal.hpp"
25+
#include "openPMD/auxiliary/JSONMatcher.hpp"
2526

2627
namespace openPMD
2728
{
@@ -43,4 +44,42 @@ std::future<void> AbstractIOHandler::flush(internal::FlushParams const &params)
4344
json::warnGlobalUnusedOptions(parsedParams.backendConfig);
4445
return future;
4546
}
47+
48+
#if openPMD_HAVE_MPI
49+
template <typename TracingJSON>
50+
AbstractIOHandler::AbstractIOHandler(
51+
std::string path, Access at, TracingJSON &&jsonConfig, MPI_Comm)
52+
: jsonMatcher(std::make_unique<json::JsonMatcher>(
53+
std::forward<TracingJSON>(jsonConfig)))
54+
, directory{std::move(path)}
55+
, m_backendAccess{at}
56+
, m_frontendAccess{at}
57+
{}
58+
59+
template AbstractIOHandler::AbstractIOHandler(
60+
std::string path, Access at, json::TracingJSON &&jsonConfig, MPI_Comm);
61+
#endif
62+
63+
template <typename TracingJSON>
64+
AbstractIOHandler::AbstractIOHandler(
65+
std::string path, Access at, TracingJSON &&jsonConfig)
66+
: jsonMatcher(std::make_unique<json::JsonMatcher>(
67+
std::forward<TracingJSON>(jsonConfig)))
68+
, directory{std::move(path)}
69+
, m_backendAccess{at}
70+
, m_frontendAccess{at}
71+
{}
72+
73+
template AbstractIOHandler::AbstractIOHandler(
74+
std::string path, Access at, json::TracingJSON &&jsonConfig);
75+
76+
AbstractIOHandler::~AbstractIOHandler() = default;
77+
78+
// AbstractIOHandler::AbstractIOHandler(AbstractIOHandler const &) = default;
79+
AbstractIOHandler::AbstractIOHandler(AbstractIOHandler &&) noexcept = default;
80+
81+
// AbstractIOHandler &
82+
// AbstractIOHandler::operator=(AbstractIOHandler const &) = default;
83+
AbstractIOHandler &
84+
AbstractIOHandler::operator=(AbstractIOHandler &&) noexcept = default;
4685
} // namespace openPMD

src/IO/DummyIOHandler.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@
1919
* If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121
#include "openPMD/IO/DummyIOHandler.hpp"
22+
#include "openPMD/auxiliary/JSON_internal.hpp"
2223

2324
#include <iostream>
2425
#include <utility>
2526

2627
namespace openPMD
2728
{
2829
DummyIOHandler::DummyIOHandler(std::string path, Access at)
29-
: AbstractIOHandler(std::move(path), at)
30+
: AbstractIOHandler(
31+
std::move(path),
32+
at,
33+
json::TracingJSON(
34+
nlohmann::json::object(), json::SupportedLanguages::JSON))
3035
{}
3136

3237
void DummyIOHandler::enqueue(IOTask const &)

src/IO/HDF5/HDF5IOHandler.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "openPMD/IO/HDF5/HDF5FilePosition.hpp"
3535
#include "openPMD/IO/IOTask.hpp"
3636
#include "openPMD/auxiliary/Filesystem.hpp"
37+
#include "openPMD/auxiliary/JSONMatcher.hpp"
3738
#include "openPMD/auxiliary/Mpi.hpp"
3839
#include "openPMD/auxiliary/StringManip.hpp"
3940
#include "openPMD/auxiliary/TypeTraits.hpp"
@@ -71,9 +72,7 @@ namespace openPMD
7172
#endif
7273

7374
HDF5IOHandlerImpl::HDF5IOHandlerImpl(
74-
AbstractIOHandler *handler,
75-
json::TracingJSON config,
76-
bool do_warn_unused_params)
75+
AbstractIOHandler *handler, bool do_warn_unused_params)
7776
: AbstractIOHandlerImpl(handler)
7877
, m_datasetTransferProperty{H5P_DEFAULT}
7978
, m_fileAccessProperty{H5P_DEFAULT}
@@ -139,6 +138,8 @@ HDF5IOHandlerImpl::HDF5IOHandlerImpl(
139138
m_H5T_LONG_DOUBLE_80_LE >= 0,
140139
"[HDF5] Internal error: Failed to create 128-bit complex long double");
141140

141+
auto config = handler->jsonMatcher->getDefault();
142+
142143
// JSON option can overwrite env option:
143144
if (config.json().contains("hdf5"))
144145
{
@@ -2938,8 +2939,8 @@ HDF5IOHandlerImpl::getFile(Writable *writable)
29382939
#if openPMD_HAVE_HDF5
29392940
HDF5IOHandler::HDF5IOHandler(
29402941
std::string path, Access at, json::TracingJSON config)
2941-
: AbstractIOHandler(std::move(path), at)
2942-
, m_impl{new HDF5IOHandlerImpl(this, std::move(config))}
2942+
: AbstractIOHandler(std::move(path), at, std::move(config))
2943+
, m_impl{new HDF5IOHandlerImpl(this)}
29432944
{}
29442945

29452946
HDF5IOHandler::~HDF5IOHandler() = default;

0 commit comments

Comments
 (0)