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;
72 using A_MAP = std::map<std::string, Attribute>;
83 auto *
self =
dynamic_cast<typename T::Data_t *
>(
this);
86 if constexpr (std::is_same_v<Series, T>)
88 throw std::runtime_error(
89 "[Attributable::retrieveSeries] Error when trying to "
90 "retrieve the Series object. Note: An instance of the "
91 "Series object must still exist when flushing. A "
92 "common cause for this error is using a flush call on "
93 "a handle (e.g. `Iteration::seriesFlush()`) when the "
94 "original Series object has already gone out of "
99 throw std::runtime_error(
101 "[AttributableData::asInternalCopyOf<T>] Error when "
102 "trying to retrieve a containing object. Note: An "
103 "instance of the Series object must still exist when "
104 "flushing. A common cause for this error is using a "
105 "flush call on a handle (e.g. "
106 "`Iteration::seriesFlush()`) when the original Series "
107 "object has already gone out of scope.");
112 std::shared_ptr<typename T::Data_t>(
self, [](
auto const *) {}));
123 template <
typename,
typename>
124 class BaseRecordData;
126 class RecordComponentData;
140 template <
typename T>
141 T &makeOwning(T &
self,
Series);
146 void printDirty(Series
const &);
157 using A_MAP = std::map<std::string, Attribute>;
159 template <
typename T_elem>
161 template <
typename T_elem>
162 friend class BaseRecordInterface;
163 template <
typename,
typename>
165 template <
typename T,
typename T_key,
typename T_container>
167 template <
typename T>
174 friend void debug::printDirty(
Series const &);
175 template <
typename T>
176 friend T &internal::makeOwning(
T &
self,
Series);
184 std::shared_ptr<Data_t> m_attri;
206 template <
typename T>
208 bool setAttribute(std::string
const &key,
char const value[]);
274 void seriesFlush(std::string backendConfig =
"{}");
298 std::string directory;
335 Series retrieveSeries()
const;
345 std::optional<internal::IterationData const *>,
346 internal::SeriesData const *>;
348 pair<std::optional<internal::IterationData *>, internal::SeriesData *>;
351 template <
bool flush_entire_series>
352 void seriesFlush_impl(internal::FlushParams const &);
354 void flushAttributes(internal::FlushParams const &);
396 template <
typename T>
419 template <
typename T>
430 AbstractIOHandler
const *IOHandler()
const
432 auto &opt = m_attri->m_writable.IOHandler;
433 if (!opt || !opt->has_value())
437 return &*opt->value();
441 return m_attri->m_writable.parent;
443 Writable
const *parent()
const
445 return m_attri->m_writable.parent;
449 return m_attri->m_writable;
451 Writable
const &writable()
const
453 return m_attri->m_writable;
456 inline void setData(std::shared_ptr<internal::AttributableData> attri)
458 m_attri = std::move(attri);
461 inline internal::AttributableData &get()
465 inline internal::AttributableData
const &get()
const
480 void setDirty(
bool dirty_in)
482 auto &w = writable();
483 w.dirtySelf = dirty_in;
484 setDirtyRecursive(dirty_in);
502 void setDirtyRecursive(
bool dirty_in)
504 auto &w = writable();
505 w.dirtyRecursive = dirty_in;
508 auto current = w.parent;
509 while (current && !current->dirtyRecursive)
511 current->dirtyRecursive =
true;
512 current = current->parent;
520 enum class EnqueueAsynchronously : bool
535 void setWritten(
bool val, EnqueueAsynchronously);
543 virtual void linkHierarchy(Writable &w);
548 template <
typename T>
557 "Attribute",
"can not be set (read-only).");
558 error::throwNoSuchAttribute(out_of_range_msg(key));
562 auto it = attri.m_attributes.lower_bound(key);
563 if (it != attri.m_attributes.end() &&
564 !attri.m_attributes.key_comp()(key, it->first))
567 it->second =
Attribute(std::move(value));
573 attri.m_attributes.emplace_hint(
574 it, std::make_pair(key,
Attribute(std::move(value))));
585 template <
typename T>
589 std::is_floating_point<T>::value,
590 "Type of attribute must be floating point");
595 template <
typename T>
596 inline std::vector<T>
600 std::is_floating_point<T>::value,
601 "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:155
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:597
bool containsAttribute(std::string const &key) const
Check whether am Attribute with a given key exists.
Definition: Attributable.cpp:104
MyPath myPath() const
The path to this object within its containing Series.
Definition: Attributable.cpp:222
ReadMode
Definition: Attributable.hpp:357
@ FullyReread
Remove all attributes that have been read previously and read everything that the backend currently h...
Definition: Attributable.hpp:372
@ IgnoreExisting
Don't read an attribute from the backend if it has been previously read.
Definition: Attributable.hpp:362
@ OverrideExisting
Read all the attributes that the backend has to offer and override if it has been read previously.
Definition: Attributable.hpp:367
std::vector< std::string > attributes() const
List all currently stored Attributes' keys.
Definition: Attributable.cpp:88
Attribute getAttribute(std::string const &key) const
Retrieve value of Attribute stored with provided key.
Definition: Attributable.cpp:58
void seriesFlush(std::string backendConfig="{}")
Flush the corresponding Series object.
Definition: Attributable.cpp:121
bool dirtyRecursive() const
O(1).
Definition: Attributable.hpp:476
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:586
size_t numAttributes() const
Count all currently stored Attributes.
Definition: Attributable.cpp:99
bool deleteAttribute(std::string const &key)
Remove Attribute of provided value both logically and physically.
Definition: Attributable.cpp:68
auto containingIteration() const -> std::pair< std::optional< internal::IterationData const * >, internal::SeriesData const * >
Returns the corresponding Iteration.
Definition: Attributable.cpp:143
bool setAttribute(std::string const &key, T value)
Populate Attribute of provided name with provided value.
Definition: Attributable.hpp:549
Attributable & setComment(std::string const &comment)
Populate Attribute corresponding to a comment with the user-supplied comment.
Definition: Attributable.cpp:115
std::string comment() const
Retrieve a user-supplied comment associated with the object.
Definition: Attributable.cpp:110
void iterationFlush(std::string backendConfig="{}")
Flush the containing Iteration.
Definition: Attributable.cpp:127
void touch()
Sets the object dirty to make internal procedures think it has been modified.
Definition: Attributable.cpp:248
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:251
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:186
bool dirtyRecursive
Tracks if there are unwritten changes anywhere in the tree whose ancestor this Writable is.
Definition: Writable.hpp:165
bool dirtySelf
Tracks if there are unwritten changes for this specific Writable.
Definition: Writable.hpp:152
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:60
Writable m_writable
The Writable associated with this Attributable.
Definition: Attributable.hpp:78
Definition: BaseRecord.hpp:52
Definition: RecordComponent.hpp:59
@ 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:297
std::string filePath() const
Reconstructs a path that can be passed to a Series constructor.
Definition: Attributable.cpp:197
std::string seriesName
e.g., samples/git-samples/
Definition: Attributable.hpp:299
std::string seriesExtension
e.g., dataT
Definition: Attributable.hpp:300
std::vector< std::string > group
e.g., .bp, .h5, .json, ...
Definition: Attributable.hpp:309
std::string openPMDPath() const
Return the path ob the object within the openPMD file.
Definition: Attributable.cpp:202
Definition: Attributable.hpp:181
Container Element Creation Policy.
Definition: Container.hpp:52