Skip to content

Commit

Permalink
Some documentation and disallow shrinking or changing the dimensionality
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Dec 15, 2020
1 parent ab8b2a2 commit 6246456
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 16 deletions.
8 changes: 8 additions & 0 deletions include/openPMD/Dataset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ class Dataset
public:
Dataset(Datatype, Extent);

/**
* @brief Constructor that sets the datatype to undefined.
*
* Helpful for resizing datasets, since datatypes need not be given twice.
*
*/
Dataset( Extent );

Dataset& extend(Extent newExtent);
Dataset& setChunkSize(Extent const&);
Dataset& setCompression(std::string const&, uint8_t const);
Expand Down
21 changes: 20 additions & 1 deletion include/openPMD/RecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,26 @@ class RecordComponent : public BaseRecordComponent

RecordComponent& setUnitSI(double);

RecordComponent& resetDataset(Dataset);
/**
* @brief Declare the dataset's type and extent.
*
* Calling this again after flushing will require resizing the dataset.
* Support for this depends on the backend.
* Unsupported are:
* * Changing the datatype.
* * Shrinking any dimension's extent.
* * Changing the number of dimensions.
*
* Backend support for resizing datasets:
* * JSON: Supported
* * ADIOS1: Unsupported
* * ADIOS2: (Currently) unsupported
* * HDF5: (Currently) unsupported.
* Will be probably supported as soon as chunking is supported in HDF5.
*
* @return RecordComponent&
*/
RecordComponent & resetDataset( Dataset );

uint8_t getDimensionality() const;
Extent getExtent() const;
Expand Down
8 changes: 6 additions & 2 deletions src/Dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ Dataset::Dataset(Datatype d, Extent e)
chunkSize{e}
{ }

Dataset&
Dataset::extend(Extent newExtents)
Dataset::Dataset( Extent e ) : Dataset( Datatype::UNDEFINED, std::move( e ) )
{
}

Dataset &
Dataset::extend( Extent newExtents )
{
if( newExtents.size() != rank )
throw std::runtime_error("Dimensionality of extended Dataset must match the original dimensionality");
Expand Down
20 changes: 17 additions & 3 deletions src/RecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,16 @@ RecordComponent::resetDataset( Dataset d )
else
*m_isEmpty = false;

*m_dataset = std::move( d );
if( written() )
{
m_dataset->extend( std::move( d.extent ) );
}
else
{
*m_dataset = std::move( d );
}


dirty() = true;
return *this;
}
Expand Down Expand Up @@ -141,13 +150,18 @@ RecordComponent::makeEmpty( Dataset d )
throw std::runtime_error(
"Cannot change the datatype of a dataset." );
}
m_dataset->extend( std::move( d.extent ) );
*m_hasBeenExtended = true;
}
if( d.extent.size() == 0 )
else
{
*m_dataset = std::move( d );
}

if( m_dataset->extent.size() == 0 )
throw std::runtime_error( "Dataset extent must be at least 1D." );

*m_isEmpty = true;
*m_dataset = std::move( d );
dirty() = true;
if( !written() )
{
Expand Down
19 changes: 9 additions & 10 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2970,8 +2970,10 @@ extendDataset( std::string const & ext )

// empty record component -> empty record component
// should work
// this does not make a lot of sense since we don't allow shrinking,
// but let's just reset it to itself
auto E_z = write.iterations[ 0 ].meshes[ "E" ][ "z" ];
E_z.makeEmpty< int >( 5 );
E_z.makeEmpty< int >( 3 );
write.flush();

E_z.makeEmpty< int >( 3 );
Expand All @@ -2981,29 +2983,28 @@ extendDataset( std::string const & ext )
// (created by resetDataset)
// should work
auto E_a = write.iterations[ 0 ].meshes[ "E" ][ "a" ];
E_a.makeEmpty< int >( 5 );
E_a.makeEmpty< int >( 3 );
write.flush();

E_a.resetDataset( Dataset( Datatype::UNDEFINED, { 0, 1, 2 } ) );
write.flush();

// constant record component -> empty record component
// should work
// should fail, since this implies shrinking
auto E_b = write.iterations[ 0 ].meshes[ "E" ][ "b" ];
E_b.resetDataset( ds1 );
E_b.makeConstant( 10 );
write.flush();

E_b.makeEmpty< int >( 3 );
write.flush();
REQUIRE_THROWS( E_b.makeEmpty< int >( 2 ) );

// empty record component -> constant record component
// should work
auto E_c = write.iterations[ 0 ].meshes[ "E" ][ "c" ];
E_c.makeEmpty< int >( 5 );
E_c.makeEmpty< int >( 3 );
write.flush();

E_c.resetDataset( Dataset( Datatype::UNDEFINED, { 1, 1, 2 } ) );
E_c.resetDataset( Dataset( { 1, 1, 2 } ) );
write.flush();

// array record component -> constant record component
Expand Down Expand Up @@ -3046,9 +3047,7 @@ extendDataset( std::string const & ext )
auto E_a = read.iterations[ 0 ].meshes[ "E" ][ "a" ];
REQUIRE( E_a.getExtent() == Extent{ 0, 1, 2 } );

auto E_b = read.iterations[ 0 ].meshes[ "E" ][ "b" ];
REQUIRE( E_b.getExtent() == Extent{ 0, 0, 0 } );
REQUIRE( E_b.empty() );
// E_b could not be changed

auto E_c = read.iterations[ 0 ].meshes[ "E" ][ "c" ];
REQUIRE( E_c.getExtent() == Extent{ 1, 1, 2 } );
Expand Down

0 comments on commit 6246456

Please sign in to comment.