Skip to content

Commit

Permalink
Use TracingJSON from the start already
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Aug 19, 2021
1 parent 9e2d3f4 commit 7546d93
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 43 deletions.
10 changes: 5 additions & 5 deletions include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ class ADIOS2IOHandlerImpl
ADIOS2IOHandlerImpl(
AbstractIOHandler *,
MPI_Comm,
nlohmann::json config,
json::TracingJSON config,
std::string engineType );

#endif // openPMD_HAVE_MPI

explicit ADIOS2IOHandlerImpl(
AbstractIOHandler *,
nlohmann::json config,
json::TracingJSON config,
std::string engineType );


Expand Down Expand Up @@ -281,7 +281,7 @@ class ADIOS2IOHandlerImpl
static json::TracingJSON nullvalue;

void
init( nlohmann::json config );
init( json::TracingJSON config );

template< typename Key >
json::TracingJSON
Expand Down Expand Up @@ -1413,15 +1413,15 @@ friend class ADIOS2IOHandlerImpl;
std::string path,
Access,
MPI_Comm,
nlohmann::json options,
json::TracingJSON options,
std::string engineType );

#endif

ADIOS2IOHandler(
std::string path,
Access,
nlohmann::json options,
json::TracingJSON options,
std::string engineType );

std::string backendName() const override { return "ADIOS2"; }
Expand Down
5 changes: 2 additions & 3 deletions include/openPMD/IO/HDF5/HDF5IOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
*/
#pragma once

#include "openPMD/auxiliary/JSON.hpp"
#include "openPMD/IO/AbstractIOHandler.hpp"

#include <nlohmann/json.hpp>

