23 #include "openPMD/IO/ADIOS/ADIOS1FilePosition.hpp" 24 #include "openPMD/auxiliary/StringManip.hpp" 25 #include "openPMD/backend/Attribute.hpp" 26 #include "openPMD/backend/Writable.hpp" 28 #include <adios_types.h> 40 getBP1Extent(Extent
const &e, std::string
const &delimiter =
",")
47 return std::to_string(e[0]);
49 std::ostringstream os;
51 e.begin(), e.end() - 1, [&os, &delimiter](std::uint64_t
const ext) {
52 os << std::to_string(ext) << delimiter;
54 os << std::to_string(*e.rbegin());
60 getZerosLikeBP1Extent(Extent
const &e, std::string
const &delimiter =
",")
69 std::ostringstream os;
71 e.begin(), e.end() - 1, [&os, &delimiter](std::uint64_t
const) {
72 os <<
"0" << delimiter;
79 inline ADIOS_DATATYPES getBP1DataType(
Datatype dtype)
93 return adios_unsigned_byte;
96 if (
sizeof(
short) == 2u)
98 else if (
sizeof(
short) == 4u)
100 else if (
sizeof(
long) == 8u)
103 throw unsupported_data_error(
104 "No native equivalent for Datatype::SHORT found.");
107 if (
sizeof(
int) == 2u)
109 else if (
sizeof(
int) == 4u)
110 return adios_integer;
111 else if (
sizeof(
int) == 8u)
114 throw unsupported_data_error(
115 "No native equivalent for Datatype::INT found.");
118 if (
sizeof(
long) == 2u)
120 else if (
sizeof(
long) == 4u)
121 return adios_integer;
122 else if (
sizeof(
long) == 8u)
125 throw unsupported_data_error(
126 "No native equivalent for Datatype::LONG found.");
128 case DT::VEC_LONGLONG:
129 if (
sizeof(
long long) == 2u)
131 else if (
sizeof(
long long) == 4u)
132 return adios_integer;
133 else if (
sizeof(
long long) == 8u)
136 throw unsupported_data_error(
137 "No native equivalent for Datatype::LONGLONG found.");
140 if (
sizeof(
unsigned short) == 2u)
141 return adios_unsigned_short;
142 else if (
sizeof(
unsigned short) == 4u)
143 return adios_unsigned_integer;
144 else if (
sizeof(
unsigned long) == 8u)
145 return adios_unsigned_long;
147 throw unsupported_data_error(
148 "No native equivalent for Datatype::USHORT found.");
151 if (
sizeof(
unsigned int) == 2u)
152 return adios_unsigned_short;
153 else if (
sizeof(
unsigned int) == 4u)
154 return adios_unsigned_integer;
155 else if (
sizeof(
unsigned int) == 8u)
156 return adios_unsigned_long;
158 throw unsupported_data_error(
159 "No native equivalent for Datatype::UINT found.");
162 if (
sizeof(
unsigned long) == 2u)
163 return adios_unsigned_short;
164 else if (
sizeof(
unsigned long) == 4u)
165 return adios_unsigned_integer;
166 else if (
sizeof(
unsigned long) == 8u)
167 return adios_unsigned_long;
169 throw unsupported_data_error(
170 "No native equivalent for Datatype::ULONG found.");
172 case DT::VEC_ULONGLONG:
173 if (
sizeof(
unsigned long long) == 2u)
174 return adios_unsigned_short;
175 else if (
sizeof(
unsigned long long) == 4u)
176 return adios_unsigned_integer;
177 else if (
sizeof(
unsigned long long) == 8u)
178 return adios_unsigned_long;
180 throw unsupported_data_error(
181 "No native equivalent for Datatype::ULONGLONG found.");
189 case DT::LONG_DOUBLE:
190 case DT::VEC_LONG_DOUBLE:
191 return adios_long_double;
194 return adios_complex;
196 case DT::VEC_CDOUBLE:
197 return adios_double_complex;
198 case DT::CLONG_DOUBLE:
199 case DT::VEC_CLONG_DOUBLE:
200 throw unsupported_data_error(
201 "No native equivalent for Datatype::CLONG_DOUBLE found.");
205 return adios_string_array;
207 throw std::runtime_error(
"Meta-Datatype leaked into IO");
209 throw std::runtime_error(
"Unknown Attribute datatype (ADIOS datatype)");
211 throw std::runtime_error(
"Datatype not implemented in ADIOS IO");
215 inline std::string concrete_bp1_file_position(Writable *w)
217 std::stack<Writable *> hierarchy;
218 if (!w->abstractFilePosition)
227 while (!hierarchy.empty())
229 auto const tmp_ptr = std::dynamic_pointer_cast<ADIOS1FilePosition>(
230 hierarchy.top()->abstractFilePosition);
231 if (tmp_ptr ==
nullptr)
232 throw std::runtime_error(
233 "Dynamic pointer cast returned a nullptr!");
234 pos += tmp_ptr->location;
238 return auxiliary::replace_all(pos,
"//",
"/");
242 getEnvNum(std::string
const &key, std::string
const &defaultValue)
244 char const *env = std::getenv(key.c_str());
247 char const *tmp = env;
254 std::cerr << key <<
" is invalid" << std::endl;
259 return std::string(env, std::strlen(env));
267 template <
typename T>
268 inline Attribute readVectorAttributeInternal(
void *data,
int size)
270 auto d =
reinterpret_cast<T *
>(data);
273 for (
int i = 0; i < size; ++i)
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:45
Public definitions of openPMD-api.
Definition: Date.cpp:28