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/Writable.hpp"
35 #include <type_traits>
39 #ifndef OPENPMD_protected
40 #define OPENPMD_protected protected:
48 struct GenerationPolicy;
50 class AbstractFilePosition;
59 struct HomogenizeExtents;
75 using A_MAP = std::map<std::string, Attribute>;
110 using SharedData_t = std::shared_ptr<SharedAttributableData>;
111 using A_MAP = SharedData_t::element_type::A_MAP;
127 template <
typename T>
130 auto *
self =
dynamic_cast<typename T::Data_t *
>(
this);
133 if constexpr (std::is_same_v<Series, T>)
135 throw std::runtime_error(
136 "[Attributable::retrieveSeries] Error when trying to "
137 "retrieve the Series object. Note: An instance of the "
138 "Series object must still exist when flushing. A "
139 "common cause for this error is using a flush call on "
140 "a handle (e.g. `Iteration::seriesFlush()`) when the "
141 "original Series object has already gone out of "
146 throw std::runtime_error(
148 "[AttributableData::asInternalCopyOf<T>] Error when "
149 "trying to retrieve a containing object. Note: An "
150 "instance of the Series object must still exist when "
151 "flushing. A common cause for this error is using a "
152 "flush call on a handle (e.g. "
153 "`Iteration::seriesFlush()`) when the original Series "
154 "object has already gone out of scope.");
159 std::shared_ptr<typename T::Data_t>(
self, [](
auto const *) {}));
165 return operator*().m_attributes;
167 [[nodiscard]]
inline auto attributes()
const -> A_MAP
const &
169 return operator*().m_attributes;
171 [[nodiscard]]
inline auto readAttribute(std::string
const &name)
const
175 if (
auto it = attr.find(name); it != attr.end())
182 error::AffectedObject::Attribute,
183 error::Reason::NotFound,
185 "Not found: '" + name +
"'.");
190 template <
typename,
typename>
207 template <
typename T>
208 T &makeOwning(T &
self,
Series);
213 void printDirty(
Series const &);
224 using A_MAP = std::map<std::string, Attribute>;
226 template <
typename T_elem>
228 template <
typename T_elem>
229 friend class BaseRecordInterface;
230 template <
typename,
typename>
232 template <
typename T,
typename T_key,
typename T_container>
234 template <
typename T>
240 friend void debug::printDirty(
Series const &);
241 template <
typename T>
242 friend T &internal::makeOwning(
T &
self,
Series);
254 std::shared_ptr<Data_t> m_attri;
276 template <
typename T>
278 bool setAttribute(std::string
const &key,
char const value[]);
344 void seriesFlush(std::string backendConfig =
"{}");
368 std::string directory;
401 [[nodiscard]] OpenpmdStandard openPMDStandard()
const;
407 Series retrieveSeries()
const;
417 std::optional<internal::IterationData const *>,
418 internal::SeriesData const *>;
420 pair<std::optional<internal::IterationData *>, internal::SeriesData *>;
423 template <
bool flush_entire_series>
424 void seriesFlush_impl(internal::FlushParams const &);
426 void flushAttributes(internal::FlushParams const &);
468 template <
typename T>
491 template <
typename T>
502 AbstractIOHandler
const *IOHandler()
const
504 auto &opt = writable().IOHandler;
505 if (!opt || !opt->has_value())
509 return &*opt->value();
513 return writable().parent;
515 Writable
const *parent()
const
517 return writable().parent;
521 return (*m_attri)->m_writable;
523 Writable
const &writable()
const
525 return (*m_attri)->m_writable;
528 inline void setData(std::shared_ptr<internal::AttributableData> attri)
530 m_attri = std::move(attri);
533 inline internal::SharedAttributableData &get()
537 inline internal::SharedAttributableData
const &get()
const
552 void setDirty(
bool dirty_in)
554 auto &w = writable();
555 w.dirtySelf = dirty_in;
556 setDirtyRecursive(dirty_in);
574 void setDirtyRecursive(
bool dirty_in)
576 auto &w = writable();
577 w.dirtyRecursive = dirty_in;
580 auto current = w.parent;
581 while (current && !current->dirtyRecursive)
583 current->dirtyRecursive =
true;
584 current = current->parent;
592 enum class EnqueueAsynchronously : bool
607 void setWritten(
bool val, EnqueueAsynchronously);
615 virtual void linkHierarchy(Writable &w);
620 template <
typename T>
625 IOHandler()->m_seriesStatus == internal::SeriesStatus::Default &&
626 Access::READ_ONLY == IOHandler()->m_frontendAccess)
629 "Attribute",
"can not be set (read-only).");
630 error::throwNoSuchAttribute(out_of_range_msg(key));
634 auto it = attri.m_attributes.lower_bound(key);
635 if (it != attri.m_attributes.end() &&
636 !attri.m_attributes.key_comp()(key, it->first))
639 it->second =
Attribute(std::move(value));
645 attri.m_attributes.emplace_hint(
646 it, std::make_pair(key,
Attribute(std::move(value))));
657 template <
typename T>
661 std::is_floating_point<T>::value,
662 "Type of attribute must be floating point");
667 template <
typename T>
668 inline std::vector<T>
672 std::is_floating_point<T>::value,
673 "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:222
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:669
bool containsAttribute(std::string const &key) const
Check whether am Attribute with a given key exists.
Definition: Attributable.cpp:121
MyPath myPath() const
The path to this object within its containing Series.
Definition: Attributable.cpp:236
ReadMode
Definition: Attributable.hpp:429
@ FullyReread
Remove all attributes that have been read previously and read everything that the backend currently h...
Definition: Attributable.hpp:444
@ IgnoreExisting
Don't read an attribute from the backend if it has been previously read.
Definition: Attributable.hpp:434
@ OverrideExisting
Read all the attributes that the backend has to offer and override if it has been read previously.
Definition: Attributable.hpp:439
std::vector< std::string > attributes() const
List all currently stored Attributes' keys.
Definition: Attributable.cpp:105
Attribute getAttribute(std::string const &key) const
Retrieve value of Attribute stored with provided key.
Definition: Attributable.cpp:75
void seriesFlush(std::string backendConfig="{}")
Flush the corresponding Series object.
Definition: Attributable.cpp:138
bool dirtyRecursive() const
O(1).
Definition: Attributable.hpp:548
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:658
size_t numAttributes() const
Count all currently stored Attributes.
Definition: Attributable.cpp:116
bool deleteAttribute(std::string const &key)
Remove Attribute of provided value both logically and physically.
Definition: Attributable.cpp:85
auto containingIteration() const -> std::pair< std::optional< internal::IterationData const * >, internal::SeriesData const * >
Returns the corresponding Iteration.
Definition: Attributable.cpp:160
bool setAttribute(std::string const &key, T value)
Populate Attribute of provided name with provided value.
Definition: Attributable.hpp:621
Attributable & setComment(std::string const &comment)
Populate Attribute corresponding to a comment with the user-supplied comment.
Definition: Attributable.cpp:132
std::string comment() const
Retrieve a user-supplied comment associated with the object.
Definition: Attributable.cpp:127
void iterationFlush(std::string backendConfig="{}")
Flush the containing Iteration.
Definition: Attributable.cpp:144
void touch()
Sets the object dirty to make internal procedures think it has been modified.
Definition: Attributable.cpp:263
Definition: Attribute.hpp:64
U get() const
Retrieve a stored specific Attribute and cast if convertible.
Definition: Attribute.cpp:105
Base class for any type of record (e.g.
Definition: BaseRecord.hpp:182
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:146
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:76
bool written
Whether a Writable has been written to the backend.
Definition: Writable.hpp:196
bool dirtyRecursive
Tracks if there are unwritten changes anywhere in the tree whose ancestor this Writable is.
Definition: Writable.hpp:175
bool dirtySelf
Tracks if there are unwritten changes for this specific Writable.
Definition: Writable.hpp:162
Return an error string for read-only access.
Definition: OutOfRangeMsg.hpp:37
Definition: Error.hpp:112
Definition: Attributable.hpp:107
Definition: BaseRecord.hpp:52
Definition: RecordComponent.hpp:63
Definition: Attributable.hpp:62
Writable m_writable
The Writable associated with this Attributable.
Definition: Attributable.hpp:81
A_MAP m_attributes
The attributes defined by this Attributable.
Definition: Attributable.hpp:86
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:367
std::string filePath() const
Reconstructs a path that can be passed to a Series constructor.
Definition: Attributable.cpp:214
std::string seriesName
e.g., samples/git-samples/
Definition: Attributable.hpp:369
std::string seriesExtension
e.g., dataT
Definition: Attributable.hpp:370
std::vector< std::string > group
e.g., .bp, .h5, .json, ...
Definition: Attributable.hpp:379
std::string openPMDPath() const
Return the path ob the object within the openPMD file.
Definition: Attributable.cpp:219
Definition: Attributable.hpp:251
Definition: RecordComponent.hpp:550
Container Element Creation Policy.
Definition: Container.hpp:52