23 #include "openPMD/auxiliary/ShareRawInternal.hpp" 24 #include "openPMD/backend/BaseRecordComponent.hpp" 29 #include <unordered_map> 32 #ifndef OPENPMD_private 33 #define OPENPMD_private private: 65 template <
typename T,
typename T_key,
typename T_container>
79 uint8_t getDimensionality()
const;
80 Extent getExtent()
const;
83 std::shared_ptr<T> load();
86 void load(std::shared_ptr<T>);
89 void load(std::shared_ptr<
T[]>);
95 void store(uint64_t idx,
T);
112 bool dirtyRecursive()
const;
114 std::shared_ptr<internal::PatchRecordComponentData>
127 return *m_patchRecordComponentData;
132 return *m_patchRecordComponentData;
136 setData(std::shared_ptr<internal::PatchRecordComponentData> data)
138 m_patchRecordComponentData = std::move(data);
139 BaseRecordComponent::setData(m_patchRecordComponentData);
143 template <
typename T>
144 inline std::shared_ptr<T> PatchRecordComponent::load()
146 uint64_t numPoints = getExtent()[0];
147 #if defined(__clang_major__) && __clang_major__ < 7 149 std::shared_ptr<T>(
new T[numPoints], [](T *p) {
delete[] p; });
153 auto newData = std::shared_ptr<T[]>(
new T[numPoints]);
155 return std::static_pointer_cast<T>(std::move(newData));
159 template <
typename T>
160 inline void PatchRecordComponent::load(std::shared_ptr<T> data)
162 Datatype dtype = determineDatatype<T>();
163 if (dtype != getDatatype())
164 throw std::runtime_error(
165 "Type conversion during particle patch loading not yet " 169 throw std::runtime_error(
170 "Unallocated pointer passed during ParticlePatch loading.");
172 uint64_t numPoints = getExtent()[0];
178 dRead.extent = {numPoints};
179 dRead.dtype = getDatatype();
180 dRead.data = std::static_pointer_cast<
void>(data);
182 rc.m_chunks.push(
IOTask(
this, dRead));
185 template <
typename T>
186 inline void PatchRecordComponent::load(std::shared_ptr<
T[]> data)
188 load(std::static_pointer_cast<T>(std::move(data)));
191 template <
typename T>
192 inline void PatchRecordComponent::loadRaw(
T *data)
194 load<T>(auxiliary::shareRaw(data));
197 template <
typename T>
198 inline void PatchRecordComponent::store(uint64_t idx,
T data)
200 Datatype dtype = determineDatatype<T>();
201 if (dtype != getDatatype())
203 std::ostringstream oss;
204 oss <<
"Datatypes of patch data (" << dtype <<
") and dataset (" 205 << getDatatype() <<
") do not match.";
206 throw std::runtime_error(oss.str());
209 Extent dse = getExtent();
210 if (dse[0] - 1u < idx)
211 throw std::runtime_error(
212 "Index does not reside inside patch (no. patches: " +
213 std::to_string(dse[0]) +
" - index: " + std::to_string(idx) +
")");
216 dWrite.offset = {idx};
218 dWrite.dtype = dtype;
219 dWrite.data = std::make_shared<T>(data);
221 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:40
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:46
Definition: ParticleSpecies.hpp:33
Definition: PatchRecordComponent.hpp:63
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