23 #include "openPMD/backend/Container.hpp" 24 #include "openPMD/RecordComponent.hpp" 25 #include "openPMD/UnitDimension.hpp" 35 template<
typename T_elem >
59 mapped_type& operator[](key_type
const& key)
override;
60 mapped_type& operator[](key_type&& key)
override;
61 size_type erase(key_type
const& key)
override;
62 iterator erase(iterator res)
override;
94 std::shared_ptr< bool > m_containsScalar;
97 void flush(std::string
const&)
final;
98 virtual void flush_impl(std::string
const&) = 0;
99 virtual void read() = 0;
110 dirtyRecursive()
const;
114 template<
typename T_elem >
117 m_containsScalar{b.m_containsScalar}
120 template<
typename T_elem >
123 m_containsScalar = b.m_containsScalar;
127 template<
typename T_elem >
130 m_containsScalar{std::make_shared< bool >(
false)}
133 std::array< double, 7 >{{0., 0., 0., 0., 0., 0., 0.}});
137 template<
typename T_elem >
138 inline typename BaseRecord< T_elem >::mapped_type&
141 auto it = this->find(key);
142 if( it != this->end() )
146 bool const keyScalar = (key == RecordComponent::SCALAR);
148 throw std::runtime_error(
"A scalar component can not be contained at " 149 "the same time as one or more regular components.");
154 *m_containsScalar =
true;
155 ret.m_writable->parent = this->m_writable->parent;
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);
173 throw std::runtime_error(
"A scalar component can not be contained at " 174 "the same time as one or more regular components.");
179 *m_containsScalar =
true;
180 ret.m_writable->parent = this->m_writable->parent;
181 ret.parent = this->parent;
187 template<
typename T_elem >
188 inline typename BaseRecord< T_elem >::size_type
191 bool const keyScalar = (key == RecordComponent::SCALAR);
193 if( !keyScalar || (keyScalar && this->at(key).constant()) )
197 mapped_type& rc = this->find(RecordComponent::SCALAR)->second;
203 this->IOHandler->
flush();
210 this->written() =
false;
211 this->m_writable->abstractFilePosition.reset();
212 *this->m_containsScalar =
false;
217 template<
typename T_elem >
218 inline typename BaseRecord< T_elem >::iterator
221 bool const keyScalar = (res->first == RecordComponent::SCALAR);
223 if( !keyScalar || (keyScalar && this->at(res->first).constant()) )
227 mapped_type& rc = this->find(RecordComponent::SCALAR)->second;
233 this->IOHandler->
flush();
240 this->written() =
false;
241 this->m_writable->abstractFilePosition.reset();
242 *this->m_containsScalar =
false;
247 template<
typename T_elem >
248 inline std::array< double, 7 >
254 template<
typename T_elem >
258 return *m_containsScalar;
261 template<
typename T_elem >
268 aRead.name =
"unitDimension";
270 this->IOHandler->
flush();
271 if( *aRead.dtype == DT::ARR_DBL_7 )
272 this->
setAttribute(
"unitDimension",
Attribute(*aRead.resource).template
get< std::array< double, 7 > >());
273 else if( *aRead.dtype == DT::VEC_DOUBLE )
275 auto vec =
Attribute(*aRead.resource).template get< std::vector< double > >();
276 if( vec.size() == 7 )
278 std::array< double, 7 > arr;
279 std::copy(vec.begin(),
284 throw std::runtime_error(
"Unexpected Attribute datatype for 'unitDimension'");
287 throw std::runtime_error(
"Unexpected Attribute datatype for 'unitDimension'");
289 aRead.name =
"timeOffset";
291 this->IOHandler->
flush();
292 if( *aRead.dtype == DT::FLOAT )
294 else if( *aRead.dtype == DT::DOUBLE )
297 throw std::runtime_error(
"Unexpected Attribute datatype for 'timeOffset'");
300 template<
typename T_elem >
304 if( !this->written() && this->empty() )
305 throw std::runtime_error(
"A Record can not be written without any contained RecordComponents: " + name);
307 this->flush_impl(name);
308 this->dirty() =
false;
311 template<
typename T_elem >
315 if( Attributable::dirty() )
319 for(
auto const & pair : *
this )
321 if( pair.second.dirtyRecursive() )
Attribute getAttribute(std::string const &key) const
Retrieve value of Attribute stored with provided key.
Definition: Attributable.cpp:62
Self-contained description of a single IO operation.
Definition: IOTask.hpp:550
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:142
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:38
virtual void enqueue(IOTask const &iotask)
Add provided task to queue according to FIFO.
Definition: AbstractIOHandler.hpp:89
Definition: IOTask.hpp:320
virtual std::future< void > flush()=0
Process operations in queue according to FIFO.
virtual size_type erase(key_type const &key)
Remove a single element from the container and (if written) from disk.
Definition: Container.hpp:215
bool setAttribute(std::string const &key, T const &value)
Populate Attribute of provided name with provided value.
Definition: Attributable.hpp:209
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:42
Varidic datatype supporting at least all formats for attributes specified in the openPMD standard...
Definition: Attribute.hpp:50
Public definitions of openPMD-api.
Definition: Date.cpp:29
Definition: BaseRecord.hpp:36
bool scalar() const
Returns true if this record only contains a single component.
Definition: BaseRecord.hpp:256
Definition: ParticleSpecies.hpp:34
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:70
std::array< double, 7 > unitDimension() const
Return the physical dimension (quantity) of a record.
Definition: BaseRecord.hpp:249
Definition: IOTask.hpp:447