Skip to content

Commit 7c3c985

Browse files
committed
Use TracingJSON from the start already
1 parent 9e2d3f4 commit 7c3c985

10 files changed

+56
-44
lines changed

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ class ADIOS2IOHandlerImpl
130130
ADIOS2IOHandlerImpl(
131131
AbstractIOHandler *,
132132
MPI_Comm,
133-
nlohmann::json config,
133+
json::TracingJSON config,
134134
std::string engineType );
135135

136136
#endif // openPMD_HAVE_MPI
137137

138138
explicit ADIOS2IOHandlerImpl(
139139
AbstractIOHandler *,
140-
nlohmann::json config,
140+
json::TracingJSON config,
141141
std::string engineType );
142142

143143

@@ -281,7 +281,7 @@ class ADIOS2IOHandlerImpl
281281
static json::TracingJSON nullvalue;
282282

283283
void
284-
init( nlohmann::json config );
284+
init( json::TracingJSON config );
285285

286286
template< typename Key >
287287
json::TracingJSON
@@ -1413,15 +1413,15 @@ friend class ADIOS2IOHandlerImpl;
14131413
std::string path,
14141414
Access,
14151415
MPI_Comm,
1416-
nlohmann::json options,
1416+
json::TracingJSON options,
14171417
std::string engineType );
14181418

14191419
#endif
14201420

14211421
ADIOS2IOHandler(
14221422
std::string path,
14231423
Access,
1424-
nlohmann::json options,
1424+
json::TracingJSON options,
14251425
std::string engineType );
14261426

14271427
std::string backendName() const override { return "ADIOS2"; }

include/openPMD/IO/HDF5/HDF5IOHandler.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
*/
2121
#pragma once
2222

23+
#include "openPMD/auxiliary/JSON.hpp"
2324
#include "openPMD/IO/AbstractIOHandler.hpp"
2425

