From 85e9018a6528a1bb5212410b760d5e276e70136b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Mon, 6 May 2024 16:26:18 +0200 Subject: [PATCH] Add normalizingVariableType --- include/openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp | 36 +-------- src/IO/ADIOS/ADIOS2Auxiliary.cpp | 78 ++++++++++---------- 2 files changed, 42 insertions(+), 72 deletions(-) diff --git a/include/openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp b/include/openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp index 0b279f38cb..bcf18610b5 100644 --- a/include/openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp +++ b/include/openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp @@ -95,39 +95,6 @@ namespace detail // we represent booleans as unsigned chars using bool_representation = unsigned char; - template - struct ToDatatypeHelper - { - static std::string type(); - }; - - template - struct ToDatatypeHelper> - { - static std::string type(); - }; - - template - struct ToDatatypeHelper> - { - static std::string type(); - }; - - template <> - struct ToDatatypeHelper - { - static std::string type(); - }; - - struct ToDatatype - { - template - std::string operator()(); - - template - std::string operator()(); - }; - /** * @brief Convert ADIOS2 datatype to openPMD type. * @param dt @@ -210,6 +177,9 @@ namespace detail } throw error::Internal("Control flow error: No ADIOS2 open mode."); } + + std::string + normalizingVariableType(adios2::IO const &, std::string const &name); } // namespace detail /** diff --git a/src/IO/ADIOS/ADIOS2Auxiliary.cpp b/src/IO/ADIOS/ADIOS2Auxiliary.cpp index 366be2b893..ec36ce7c1b 100644 --- a/src/IO/ADIOS/ADIOS2Auxiliary.cpp +++ b/src/IO/ADIOS/ADIOS2Auxiliary.cpp @@ -19,6 +19,7 @@ * If not, see . */ +#include "openPMD/auxiliary/TypeTraits.hpp" #include "openPMD/config.hpp" #if openPMD_HAVE_ADIOS2 #include "openPMD/Datatype.hpp" @@ -61,45 +62,6 @@ FlushTarget flushTargetFromString(std::string const &str) namespace openPMD::detail { -template -std::string ToDatatypeHelper::type() -{ - return adios2::GetType(); -} - -template -std::string ToDatatypeHelper>::type() -{ - return - - adios2::GetType(); -} - -template -std::string ToDatatypeHelper>::type() -{ - return - - adios2::GetType(); -} - -std::string ToDatatypeHelper::type() -{ - return ToDatatypeHelper::type(); -} - -template -std::string ToDatatype::operator()() -{ - return ToDatatypeHelper::type(); -} - -template -std::string ToDatatype::operator()() -{ - return ""; -} - Datatype fromADIOS2Type(std::string const &dt, bool verbose) { static std::map map{ @@ -272,5 +234,43 @@ Datatype attributeInfo( throw std::runtime_error("Unreachable!"); } } + +namespace +{ + struct ToDatatype + { + template + static std::string call() + { + if constexpr (std::is_same_v) + { + return ToDatatype::call(); + } + else if constexpr ( + auxiliary::IsVector_v || auxiliary::IsArray_v) + { + return ToDatatype::call(); + } + else + { + return adios2::GetType(); + } + } + + template + static std::string call() + { + return {}; + } + }; +} // namespace + +std::string +normalizingVariableType(const adios2::IO &IO, const std::string &name) +{ + auto const &unsanitized_result = IO.VariableType(name); + auto openpmd_type = fromADIOS2Type(unsanitized_result); + return switchAdios2VariableType(openpmd_type); +} } // namespace openPMD::detail #endif