Skip to content

Commit e8973bd

Browse files
committed
Add more CustomHierarchyFlush operations
1 parent 1fc92ee commit e8973bd

8 files changed

Lines changed: 47 additions & 6 deletions

File tree

include/openPMD/backend/ContainerImpl.tpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,11 @@ auto Container<T, T_key, T_container>::flush(
359359
IOHandler()->enqueue(IOTask(this, pCreate));
360360
}
361361

362-
flushAttributes(flushParams);
362+
customHierarchyFlush(flushParams, /* unset_dirty = */ false);
363+
if (access::write(IOHandler()->m_frontendAccess))
364+
{
365+
flushAttributes(flushParams);
366+
}
363367
}
364368

365369
template <typename T, typename T_key, typename T_container>

src/Mesh.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,11 @@ void Mesh::flush_impl(
451451
}
452452
else
453453
{
454+
customHierarchyFlush(flushParams, /* unset_dirty = */ false);
454455
for (auto &comp : *this)
455456
comp.second.flush(comp.first, flushParams);
456457
}
458+
// TODO why is there no unsetDirty operation here?
457459
}
458460
else
459461
{
@@ -469,6 +471,8 @@ void Mesh::flush_impl(
469471
Parameter<Operation::CREATE_PATH> pCreate;
470472
pCreate.path = name;
471473
IOHandler()->enqueue(IOTask(this, pCreate));
474+
475+
customHierarchyFlush(flushParams, /* unset_dirty = */ false);
472476
for (auto &comp : *this)
473477
{
474478
comp.second.parent() = &this->writable();
@@ -484,6 +488,7 @@ void Mesh::flush_impl(
484488
}
485489
else
486490
{
491+
customHierarchyFlush(flushParams, /* unset_dirty = */ false);
487492
for (auto &comp : *this)
488493
comp.second.flush(comp.first, flushParams);
489494
}

src/ParticleSpecies.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ void ParticleSpecies::flush(
182182
}
183183
if (access::readOnly(IOHandler()->m_frontendAccess))
184184
{
185+
customHierarchyFlush(flushParams, /* unset_dirty = */ false);
185186
for (auto &record : *this)
186187
record.second.flush(record.first, flushParams);
187188
for (auto &patch : particlePatches)

src/Record.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ void Record::flush_impl(
7171
}
7272
else
7373
{
74+
customHierarchyFlush(flushParams, /* unset_dirty = */ false);
7475
for (auto &comp : *this)
7576
comp.second.flush(comp.first, flushParams);
7677
}
78+
// TODO why is there no unsetDirty operation here?
7779
}
7880
else
7981
{
@@ -89,6 +91,8 @@ void Record::flush_impl(
8991
Parameter<Operation::CREATE_PATH> pCreate;
9092
pCreate.path = name;
9193
IOHandler()->enqueue(IOTask(this, pCreate));
94+
95+
customHierarchyFlush(flushParams, /* unset_dirty = */ false);
9296
for (auto &comp : *this)
9397
{
9498
comp.second.parent() = getWritable(this);
@@ -98,13 +102,13 @@ void Record::flush_impl(
98102
}
99103
else
100104
{
101-
102105
if (scalar())
103106
{
104107
T_RecordComponent::flush(name, flushParams);
105108
}
106109
else
107110
{
111+
customHierarchyFlush(flushParams, /* unset_dirty = */ false);
108112
for (auto &comp : *this)
109113
comp.second.flush(comp.first, flushParams);
110114
}

src/RecordComponent.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ void RecordComponent::flush(
433433
}
434434
if (access::readOnly(IOHandler()->m_frontendAccess))
435435
{
436+
// TODO maybe guard against custom hierarchies on datasets?
437+
// they can be created upon constant components however..
438+
customHierarchyFlush(flushParams, /* unset_dirty = */ false);
436439
while (!rc.m_chunks.empty())
437440
{
438441
IOHandler()->enqueue(rc.m_chunks.front());
@@ -552,6 +555,10 @@ void RecordComponent::flush(
552555
rc.m_chunks.pop();
553556
}
554557

558+
// TODO maybe guard against custom hierarchies on datasets?
559+
// they can be created upon constant components however..
560+
customHierarchyFlush(flushParams, /* unset_dirty = */ false);
561+
555562
flushAttributes(flushParams);
556563
}
557564
determineUnsetDirty(flushParams.flushLevel);

src/Series.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,11 @@ void Series::flushGorVBased(
16671667
}
16681668
}
16691669

1670+
if (begin == end)
1671+
{
1672+
customHierarchyFlush(flushParams, /* unset_dirty = */ false);
1673+
}
1674+
16701675
// Phase 3
16711676
Parameter<Operation::TOUCH> touch;
16721677
IOHandler()->enqueue(IOTask(&writable(), touch));
@@ -1757,6 +1762,11 @@ void Series::flushGorVBased(
17571762
}
17581763
}
17591764

1765+
if (begin == end)
1766+
{
1767+
customHierarchyFlush(flushParams, /* unset_dirty = */ false);
1768+
}
1769+
17601770
flushAttributes(flushParams);
17611771
Parameter<Operation::TOUCH> touch;
17621772
IOHandler()->enqueue(IOTask(&writable(), touch));

src/backend/Attributable.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "openPMD/CustomHierarchy.hpp"
2323
#include "openPMD/Error.hpp"
2424
#include "openPMD/IO/AbstractIOHandler.hpp"
25+
#include "openPMD/IO/Access.hpp"
2526
#include "openPMD/Iteration.hpp"
2627
#include "openPMD/ParticleSpecies.hpp"
2728
#include "openPMD/RecordComponent.hpp"
@@ -197,6 +198,11 @@ void Attributable::customHierarchyFlush(
197198
// customHierarchies().printRecursively();
198199
if (!dirtyRecursive())
199200
{
201+
if (!unset_dirty)
202+
{
203+
throw std::runtime_error(
204+
"Control flow error: Should be called upon a dirty object.");
205+
}
200206
return;
201207
}
202208

@@ -431,6 +437,10 @@ template void Attributable::seriesFlush_impl<false>(
431437

432438
void Attributable::flushAttributes(internal::FlushParams const &flushParams)
433439
{
440+
if (access::readOnly(IOHandler()->m_frontendAccess))
441+
{
442+
throw std::runtime_error("Control flow error");
443+
}
434444
if (!flush_level::write_attributes(flushParams.flushLevel))
435445
{
436446
return;

src/backend/PatchRecord.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ void PatchRecord::flush_impl(
6161
}
6262
if (!this->scalar())
6363
{
64-
if (IOHandler()->m_frontendAccess != Access::READ_ONLY)
65-
Container<PatchRecordComponent>::flush(
66-
path, flushParams); // warning (clang-tidy-10):
67-
// bugprone-parent-virtual-call
64+
Container<PatchRecordComponent>::flush(
65+
path, flushParams); // warning (clang-tidy-10):
66+
// bugprone-parent-virtual-call
67+
6868
for (auto &comp : *this)
6969
comp.second.flush(comp.first, flushParams);
7070
}

0 commit comments

Comments
 (0)