Skip to content

Commit 2115ede

Browse files
committed
Remove flush-time check for populized components
Moved to finalize(), degraded to warning
1 parent af0d1a9 commit 2115ede

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

src/backend/BaseRecord.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,10 @@ inline void BaseRecord<T_elem>::flush(
813813
}
814814

815815
if (!this->written() && this->empty() && !this->datasetDefined())
816-
throw std::runtime_error(
817-
"A Record can not be written without any contained "
818-
"RecordComponents: " +
819-
name);
816+
// Verify upon ScientificDefaults::finalize() that the Record has been
817+
// populized. For now, we will assume that data will come later; ignore
818+
// this Record at the moment.
819+
return;
820820

821821
/*
822822
* Defensive programming. Normally, this error should yield as soon as

src/backend/ScientificDefaults.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,24 @@ void ScientificDefaults<Child>::addDefaults()
169169
std::cout << "Adding defaults for '" << asChild().myPath().openPMDPath()
170170
<< "'" << std::endl;
171171

172+
// First some verifications
173+
if constexpr (auxiliary::IsTemplateBaseOf_v<BaseRecord, Child>)
174+
{
175+
if (asChild().empty() && !asChild().datasetDefined())
176+
{
177+
std::cerr
178+
<< "Cannot flush Record without any contained components: '"
179+
<< asChild().myPath().openPMDPath() << "'. Will ignore.";
180+
if (asChild().written())
181+
{
182+
std::cerr << "\n(Note: The Record seems to have been written "
183+
"previously?)";
184+
}
185+
std::cerr << std::endl;
186+
return;
187+
}
188+
}
189+
172190
if constexpr (std::is_same_v<Child, Iteration>)
173191
{
174192
addDefaultFor("time", 0., &Iteration::setTime);
@@ -267,11 +285,6 @@ void ScientificDefaults<Child>::addDefaults()
267285
{
268286
addParentDefaults<BaseRecord<PatchRecordComponent>>();
269287
}
270-
else if constexpr (auxiliary::IsTemplateBaseOf_v<BaseRecord, Child>)
271-
{
272-
addDefaultFor<unit_representations::AsArray const &>(
273-
"unitDimension", unit_representations::AsArray{});
274-
}
275288
else if constexpr (std::is_same_v<Child, RecordComponent>)
276289
{
277290
addDefaultFor("unitSI", 1.0, &RecordComponent::setUnitSI);
@@ -299,6 +312,11 @@ void ScientificDefaults<Child>::addDefaults()
299312
{
300313
addParentDefaults<RecordComponent>();
301314
}
315+
else if constexpr (auxiliary::IsTemplateBaseOf_v<BaseRecord, Child>)
316+
{
317+
addDefaultFor<unit_representations::AsArray const &>(
318+
"unitDimension", unit_representations::AsArray{});
319+
}
302320
}
303321

304322
template class ScientificDefaults<Iteration>;

test/CoreTest.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,16 +1299,14 @@ TEST_CASE("empty_record_test", "[core]")
12991299

13001300
o.iterations[1].meshes["E"].setComment(
13011301
"No assumption about contained RecordComponents will be made");
1302-
REQUIRE_THROWS_WITH(
1303-
o.flush(),
1304-
Catch::Equals(
1305-
"A Record can not be written without any contained "
1306-
"RecordComponents: E"));
1307-
o.iterations[1].meshes["E"][RecordComponent::SCALAR].resetDataset(
1308-
Dataset(Datatype::DOUBLE, {1}));
13091302
auto B = o.iterations[1].meshes["B"];
13101303
B.resetDataset(Dataset(Datatype::DOUBLE, {1}));
1311-
o.flush();
1304+
auto sneakily_keep_meshes_alive = o.iterations[1].meshes;
1305+
o.close();
1306+
#if openPMD_USE_INVASIVE_TESTS
1307+
REQUIRE(!sneakily_keep_meshes_alive["E"].written());
1308+
REQUIRE(sneakily_keep_meshes_alive["B"].written());
1309+
#endif
13121310
}
13131311

13141312
TEST_CASE("zero_extent_component", "[core]")

0 commit comments

Comments
 (0)