Skip to content

Commit

Permalink
[wip] partially working implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Feb 21, 2022
1 parent e9bfbea commit 54b5810
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 16 deletions.
2 changes: 1 addition & 1 deletion include/openPMD/backend/Attributable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Attributable
template <typename T_elem, typename T_RecordComponent>
friend class BaseRecord;
template <typename T_elem> friend class BaseRecordInterface;
template <typename> friend class internal::BaseRecordData;
template <typename, typename> friend class internal::BaseRecordData;
template <
typename T,
typename T_key,
Expand Down
33 changes: 27 additions & 6 deletions include/openPMD/backend/BaseRecord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ class BaseRecord
using iterator = typename T_container::iterator;
using const_iterator = typename T_container::const_iterator;

// this avoids object slicing
operator T_RecordComponent() const
{
return {m_baseRecordData};
}

virtual ~BaseRecord() = default;

mapped_type &operator[](key_type const &key) override;
Expand Down Expand Up @@ -176,6 +182,8 @@ class BaseRecord
protected:
void readBase();

void datasetDefined() override;

private:
void flush(std::string const &) final;
virtual void flush_impl(std::string const &) = 0;
Expand Down Expand Up @@ -235,12 +243,11 @@ BaseRecord<T_elem, T_RecordComponent>::operator[](key_type const &key)
"A scalar component can not be contained at "
"the same time as one or more regular components.");

mapped_type &ret = T_container::operator[](key);
if (keyScalar)
{
get().m_containsScalar = true;
ret.parent() = this->parent();
datasetDefined();
}
mapped_type &ret = keyScalar ? *this : T_container::operator[](key);
return ret;
}
}
Expand All @@ -261,12 +268,12 @@ inline auto BaseRecord<T_elem, T_RecordComponent>::operator[](key_type &&key)
"A scalar component can not be contained at "
"the same time as one or more regular components.");

mapped_type &ret = T_container::operator[](std::move(key));
if (keyScalar)
{
get().m_containsScalar = true;
ret.parent() = this->parent();
datasetDefined();
}
mapped_type &ret =
keyScalar ? *this : T_container::operator[](std::move(key));
return ret;
}
}
Expand Down Expand Up @@ -421,4 +428,18 @@ inline bool BaseRecord<T_elem, T_RecordComponent>::dirtyRecursive() const
}
return false;
}

template <typename T_elem, typename T_RecordComponent>
void BaseRecord<T_elem, T_RecordComponent>::datasetDefined()
{
// If the RecordComponent API of this object has been used, then the record
// is a scalar one
T_container::emplace(
RecordComponent::SCALAR,
// need to construct it in this line already, construction inside
// emplace is impossible due to private constructors
T_RecordComponent{m_baseRecordData});
get().m_containsScalar = true;
T_RecordComponent::datasetDefined();
}
} // namespace openPMD
2 changes: 2 additions & 0 deletions include/openPMD/backend/BaseRecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class BaseRecordComponent : public Attributable

BaseRecordComponent(std::shared_ptr<internal::BaseRecordComponentData>);

virtual void datasetDefined();

private:
BaseRecordComponent();
}; // BaseRecordComponent
Expand Down
3 changes: 3 additions & 0 deletions include/openPMD/backend/MeshRecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class MeshRecordComponent : public RecordComponent
* @return A reference to this RecordComponent.
*/
template <typename T> MeshRecordComponent &makeConstant(T);

protected:
void datasetDefined() override;
};

template <typename T> std::vector<T> MeshRecordComponent::position() const
Expand Down
6 changes: 0 additions & 6 deletions src/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,8 @@ void Mesh::flush_impl(std::string const &name)
if (scalar())
{
MeshRecordComponent &mrc = at(RecordComponent::SCALAR);
mrc.parent() = parent();
mrc.flush(name);
IOHandler()->flush();
writable().abstractFilePosition =
mrc.writable().abstractFilePosition;
written() = true;
}
else
{
Expand All @@ -248,8 +244,6 @@ void Mesh::flush_impl(std::string const &name)
for (auto &comp : *this)
{
comp.second.flush(name);
writable().abstractFilePosition =
comp.second.writable().abstractFilePosition;
}
}
else
Expand Down
3 changes: 3 additions & 0 deletions src/RecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ RecordComponent &RecordComponent::resetDataset(Dataset d)
throw error::WrongAPIUsage(
"[RecordComponent] Must set specific datatype.");
}

datasetDefined();
// if( d.extent.empty() )
// throw std::runtime_error("Dataset extent must be at least 1D.");
if (std::any_of(
Expand Down Expand Up @@ -176,6 +178,7 @@ RecordComponent &RecordComponent::makeEmpty(Dataset d)
if (rc.m_dataset.extent.size() == 0)
throw std::runtime_error("Dataset extent must be at least 1D.");

datasetDefined();
rc.m_isEmpty = true;
dirty() = true;
if (!written())
Expand Down
4 changes: 4 additions & 0 deletions src/backend/BaseRecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ BaseRecordComponent &BaseRecordComponent::resetDatatype(Datatype d)
"A Records Datatype can not (yet) be changed after it has been "
"written.");

datasetDefined();
get().m_dataset.dtype = d;
return *this;
}
Expand Down Expand Up @@ -74,4 +75,7 @@ BaseRecordComponent::BaseRecordComponent() : Attributable{nullptr}
{
Attributable::setData(m_baseRecordComponentData);
}

void BaseRecordComponent::datasetDefined()
{}
} // namespace openPMD
10 changes: 7 additions & 3 deletions src/backend/MeshRecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
namespace openPMD
{
MeshRecordComponent::MeshRecordComponent() : RecordComponent()
{
setPosition(std::vector<double>{0});
}
{}

void MeshRecordComponent::read()
{
Expand Down Expand Up @@ -61,6 +59,12 @@ MeshRecordComponent &MeshRecordComponent::setPosition(std::vector<T> pos)
return *this;
}

void MeshRecordComponent::datasetDefined()
{
setPosition(std::vector<double>{0});
RecordComponent::datasetDefined();
}

template MeshRecordComponent &
MeshRecordComponent::setPosition(std::vector<float> pos);
template MeshRecordComponent &
Expand Down
1 change: 1 addition & 0 deletions src/backend/PatchRecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ PatchRecordComponent &PatchRecordComponent::resetDataset(Dataset d)
throw std::runtime_error(
"Dataset extent must not be zero in any dimension.");

datasetDefined();
get().m_dataset = d;
dirty() = true;
return *this;
Expand Down

0 comments on commit 54b5810

Please sign in to comment.