Skip to content

Commit e5b23b0

Browse files
committed
Some testing and some edge cases
1 parent 1350671 commit e5b23b0

File tree

2 files changed

+129
-18
lines changed

2 files changed

+129
-18
lines changed

src/RecordComponent.cpp

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ RecordComponent::resetDataset( Dataset d )
5252
{
5353
if( written() )
5454
{
55-
if( d.dtype != m_dataset->dtype )
55+
if( d.dtype == Datatype::UNDEFINED )
56+
{
57+
d.dtype = m_dataset->dtype;
58+
}
59+
else if( d.dtype != m_dataset->dtype )
5660
{
5761
throw std::runtime_error(
5862
"Cannot change the datatype of a dataset." );
@@ -70,6 +74,8 @@ RecordComponent::resetDataset( Dataset d )
7074
* written().
7175
*/
7276
return makeEmpty( std::move( d ) );
77+
else
78+
*m_isEmpty = false;
7379

7480
*m_dataset = std::move( d );
7581
dirty() = true;
@@ -118,20 +124,36 @@ RecordComponent&
118124
RecordComponent::makeEmpty( Dataset d )
119125
{
120126
if( written() )
121-
throw std::runtime_error(
122-
"A RecordComponent cannot (yet) be made"
123-
" empty after it has been written.");
127+
{
128+
if( !constant() )
129+
{
130+
throw std::runtime_error(
131+
"An empty record component's extent can only be changed"
132+
" in case it has been initialized as an empty or constant"
133+
" record component." );
134+
}
135+
if( d.dtype == Datatype::UNDEFINED )
136+
{
137+
d.dtype = m_dataset->dtype;
138+
}
139+
else if( d.dtype != m_dataset->dtype )
140+
{
141+
throw std::runtime_error(
142+
"Cannot change the datatype of a dataset." );
143+
}
144+
*m_hasBeenExtended = true;
145+
}
124146
if( d.extent.size() == 0 )
125-
throw std::runtime_error("Dataset extent must be at least 1D.");
147+
throw std::runtime_error( "Dataset extent must be at least 1D." );
126148

127149
*m_isEmpty = true;
128-
*m_dataset = std::move(d);
150+
*m_dataset = std::move( d );
129151
dirty() = true;
130-
static detail::DefaultValue< RecordComponent > dv;
131-
switchType(
132-
m_dataset->dtype,
133-
dv,
134-
*this );
152+
if( !written() )
153+
{
154+
static detail::DefaultValue< RecordComponent > dv;
155+
switchType( m_dataset->dtype, dv, *this );
156+
}
135157
return *this;
136158
}
137159

@@ -185,15 +207,27 @@ RecordComponent::flush(std::string const& name)
185207

186208
if( *m_hasBeenExtended )
187209
{
188-
Parameter< Operation::EXTEND_DATASET > pExtend;
189-
pExtend.extent = m_dataset->extent;
190-
IOHandler->enqueue( IOTask( this, std::move( pExtend ) ) );
191-
*m_hasBeenExtended = false;
210+
if( constant() )
211+
{
212+
Parameter< Operation::WRITE_ATT > aWrite;
213+
aWrite.name = "shape";
214+
Attribute a( getExtent() );
215+
aWrite.dtype = a.dtype;
216+
aWrite.resource = a.getResource();
217+
IOHandler->enqueue( IOTask( this, aWrite ) );
218+
}
219+
else
220+
{
221+
Parameter< Operation::EXTEND_DATASET > pExtend;
222+
pExtend.extent = m_dataset->extent;
223+
IOHandler->enqueue( IOTask( this, std::move( pExtend ) ) );
224+
*m_hasBeenExtended = false;
225+
}
192226
}
193227

194228
while( !m_chunks->empty() )
195229
{
196-
IOHandler->enqueue(m_chunks->front());
230+
IOHandler->enqueue( m_chunks->front() );
197231
m_chunks->pop();
198232
}
199233

test/SerialIOTest.cpp

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,15 +2899,75 @@ extendDataset( std::string const & ext )
28992899
// dataset resizing unsupported in ADIOS1
29002900
return;
29012901
}
2902-
auto E_x = write.iterations[ 0 ].meshes[ "E" ][ "x" ];
29032902
Dataset ds1{ Datatype::INT, { 5, 5 } };
29042903
Dataset ds2{ Datatype::INT, { 10, 5 } };
2904+
2905+
// array record component -> array record component
2906+
// should work
2907+
auto E_x = write.iterations[ 0 ].meshes[ "E" ][ "x" ];
29052908
E_x.resetDataset( ds1 );
29062909
E_x.storeChunk( data1, { 0, 0 }, { 5, 5 } );
29072910
write.flush();
29082911

29092912
E_x.resetDataset( ds2 );
29102913
E_x.storeChunk( data2, { 5, 0 }, { 5, 5 } );
2914+
2915+
// constant record component -> constant record component
2916+
// should work
2917+
auto E_y = write.iterations[ 0 ].meshes[ "E" ][ "y" ];
2918+
E_y.resetDataset( ds1 );
2919+
E_y.makeConstant( 10 );
2920+
write.flush();
2921+
2922+
E_y.resetDataset( ds2 );
2923+
write.flush();
2924+
2925+
// empty record component -> empty record component
2926+
// should work
2927+
auto E_z = write.iterations[ 0 ].meshes[ "E" ][ "z" ];
2928+
E_z.makeEmpty< int >( 5 );
2929+
write.flush();
2930+
2931+
E_z.makeEmpty< int >( 3 );
2932+
write.flush();
2933+
2934+
// empty record component -> empty record component
2935+
// (created by resetDataset)
2936+
// should work
2937+
auto E_a = write.iterations[ 0 ].meshes[ "E" ][ "a" ];
2938+
E_a.makeEmpty< int >( 5 );
2939+
write.flush();
2940+
2941+
E_a.resetDataset( Dataset( Datatype::UNDEFINED, { 0, 1, 2 } ) );
2942+
write.flush();
2943+
2944+
// constant record component -> empty record component
2945+
// should work
2946+
auto E_b = write.iterations[ 0 ].meshes[ "E" ][ "b" ];
2947+
E_b.resetDataset( ds1 );
2948+
E_b.makeConstant( 10 );
2949+
write.flush();
2950+
2951+
E_b.makeEmpty< int >( 3 );
2952+
write.flush();
2953+
2954+
// empty record component -> constant record component
2955+
// should work
2956+
auto E_c = write.iterations[ 0 ].meshes[ "E" ][ "c" ];
2957+
E_c.makeEmpty< int >( 5 );
2958+
write.flush();
2959+
2960+
E_c.resetDataset( Dataset( Datatype::UNDEFINED, { 1, 1, 2 } ) );
2961+
write.flush();
2962+
2963+
// array record component -> constant record component
2964+
// should fail
2965+
auto E_d = write.iterations[ 0 ].meshes[ "E" ][ "d" ];
2966+
E_d.resetDataset( ds1 );
2967+
E_d.storeChunk( data1, { 0, 0 }, { 5, 5 } );
2968+
write.flush();
2969+
2970+
REQUIRE_THROWS( E_d.makeConstant( 5 ) );
29112971
}
29122972

29132973
{
@@ -2921,14 +2981,31 @@ extendDataset( std::string const & ext )
29212981
{
29222982
REQUIRE( chunk.get()[ i ] == i );
29232983
}
2984+
2985+
auto E_y = read.iterations[ 0 ].meshes[ "E" ][ "y" ];
2986+
REQUIRE( E_y.getExtent() == Extent{ 10, 5 } );
2987+
2988+
auto E_z = read.iterations[ 0 ].meshes[ "E" ][ "z" ];
2989+
REQUIRE( E_z.getExtent() == Extent{ 0, 0, 0 } );
2990+
2991+
auto E_a = read.iterations[ 0 ].meshes[ "E" ][ "a" ];
2992+
REQUIRE( E_a.getExtent() == Extent{ 0, 1, 2 } );
2993+
2994+
auto E_b = read.iterations[ 0 ].meshes[ "E" ][ "b" ];
2995+
REQUIRE( E_b.getExtent() == Extent{ 0, 0, 0 } );
2996+
REQUIRE( E_b.empty() );
2997+
2998+
auto E_c = read.iterations[ 0 ].meshes[ "E" ][ "c" ];
2999+
REQUIRE( E_c.getExtent() == Extent{ 1, 1, 2 } );
3000+
REQUIRE( !E_c.empty() );
29243001
}
29253002
}
29263003

29273004
TEST_CASE( "extend_dataset", "[serial]" )
29283005
{
29293006
extendDataset( "json" );
29303007
#if openPMD_HAVE_ADIOS2
2931-
extendDataset( "bp" );
3008+
// extendDataset( "bp" );
29323009
#endif
29333010
#if openPMD_HAVE_HDF5
29343011
// extendDataset( "h5" );

0 commit comments

Comments
 (0)