Skip to content

Commit e26b8c3

Browse files
committed
Check for extent consistency, fill in undefined extents
1 parent dddb1d0 commit e26b8c3

2 files changed

Lines changed: 39 additions & 12 deletions

File tree

include/openPMD/RecordComponent.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ namespace internal
118118
std::deque<RecordComponent> without_extent;
119119
std::optional<Extent> retrieved_extent;
120120

121+
static constexpr char const *env_var_check_dataset_consistency =
122+
"OPENPMD_VERIFY_HOMOGENEOUS_EXTENTS";
123+
121124
void check_extent(Attributable const &callsite, RecordComponent &);
122125
auto merge(Attributable const &callsite, HomogenizeExtents)
123126
-> HomogenizeExtents &;

src/RecordComponent.cpp

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
#include "openPMD/Error.hpp"
2525
#include "openPMD/IO/Format.hpp"
2626
#include "openPMD/Series.hpp"
27+
#include "openPMD/auxiliary/Environment.hpp"
2728
#include "openPMD/auxiliary/Memory.hpp"
29+
#include "openPMD/auxiliary/StringManip.hpp"
2830
#include "openPMD/backend/Attributable.hpp"
2931
#include "openPMD/backend/BaseRecord.hpp"
3032

@@ -66,14 +68,21 @@ namespace internal
6668
}
6769
else if (retrieved_extent.has_value())
6870
{
69-
if (extent != *retrieved_extent)
71+
if (extent != *retrieved_extent &&
72+
auxiliary::getEnvNum(env_var_check_dataset_consistency, 1) != 0)
7073
{
74+
std::stringstream error_msg;
75+
error_msg << "Inconsistent extents found for Record '"
76+
<< callsite.myPath().openPMDPath() << "': Component '"
77+
<< rc.myPath().openPMDPath() << "' has extent";
78+
auxiliary::write_vec_to_stream(error_msg, extent) << ", but ";
79+
auxiliary::write_vec_to_stream(error_msg, *retrieved_extent)
80+
<< " was found previously.";
7181
throw error::ReadError(
7282
error::AffectedObject::Group,
7383
error::Reason::UnexpectedContent,
7484
std::nullopt,
75-
"Inconsistent extents found for Record '" +
76-
callsite.myPath().openPMDPath() + "'.");
85+
error_msg.str());
7786
}
7887
}
7988
else
@@ -88,14 +97,22 @@ namespace internal
8897
{
8998
if (retrieved_extent.has_value() && other.retrieved_extent.has_value())
9099
{
91-
if (*retrieved_extent != *other.retrieved_extent)
100+
if (*retrieved_extent != *other.retrieved_extent &&
101+
auxiliary::getEnvNum(env_var_check_dataset_consistency, 1) != 0)
92102
{
103+
std::stringstream error_msg;
104+
error_msg << "Inconsistent extents found for Record '"
105+
<< callsite.myPath().openPMDPath() << "': ";
106+
auxiliary::write_vec_to_stream(error_msg, *retrieved_extent)
107+
<< " vs. ";
108+
auxiliary::write_vec_to_stream(
109+
error_msg, *other.retrieved_extent)
110+
<< ".";
93111
throw error::ReadError(
94112
error::AffectedObject::Group,
95113
error::Reason::UnexpectedContent,
96114
std::nullopt,
97-
"Inconsistent extents found for Record '" +
98-
callsite.myPath().openPMDPath() + "'.");
115+
error_msg.str());
99116
}
100117
}
101118
else if (!retrieved_extent.has_value())
@@ -114,12 +131,19 @@ namespace internal
114131
{
115132
if (!retrieved_extent.has_value())
116133
{
117-
throw error::ReadError(
118-
error::AffectedObject::Group,
119-
error::Reason::UnexpectedContent,
120-
std::nullopt,
121-
"No extent found for any component contained in '" +
122-
callsite.myPath().openPMDPath() + "'.");
134+
if (auxiliary::getEnvNum(env_var_check_dataset_consistency, 1) != 0)
135+
{
136+
throw error::ReadError(
137+
error::AffectedObject::Group,
138+
error::Reason::UnexpectedContent,
139+
std::nullopt,
140+
"No extent found for any component contained in '" +
141+
callsite.myPath().openPMDPath() + "'.");
142+
}
143+
else
144+
{
145+
return;
146+
}
123147
}
124148
auto &ext = *retrieved_extent;
125149
for (auto &rc : without_extent)

0 commit comments

Comments
 (0)