Skip to content

Commit

Permalink
Some testing and some edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Feb 24, 2021
1 parent 19ddf9a commit 730ea77
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 18 deletions.
66 changes: 50 additions & 16 deletions src/RecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ RecordComponent::resetDataset( Dataset d )
{
if( written() )
{
if( d.dtype != m_dataset->dtype )
if( d.dtype == Datatype::UNDEFINED )
{
d.dtype = m_dataset->dtype;
}
else if( d.dtype != m_dataset->dtype )
{
throw std::runtime_error(
"Cannot change the datatype of a dataset." );
Expand All @@ -70,6 +74,8 @@ RecordComponent::resetDataset( Dataset d )
* written().
*/
return makeEmpty( std::move( d ) );
else
*m_isEmpty = false;

*m_dataset = std::move( d );
dirty() = true;
Expand Down Expand Up @@ -118,20 +124,36 @@ RecordComponent&
RecordComponent::makeEmpty( Dataset d )
{
if( written() )
throw std::runtime_error(
"A RecordComponent cannot (yet) be made"
" empty after it has been written.");
{
if( !constant() )
{
throw std::runtime_error(
"An empty record component's extent can only be changed"
" in case it has been initialized as an empty or constant"
" record component." );
}
if( d.dtype == Datatype::UNDEFINED )
{
d.dtype = m_dataset->dtype;
}
else if( d.dtype != m_dataset->dtype )
{
throw std::runtime_error(
"Cannot change the datatype of a dataset." );
}
*m_hasBeenExtended = true;
}
if( d.extent.size() == 0 )
throw std::runtime_error("Dataset extent must be at least 1D.");
throw std::runtime_error( "Dataset extent must be at least 1D." );

*m_isEmpty = true;
*m_dataset = std::move(d);
*m_dataset = std::move( d );
dirty() = true;
static detail::DefaultValue< RecordComponent > dv;
switchType(
m_dataset->dtype,
dv,
*this );
if( !written() )
{
static detail::DefaultValue< RecordComponent > dv;
switchType( m_dataset->dtype, dv, *this );
}
return *this;
}

Expand Down Expand Up @@ -186,15 +208,27 @@ RecordComponent::flush(std::string const& name)

if( *m_hasBeenExtended )
{
Parameter< Operation::EXTEND_DATASET > pExtend;
pExtend.extent = m_dataset->extent;
IOHandler->enqueue( IOTask( this, std::move( pExtend ) ) );
*m_hasBeenExtended = false;
if( constant() )
{
Parameter< Operation::WRITE_ATT > aWrite;
aWrite.name = "shape";
Attribute a( getExtent() );
aWrite.dtype = a.dtype;
aWrite.resource = a.getResource();
IOHandler->enqueue( IOTask( this, aWrite ) );
}
else
{
Parameter< Operation::EXTEND_DATASET > pExtend;
pExtend.extent = m_dataset->extent;
IOHandler->enqueue( IOTask( this, std::move( pExtend ) ) );
*m_hasBeenExtended = false;
}
}

while( !m_chunks->empty() )
{
IOHandler->enqueue(m_chunks->front());
IOHandler->enqueue( m_chunks->front() );
m_chunks->pop();
}

Expand Down
90 changes: 88 additions & 2 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3331,15 +3331,84 @@ extendDataset( std::string const & ext )
// dataset resizing unsupported in ADIOS1
return;
}
auto E_x = write.iterations[ 0 ].meshes[ "E" ][ "x" ];
Dataset ds1{ Datatype::INT, { 5, 5 } };
Dataset ds2{ Datatype::INT, { 10, 5 } };

// array record component -> array record component
// should work
auto E_x = write.iterations[ 0 ].meshes[ "E" ][ "x" ];
E_x.resetDataset( ds1 );
E_x.storeChunk( data1, { 0, 0 }, { 5, 5 } );
write.flush();

E_x.resetDataset( ds2 );
E_x.storeChunk( data2, { 5, 0 }, { 5, 5 } );

// constant record component -> constant record component
// should work
auto E_y = write.iterations[ 0 ].meshes[ "E" ][ "y" ];
E_y.resetDataset( ds1 );
E_y.makeConstant( 10 );
write.flush();

E_y.resetDataset( ds2 );
write.flush();

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

E_z.makeEmpty< int >( 3 );
write.flush();

// empty record component -> empty record component
// (created by resetDataset)
// should work
auto E_a = write.iterations[ 0 ].meshes[ "E" ][ "a" ];
E_a.makeEmpty< int >( 5 );
write.flush();

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

// constant record component -> empty record component
// should work
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();

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

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

// array record component -> constant record component
// should fail
auto E_d = write.iterations[ 0 ].meshes[ "E" ][ "d" ];
E_d.resetDataset( ds1 );
E_d.storeChunk( data1, { 0, 0 }, { 5, 5 } );
write.flush();

REQUIRE_THROWS( E_d.makeConstant( 5 ) );

// array record component -> empty record component
// should fail
auto E_e = write.iterations[ 0 ].meshes[ "E" ][ "e" ];
E_e.resetDataset( ds1 );
E_e.storeChunk( data1, { 0, 0 }, { 5, 5 } );
write.flush();

REQUIRE_THROWS( E_e.makeEmpty< int >( 5 ) );
}

{
Expand All @@ -3353,14 +3422,31 @@ extendDataset( std::string const & ext )
{
REQUIRE( chunk.get()[ i ] == i );
}

auto E_y = read.iterations[ 0 ].meshes[ "E" ][ "y" ];
REQUIRE( E_y.getExtent() == Extent{ 10, 5 } );

auto E_z = read.iterations[ 0 ].meshes[ "E" ][ "z" ];
REQUIRE( E_z.getExtent() == Extent{ 0, 0, 0 } );

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() );

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

TEST_CASE( "extend_dataset", "[serial]" )
{
extendDataset( "json" );
#if openPMD_HAVE_ADIOS2
extendDataset( "bp" );
// extendDataset( "bp" );
#endif
#if openPMD_HAVE_HDF5
// extendDataset( "h5" );
Expand Down

0 comments on commit 730ea77

Please sign in to comment.