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 Jan 3, 2022
1 parent 55a15c7 commit d6e1bca
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 15 deletions.
2 changes: 1 addition & 1 deletion include/openPMD/backend/Attributable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class Attributable
friend class BaseRecord;
template< typename T_elem >
friend class BaseRecordInterface;
template< typename >
template< typename, typename >
friend class internal::BaseRecordData;
template<
typename T,
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 @@ -142,6 +142,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 @@ -178,6 +184,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 @@ -238,12 +246,11 @@ BaseRecord< T_elem, T_RecordComponent >::operator[]( key_type const & key )
throw std::runtime_error("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 @@ -263,12 +270,12 @@ BaseRecord< T_elem, T_RecordComponent >::operator[](key_type&& key)
throw std::runtime_error("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 @@ -417,4 +424,18 @@ 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 @@ -133,6 +133,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 @@ -86,6 +86,9 @@ class MeshRecordComponent : public RecordComponent
*/
template< typename T >
MeshRecordComponent& makeConstant(T);

protected:
void datasetDefined() override;
};


Expand Down
5 changes: 0 additions & 5 deletions src/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,8 @@ 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
{
Parameter< Operation::CREATE_PATH > pCreate;
Expand All @@ -257,8 +254,6 @@ 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 @@ -93,6 +93,8 @@ 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 @@ -186,6 +188,7 @@ 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::resetDatatype(Datatype d)
if( written() )
throw std::runtime_error("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 @@ -79,4 +80,7 @@ BaseRecordComponent::BaseRecordComponent()
{
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 @@ -25,9 +25,7 @@ namespace openPMD
{
MeshRecordComponent::MeshRecordComponent()
: RecordComponent()
{
setPosition(std::vector< double >{0});
}
{}

void
MeshRecordComponent::read()
Expand Down Expand Up @@ -62,6 +60,12 @@ 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);
Expand Down
1 change: 1 addition & 0 deletions src/backend/PatchRecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ PatchRecordComponent::resetDataset(Dataset d)
[](Extent::value_type const& i) { return i == 0u; }) )
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 d6e1bca

Please sign in to comment.