#include <future>
#include <memory>
#include <string>
Expand All @@ -36,7 +35,7 @@ class HDF5IOHandlerImpl;
class HDF5IOHandler : public AbstractIOHandler
{
public:
HDF5IOHandler(std::string path, Access, nlohmann::json config);
HDF5IOHandler(std::string path, Access, json::TracingJSON config);
~HDF5IOHandler() override;

std::string backendName() const override { return "HDF5"; }
Expand Down
2 changes: 1 addition & 1 deletion include/openPMD/IO/HDF5/HDF5IOHandlerImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace openPMD
class HDF5IOHandlerImpl : public AbstractIOHandlerImpl
{
public:
HDF5IOHandlerImpl(AbstractIOHandler*, nlohmann::json config);
HDF5IOHandlerImpl(AbstractIOHandler*, json::TracingJSON config);
~HDF5IOHandlerImpl() override;

void createFile(Writable*, Parameter< Operation::CREATE_FILE > const&) override;
Expand Down
5 changes: 2 additions & 3 deletions include/openPMD/IO/HDF5/ParallelHDF5IOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
#pragma once

#include "openPMD/config.hpp"
#include "openPMD/auxiliary/JSON.hpp"
#include "openPMD/IO/AbstractIOHandler.hpp"

#include <nlohmann/json.hpp>

#include <future>
#include <memory>
#include <string>
Expand All @@ -39,7 +38,7 @@ namespace openPMD
public:
#if openPMD_HAVE_MPI
ParallelHDF5IOHandler(
std::string path, Access, MPI_Comm, nlohmann::json config);
std::string path, Access, MPI_Comm, json::TracingJSON config);
#else
ParallelHDF5IOHandler(std::string path, Access, nlohmann::json config);
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/openPMD/IO/HDF5/ParallelHDF5IOHandlerImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace openPMD
{
public:
ParallelHDF5IOHandlerImpl(
AbstractIOHandler*, MPI_Comm, nlohmann::json config);
AbstractIOHandler*, MPI_Comm, json::TracingJSON config);
~ParallelHDF5IOHandlerImpl() override;

MPI_Comm m_mpiComm;
Expand Down
12 changes: 6 additions & 6 deletions src/IO/ADIOS/ADIOS2IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace openPMD
ADIOS2IOHandlerImpl::ADIOS2IOHandlerImpl(
AbstractIOHandler * handler,
MPI_Comm communicator,
nlohmann::json cfg,
json::TracingJSON cfg,
std::string engineType )
: AbstractIOHandlerImplCommon( handler )
, m_ADIOS{ communicator, ADIOS2_DEBUG_MODE }
Expand All @@ -80,7 +80,7 @@ ADIOS2IOHandlerImpl::ADIOS2IOHandlerImpl(

ADIOS2IOHandlerImpl::ADIOS2IOHandlerImpl(
AbstractIOHandler * handler,
nlohmann::json cfg,
json::TracingJSON cfg,
std::string engineType )
: AbstractIOHandlerImplCommon( handler )
, m_ADIOS{ ADIOS2_DEBUG_MODE }
Expand Down Expand Up @@ -120,9 +120,9 @@ ADIOS2IOHandlerImpl::~ADIOS2IOHandlerImpl()
}

void
ADIOS2IOHandlerImpl::init( nlohmann::json cfg )
ADIOS2IOHandlerImpl::init( json::TracingJSON cfg )
{
if( cfg.contains( "adios2" ) )
if( cfg.json().contains( "adios2" ) )
{
m_config = std::move( cfg[ "adios2" ] );

Expand Down Expand Up @@ -2917,7 +2917,7 @@ ADIOS2IOHandler::ADIOS2IOHandler(
std::string path,
openPMD::Access at,
MPI_Comm comm,
nlohmann::json options,
json::TracingJSON options,
std::string engineType )
: AbstractIOHandler( std::move( path ), at, comm )
, m_impl{ this, comm, std::move( options ), std::move( engineType ) }
Expand All @@ -2929,7 +2929,7 @@ ADIOS2IOHandler::ADIOS2IOHandler(
ADIOS2IOHandler::ADIOS2IOHandler(
std::string path,
Access at,
nlohmann::json options,
json::TracingJSON options,
std::string engineType )
: AbstractIOHandler( std::move( path ), at )
, m_impl{ this, std::move( options ), std::move( engineType ) }
Expand Down
13 changes: 8 additions & 5 deletions src/IO/AbstractIOHandlerHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ namespace openPMD
#if openPMD_HAVE_MPI
template<>
std::shared_ptr< AbstractIOHandler >
createIOHandler< nlohmann::json >(
createIOHandler< json::TracingJSON >(
std::string path,
Access access,
Format format,
MPI_Comm comm,
nlohmann::json options )
json::TracingJSON options )
{
(void) options;
switch( format )
Expand Down Expand Up @@ -71,11 +71,11 @@ namespace openPMD

template<>
std::shared_ptr< AbstractIOHandler >
createIOHandler< nlohmann::json >(
createIOHandler< json::TracingJSON >(
std::string path,
Access access,
Format format,
nlohmann::json options )
json::TracingJSON options )
{
(void) options;
switch( format )
Expand Down Expand Up @@ -112,6 +112,9 @@ namespace openPMD
createIOHandler( std::string path, Access access, Format format )
{
return createIOHandler(
std::move( path ), access, format, nlohmann::json::object() );
std::move( path ),
access,
format,
json::TracingJSON( nlohmann::json::object() ));
}
} // namespace openPMD
6 changes: 3 additions & 3 deletions src/IO/HDF5/HDF5IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace openPMD
# endif

HDF5IOHandlerImpl::HDF5IOHandlerImpl(
AbstractIOHandler* handler, nlohmann::json config)
AbstractIOHandler* handler, json::TracingJSON config)
: AbstractIOHandlerImpl(handler),
m_datasetTransferProperty{H5P_DEFAULT},
m_fileAccessProperty{H5P_DEFAULT},
Expand Down Expand Up @@ -87,7 +87,7 @@ HDF5IOHandlerImpl::HDF5IOHandlerImpl(

m_chunks = auxiliary::getEnvString( "OPENPMD_HDF5_CHUNKS", "auto" );
// JSON option can overwrite env option:
if( config.contains( "hdf5" ) )
if( config.json().contains( "hdf5" ) )
{
m_config = std::move( config[ "hdf5" ] );

Expand Down Expand Up @@ -1914,7 +1914,7 @@ HDF5IOHandlerImpl::getFile( Writable * writable )
#endif

#if openPMD_HAVE_HDF5
HDF5IOHandler::HDF5IOHandler(std::string path, Access at, nlohmann::json config)
HDF5IOHandler::HDF5IOHandler(std::string path, Access at, json::TracingJSON config)
: AbstractIOHandler(std::move(path), at),
m_impl{new HDF5IOHandlerImpl(this, std::move(config))}
{ }
Expand Down
4 changes: 2 additions & 2 deletions src/IO/HDF5/ParallelHDF5IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace openPMD
# endif

ParallelHDF5IOHandler::ParallelHDF5IOHandler(
std::string path, Access at, MPI_Comm comm, nlohmann::json config )
std::string path, Access at, MPI_Comm comm, json::TracingJSON config )
: AbstractIOHandler(std::move(path), at, comm),
m_impl{new ParallelHDF5IOHandlerImpl(this, comm, std::move(config))}
{ }
Expand All @@ -53,7 +53,7 @@ ParallelHDF5IOHandler::flush()
}

ParallelHDF5IOHandlerImpl::ParallelHDF5IOHandlerImpl(
AbstractIOHandler* handler, MPI_Comm comm, nlohmann::json config )
AbstractIOHandler* handler, MPI_Comm comm, json::TracingJSON config )
: HDF5IOHandlerImpl{handler, std::move(config)},
m_mpiComm{comm},
m_mpiInfo{MPI_INFO_NULL} /* MPI 3.0+: MPI_INFO_ENV */
Expand Down
39 changes: 25 additions & 14 deletions src/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,21 +1444,32 @@ void SeriesInterface::openIteration( uint64_t index, Iteration iteration )

namespace
{
template< typename T >
void getJsonOption(
nlohmann::json const & config, std::string const & key, T & dest )
{
if( config.contains( key ) )
template< typename From, typename Dest = From >
void getJsonOption(
json::TracingJSON & config, std::string const & key, Dest & dest )
{
dest = config.at( key ).get< T >();
if( config.json().contains( key ) )
{
dest = config[ key ].json().get< From >();
}
}
}

void parseJsonOptions(
internal::SeriesData & series, nlohmann::json const & options )
{
getJsonOption( options, "defer_iteration_parsing", series.m_parseLazily );
}
template< typename Dest = std::string >
void getJsonOptionLowerCase(
json::TracingJSON & config, std::string const & key, Dest & dest )
{
if( config.json().contains( key ) )
{
dest = json::asLowerCaseStringDynamic( config[ key ].json() );
}
}

void parseJsonOptions(
internal::SeriesData & series, json::TracingJSON & options )
{
getJsonOption< bool >(
options, "defer_iteration_parsing", series.m_parseLazily );
}
}

namespace internal
Expand All @@ -1473,7 +1484,7 @@ SeriesInternal::SeriesInternal(
static_cast< internal::SeriesData * >( this ),
static_cast< internal::AttributableData * >( this ) }
{
nlohmann::json optionsJson = json::parseOptions( options, comm );
json::TracingJSON optionsJson = json::parseOptions( options, comm );
parseJsonOptions( *this, optionsJson );
auto input = parseInput( filepath );
auto handler = createIOHandler(
Expand All @@ -1488,7 +1499,7 @@ SeriesInternal::SeriesInternal(
static_cast< internal::SeriesData * >( this ),
static_cast< internal::AttributableData * >( this ) }
{
nlohmann::json optionsJson = json::parseOptions( options );
json::TracingJSON optionsJson = json::parseOptions( options );
parseJsonOptions( *this, optionsJson );
auto input = parseInput( filepath );
auto handler = createIOHandler(
Expand Down

0 comments on commit 7546d93

Please sign in to comment.