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>
48 friend class Container;
50 friend class BaseRecord;
51 template <
typename,
typename>
53 friend class ParticlePatches;
54 friend class PatchRecord;
55 friend class ParticleSpecies;
69 uint8_t getDimensionality()
const;
70 Extent getExtent()
const;
73 std::shared_ptr<T> load();
76 void load(std::shared_ptr<T>);
79 void load(std::shared_ptr<
T[]>);
85 void store(uint64_t idx,
T);
94 using RecordComponent::flush;
105inline std::shared_ptr<T> PatchRecordComponent::load()
107 uint64_t numPoints = getExtent()[0];
108#if (defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 11000) || \
109 (defined(__apple_build_version__) && __clang_major__ < 14)
111 std::shared_ptr<T>(
new T[numPoints], [](
T *p) {
delete[] p; });
115 auto newData = std::shared_ptr<T[]>(
new T[numPoints]);
117 return std::static_pointer_cast<T>(std::move(newData));
122inline void PatchRecordComponent::load(std::shared_ptr<T> data)
124 Datatype dtype = determineDatatype<T>();
125 if (dtype != getDatatype())
126 throw std::runtime_error(
127 "Type conversion during particle patch loading not yet "
131 throw std::runtime_error(
132 "Unallocated pointer passed during ParticlePatch loading.");
134 uint64_t numPoints = getExtent()[0];
140 dRead.extent = {numPoints};
141 dRead.dtype = getDatatype();
142 dRead.data = std::static_pointer_cast<void>(data);
144 rc.push_chunk(
IOTask(
this, dRead));
148inline void PatchRecordComponent::load(std::shared_ptr<
T[]> data)
150 load(std::static_pointer_cast<T>(std::move(data)));
154inline void PatchRecordComponent::loadRaw(
T *data)
156 load<T>(auxiliary::shareRaw(data));
160inline void PatchRecordComponent::store(uint64_t idx,
T data)
162 Datatype dtype = determineDatatype<T>();
163 if (dtype != getDatatype())
165 std::ostringstream oss;
166 oss <<
"Datatypes of patch data (" << dtype <<
") and dataset ("
167 << getDatatype() <<
") do not match.";
168 throw std::runtime_error(oss.str());
171 Extent dse = getExtent();
172 if (dse[0] - 1u < idx)
173 throw std::runtime_error(
174 "Index does not reside inside patch (no. patches: " +
175 std::to_string(dse[0]) +
" - index: " + std::to_string(idx) +
")");
177 Parameter<Operation::WRITE_DATASET> dWrite;
178 dWrite.offset = {idx};
180 dWrite.dtype = dtype;
181 dWrite.data = std::make_shared<T>(data);
183 rc.push_chunk(IOTask(
this, std::move(dWrite)));
187inline void PatchRecordComponent::store(
T data)
189 Datatype dtype = determineDatatype<T>();
190 if (dtype != getDatatype())
192 std::ostringstream oss;
193 oss <<
"Datatypes of patch data (" << dtype <<
") and dataset ("
194 << getDatatype() <<
") do not match.";
195 throw std::runtime_error(oss.str());
198 if (!joinedDimension().has_value())
200 throw error::WrongAPIUsage(
201 "[PatchRecordComponent::store] API call without explicit "
202 "specification of index only allowed when a joined dimension is "
206 Parameter<Operation::WRITE_DATASET> dWrite;
209 dWrite.dtype = dtype;
210 dWrite.data = std::make_shared<T>(data);
212 rc.push_chunk(IOTask(
this, std::move(dWrite)));
Self-contained description of a single IO operation.
Definition IOTask.hpp:836
PatchRecordComponent(BaseRecord< PatchRecordComponent > const &)
Avoid object slicing when using a Record as a scalar Record Component.
Definition PatchRecordComponent.cpp:55
RecordComponent(BaseRecord< RecordComponent > const &)
Avoid object slicing when using a Record as a scalar Record Component.
Definition RecordComponent.cpp:190
Definition BaseRecord.hpp:52
Public definitions of openPMD-api.
Definition Date.cpp:29
@ T
time
Definition UnitDimension.hpp:41
Datatype
Concrete datatype of an object available at runtime.
Definition Datatype.hpp:51
Definition Attributable.hpp:251
Typesafe description of all required arguments for a specified Operation.
Definition IOTask.hpp:148