@@ -4855,3 +4855,103 @@ TEST_CASE( "append_mode_filebased", "[serial]" )
48554855 append_mode_filebased ( t );
48564856 }
48574857}
4858+
4859+ void groupbased_read_write ( std::string const & ext )
4860+ {
4861+ int data = 0 ;
4862+ Dataset ds ( Datatype::INT, { 1 } );
4863+ std::string filename = " ../samples/groupbased_read_write." + ext;
4864+
4865+ {
4866+ Series write ( filename, Access::CREATE );
4867+ auto E_x = write.iterations [ 0 ].meshes [ " E" ][ " x" ];
4868+ auto E_y = write.iterations [ 0 ].meshes [ " E" ][ " y" ];
4869+ E_x.resetDataset ( ds );
4870+ E_y.resetDataset ( ds );
4871+ E_x.storeChunk ( shareRaw ( &data ), { 0 }, { 1 } );
4872+ E_y.storeChunk ( shareRaw ( &data ), { 0 }, { 1 } );
4873+
4874+ E_x.setAttribute ( " updated_in_run" , 0 );
4875+ E_y.setAttribute ( " updated_in_run" , 0 );
4876+ }
4877+
4878+ {
4879+ Series write ( filename, Access::READ_WRITE );
4880+ // create a new iteration
4881+ auto E_x = write.iterations [ 1 ].meshes [ " E" ][ " x" ];
4882+ E_x.resetDataset ( ds );
4883+
4884+ // overwrite old dataset
4885+ auto E_y = write.iterations [ 0 ].meshes [ " E" ][ " y" ];
4886+
4887+ data = 1 ;
4888+
4889+ E_x.storeChunk ( shareRaw ( &data ), { 0 }, { 1 } );
4890+ E_y.storeChunk ( shareRaw ( &data ), { 0 }, { 1 } );
4891+
4892+ E_x.setAttribute ( " updated_in_run" , 1 );
4893+ E_y.setAttribute ( " updated_in_run" , 1 );
4894+ }
4895+
4896+ {
4897+ Series read ( filename, Access::READ_ONLY );
4898+ auto E_x_0_fromRun0 = read.iterations [ 0 ].meshes [ " E" ][ " x" ];
4899+ auto E_x_1_fromRun1 = read.iterations [ 1 ].meshes [ " E" ][ " x" ];
4900+ auto E_y_0_fromRun1 = read.iterations [ 0 ].meshes [ " E" ][ " y" ];
4901+
4902+ REQUIRE (
4903+ E_x_0_fromRun0.getAttribute ( " updated_in_run" ).get < int >() == 0 );
4904+ REQUIRE (
4905+ E_x_1_fromRun1.getAttribute ( " updated_in_run" ).get < int >() == 1 );
4906+ REQUIRE (
4907+ E_y_0_fromRun1.getAttribute ( " updated_in_run" ).get < int >() == 1 );
4908+
4909+ auto chunk_E_x_0_fromRun0 =
4910+ E_x_0_fromRun0.loadChunk < int >( { 0 }, { 1 } );
4911+ auto chunk_E_x_1_fromRun1 =
4912+ E_x_1_fromRun1.loadChunk < int >( { 0 }, { 1 } );
4913+ auto chunk_E_y_0_fromRun1 =
4914+ E_y_0_fromRun1.loadChunk < int >( { 0 }, { 1 } );
4915+
4916+ read.flush ();
4917+
4918+ REQUIRE ( *chunk_E_x_0_fromRun0 == 0 );
4919+ REQUIRE ( *chunk_E_x_1_fromRun1 == 1 );
4920+ REQUIRE ( *chunk_E_y_0_fromRun1 == 1 );
4921+ }
4922+
4923+ // check that truncation works correctly
4924+ {
4925+ Series write ( filename, Access::CREATE );
4926+ // create a new iteration
4927+ auto E_x = write.iterations [ 2 ].meshes [ " E" ][ " x" ];
4928+ E_x.resetDataset ( ds );
4929+
4930+ data = 2 ;
4931+
4932+ E_x.storeChunk ( shareRaw ( &data ), { 0 }, { 1 } );
4933+ E_x.setAttribute ( " updated_in_run" , 2 );
4934+ }
4935+
4936+ {
4937+ Series read ( filename, Access::READ_ONLY );
4938+ REQUIRE ( read.iterations .size () == 1 );
4939+ REQUIRE ( read.iterations .count ( 2 ) == 1 );
4940+ }
4941+ }
4942+
4943+ TEST_CASE ( " groupbased_read_write" , " [serial]" )
4944+ {
4945+ constexpr char const * supportsGroupbasedRW[] = { " h5" , " json" };
4946+ for ( auto const & t : testedFileExtensions () )
4947+ {
4948+ for ( auto const supported : supportsGroupbasedRW )
4949+ {
4950+ if ( t == supported )
4951+ {
4952+ groupbased_read_write ( t );
4953+ break ;
4954+ }
4955+ }
4956+ }
4957+ }
0 commit comments