23 #include "openPMD/RecordComponent.hpp" 24 #include "openPMD/UnitDimension.hpp" 25 #include "openPMD/backend/Container.hpp" 34 template <
typename T_elem>
58 mapped_type &operator[](key_type
const &key)
override;
59 mapped_type &operator[](key_type &&key)
override;
60 size_type erase(key_type
const &key)
override;
61 iterator erase(iterator res)
override;
95 std::shared_ptr<bool> m_containsScalar;
101 virtual void read() = 0;
111 bool dirtyRecursive()
const;
114 template <
typename T_elem>
119 template <
typename T_elem>
124 m_containsScalar = b.m_containsScalar;
128 template <
typename T_elem>
133 "unitDimension", std::array<double, 7>{{0., 0., 0., 0., 0., 0., 0.}});
136 template <
typename T_elem>
137 inline typename BaseRecord<T_elem>::mapped_type &
140 auto it = this->find(key);
141 if (it != this->end())
145 bool const keyScalar = (key == RecordComponent::SCALAR);
148 throw std::runtime_error(
149 "A scalar component can not be contained at " 150 "the same time as one or more regular components.");
155 *m_containsScalar =
true;
156 ret.parent() = this->parent();
162 template <
typename T_elem>
163 inline typename BaseRecord<T_elem>::mapped_type &
166 auto it = this->find(key);
167 if (it != this->end())
171 bool const keyScalar = (key == RecordComponent::SCALAR);
174 throw std::runtime_error(
175 "A scalar component can not be contained at " 176 "the same time as one or more regular components.");
181 *m_containsScalar =
true;
182 ret.parent() = this->parent();
188 template <
typename T_elem>
189 inline typename BaseRecord<T_elem>::size_type
192 bool const keyScalar = (key == RecordComponent::SCALAR);
194 if (!keyScalar || (keyScalar && this->at(key).constant()))
198 mapped_type &rc = this->find(RecordComponent::SCALAR)->second;
204 this->IOHandler()->
flush(internal::defaultFlushParams);
211 this->written() =
false;
212 this->writable().abstractFilePosition.reset();
213 *this->m_containsScalar =
false;
218 template <
typename T_elem>
219 inline typename BaseRecord<T_elem>::iterator
222 bool const keyScalar = (res->first == RecordComponent::SCALAR);
224 if (!keyScalar || (keyScalar && this->at(res->first).constant()))
228 mapped_type &rc = this->find(RecordComponent::SCALAR)->second;
234 this->IOHandler()->
flush(internal::defaultFlushParams);
241 this->written() =
false;
242 this->writable().abstractFilePosition.reset();
243 *this->m_containsScalar =
false;
248 template <
typename T_elem>
252 .template get<std::array<double, 7> >();
255 template <
typename T_elem>
258 return *m_containsScalar;
261 template <
typename T_elem>
267 aRead.name =
"unitDimension";
269 this->IOHandler()->
flush(internal::defaultFlushParams);
270 if (*aRead.dtype == DT::ARR_DBL_7)
273 Attribute(*aRead.resource).template
get<std::array<double, 7> >());
274 else if (*aRead.dtype == DT::VEC_DOUBLE)
277 Attribute(*aRead.resource).template get<std::vector<double> >();
280 std::array<double, 7> arr;
281 std::copy(vec.begin(), vec.end(), arr.begin());
285 throw std::runtime_error(
286 "Unexpected Attribute datatype for 'unitDimension'");
289 throw std::runtime_error(
290 "Unexpected Attribute datatype for 'unitDimension'");
292 aRead.name =
"timeOffset";
294 this->IOHandler()->
flush(internal::defaultFlushParams);
295 if (*aRead.dtype == DT::FLOAT)
297 "timeOffset",
Attribute(*aRead.resource).template get<float>());
298 else if (*aRead.dtype == DT::DOUBLE)
300 "timeOffset",
Attribute(*aRead.resource).template get<double>());
302 throw std::runtime_error(
303 "Unexpected Attribute datatype for 'timeOffset'");
306 template <
typename T_elem>
310 if (!this->written() && this->empty())
311 throw std::runtime_error(
312 "A Record can not be written without any contained " 313 "RecordComponents: " +
316 this->flush_impl(name, flushParams);
321 template <
typename T_elem>
328 for (
auto const &pair : *
this)
330 if (pair.second.dirtyRecursive())
Attribute getAttribute(std::string const &key) const
Retrieve value of Attribute stored with provided key.
Definition: Attributable.cpp:44
Self-contained description of a single IO operation.
Definition: IOTask.hpp:615
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:240
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:40
virtual void enqueue(IOTask const &iotask)
Add provided task to queue according to FIFO.
Definition: AbstractIOHandler.hpp:140
Definition: IOTask.hpp:333
virtual size_type erase(key_type const &key)
Remove a single element from the container and (if written) from disk.
Definition: Container.hpp:335
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:51
Public definitions of openPMD-api.
Definition: Date.cpp:28
virtual std::future< void > flush(internal::FlushParams const &)=0
Process operations in queue according to FIFO.
bool setAttribute(std::string const &key, T value)
Populate Attribute of provided name with provided value.
Definition: Attributable.hpp:458
Definition: BaseRecord.hpp:35
Parameters recursively passed through the openPMD hierarchy when flushing.
Definition: AbstractIOHandler.hpp:103
bool scalar() const
Returns true if this record only contains a single component.
Definition: BaseRecord.hpp:256
Definition: ParticleSpecies.hpp:33
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:105
std::array< double, 7 > unitDimension() const
Return the physical dimension (quantity) of a record.
Definition: BaseRecord.hpp:249
Definition: IOTask.hpp:511