23 #include "openPMD/RecordComponent.hpp" 24 #include "openPMD/UnitDimension.hpp" 25 #include "openPMD/backend/Container.hpp" 35 template <
typename T_elem>
36 class BaseRecordData :
public ContainerData<T_elem>
57 template <
typename T_elem>
66 std::shared_ptr<internal::BaseRecordData<T_elem> > m_baseRecordData{
71 return *m_baseRecordData;
76 return *m_baseRecordData;
86 m_baseRecordData = std::move(data);
106 mapped_type &operator[](key_type
const &key)
override;
107 mapped_type &operator[](key_type &&key)
override;
108 size_type erase(key_type
const &key)
override;
109 iterator erase(iterator res)
override;
131 std::array<double, 7> unitDimension()
const;
147 virtual void read() = 0;
157 bool dirtyRecursive()
const;
164 template <
typename T_elem>
165 BaseRecordData<T_elem>::BaseRecordData()
170 std::array<double, 7>{{0., 0., 0., 0., 0., 0., 0.}});
174 template <
typename T_elem>
180 template <
typename T_elem>
186 template <
typename T_elem>
187 inline typename BaseRecord<T_elem>::mapped_type &
190 auto it = this->find(key);
191 if (it != this->end())
195 bool const keyScalar = (key == RecordComponent::SCALAR);
197 (scalar() && !keyScalar))
198 throw std::runtime_error(
199 "A scalar component can not be contained at " 200 "the same time as one or more regular components.");
206 ret.parent() = this->parent();
212 template <
typename T_elem>
213 inline typename BaseRecord<T_elem>::mapped_type &
216 auto it = this->find(key);
217 if (it != this->end())
221 bool const keyScalar = (key == RecordComponent::SCALAR);
223 (scalar() && !keyScalar))
224 throw std::runtime_error(
225 "A scalar component can not be contained at " 226 "the same time as one or more regular components.");
232 ret.parent() = this->parent();
238 template <
typename T_elem>
239 inline typename BaseRecord<T_elem>::size_type
242 bool const keyScalar = (key == RecordComponent::SCALAR);
244 if (!keyScalar || (keyScalar && this->at(key).constant()))
248 mapped_type &rc = this->find(RecordComponent::SCALAR)->second;
253 this->IOHandler()->enqueue(
IOTask(&rc, dDelete));
254 this->IOHandler()->flush(internal::defaultFlushParams);
261 this->written() =
false;
262 this->writable().abstractFilePosition.reset();
268 template <
typename T_elem>
269 inline typename BaseRecord<T_elem>::iterator
272 bool const keyScalar = (res->first == RecordComponent::SCALAR);
274 if (!keyScalar || (keyScalar && this->at(res->first).constant()))
278 mapped_type &rc = this->find(RecordComponent::SCALAR)->second;
283 this->IOHandler()->enqueue(
IOTask(&rc, dDelete));
284 this->IOHandler()->flush(internal::defaultFlushParams);
291 this->written() =
false;
292 this->writable().abstractFilePosition.reset();
298 template <
typename T_elem>
301 return this->getAttribute(
"unitDimension")
302 .template get<std::array<double, 7> >();
305 template <
typename T_elem>
311 template <
typename T_elem>
317 aRead.name =
"unitDimension";
318 this->IOHandler()->enqueue(
IOTask(
this, aRead));
319 this->IOHandler()->flush(internal::defaultFlushParams);
323 this->setAttribute(
"unitDimension", val.value());
325 throw std::runtime_error(
326 "Unexpected Attribute datatype for 'unitDimension'");
328 aRead.name =
"timeOffset";
329 this->IOHandler()->enqueue(
IOTask(
this, aRead));
330 this->IOHandler()->flush(internal::defaultFlushParams);
331 if (*aRead.dtype == DT::FLOAT)
334 else if (*aRead.dtype == DT::DOUBLE)
336 "timeOffset",
Attribute(*aRead.resource).
get<
double>());
340 this->setAttribute(
"timeOffset", val.value());
342 throw std::runtime_error(
343 "Unexpected Attribute datatype for 'timeOffset'");
346 template <
typename T_elem>
350 if (!this->written() && this->empty())
351 throw std::runtime_error(
352 "A Record can not be written without any contained " 353 "RecordComponents: " +
356 this->flush_impl(name, flushParams);
361 template <
typename T_elem>
368 for (
auto const &pair : *
this)
370 if (pair.second.dirtyRecursive())
Self-contained description of a single IO operation.
Definition: IOTask.hpp:695
U get() const
Retrieve a stored specific Attribute and cast if convertible.
Definition: Attribute.hpp:253
Definition: Attributable.hpp:85
virtual mapped_type & operator[](key_type const &key)
Access the value that is mapped to a key equivalent to key, creating it if such key does not exist al...
Definition: Container.hpp:285
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:126
Definition: IOTask.hpp:407
Definition: PatchRecord.hpp:31
virtual size_type erase(key_type const &key)
Remove a single element from the container and (if written) from disk.
Definition: Container.hpp:384
std::optional< U > getOptional() const
Retrieve a stored specific Attribute and cast if convertible.
Definition: Attribute.hpp:277
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:45
Varidic datatype supporting at least all formats for attributes specified in the openPMD standard...
Definition: Attribute.hpp:54
bool setAttribute(std::string const &key, T value)
Populate Attribute of provided name with provided value.
Definition: Attributable.hpp:402
Public definitions of openPMD-api.
Definition: Record.hpp:32
std::array< double, 7 > unitDimension() const
Return the physical dimension (quantity) of a record.
Definition: BaseRecord.hpp:58
Parameters recursively passed through the openPMD hierarchy when flushing.
Definition: AbstractIOHandler.hpp:84
bool m_containsScalar
True if this Record contains a scalar record component.
Definition: BaseRecord.hpp:45
bool scalar() const
Returns true if this record only contains a single component.
Definition: ParticleSpecies.hpp:33
Container for N-dimensional, homogeneous Records.
Definition: Mesh.hpp:40
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:131
Definition: IOTask.hpp:569
Layer to manage storage of attributes associated with file objects.
Definition: Attributable.hpp:93