23 #include "openPMD/backend/BaseRecordComponent.hpp"
25 #include <unordered_map>
31 #ifndef OPENPMD_private
32 # define OPENPMD_private private
61 uint8_t getDimensionality()
const;
62 Extent getExtent()
const;
64 template<
typename T >
65 std::shared_ptr< T > load();
66 template<
typename T >
67 void load(std::shared_ptr< T >);
68 template<
typename T >
69 void store(uint64_t idx,
T);
74 void flush(std::string
const&);
77 std::shared_ptr< std::queue< IOTask > > m_chunks;
88 dirtyRecursive()
const;
91 template<
typename T >
92 inline std::shared_ptr< T >
93 PatchRecordComponent::load()
95 uint64_t numPoints = getExtent()[0];
96 auto newData = std::shared_ptr< T >(
new T[numPoints], []( T *p ){
delete [] p; });
101 template<
typename T >
103 PatchRecordComponent::load(std::shared_ptr< T > data)
105 Datatype dtype = determineDatatype< T >();
106 if( dtype != getDatatype() )
107 throw std::runtime_error(
"Type conversion during particle patch loading not yet implemented");
110 throw std::runtime_error(
"Unallocated pointer passed during ParticlePatch loading.");
112 uint64_t numPoints = getExtent()[0];
118 dRead.extent = {numPoints};
119 dRead.dtype = getDatatype();
120 dRead.data = std::static_pointer_cast< void >(data);
121 m_chunks->push(
IOTask(
this, dRead));
124 template<
typename T >
126 PatchRecordComponent::store(uint64_t idx, T data)
128 Datatype dtype = determineDatatype< T >();
129 if( dtype != getDatatype() )
131 std::ostringstream oss;
132 oss <<
"Datatypes of patch data ("
136 <<
") do not match.";
137 throw std::runtime_error(oss.str());
140 Extent dse = getExtent();
141 if( dse[0] - 1u < idx )
142 throw std::runtime_error(
"Index does not reside inside patch (no. patches: " + std::to_string(dse[0])
143 +
" - index: " + std::to_string(idx) +
")");
145 Parameter< Operation::WRITE_DATASET > dWrite;
146 dWrite.offset = {idx};
148 dWrite.dtype = dtype;
149 dWrite.data = std::make_shared< T >(data);
150 m_chunks->push(IOTask(
this, dWrite));