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/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp b/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp index c23fb81d49..610614ea18 100644 --- a/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp +++ b/include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp @@ -403,16 +403,15 @@ class ADIOS2IOHandlerImpl { { auto requiredType = adios2::GetType(); - auto actualType = IO.VariableType(varName); + auto actualType = detail::normalizingVariableType(IO, varName); if (requiredType != actualType) { std::stringstream errorMessage; errorMessage << "Trying to access a dataset with wrong type " - "(trying to access dataset with type " - << determineDatatype() << ", but has type " - << detail::fromADIOS2Type(actualType, false) - << ")"; + "(trying to access dataset with type '" + << requiredType << "', but has type '" + << actualType << "')"; throw error::ReadError( error::AffectedObject::Dataset, error::Reason::UnexpectedContent, diff --git a/include/openPMD/IO/ADIOS/macros.hpp b/include/openPMD/IO/ADIOS/macros.hpp index 59b630a112..0c90e55043 100644 --- a/include/openPMD/IO/ADIOS/macros.hpp +++ b/include/openPMD/IO/ADIOS/macros.hpp @@ -19,6 +19,11 @@ #define openPMD_HAS_ADIOS_2_9 \ (ADIOS2_VERSION_MAJOR * 100 + ADIOS2_VERSION_MINOR >= 209) +#if !defined(ADIOS2_HAVE_BP5) && openPMD_HAS_ADIOS_2_9 +// ADIOS2 v2.10 no longer defines this +#define ADIOS2_HAVE_BP5 +#endif + #else #define openPMD_HAS_ADIOS_2_8 0 diff --git a/src/IO/ADIOS/ADIOS2Auxiliary.cpp b/src/IO/ADIOS/ADIOS2Auxiliary.cpp index 366be2b893..3fb76760e0 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{ @@ -204,7 +166,7 @@ Datatype attributeInfo( type = IO.AttributeType(attributeName); break; case VariableOrAttribute::Variable: - type = IO.VariableType(attributeName); + type = normalizingVariableType(IO, attributeName); break; } if (type.empty()) @@ -272,5 +234,46 @@ 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); + auto res = switchAdios2VariableType(openpmd_type); + std::cout << "[normalizingVariableType] for '" << name << "' " << res + << " (non-normalized: " << unsanitized_result << ")" << std::endl; + return res; +} } // namespace openPMD::detail #endif diff --git a/src/IO/ADIOS/ADIOS2IOHandler.cpp b/src/IO/ADIOS/ADIOS2IOHandler.cpp index 2d93837980..e4e3ab5dbf 100644 --- a/src/IO/ADIOS/ADIOS2IOHandler.cpp +++ b/src/IO/ADIOS/ADIOS2IOHandler.cpp @@ -865,7 +865,8 @@ void ADIOS2IOHandlerImpl::extendDataset( auto file = refreshFileFromParent(writable, /* preferParentFile = */ false); std::string name = nameOfVariable(writable); auto &filedata = getFileData(file, IfFileNotOpen::ThrowError); - Datatype dt = detail::fromADIOS2Type(filedata.m_IO.VariableType(name)); + Datatype dt = detail::fromADIOS2Type( + detail::normalizingVariableType(filedata.m_IO, name)); switchAdios2VariableType( dt, filedata.m_IO, name, parameters.extent); } @@ -962,8 +963,10 @@ void ADIOS2IOHandlerImpl::openDataset( auto file = refreshFileFromParent(writable, /* preferParentFile = */ true); auto varName = nameOfVariable(writable); auto &fileData = getFileData(file, IfFileNotOpen::ThrowError); - *parameters.dtype = - detail::fromADIOS2Type(fileData.m_IO.VariableType(varName)); + *parameters.dtype = detail::fromADIOS2Type( + detail::normalizingVariableType(fileData.m_IO, varName)); + std::cout << "[openDataset] opened '" << varName << "'as " + << *parameters.dtype << std::endl; switchAdios2VariableType( *parameters.dtype, this, file, varName, parameters); writable->written = true; @@ -1464,7 +1467,8 @@ void ADIOS2IOHandlerImpl::availableChunks( detail::ADIOS2File &ba = getFileData(file, IfFileNotOpen::ThrowError); std::string varName = nameOfVariable(writable); auto engine = ba.getEngine(); // make sure that data are present - auto datatype = detail::fromADIOS2Type(ba.m_IO.VariableType(varName)); + auto datatype = detail::fromADIOS2Type( + detail::normalizingVariableType(ba.m_IO, varName)); bool allSteps = ba.m_mode != adios2::Mode::Read && ba.streamStatus == detail::ADIOS2File::StreamStatus::ReadWithoutStream; switchAdios2VariableType( diff --git a/src/config.cpp b/src/config.cpp index 89a824500c..9245333026 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -22,6 +22,7 @@ #include "openPMD/version.hpp" #if openPMD_HAVE_ADIOS2 +#include "openPMD/IO/ADIOS/macros.hpp" #include #endif #include