diff --git a/include/openPMD/Dataset.hpp b/include/openPMD/Dataset.hpp index c511d5a9ae..0c79ed9909 100644 --- a/include/openPMD/Dataset.hpp +++ b/include/openPMD/Dataset.hpp @@ -55,5 +55,7 @@ class Dataset uint8_t rank; std::optional joinedDimension; std::string options = "{}"; //!< backend-dependent JSON configuration + + bool empty() const; }; } // namespace openPMD diff --git a/src/Dataset.cpp b/src/Dataset.cpp index 587598db63..f3682c4528 100644 --- a/src/Dataset.cpp +++ b/src/Dataset.cpp @@ -49,4 +49,17 @@ Dataset &Dataset::extend(Extent newExtents) extent = newExtents; return *this; } + +bool Dataset::empty() const +{ + for (size_t i = 0; i < extent.size(); ++i) + { + if (extent[i] == 0 && + (!joinedDimension.has_value() || joinedDimension.value() != i)) + { + return true; + } + } + return false; +} } // namespace openPMD diff --git a/src/RecordComponent.cpp b/src/RecordComponent.cpp index ee01491c75..2d6a6dc5f2 100644 --- a/src/RecordComponent.cpp +++ b/src/RecordComponent.cpp @@ -95,10 +95,7 @@ RecordComponent &RecordComponent::resetDataset(Dataset d) } // if( d.extent.empty() ) // throw std::runtime_error("Dataset extent must be at least 1D."); - if (std::any_of( - d.extent.begin(), d.extent.end(), [](Extent::value_type const &i) { - return i == 0u; - })) + if (d.empty()) return makeEmpty(std::move(d)); rc.m_isEmpty = false; diff --git a/src/backend/PatchRecordComponent.cpp b/src/backend/PatchRecordComponent.cpp index d4d5d04f76..681c0d8916 100644 --- a/src/backend/PatchRecordComponent.cpp +++ b/src/backend/PatchRecordComponent.cpp @@ -48,10 +48,7 @@ PatchRecordComponent &PatchRecordComponent::resetDataset(Dataset d) "written."); if (d.extent.empty()) throw std::runtime_error("Dataset extent must be at least 1D."); - if (std::any_of( - d.extent.begin(), d.extent.end(), [](Extent::value_type const &i) { - return i == 0u; - })) + if (d.empty()) throw std::runtime_error( "Dataset extent must not be zero in any dimension."); diff --git a/test/ParallelIOTest.cpp b/test/ParallelIOTest.cpp index 562c43c92d..ce183ce1af 100644 --- a/test/ParallelIOTest.cpp +++ b/test/ParallelIOTest.cpp @@ -1788,7 +1788,7 @@ void joined_dim(std::string const &ext) auto it = s.writeIterations()[100]; - Dataset numParticlesDS(determineDatatype(), {1}); + Dataset numParticlesDS(determineDatatype(), {0}); numParticlesDS.joinedDimension = 0; auto numParticles = it.particles["e"] @@ -1801,7 +1801,7 @@ void joined_dim(std::string const &ext) auto patchOffset = it.particles["e"].particlePatches["offset"]["x"]; auto patchExtent = it.particles["e"].particlePatches["extent"]["x"]; - Dataset particlePatchesDS(determineDatatype(), {1}); + Dataset particlePatchesDS(determineDatatype(), {0}); particlePatchesDS.joinedDimension = 0; patchOffset.resetDataset(particlePatchesDS); patchExtent.resetDataset(particlePatchesDS); diff --git a/test/SerialIOTest.cpp b/test/SerialIOTest.cpp index 43e6757651..3035e73d83 100644 --- a/test/SerialIOTest.cpp +++ b/test/SerialIOTest.cpp @@ -7229,7 +7229,7 @@ void joined_dim(std::string const &ext) auto it = s.writeIterations()[100]; - Dataset numParticlesDS(determineDatatype(), {1}); + Dataset numParticlesDS(determineDatatype(), {0}); numParticlesDS.joinedDimension = 0; auto numParticles = it.particles["e"] @@ -7242,7 +7242,7 @@ void joined_dim(std::string const &ext) auto patchOffset = it.particles["e"].particlePatches["offset"]["x"]; auto patchExtent = it.particles["e"].particlePatches["extent"]["x"]; - Dataset particlePatchesDS(determineDatatype(), {1}); + Dataset particlePatchesDS(determineDatatype(), {0}); particlePatchesDS.joinedDimension = 0; patchOffset.resetDataset(particlePatchesDS); patchExtent.resetDataset(particlePatchesDS);