|
19 | 19 | * If not, see <http://www.gnu.org/licenses/>. |
20 | 20 | */ |
21 | 21 |
|
| 22 | +#include "openPMD/auxiliary/TypeTraits.hpp" |
22 | 23 | #include "openPMD/config.hpp" |
23 | 24 | #if openPMD_HAVE_ADIOS2 |
24 | 25 | #include "openPMD/Datatype.hpp" |
@@ -61,45 +62,6 @@ FlushTarget flushTargetFromString(std::string const &str) |
61 | 62 |
|
62 | 63 | namespace openPMD::detail |
63 | 64 | { |
64 | | -template <typename T> |
65 | | -std::string ToDatatypeHelper<T>::type() |
66 | | -{ |
67 | | - return adios2::GetType<T>(); |
68 | | -} |
69 | | - |
70 | | -template <typename T> |
71 | | -std::string ToDatatypeHelper<std::vector<T>>::type() |
72 | | -{ |
73 | | - return |
74 | | - |
75 | | - adios2::GetType<T>(); |
76 | | -} |
77 | | - |
78 | | -template <typename T, size_t n> |
79 | | -std::string ToDatatypeHelper<std::array<T, n>>::type() |
80 | | -{ |
81 | | - return |
82 | | - |
83 | | - adios2::GetType<T>(); |
84 | | -} |
85 | | - |
86 | | -std::string ToDatatypeHelper<bool>::type() |
87 | | -{ |
88 | | - return ToDatatypeHelper<bool_representation>::type(); |
89 | | -} |
90 | | - |
91 | | -template <typename T> |
92 | | -std::string ToDatatype::operator()() |
93 | | -{ |
94 | | - return ToDatatypeHelper<T>::type(); |
95 | | -} |
96 | | - |
97 | | -template <int n> |
98 | | -std::string ToDatatype::operator()() |
99 | | -{ |
100 | | - return ""; |
101 | | -} |
102 | | - |
103 | 65 | Datatype fromADIOS2Type(std::string const &dt, bool verbose) |
104 | 66 | { |
105 | 67 | static std::map<std::string, Datatype> map{ |
@@ -204,7 +166,7 @@ Datatype attributeInfo( |
204 | 166 | type = IO.AttributeType(attributeName); |
205 | 167 | break; |
206 | 168 | case VariableOrAttribute::Variable: |
207 | | - type = IO.VariableType(attributeName); |
| 169 | + type = normalizingVariableType(IO, attributeName); |
208 | 170 | break; |
209 | 171 | } |
210 | 172 | if (type.empty()) |
@@ -272,5 +234,46 @@ Datatype attributeInfo( |
272 | 234 | throw std::runtime_error("Unreachable!"); |
273 | 235 | } |
274 | 236 | } |
| 237 | + |
| 238 | +namespace |
| 239 | +{ |
| 240 | + struct ToDatatype |
| 241 | + { |
| 242 | + template <typename T> |
| 243 | + static std::string call() |
| 244 | + { |
| 245 | + if constexpr (std::is_same_v<T, bool>) |
| 246 | + { |
| 247 | + return ToDatatype::call<bool_representation>(); |
| 248 | + } |
| 249 | + else if constexpr ( |
| 250 | + auxiliary::IsVector_v<T> || auxiliary::IsArray_v<T>) |
| 251 | + { |
| 252 | + return ToDatatype::call<typename T::value_type>(); |
| 253 | + } |
| 254 | + else |
| 255 | + { |
| 256 | + return adios2::GetType<T>(); |
| 257 | + } |
| 258 | + } |
| 259 | + |
| 260 | + template <int> |
| 261 | + static std::string call() |
| 262 | + { |
| 263 | + return {}; |
| 264 | + } |
| 265 | + }; |
| 266 | +} // namespace |
| 267 | + |
| 268 | +std::string |
| 269 | +normalizingVariableType(const adios2::IO &IO, const std::string &name) |
| 270 | +{ |
| 271 | + auto const &unsanitized_result = IO.VariableType(name); |
| 272 | + auto openpmd_type = fromADIOS2Type(unsanitized_result); |
| 273 | + auto res = switchAdios2VariableType<ToDatatype>(openpmd_type); |
| 274 | + std::cout << "[normalizingVariableType] for '" << name << "' " << res |
| 275 | + << " (non-normalized: " << unsanitized_result << ")" << std::endl; |
| 276 | + return res; |
| 277 | +} |
275 | 278 | } // namespace openPMD::detail |
276 | 279 | #endif |
0 commit comments