25-
#include <nlohmann/json.hpp>
26-
2726
#include <future>
2827
#include <memory>
2928
#include <string>
@@ -36,7 +35,7 @@ class HDF5IOHandlerImpl;
3635
class HDF5IOHandler : public AbstractIOHandler
3736
{
3837
public:
39-
HDF5IOHandler(std::string path, Access, nlohmann::json config);
38+
HDF5IOHandler(std::string path, Access, json::TracingJSON config);
4039
~HDF5IOHandler() override;
4140

4241
std::string backendName() const override { return "HDF5"; }

include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace openPMD
3939
class HDF5IOHandlerImpl : public AbstractIOHandlerImpl
4040
{
4141
public:
42-
HDF5IOHandlerImpl(AbstractIOHandler*, nlohmann::json config);
42+
HDF5IOHandlerImpl(AbstractIOHandler*, json::TracingJSON config);
4343
~HDF5IOHandlerImpl() override;
4444

4545
void createFile(Writable*, Parameter< Operation::CREATE_FILE > const&) override;

include/openPMD/IO/HDF5/ParallelHDF5IOHandler.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
#pragma once
2222

2323
#include "openPMD/config.hpp"
24+
#include "openPMD/auxiliary/JSON.hpp"
2425
#include "openPMD/IO/AbstractIOHandler.hpp"
2526

26-
#include <nlohmann/json.hpp>
27-
2827
#include <future>
2928
#include <memory>
3029
#include <string>
@@ -39,7 +38,7 @@ namespace openPMD
3938
public:
4039
#if openPMD_HAVE_MPI
4140
ParallelHDF5IOHandler(
42-
std::string path, Access, MPI_Comm, nlohmann::json config);
41+
std::string path, Access, MPI_Comm, json::TracingJSON config);
4342
#else
4443
ParallelHDF5IOHandler(std::string path, Access, nlohmann::json config);
4544
#endif

include/openPMD/IO/HDF5/ParallelHDF5IOHandlerImpl.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace openPMD
3939
{
4040
public:
4141
ParallelHDF5IOHandlerImpl(
42-
AbstractIOHandler*, MPI_Comm, nlohmann::json config);
42+
AbstractIOHandler*, MPI_Comm, json::TracingJSON config);
4343
~ParallelHDF5IOHandlerImpl() override;
4444

4545
MPI_Comm m_mpiComm;

src/IO/ADIOS/ADIOS2IOHandler.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace openPMD
6767
ADIOS2IOHandlerImpl::ADIOS2IOHandlerImpl(
6868
AbstractIOHandler * handler,
6969
MPI_Comm communicator,
70-
nlohmann::json cfg,
70+
json::TracingJSON cfg,
7171
std::string engineType )
7272
: AbstractIOHandlerImplCommon( handler )
7373
, m_ADIOS{ communicator, ADIOS2_DEBUG_MODE }
@@ -80,7 +80,7 @@ ADIOS2IOHandlerImpl::ADIOS2IOHandlerImpl(
8080

8181
ADIOS2IOHandlerImpl::ADIOS2IOHandlerImpl(
8282
AbstractIOHandler * handler,
83-
nlohmann::json cfg,
83+
json::TracingJSON cfg,
8484
std::string engineType )
8585
: AbstractIOHandlerImplCommon( handler )
8686
, m_ADIOS{ ADIOS2_DEBUG_MODE }
@@ -120,9 +120,9 @@ ADIOS2IOHandlerImpl::~ADIOS2IOHandlerImpl()
120120
}
121121

122122
void
123-
ADIOS2IOHandlerImpl::init( nlohmann::json cfg )
123+
ADIOS2IOHandlerImpl::init( json::TracingJSON cfg )
124124
{
125-
if( cfg.contains( "adios2" ) )
125+
if( cfg.json().contains( "adios2" ) )
126126
{
127127
m_config = std::move( cfg[ "adios2" ] );
128128

@@ -2917,7 +2917,7 @@ ADIOS2IOHandler::ADIOS2IOHandler(
29172917
std::string path,
29182918
openPMD::Access at,
29192919
MPI_Comm comm,
2920-
nlohmann::json options,
2920+
json::TracingJSON options,
29212921
std::string engineType )
29222922
: AbstractIOHandler( std::move( path ), at, comm )
29232923
, m_impl{ this, comm, std::move( options ), std::move( engineType ) }
@@ -2929,7 +2929,7 @@ ADIOS2IOHandler::ADIOS2IOHandler(
29292929
ADIOS2IOHandler::ADIOS2IOHandler(
29302930
std::string path,
29312931
Access at,
2932-
nlohmann::json options,
2932+
json::TracingJSON options,
29332933
std::string engineType )
29342934
: AbstractIOHandler( std::move( path ), at )
29352935
, m_impl{ this, std::move( options ), std::move( engineType ) }

src/IO/AbstractIOHandlerHelper.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ namespace openPMD
3434
#if openPMD_HAVE_MPI
3535
template<>
3636
std::shared_ptr< AbstractIOHandler >
37-
createIOHandler< nlohmann::json >(
37+
createIOHandler< json::TracingJSON >(
3838
std::string path,
3939
Access access,
4040
Format format,
4141
MPI_Comm comm,
42-
nlohmann::json options )
42+
json::TracingJSON options )
4343
{
4444
(void) options;
4545
switch( format )
@@ -71,11 +71,11 @@ namespace openPMD
7171

7272
template<>
7373
std::shared_ptr< AbstractIOHandler >
74-
createIOHandler< nlohmann::json >(
74+
createIOHandler< json::TracingJSON >(
7575
std::string path,
7676
Access access,
7777
Format format,
78-
nlohmann::json options )
78+
json::TracingJSON options )
7979
{
8080
(void) options;
8181
switch( format )
@@ -112,6 +112,9 @@ namespace openPMD
112112
createIOHandler( std::string path, Access access, Format format )
113113
{
114114
return createIOHandler(
115-
std::move( path ), access, format, nlohmann::json::object() );
115+
std::move( path ),
116+
access,
117+
format,
118+
json::TracingJSON( nlohmann::json::object() ));
116119
}
117120
} // namespace openPMD

src/IO/HDF5/HDF5IOHandler.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace openPMD
5353
# endif
5454

5555
HDF5IOHandlerImpl::HDF5IOHandlerImpl(
56-
AbstractIOHandler* handler, nlohmann::json config)
56+
AbstractIOHandler* handler, json::TracingJSON config)
5757
: AbstractIOHandlerImpl(handler),
5858
m_datasetTransferProperty{H5P_DEFAULT},
5959
m_fileAccessProperty{H5P_DEFAULT},
@@ -87,7 +87,7 @@ HDF5IOHandlerImpl::HDF5IOHandlerImpl(
8787

8888
m_chunks = auxiliary::getEnvString( "OPENPMD_HDF5_CHUNKS", "auto" );
8989
// JSON option can overwrite env option:
90-
if( config.contains( "hdf5" ) )
90+
if( config.json().contains( "hdf5" ) )
9191
{
9292
m_config = std::move( config[ "hdf5" ] );
9393

@@ -1914,7 +1914,7 @@ HDF5IOHandlerImpl::getFile( Writable * writable )
19141914
#endif
19151915

19161916
#if openPMD_HAVE_HDF5
1917-
HDF5IOHandler::HDF5IOHandler(std::string path, Access at, nlohmann::json config)
1917+
HDF5IOHandler::HDF5IOHandler(std::string path, Access at, json::TracingJSON config)
19181918
: AbstractIOHandler(std::move(path), at),
19191919
m_impl{new HDF5IOHandlerImpl(this, std::move(config))}
19201920
{ }
@@ -1927,7 +1927,7 @@ HDF5IOHandler::flush()
19271927
return m_impl->flush();
19281928
}
19291929
#else
1930-
HDF5IOHandler::HDF5IOHandler(std::string path, Access at, nlohmann::json /* config */)
1930+
HDF5IOHandler::HDF5IOHandler(std::string path, Access at, json::TracingJSON /* config */)
19311931
: AbstractIOHandler(std::move(path), at)
19321932
{
19331933
throw std::runtime_error("openPMD-api built without HDF5 support");

src/IO/HDF5/ParallelHDF5IOHandler.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace openPMD
3939
# endif
4040

4141
ParallelHDF5IOHandler::ParallelHDF5IOHandler(
42-
std::string path, Access at, MPI_Comm comm, nlohmann::json config )
42+
std::string path, Access at, MPI_Comm comm, json::TracingJSON config )
4343
: AbstractIOHandler(std::move(path), at, comm),
4444
m_impl{new ParallelHDF5IOHandlerImpl(this, comm, std::move(config))}
4545
{ }
@@ -53,7 +53,7 @@ ParallelHDF5IOHandler::flush()
5353
}
5454

5555
ParallelHDF5IOHandlerImpl::ParallelHDF5IOHandlerImpl(
56-
AbstractIOHandler* handler, MPI_Comm comm, nlohmann::json config )
56+
AbstractIOHandler* handler, MPI_Comm comm, json::TracingJSON config )
5757
: HDF5IOHandlerImpl{handler, std::move(config)},
5858
m_mpiComm{comm},
5959
m_mpiInfo{MPI_INFO_NULL} /* MPI 3.0+: MPI_INFO_ENV */

src/Series.cpp

+25-14
Original file line numberDiff line numberDiff line change
@@ -1444,21 +1444,32 @@ void SeriesInterface::openIteration( uint64_t index, Iteration iteration )
14441444

14451445
namespace
14461446
{
1447-
template< typename T >
1448-
void getJsonOption(
1449-
nlohmann::json const & config, std::string const & key, T & dest )
1450-
{
1451-
if( config.contains( key ) )
1447+
template< typename From, typename Dest = From >
1448+
void getJsonOption(
1449+
json::TracingJSON & config, std::string const & key, Dest & dest )
14521450
{
1453-
dest = config.at( key ).get< T >();
1451+
if( config.json().contains( key ) )
1452+
{
1453+
dest = config[ key ].json().get< From >();
1454+
}
14541455
}
1455-
}
14561456

1457-
void parseJsonOptions(
1458-
internal::SeriesData & series, nlohmann::json const & options )
1459-
{
1460-
getJsonOption( options, "defer_iteration_parsing", series.m_parseLazily );
1461-
}
1457+
template< typename Dest = std::string >
1458+
void getJsonOptionLowerCase(
1459+
json::TracingJSON & config, std::string const & key, Dest & dest )
1460+
{
1461+
if( config.json().contains( key ) )
1462+
{
1463+
dest = json::asLowerCaseStringDynamic( config[ key ].json() );
1464+
}
1465+
}
1466+
1467+
void parseJsonOptions(
1468+
internal::SeriesData & series, json::TracingJSON & options )
1469+
{
1470+
getJsonOption< bool >(
1471+
options, "defer_iteration_parsing", series.m_parseLazily );
1472+
}
14621473
}
14631474

14641475
namespace internal
@@ -1473,7 +1484,7 @@ SeriesInternal::SeriesInternal(
14731484
static_cast< internal::SeriesData * >( this ),
14741485
static_cast< internal::AttributableData * >( this ) }
14751486
{
1476-
nlohmann::json optionsJson = json::parseOptions( options, comm );
1487+
json::TracingJSON optionsJson = json::parseOptions( options, comm );
14771488
parseJsonOptions( *this, optionsJson );
14781489
auto input = parseInput( filepath );
14791490
auto handler = createIOHandler(
@@ -1488,7 +1499,7 @@ SeriesInternal::SeriesInternal(
14881499
static_cast< internal::SeriesData * >( this ),
14891500
static_cast< internal::AttributableData * >( this ) }
14901501
{
1491-
nlohmann::json optionsJson = json::parseOptions( options );
1502+
json::TracingJSON optionsJson = json::parseOptions( options );
14921503
parseJsonOptions( *this, optionsJson );
14931504
auto input = parseInput( filepath );
14941505
auto handler = createIOHandler(

0 commit comments

Comments
 (0)