From e5b23b06efe93b30ac3704160ef8f31eaa929234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Thu, 26 Nov 2020 11:57:57 +0100 Subject: [PATCH] Some testing and some edge cases --- src/RecordComponent.cpp | 66 +++++++++++++++++++++++++-------- test/SerialIOTest.cpp | 81 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 129 insertions(+), 18 deletions(-) diff --git a/src/RecordComponent.cpp b/src/RecordComponent.cpp index 35ccb3b5a5..b3f5d07edc 100644 --- a/src/RecordComponent.cpp +++ b/src/RecordComponent.cpp @@ -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." ); @@ -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; @@ -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; } @@ -185,15 +207,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(); } diff --git a/test/SerialIOTest.cpp b/test/SerialIOTest.cpp index 889d693fd3..84611f3a04 100644 --- a/test/SerialIOTest.cpp +++ b/test/SerialIOTest.cpp @@ -2899,15 +2899,75 @@ 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 ) ); } { @@ -2921,6 +2981,23 @@ 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() ); } } @@ -2928,7 +3005,7 @@ TEST_CASE( "extend_dataset", "[serial]" ) { extendDataset( "json" ); #if openPMD_HAVE_ADIOS2 - extendDataset( "bp" ); + // extendDataset( "bp" ); #endif #if openPMD_HAVE_HDF5 // extendDataset( "h5" );