23 #include "openPMD/Error.hpp"
24 #include "openPMD/IO/AbstractIOHandler.hpp"
25 #include "openPMD/ThrowError.hpp"
26 #include "openPMD/auxiliary/OutOfRangeMsg.hpp"
27 #include "openPMD/backend/Attribute.hpp"
28 #include "openPMD/backend/HierarchyVisitor.hpp"
29 #include "openPMD/backend/Writable.hpp"
36 #include <type_traits>
40 #ifndef OPENPMD_protected
41 #define OPENPMD_protected protected:
49 struct GenerationPolicy;
51 class AbstractFilePosition;
60 struct HomogenizeExtents;
61 struct ConfigAttribute;
62 class ScientificDefaults;
78 using A_MAP = std::map<std::string, Attribute>;
113 using SharedData_t = std::shared_ptr<SharedAttributableData>;
114 using A_MAP = SharedData_t::element_type::A_MAP;
130 template <
typename T>
133 auto *
self =
dynamic_cast<typename T::Data_t *
>(
this);
136 if constexpr (std::is_same_v<Series, T>)
138 throw std::runtime_error(
139 "[Attributable::retrieveSeries] Error when trying to "
140 "retrieve the Series object. Note: An instance of the "
141 "Series object must still exist when flushing. A "
142 "common cause for this error is using a flush call on "
143 "a handle (e.g. `Iteration::seriesFlush()`) when the "
144 "original Series object has already gone out of "
149 throw std::runtime_error(
151 "[AttributableData::asInternalCopyOf<T>] Error when "
152 "trying to retrieve a containing object. Note: An "
153 "instance of the Series object must still exist when "
154 "flushing. A common cause for this error is using a "
155 "flush call on a handle (e.g. "
156 "`Iteration::seriesFlush()`) when the original Series "
157 "object has already gone out of scope.");
162 std::shared_ptr<typename T::Data_t>(
self, [](
auto const *) {}));
168 return operator*().m_attributes;
170 [[nodiscard]]
inline auto attributes()
const -> A_MAP
const &
172 return operator*().m_attributes;
174 [[nodiscard]]
inline auto readAttribute(std::string
const &name)
const
178 if (
auto it = attr.find(name); it != attr.end())
185 error::AffectedObject::Attribute,
186 error::Reason::NotFound,
188 "Not found: '" + name +
"'.");
193 template <
typename,
typename>
210 template <
typename T>
211 T &makeOwning(T &
self,
Series);
216 void printDirty(
Series const &);
227 using A_MAP = std::map<std::string, Attribute>;
229 template <
typename T_elem>
231 template <
typename T_elem>
232 friend class BaseRecordInterface;
233 template <
typename,
typename>
235 template <
typename T,
typename T_key,
typename T_container>
237 template <
typename T>
243 friend void debug::printDirty(
Series const &);
244 template <
typename T>
245 friend T &internal::makeOwning(
T &
self,
Series);
259 std::shared_ptr<Data_t> m_attri;
281 template <
typename T>
283 bool setAttribute(std::string
const &key,
char const value[]);
350 void seriesFlush(std::string backendConfig =
"{}");
374 std::string directory;
434 template <
typename Lambda>
458 [[nodiscard]] OpenpmdStandard openPMDStandard()
const;
464 Series retrieveSeries()
const;
474 std::optional<internal::IterationData const *>,
475 internal::SeriesData const *>;
477 pair<std::optional<internal::IterationData *>, internal::SeriesData *>;
480 template <
bool flush_entire_series>
481 void seriesFlush_impl(internal::FlushParams const &);
483 void flushAttributes(internal::FlushParams const &);
525 template <
typename T>
548 template <
typename T>
559 AbstractIOHandler
const *IOHandler()
const
561 auto &opt = writable().IOHandler;
562 if (!opt || !opt->has_value())
566 return &*opt->value();
570 return writable().parent;
572 Writable
const *parent()
const
574 return writable().parent;
578 return (*m_attri)->m_writable;
580 Writable
const &writable()
const
582 return (*m_attri)->m_writable;
585 inline void setData(std::shared_ptr<internal::AttributableData> attri)
587 m_attri = std::move(attri);
590 inline internal::SharedAttributableData &get()
594 inline internal::SharedAttributableData
const &get()
const
609 void setDirty(
bool dirty_in)
611 auto &w = writable();
612 w.dirtySelf = dirty_in;
613 setDirtyRecursive(dirty_in);
631 void setDirtyRecursive(
bool dirty_in)
633 auto &w = writable();
634 w.dirtyRecursive = dirty_in;
637 auto current = w.parent;
638 while (current && !current->dirtyRecursive)
640 current->dirtyRecursive =
true;
641 current = current->parent;
649 enum class EnqueueAsynchronously : uint8_t
665 void setWritten(
bool val, EnqueueAsynchronously);
673 virtual void linkHierarchy(Writable &w);
678 template <
typename T>
683 IOHandler()->m_seriesStatus == internal::SeriesStatus::Default &&
684 Access::READ_ONLY == IOHandler()->m_frontendAccess)
687 "Attribute",
"can not be set (read-only).");
688 error::throwNoSuchAttribute(out_of_range_msg(key));
692 auto it = attri.m_attributes.lower_bound(key);
693 if (it != attri.m_attributes.end() &&
694 !attri.m_attributes.key_comp()(key, it->first))
697 it->second =
Attribute(std::move(value));
703 attri.m_attributes.emplace_hint(
704 it, std::make_pair(key,
Attribute(std::move(value))));
715 template <
typename T>
719 std::is_floating_point<T>::value,
720 "Type of attribute must be floating point");
725 template <
typename T>
726 inline std::vector<T>
730 std::is_floating_point<T>::value,
731 "Type of attribute must be floating point");
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:206
Layer to manage storage of attributes associated with file objects.
Definition: Attributable.hpp:225
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:727
bool containsAttribute(std::string const &key) const
Check whether am Attribute with a given key exists.
Definition: Attributable.cpp:153
MyPath myPath() const
The path to this object within its containing Series.
Definition: Attributable.cpp:268
void populateMissingMetadata(bool recursive)
Create standard defined attributes with default values now, insofar they are still missing.
Definition: Attributable.cpp:306
ReadMode
Definition: Attributable.hpp:486
@ FullyReread
Remove all attributes that have been read previously and read everything that the backend currently h...
Definition: Attributable.hpp:501
@ IgnoreExisting
Don't read an attribute from the backend if it has been previously read.
Definition: Attributable.hpp:491
@ OverrideExisting
Read all the attributes that the backend has to offer and override if it has been read previously.
Definition: Attributable.hpp:496
std::vector< std::string > attributes() const
List all currently stored Attributes' keys.
Definition: Attributable.cpp:137
Attribute getAttribute(std::string const &key) const
Retrieve value of Attribute stored with provided key.
Definition: Attributable.cpp:107
void seriesFlush(std::string backendConfig="{}")
Flush the corresponding Series object.
Definition: Attributable.cpp:170
bool dirtyRecursive() const
O(1).
Definition: Attributable.hpp:605
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:716
size_t numAttributes() const
Count all currently stored Attributes.
Definition: Attributable.cpp:148
bool deleteAttribute(std::string const &key)
Remove Attribute of provided value both logically and physically.
Definition: Attributable.cpp:117
auto containingIteration() const -> std::pair< std::optional< internal::IterationData const * >, internal::SeriesData const * >
Returns the corresponding Iteration.
Definition: Attributable.cpp:192
bool setAttribute(std::string const &key, T value)
Populate Attribute of provided name with provided value.
Definition: Attributable.hpp:679
Attributable & setComment(std::string const &comment)
Populate Attribute corresponding to a comment with the user-supplied comment.
Definition: Attributable.cpp:164
std::string comment() const
Retrieve a user-supplied comment associated with the object.
Definition: Attributable.cpp:159
void iterationFlush(std::string backendConfig="{}")
Flush the containing Iteration.
Definition: Attributable.cpp:176
void touch()
Sets the object dirty to make internal procedures think it has been modified.
Definition: Attributable.cpp:295
void visitHierarchyFromLambda(Lambda &&lambda, bool recursive)
Visitor pattern for the openPMD object hierarchy in postfix traversal, lambda version.
Definition: HierarchyVisitorImpl.hpp:88
virtual void visitHierarchy(HierarchyVisitor &visitor, bool recursive)
Visitor pattern for the openPMD object hierarchy in postfix traversal.
Definition: Attributable.cpp:300
Definition: Attribute.hpp:64
U get() const
Retrieve a stored specific Attribute and cast if convertible.
Definition: Attribute.cpp:112
Base class for any type of record (e.g.
Definition: BaseRecord.hpp:186
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:106
Definition: HierarchyVisitor.hpp:20
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:172
Implementation for the root level of the openPMD hierarchy.
Definition: Series.hpp:288
Entry point for accessing Snapshots/Iterations.
Definition: Snapshots.hpp:50
Definition: ContainerImpls.hpp:36
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:77
bool written
Whether a Writable has been written to the backend.
Definition: Writable.hpp:198
bool dirtyRecursive
Tracks if there are unwritten changes anywhere in the tree whose ancestor this Writable is.
Definition: Writable.hpp:177
bool dirtySelf
Tracks if there are unwritten changes for this specific Writable.
Definition: Writable.hpp:164
Return an error string for read-only access.
Definition: OutOfRangeMsg.hpp:37
Definition: Error.hpp:112
Definition: Attributable.hpp:110
Definition: BaseRecord.hpp:54
Definition: RecordComponent.hpp:65
Definition: ScientificDefaults.hpp:23
Definition: Attributable.hpp:65
Writable m_writable
The Writable associated with this Attributable.
Definition: Attributable.hpp:84
A_MAP m_attributes
The attributes defined by this Attributable.
Definition: Attributable.hpp:89
Public definitions of openPMD-api.
Definition: Date.cpp:29
Access
File access mode to use during IO.
Definition: Access.hpp:58
String serialization to describe an Attributable.
Definition: Attributable.hpp:373
std::string filePath() const
Reconstructs a path that can be passed to a Series constructor.
Definition: Attributable.cpp:246
std::string seriesName
e.g., samples/git-samples/
Definition: Attributable.hpp:375
std::string seriesExtension
e.g., dataT
Definition: Attributable.hpp:376
std::vector< std::string > group
e.g., .bp, .h5, .json, ...
Definition: Attributable.hpp:385
std::string openPMDPath() const
Return the path ob the object within the openPMD file.
Definition: Attributable.cpp:251
Definition: Attributable.hpp:256
Definition: ConfigAttribute.hpp:18
Definition: RecordComponent.hpp:562
Container Element Creation Policy.
Definition: Container.hpp:54