Skip to content

Commit b80dfee

Browse files
Add define for ADIOS2_HAVE_BP5 (#1614)
This was removed from ADIOS2 v2.9 to v2.10
1 parent 805c760 commit b80dfee

File tree

6 files changed

+64
-82
lines changed

6 files changed

+64
-82
lines changed

include/openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp

+3-33
Original file line numberDiff line numberDiff line change
@@ -95,39 +95,6 @@ namespace detail
9595
// we represent booleans as unsigned chars
9696
using bool_representation = unsigned char;
9797

98-
template <typename T>
99-
struct ToDatatypeHelper
100-
{
101-
static std::string type();
102-
};
103-
104-
template <typename T>
105-
struct ToDatatypeHelper<std::vector<T>>
106-
{
107-
static std::string type();
108-
};
109-
110-
template <typename T, size_t n>
111-
struct ToDatatypeHelper<std::array<T, n>>
112-
{
113-
static std::string type();
114-
};
115-
116-
template <>
117-
struct ToDatatypeHelper<bool>
118-
{
119-
static std::string type();
120-
};
121-
122-
struct ToDatatype
123-
{
124-
template <typename T>
125-
std::string operator()();
126-
127-
template <int n>
128-
std::string operator()();
129-
};
130-
13198
/**
13299
* @brief Convert ADIOS2 datatype to openPMD type.
133100
* @param dt
@@ -210,6 +177,9 @@ namespace detail
210177
}
211178
throw error::Internal("Control flow error: No ADIOS2 open mode.");
212179
}
180+
181+
std::string
182+
normalizingVariableType(adios2::IO const &, std::string const &name);
213183
} // namespace detail
214184

215185
/**

include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -403,16 +403,15 @@ class ADIOS2IOHandlerImpl
403403
{
404404
{
405405
auto requiredType = adios2::GetType<T>();
406-
auto actualType = IO.VariableType(varName);
406+
auto actualType = detail::normalizingVariableType(IO, varName);
407407

408408
if (requiredType != actualType)
409409
{
410410
std::stringstream errorMessage;
411411
errorMessage << "Trying to access a dataset with wrong type "
412-
"(trying to access dataset with type "
413-
<< determineDatatype<T>() << ", but has type "
414-
<< detail::fromADIOS2Type(actualType, false)
415-
<< ")";
412+
"(trying to access dataset with type '"
413+
<< requiredType << "', but has type '"
414+
<< actualType << "')";
416415
throw error::ReadError(
417416
error::AffectedObject::Dataset,
418417
error::Reason::UnexpectedContent,

include/openPMD/IO/ADIOS/macros.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
#define openPMD_HAS_ADIOS_2_9 \
2020
(ADIOS2_VERSION_MAJOR * 100 + ADIOS2_VERSION_MINOR >= 209)
2121

22+
#if !defined(ADIOS2_HAVE_BP5) && openPMD_HAS_ADIOS_2_9
23+
// ADIOS2 v2.10 no longer defines this
24+
#define ADIOS2_HAVE_BP5
25+
#endif
26+
2227
#else
2328

2429
#define openPMD_HAS_ADIOS_2_8 0

src/IO/ADIOS/ADIOS2Auxiliary.cpp

+43-40
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121

22+
#include "openPMD/auxiliary/TypeTraits.hpp"
2223
#include "openPMD/config.hpp"
2324
#if openPMD_HAVE_ADIOS2
2425
#include "openPMD/Datatype.hpp"
@@ -61,45 +62,6 @@ FlushTarget flushTargetFromString(std::string const &str)
6162

6263
namespace openPMD::detail
6364
{
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-
10365
Datatype fromADIOS2Type(std::string const &dt, bool verbose)
10466
{
10567
static std::map<std::string, Datatype> map{
@@ -204,7 +166,7 @@ Datatype attributeInfo(
204166
type = IO.AttributeType(attributeName);
205167
break;
206168
case VariableOrAttribute::Variable:
207-
type = IO.VariableType(attributeName);
169+
type = normalizingVariableType(IO, attributeName);
208170
break;
209171
}
210172
if (type.empty())
@@ -272,5 +234,46 @@ Datatype attributeInfo(
272234
throw std::runtime_error("Unreachable!");
273235
}
274236
}
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+
}
275278
} // namespace openPMD::detail
276279
#endif

src/IO/ADIOS/ADIOS2IOHandler.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,8 @@ void ADIOS2IOHandlerImpl::extendDataset(
865865
auto file = refreshFileFromParent(writable, /* preferParentFile = */ false);
866866
std::string name = nameOfVariable(writable);
867867
auto &filedata = getFileData(file, IfFileNotOpen::ThrowError);
868-
Datatype dt = detail::fromADIOS2Type(filedata.m_IO.VariableType(name));
868+
Datatype dt = detail::fromADIOS2Type(
869+
detail::normalizingVariableType(filedata.m_IO, name));
869870
switchAdios2VariableType<detail::DatasetExtender>(
870871
dt, filedata.m_IO, name, parameters.extent);
871872
}
@@ -962,8 +963,10 @@ void ADIOS2IOHandlerImpl::openDataset(
962963
auto file = refreshFileFromParent(writable, /* preferParentFile = */ true);
963964
auto varName = nameOfVariable(writable);
964965
auto &fileData = getFileData(file, IfFileNotOpen::ThrowError);
965-
*parameters.dtype =
966-
detail::fromADIOS2Type(fileData.m_IO.VariableType(varName));
966+
*parameters.dtype = detail::fromADIOS2Type(
967+
detail::normalizingVariableType(fileData.m_IO, varName));
968+
std::cout << "[openDataset] opened '" << varName << "'as "
969+
<< *parameters.dtype << std::endl;
967970
switchAdios2VariableType<detail::DatasetOpener>(
968971
*parameters.dtype, this, file, varName, parameters);
969972
writable->written = true;
@@ -1464,7 +1467,8 @@ void ADIOS2IOHandlerImpl::availableChunks(
14641467
detail::ADIOS2File &ba = getFileData(file, IfFileNotOpen::ThrowError);
14651468
std::string varName = nameOfVariable(writable);
14661469
auto engine = ba.getEngine(); // make sure that data are present
1467-
auto datatype = detail::fromADIOS2Type(ba.m_IO.VariableType(varName));
1470+
auto datatype = detail::fromADIOS2Type(
1471+
detail::normalizingVariableType(ba.m_IO, varName));
14681472
bool allSteps = ba.m_mode != adios2::Mode::Read &&
14691473
ba.streamStatus == detail::ADIOS2File::StreamStatus::ReadWithoutStream;
14701474
switchAdios2VariableType<detail::RetrieveBlocksInfo>(

src/config.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "openPMD/version.hpp"
2323

2424
#if openPMD_HAVE_ADIOS2
25+
#include "openPMD/IO/ADIOS/macros.hpp"
2526
#include <adios2.h>
2627
#endif
2728
#include <map>

0 commit comments

Comments
 (0)