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;
72 std::shared_ptr< bool > m_containsScalar;
75 void flush(std::string
const&)
final;
76 virtual void flush_impl(std::string
const&) = 0;
77 virtual void read() = 0;
81 template<
typename T_elem >
84 m_containsScalar{b.m_containsScalar}
87 template<
typename T_elem >
90 m_containsScalar = b.m_containsScalar;
94 template<
typename T_elem >
97 m_containsScalar{std::make_shared< bool >(
false)}
100 std::array< double, 7 >{{0., 0., 0., 0., 0., 0., 0.}});
104 template<
typename T_elem >
105 inline typename BaseRecord< T_elem >::mapped_type&
108 auto it = this->find(key);
109 if( it != this->end() )
113 bool scalar = (key == RecordComponent::SCALAR);
115 throw std::runtime_error(
"A scalar component can not be contained at " 116 "the same time as one or more regular components.");
121 *m_containsScalar =
true;
122 ret.m_writable->parent = this->m_writable->parent;
123 ret.parent = this->parent;
129 template<
typename T_elem >
130 inline typename BaseRecord< T_elem >::mapped_type&
133 auto it = this->find(key);
134 if( it != this->end() )
138 bool scalar = (key == RecordComponent::SCALAR);
140 throw std::runtime_error(
"A scalar component can not be contained at " 141 "the same time as one or more regular components.");
146 *m_containsScalar =
true;
147 ret.m_writable->parent = this->m_writable->parent;
148 ret.parent = this->parent;
154 template<
typename T_elem >
155 inline typename BaseRecord< T_elem >::size_type
158 bool scalar = (key == RecordComponent::SCALAR);
160 if( !scalar || (scalar && *this->at(key).m_isConstant) )
164 mapped_type& rc = this->find(RecordComponent::SCALAR)->second;
170 this->IOHandler->
flush();
177 this->written =
false;
178 this->m_writable->abstractFilePosition.reset();
179 *this->m_containsScalar =
false;
184 template<
typename T_elem >
185 inline typename BaseRecord< T_elem >::iterator
188 bool scalar = (res->first == RecordComponent::SCALAR);
190 if( !scalar || (scalar && *this->at(res->first).m_isConstant) )
194 mapped_type& rc = this->find(RecordComponent::SCALAR)->second;
200 this->IOHandler->
flush();
207 this->written =
false;
208 this->m_writable->abstractFilePosition.reset();
209 *this->m_containsScalar =
false;
214 template<
typename T_elem >
215 inline std::array< double, 7 >
221 template<
typename T_elem >
228 aRead.name =
"unitDimension";
230 this->IOHandler->
flush();
231 if( *aRead.dtype == DT::ARR_DBL_7 )
232 this->
setAttribute(
"unitDimension",
Attribute(*aRead.resource).template
get< std::array< double, 7 > >());
233 else if( *aRead.dtype == DT::VEC_DOUBLE )
235 auto vec =
Attribute(*aRead.resource).template get< std::vector< double > >();
236 if( vec.size() == 7 )
238 std::array< double, 7 > arr;
239 std::copy(vec.begin(),
244 throw std::runtime_error(
"Unexpected Attribute datatype for 'unitDimension'");
247 throw std::runtime_error(
"Unexpected Attribute datatype for 'unitDimension'");
249 aRead.name =
"timeOffset";
251 this->IOHandler->
flush();
252 if( *aRead.dtype == DT::FLOAT )
254 else if( *aRead.dtype == DT::DOUBLE )
257 throw std::runtime_error(
"Unexpected Attribute datatype for 'timeOffset'");
260 template<
typename T_elem >
264 if( !this->written && this->empty() )
265 throw std::runtime_error(
"A Record can not be written without any contained RecordComponents: " + name);
267 this->flush_impl(name);
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:468
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:35
virtual void enqueue(IOTask const &iotask)
Add provided task to queue according to FIFO.
Definition: AbstractIOHandler.hpp:89
Definition: IOTask.hpp:287
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:38
Varidic datatype supporting at least all formats for attributes specified in the openPMD standard...
Definition: Attribute.hpp:49
Public definitions of openPMD-api.
Definition: Date.cpp:28
Definition: BaseRecord.hpp:36
Definition: ParticleSpecies.hpp:34
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:70
virtual std::array< double, 7 > unitDimension() const
Definition: BaseRecord.hpp:216
Definition: IOTask.hpp:414