23 #include "openPMD/IO/AbstractIOHandler.hpp"
24 #include "openPMD/ThrowError.hpp"
25 #include "openPMD/auxiliary/OutOfRangeMsg.hpp"
26 #include "openPMD/backend/Attribute.hpp"
27 #include "openPMD/backend/Writable.hpp"
34 #include <type_traits>
38 #ifndef OPENPMD_protected
39 #define OPENPMD_protected protected:
47 struct GenerationPolicy;
49 class AbstractFilePosition;
69 using A_MAP = std::map<std::string, Attribute>;
84 template <
typename,
typename>
92 void printDirty(
Series const &);
103 using A_MAP = std::map<std::string, Attribute>;
105 template <
typename T_elem>
107 template <
typename T_elem>
108 friend class BaseRecordInterface;
109 template <
typename,
typename>
111 template <
typename T,
typename T_key,
typename T_container>
113 template <
typename T>
120 friend void debug::printDirty(
Series const &);
128 std::shared_ptr<Data_t> m_attri;
150 template <
typename T>
152 bool setAttribute(std::string
const &key,
char const value[]);
216 void seriesFlush(std::string backendConfig =
"{}");
226 std::string directory;
257 Series retrieveSeries()
const;
314 template <
typename T>
337 template <
typename T>
348 AbstractIOHandler
const *IOHandler()
const
350 auto &opt = m_attri->m_writable.IOHandler;
351 if (!opt || !opt->has_value())
355 return &*opt->value();
359 return m_attri->m_writable.parent;
361 Writable
const *parent()
const
363 return m_attri->m_writable.parent;
367 return m_attri->m_writable;
369 Writable
const &writable()
const
371 return m_attri->m_writable;
374 inline void setData(std::shared_ptr<internal::AttributableData> attri)
376 m_attri = std::move(attri);
379 inline internal::AttributableData &get()
383 inline internal::AttributableData
const &get()
const
398 void setDirty(
bool dirty_in)
400 auto &w = writable();
401 w.dirtySelf = dirty_in;
402 setDirtyRecursive(dirty_in);
420 void setDirtyRecursive(
bool dirty_in)
422 auto &w = writable();
423 w.dirtyRecursive = dirty_in;
426 auto current = w.parent;
427 while (current && !current->dirtyRecursive)
429 current->dirtyRecursive =
true;
430 current = current->parent;
449 virtual void linkHierarchy(Writable &w);
454 template <
typename T>
463 "Attribute",
"can not be set (read-only).");
464 error::throwNoSuchAttribute(out_of_range_msg(key));
468 auto it = attri.m_attributes.lower_bound(key);
469 if (it != attri.m_attributes.end() &&
470 !attri.m_attributes.key_comp()(key, it->first))
473 it->second =
Attribute(std::move(value));
479 attri.m_attributes.emplace_hint(
480 it, std::make_pair(key,
Attribute(std::move(value))));
491 template <
typename T>
495 std::is_floating_point<T>::value,
496 "Type of attribute must be floating point");
501 template <
typename T>
502 inline std::vector<T>
506 std::is_floating_point<T>::value,
507 "Type of attribute must be floating point");
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:186
Layer to manage storage of attributes associated with file objects.
Definition: Attributable.hpp:101
std::vector< T > readVectorFloatingpoint(std::string const &key) const
Retrieve a vector of values of a floating point Attributes of user-defined precision with ensured typ...
Definition: Attributable.hpp:503
bool containsAttribute(std::string const &key) const
Check whether am Attribute with a given key exists.
Definition: Attributable.cpp:101
MyPath myPath() const
The path to this object within its containing Series.
Definition: Attributable.cpp:221
ReadMode
Definition: Attributable.hpp:275
@ FullyReread
Remove all attributes that have been read previously and read everything that the backend currently h...
Definition: Attributable.hpp:290
@ IgnoreExisting
Don't read an attribute from the backend if it has been previously read.
Definition: Attributable.hpp:280
@ OverrideExisting
Read all the attributes that the backend has to offer and override if it has been read previously.
Definition: Attributable.hpp:285
std::vector< std::string > attributes() const
List all currently stored Attributes' keys.
Definition: Attributable.cpp:85
Attribute getAttribute(std::string const &key) const
Retrieve value of Attribute stored with provided key.
Definition: Attributable.cpp:55
void seriesFlush(std::string backendConfig="{}")
Flush the corresponding Series object.
Definition: Attributable.cpp:118
bool dirtyRecursive() const
O(1).
Definition: Attributable.hpp:394
T readFloatingpoint(std::string const &key) const
Retrieve the value of a floating point Attribute of user-defined precision with ensured type-safety.
Definition: Attributable.hpp:492
size_t numAttributes() const
Count all currently stored Attributes.
Definition: Attributable.cpp:96
bool deleteAttribute(std::string const &key)
Remove Attribute of provided value both logically and physically.
Definition: Attributable.cpp:65
bool setAttribute(std::string const &key, T value)
Populate Attribute of provided name with provided value.
Definition: Attributable.hpp:455
Attributable & setComment(std::string const &comment)
Populate Attribute corresponding to a comment with the user-supplied comment.
Definition: Attributable.cpp:112
std::string comment() const
Retrieve a user-supplied comment associated with the object.
Definition: Attributable.cpp:107
Iteration const & containingIteration() const
Returns the corresponding Iteration.
Definition: Attributable.cpp:147
Variant datatype supporting at least all formats for attributes specified in the openPMD standard.
Definition: Attribute.hpp:56
U get() const
Retrieve a stored specific Attribute and cast if convertible.
Definition: Attribute.hpp:316
Base class for any type of record (e.g.
Definition: BaseRecord.hpp:224
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:104
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:127
Implementation for the root level of the openPMD hierarchy.
Definition: Series.hpp:219
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:75
bool written
Whether a Writable has been written to the backend.
Definition: Writable.hpp:184
bool dirtyRecursive
Tracks if there are unwritten changes anywhere in the tree whose ancestor this Writable is.
Definition: Writable.hpp:163
bool dirtySelf
Tracks if there are unwritten changes for this specific Writable.
Definition: Writable.hpp:150
Writing side of the streaming API.
Definition: WriteIterations.hpp:67
Return an error string for read-only access.
Definition: OutOfRangeMsg.hpp:37
Definition: Attributable.hpp:57
Writable m_writable
The Writable associated with this Attributable.
Definition: Attributable.hpp:75
Definition: BaseRecord.hpp:52
Definition: RecordComponent.hpp:58
@ Default
Mutability of objects in the openPMD object model is determined by the open mode (Access enum),...
Public definitions of openPMD-api.
Definition: Date.cpp:29
Access
File access mode to use during IO.
Definition: Access.hpp:30
@ READ_ONLY
Open Series as read-only, fails if Series is not found.
String serialization to describe an Attributable.
Definition: Attributable.hpp:225
std::string filePath() const
Reconstructs a path that can be passed to a Series constructor.
Definition: Attributable.cpp:196
std::string seriesName
e.g., samples/git-samples/
Definition: Attributable.hpp:227
std::string seriesExtension
e.g., dataT
Definition: Attributable.hpp:228
std::vector< std::string > group
e.g., .bp, .h5, .json, ...
Definition: Attributable.hpp:237
std::string openPMDPath() const
Return the path ob the object within the openPMD file.
Definition: Attributable.cpp:201
Definition: Attributable.hpp:125
Parameters recursively passed through the openPMD hierarchy when flushing.
Definition: AbstractIOHandler.hpp:86
Container Element Creation Policy.
Definition: Container.hpp:52