Loading include/dca/io/adios2/adios2_reader.hpp +10 −1 Original line number Diff line number Diff line Loading @@ -65,11 +65,20 @@ public: bool open_group(const std::string& name); void close_group(); void begin_step(); void end_step(); std::string get_path(const std::string& name = ""); template <typename arbitrary_struct_t> static void from_file(adios2::ADIOS& adios, arbitrary_struct_t& arbitrary_struct, std::string file_name); /** Return number of steps in the file * file may have multiple iterations in it. * Each iteration is a step in the adios file for many variables. */ std::size_t getStepCount() { return file_.Steps(); } // `execute` returns true if the object is read correctly. template <typename Scalartype> Loading include/dca/io/hdf5/hdf5_reader.hpp +4 −1 Original line number Diff line number Diff line Loading @@ -59,6 +59,9 @@ public: paths_.pop_back(); } void begin_step(){}; void end_step(){}; std::string get_path(); template <typename arbitrary_struct_t> Loading include/dca/io/io_types.hpp +5 −5 Original line number Diff line number Diff line Loading @@ -18,11 +18,9 @@ namespace dca { namespace io { // dca::phys:: /** Possible Flavors for G4 * dummy at 0 debug automatic initialization of int to 0 * causes a bug. That is not a good code smell. /** Enum of supported file IO types */ enum class IOType : int { JSON = 0, HDF5, ADIOS2, UNKNOWN }; enum class IOType : int { JSON = 0, HDF5, ADIOS2 }; IOType stringToIOType(const std::string& name); Loading @@ -30,7 +28,9 @@ std::string toString(const IOType type); IOType extensionToIOType(const std::string& file_name); std::string extensionFromIOType(const IOType type); } // namespace io } // namespace dca #endif // DCA_PHYS_FOUR_POINT_TYPE_HPP #endif // DCA_IO_TYPES_HPP include/dca/io/json/json_reader.hpp +3 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,9 @@ public: // the root group. bool close_group() noexcept; void begin_step(){}; void end_step(){}; constexpr static bool is_reader = true; constexpr static bool is_writer = false; Loading include/dca/io/reader.hpp +44 −21 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #include <string> #include <variant> #include "dca/io/io_types.hpp" #include "dca/io/hdf5/hdf5_reader.hpp" #include "dca/io/json/json_reader.hpp" Loading @@ -29,26 +30,42 @@ namespace dca::io { template <class Concurrency> class Reader { public: // In: format. output format, HDF5 or JSON. // In: verbose. If true, the reader outputs a short log whenever it is executed. Reader(const Concurrency& concurrency, const std::string& format, bool verbose = true) using DCAReaderVariant = std::variant<io::HDF5Reader, io::JSONReader #ifdef DCA_HAVE_ADIOS2 , io::ADIOS2Reader<Concurrency> #endif >; /** * \param[in] concureency current concurrency context * \param[in] format format as IOType * \param[in] verbose If true, reader does some logging */ Reader(const Concurrency& concurrency, const IOType format, bool verbose = true) : concurrency_(concurrency) { if (format == "HDF5") { switch (format) { case IOType::HDF5: reader_.template emplace<io::HDF5Reader>(verbose); } else if (format == "JSON") { break; case IOType::JSON: reader_.template emplace<io::JSONReader>(verbose); } break; #ifdef DCA_HAVE_ADIOS2 else if (format == "ADIOS2") { case IOType::ADIOS2: reader_.template emplace<io::ADIOS2Reader<Concurrency>>(&concurrency, verbose); } break; #endif else { throw(std::logic_error("Invalid input format")); } } /** DEPRECATED -- Support for format type as string * \param[in] format string representation of format, since parameters still use string * * \todo remove need for this constructor store IO format as enum class type. */ Reader(const Concurrency& concurrency, const std::string& format, bool verbose = true) : Reader(concurrency, stringToIOType(format), verbose) {} #ifdef DCA_HAVE_ADIOS2 Reader(adios2::ADIOS& adios, const Concurrency& concurrency, const std::string& format, bool verbose = true) Loading Loading @@ -89,20 +106,26 @@ public: std::visit([&](auto& var) { var.close_group(); }, reader_); } void begin_step() { std::visit([&](auto& var) { var.begin_step(); }, reader_); } void end_step() { std::visit([&](auto& var) { var.end_step(); }, reader_); } template <class... Args> bool execute(Args&&... args) noexcept { return std::visit([&](auto& var) -> bool { return var.execute(std::forward<Args>(args)...); }, reader_); } DCAReaderVariant& getUnderlying() { return reader_; } private: std::variant<io::HDF5Reader, io::JSONReader #ifdef DCA_HAVE_ADIOS2 , io::ADIOS2Reader<Concurrency> #endif > reader_; DCAReaderVariant reader_; const Concurrency& concurrency_; }; Loading Loading
include/dca/io/adios2/adios2_reader.hpp +10 −1 Original line number Diff line number Diff line Loading @@ -65,11 +65,20 @@ public: bool open_group(const std::string& name); void close_group(); void begin_step(); void end_step(); std::string get_path(const std::string& name = ""); template <typename arbitrary_struct_t> static void from_file(adios2::ADIOS& adios, arbitrary_struct_t& arbitrary_struct, std::string file_name); /** Return number of steps in the file * file may have multiple iterations in it. * Each iteration is a step in the adios file for many variables. */ std::size_t getStepCount() { return file_.Steps(); } // `execute` returns true if the object is read correctly. template <typename Scalartype> Loading
include/dca/io/hdf5/hdf5_reader.hpp +4 −1 Original line number Diff line number Diff line Loading @@ -59,6 +59,9 @@ public: paths_.pop_back(); } void begin_step(){}; void end_step(){}; std::string get_path(); template <typename arbitrary_struct_t> Loading
include/dca/io/io_types.hpp +5 −5 Original line number Diff line number Diff line Loading @@ -18,11 +18,9 @@ namespace dca { namespace io { // dca::phys:: /** Possible Flavors for G4 * dummy at 0 debug automatic initialization of int to 0 * causes a bug. That is not a good code smell. /** Enum of supported file IO types */ enum class IOType : int { JSON = 0, HDF5, ADIOS2, UNKNOWN }; enum class IOType : int { JSON = 0, HDF5, ADIOS2 }; IOType stringToIOType(const std::string& name); Loading @@ -30,7 +28,9 @@ std::string toString(const IOType type); IOType extensionToIOType(const std::string& file_name); std::string extensionFromIOType(const IOType type); } // namespace io } // namespace dca #endif // DCA_PHYS_FOUR_POINT_TYPE_HPP #endif // DCA_IO_TYPES_HPP
include/dca/io/json/json_reader.hpp +3 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,9 @@ public: // the root group. bool close_group() noexcept; void begin_step(){}; void end_step(){}; constexpr static bool is_reader = true; constexpr static bool is_writer = false; Loading
include/dca/io/reader.hpp +44 −21 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #include <string> #include <variant> #include "dca/io/io_types.hpp" #include "dca/io/hdf5/hdf5_reader.hpp" #include "dca/io/json/json_reader.hpp" Loading @@ -29,26 +30,42 @@ namespace dca::io { template <class Concurrency> class Reader { public: // In: format. output format, HDF5 or JSON. // In: verbose. If true, the reader outputs a short log whenever it is executed. Reader(const Concurrency& concurrency, const std::string& format, bool verbose = true) using DCAReaderVariant = std::variant<io::HDF5Reader, io::JSONReader #ifdef DCA_HAVE_ADIOS2 , io::ADIOS2Reader<Concurrency> #endif >; /** * \param[in] concureency current concurrency context * \param[in] format format as IOType * \param[in] verbose If true, reader does some logging */ Reader(const Concurrency& concurrency, const IOType format, bool verbose = true) : concurrency_(concurrency) { if (format == "HDF5") { switch (format) { case IOType::HDF5: reader_.template emplace<io::HDF5Reader>(verbose); } else if (format == "JSON") { break; case IOType::JSON: reader_.template emplace<io::JSONReader>(verbose); } break; #ifdef DCA_HAVE_ADIOS2 else if (format == "ADIOS2") { case IOType::ADIOS2: reader_.template emplace<io::ADIOS2Reader<Concurrency>>(&concurrency, verbose); } break; #endif else { throw(std::logic_error("Invalid input format")); } } /** DEPRECATED -- Support for format type as string * \param[in] format string representation of format, since parameters still use string * * \todo remove need for this constructor store IO format as enum class type. */ Reader(const Concurrency& concurrency, const std::string& format, bool verbose = true) : Reader(concurrency, stringToIOType(format), verbose) {} #ifdef DCA_HAVE_ADIOS2 Reader(adios2::ADIOS& adios, const Concurrency& concurrency, const std::string& format, bool verbose = true) Loading Loading @@ -89,20 +106,26 @@ public: std::visit([&](auto& var) { var.close_group(); }, reader_); } void begin_step() { std::visit([&](auto& var) { var.begin_step(); }, reader_); } void end_step() { std::visit([&](auto& var) { var.end_step(); }, reader_); } template <class... Args> bool execute(Args&&... args) noexcept { return std::visit([&](auto& var) -> bool { return var.execute(std::forward<Args>(args)...); }, reader_); } DCAReaderVariant& getUnderlying() { return reader_; } private: std::variant<io::HDF5Reader, io::JSONReader #ifdef DCA_HAVE_ADIOS2 , io::ADIOS2Reader<Concurrency> #endif > reader_; DCAReaderVariant reader_; const Concurrency& concurrency_; }; Loading