23 #include "openPMD/Error.hpp"
24 #include "openPMD/RecordComponent.hpp"
25 #include "openPMD/auxiliary/ShareRawInternal.hpp"
26 #include "openPMD/backend/BaseRecordComponent.hpp"
32 #include <unordered_map>
35 #ifndef OPENPMD_private
36 #define OPENPMD_private private:
47 template <
typename T,
typename T_key,
typename T_container>
51 template <
typename,
typename>
71 uint8_t getDimensionality()
const;
72 Extent getExtent()
const;
75 std::shared_ptr<T> load();
78 void load(std::shared_ptr<T>);
81 void load(std::shared_ptr<
T[]>);
87 void store(uint64_t idx,
T);
96 using RecordComponent::flush;
106 template <
typename T>
107 inline std::shared_ptr<T> PatchRecordComponent::load()
109 uint64_t numPoints = getExtent()[0];
110 #if (defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 11000) || \
111 (defined(__apple_build_version__) && __clang_major__ < 14)
113 std::shared_ptr<T>(
new T[numPoints], [](T *p) {
delete[] p; });
117 auto newData = std::shared_ptr<T[]>(
new T[numPoints]);
119 return std::static_pointer_cast<T>(std::move(newData));
123 template <
typename T>
124 inline void PatchRecordComponent::load(std::shared_ptr<T> data)
126 Datatype dtype = determineDatatype<T>();
127 if (dtype != getDatatype())
128 throw std::runtime_error(
129 "Type conversion during particle patch loading not yet "
133 throw std::runtime_error(
134 "Unallocated pointer passed during ParticlePatch loading.");
136 uint64_t numPoints = getExtent()[0];
142 dRead.extent = {numPoints};
143 dRead.dtype = getDatatype();
144 dRead.data = std::static_pointer_cast<void>(data);
146 rc.push_chunk(
IOTask(
this, dRead));
149 template <
typename T>
150 inline void PatchRecordComponent::load(std::shared_ptr<T[]> data)
152 load(std::static_pointer_cast<T>(std::move(data)));
155 template <
typename T>
156 inline void PatchRecordComponent::loadRaw(T *data)
158 load<T>(auxiliary::shareRaw(data));
161 template <
typename T>
162 inline void PatchRecordComponent::store(uint64_t idx, T data)
164 Datatype dtype = determineDatatype<T>();
165 if (dtype != getDatatype())
167 std::ostringstream oss;
168 oss <<
"Datatypes of patch data (" << dtype <<
") and dataset ("
169 << getDatatype() <<
") do not match.";
170 throw std::runtime_error(oss.str());
173 Extent dse = getExtent();
174 if (dse[0] - 1u < idx)
175 throw std::runtime_error(
176 "Index does not reside inside patch (no. patches: " +
177 std::to_string(dse[0]) +
" - index: " + std::to_string(idx) +
")");
179 Parameter<Operation::WRITE_DATASET> dWrite;
180 dWrite.offset = {idx};
182 dWrite.dtype = dtype;
183 dWrite.data = std::make_shared<T>(data);
185 rc.push_chunk(IOTask(
this, std::move(dWrite)));
188 template <
typename T>
189 inline void PatchRecordComponent::store(T data)
191 Datatype dtype = determineDatatype<T>();
192 if (dtype != getDatatype())
194 std::ostringstream oss;
195 oss <<
"Datatypes of patch data (" << dtype <<
") and dataset ("
196 << getDatatype() <<
") do not match.";
197 throw std::runtime_error(oss.str());
200 if (!joinedDimension().has_value())
202 throw error::WrongAPIUsage(
203 "[PatchRecordComponent::store] API call without explicit "
204 "specification of index only allowed when a joined dimension is "
208 Parameter<Operation::WRITE_DATASET> dWrite;
211 dWrite.dtype = dtype;
212 dWrite.data = std::make_shared<T>(data);
214 rc.push_chunk(IOTask(
this, std::move(dWrite)));
Base class for any type of record (e.g.
Definition: BaseRecord.hpp:224
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:104
Definition: Dataset.hpp:38
Self-contained description of a single IO operation.
Definition: IOTask.hpp:670
Definition: ParticlePatches.hpp:32
Definition: ParticleSpecies.hpp:34
Definition: PatchRecordComponent.hpp:46
PatchRecordComponent & resetDataset(Dataset) override
Declare the dataset's type and extent.
Definition: PatchRecordComponent.cpp:37
Definition: PatchRecord.hpp:32
Definition: RecordComponent.hpp:120
Definition: BaseRecord.hpp:52
Public definitions of openPMD-api.
Definition: Date.cpp:29
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:51
Definition: Attributable.hpp:125
Definition: IOTask.hpp:429