23 #include "openPMD/auxiliary/ShareRawInternal.hpp" 24 #include "openPMD/backend/BaseRecordComponent.hpp" 30 #include <unordered_map> 33 #ifndef OPENPMD_private 34 #define OPENPMD_private private: 66 template <
typename T,
typename T_key,
typename T_container>
80 uint8_t getDimensionality()
const;
81 Extent getExtent()
const;
84 std::shared_ptr<T> load();
87 void load(std::shared_ptr<T>);
90 void load(std::shared_ptr<
T[]>);
96 void store(uint64_t idx,
T);
113 bool dirtyRecursive()
const;
115 std::shared_ptr<internal::PatchRecordComponentData>
128 return *m_patchRecordComponentData;
133 return *m_patchRecordComponentData;
137 setData(std::shared_ptr<internal::PatchRecordComponentData> data)
139 m_patchRecordComponentData = std::move(data);
140 BaseRecordComponent::setData(m_patchRecordComponentData);
144 template <
typename T>
145 inline std::shared_ptr<T> PatchRecordComponent::load()
147 uint64_t numPoints = getExtent()[0];
148 #if (defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 11000) || \ 149 (defined(__apple_build_version__) && __clang_major__ < 14) 151 std::shared_ptr<T>(
new T[numPoints], [](T *p) {
delete[] p; });
155 auto newData = std::shared_ptr<T[]>(
new T[numPoints]);
157 return std::static_pointer_cast<T>(std::move(newData));
161 template <
typename T>
162 inline void PatchRecordComponent::load(std::shared_ptr<T> data)
164 Datatype dtype = determineDatatype<T>();
165 if (dtype != getDatatype())
166 throw std::runtime_error(
167 "Type conversion during particle patch loading not yet " 171 throw std::runtime_error(
172 "Unallocated pointer passed during ParticlePatch loading.");
174 uint64_t numPoints = getExtent()[0];
180 dRead.extent = {numPoints};
181 dRead.dtype = getDatatype();
182 dRead.data = std::static_pointer_cast<
void>(data);
184 rc.m_chunks.push(
IOTask(
this, dRead));
187 template <
typename T>
188 inline void PatchRecordComponent::load(std::shared_ptr<
T[]> data)
190 load(std::static_pointer_cast<T>(std::move(data)));
193 template <
typename T>
194 inline void PatchRecordComponent::loadRaw(
T *data)
196 load<T>(auxiliary::shareRaw(data));
199 template <
typename T>
200 inline void PatchRecordComponent::store(uint64_t idx,
T data)
202 Datatype dtype = determineDatatype<T>();
203 if (dtype != getDatatype())
205 std::ostringstream oss;
206 oss <<
"Datatypes of patch data (" << dtype <<
") and dataset (" 207 << getDatatype() <<
") do not match.";
208 throw std::runtime_error(oss.str());
211 Extent dse = getExtent();
212 if (dse[0] - 1u < idx)
213 throw std::runtime_error(
214 "Index does not reside inside patch (no. patches: " +
215 std::to_string(dse[0]) +
" - index: " + std::to_string(idx) +
")");
218 dWrite.offset = {idx};
220 dWrite.dtype = dtype;
221 dWrite.data = std::make_shared<T>(data);
223 rc.m_chunks.push(
IOTask(
this, std::move(dWrite)));
Definition: ParticlePatches.hpp:31
Definition: Dataset.hpp:35
Self-contained description of a single IO operation.
Definition: IOTask.hpp:695
Definition: PatchRecord.hpp:31
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:45
Definition: PatchRecordComponent.hpp:41
Public definitions of openPMD-api.
Definition: IOTask.hpp:449
Definition: BaseRecord.hpp:58
Parameters recursively passed through the openPMD hierarchy when flushing.
Definition: AbstractIOHandler.hpp:84
std::queue< IOTask > m_chunks
Chunk reading/writing requests on the contained dataset.
Definition: PatchRecordComponent.hpp:47
Definition: ParticleSpecies.hpp:33
Definition: PatchRecordComponent.hpp:64
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:131
Definition: BaseRecordComponent.hpp:36
Definition: IOTask.hpp:426
Definition: BaseRecordComponent.hpp:62