Skip to content

Commit

Permalink
Add normalizingVariableType
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed May 6, 2024
1 parent dcba416 commit 85e9018
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 72 deletions.
36 changes: 3 additions & 33 deletions include/openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,39 +95,6 @@ namespace detail
// we represent booleans as unsigned chars
using bool_representation = unsigned char;

template <typename T>
struct ToDatatypeHelper
{
static std::string type();
};

template <typename T>
struct ToDatatypeHelper<std::vector<T>>
{
static std::string type();
};

template <typename T, size_t n>
struct ToDatatypeHelper<std::array<T, n>>
{
static std::string type();
};

template <>
struct ToDatatypeHelper<bool>
{
static std::string type();
};

struct ToDatatype
{
template <typename T>
std::string operator()();

template <int n>
std::string operator()();
};

/**
* @brief Convert ADIOS2 datatype to openPMD type.
* @param dt
Expand Down Expand Up @@ -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

/**
Expand Down
78 changes: 39 additions & 39 deletions src/IO/ADIOS/ADIOS2Auxiliary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/

#include "openPMD/auxiliary/TypeTraits.hpp"
#include "openPMD/config.hpp"
#if openPMD_HAVE_ADIOS2
#include "openPMD/Datatype.hpp"
Expand Down Expand Up @@ -61,45 +62,6 @@ FlushTarget flushTargetFromString(std::string const &str)

namespace openPMD::detail
{
template <typename T>
std::string ToDatatypeHelper<T>::type()
{
return adios2::GetType<T>();
}

template <typename T>
std::string ToDatatypeHelper<std::vector<T>>::type()
{
return

adios2::GetType<T>();
}

template <typename T, size_t n>
std::string ToDatatypeHelper<std::array<T, n>>::type()
{
return

adios2::GetType<T>();
}

std::string ToDatatypeHelper<bool>::type()
{
return ToDatatypeHelper<bool_representation>::type();
}

template <typename T>
std::string ToDatatype::operator()()
{
return ToDatatypeHelper<T>::type();
}

template <int n>
std::string ToDatatype::operator()()
{
return "";
}

Datatype fromADIOS2Type(std::string const &dt, bool verbose)
{
static std::map<std::string, Datatype> map{
Expand Down Expand Up @@ -272,5 +234,43 @@ Datatype attributeInfo(
throw std::runtime_error("Unreachable!");
}
}

namespace
{
struct ToDatatype
{
template <typename T>
static std::string call()
{
if constexpr (std::is_same_v<T, bool>)
{
return ToDatatype::call<bool_representation>();
}
else if constexpr (
auxiliary::IsVector_v<T> || auxiliary::IsArray_v<T>)
{
return ToDatatype::call<typename T::value_type>();
}
else
{
return adios2::GetType<T>();
}
}

template <int>
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<ToDatatype>(openpmd_type);
}
} // namespace openPMD::detail
#endif

0 comments on commit 85e9018

Please sign in to comment.