Skip to content

Commit 52f311e

Browse files
committed
Specifiy more precisely when to re-read attributes
1 parent ab02b9b commit 52f311e

10 files changed

Lines changed: 51 additions & 28 deletions

File tree

include/openPMD/Series.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,6 @@ class SeriesImpl : public AttributableImpl
346346
* Note on re-parsing of a Series:
347347
* If init == false, the parsing process will seek for new
348348
* Iterations/Records/Record Components etc.
349-
* Re-parsing of objects that have already been parsed is not implemented
350-
* as of yet. Such a facility will be required upon implementing things such
351-
* as resizable datasets.
352349
*/
353350
void readGorVBased( bool init = true );
354351
void readBase();

include/openPMD/backend/Attributable.hpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,24 @@ class AttributableImpl
204204
internal::SeriesInternal & retrieveSeries();
205205

206206
void flushAttributes();
207-
void readAttributes( bool reread = false );
207+
enum ReadMode {
208+
/**
209+
* Don't read an attribute from the backend if it has been previously
210+
* read.
211+
*/
212+
IgnoreExisting,
213+
/**
214+
* Read all the attributes that the backend has to offer and override
215+
* if it has been read previously.
216+
*/
217+
OverrideExisting,
218+
/**
219+
* Remove all attributes that have been read previously and read
220+
* everything that the backend currently has to offer.
221+
*/
222+
FullyReread
223+
};
224+
void readAttributes( ReadMode );
208225

209226
/** Retrieve the value of a floating point Attribute of user-defined precision with ensured type-safety.
210227
*

src/Iteration.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ void Iteration::read_impl( std::string const & groupPath )
435435
pOpen.path = s->meshesPath();
436436
IOHandler()->enqueue(IOTask(&meshes, pOpen));
437437

438-
meshes.readAttributes();
438+
meshes.readAttributes( ReadMode::FullyReread );
439439

440440
auto map = meshes.eraseStaleEntries();
441441

@@ -496,7 +496,7 @@ void Iteration::read_impl( std::string const & groupPath )
496496
pOpen.path = s->particlesPath();
497497
IOHandler()->enqueue(IOTask(&particles, pOpen));
498498

499-
particles.readAttributes();
499+
particles.readAttributes( ReadMode::FullyReread );
500500

501501
/* obtain all particle species */
502502
pList.paths->clear();
@@ -514,7 +514,7 @@ void Iteration::read_impl( std::string const & groupPath )
514514
}
515515
}
516516

517-
readAttributes();
517+
readAttributes( ReadMode::FullyReread );
518518
}
519519

520520
AdvanceStatus

src/Mesh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ Mesh::read()
367367

368368
readBase();
369369

370-
readAttributes();
370+
readAttributes( ReadMode::FullyReread );
371371
}
372372
} // openPMD
373373

src/ParticleSpecies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ ParticleSpecies::read()
119119
}
120120
}
121121

122-
readAttributes();
122+
readAttributes( ReadMode::FullyReread );
123123
}
124124

125125
namespace

src/Record.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Record::read()
124124

125125
readBase();
126126

127-
readAttributes();
127+
readAttributes( ReadMode::FullyReread );
128128
}
129129

130130
template <>

src/RecordComponent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ RecordComponent::readBase()
365365
else
366366
throw std::runtime_error("Unexpected Attribute datatype for 'unitSI'");
367367

368-
readAttributes();
368+
readAttributes( ReadMode::FullyReread );
369369
}
370370

371371
bool

src/Series.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,8 @@ void SeriesImpl::readOneIterationFileBased( std::string const & filePath )
931931
throw std::runtime_error("Unknown openPMD version - " + version);
932932
IOHandler()->enqueue(IOTask(&series.iterations, pOpen));
933933

934-
readAttributes();
935-
series.iterations.readAttributes();
934+
readAttributes( ReadMode::IgnoreExisting );
935+
series.iterations.readAttributes(ReadMode::OverrideExisting );
936936
}
937937

938938
void
@@ -1000,11 +1000,11 @@ SeriesImpl::readGorVBased( bool do_init )
10001000
throw std::runtime_error("Unknown openPMD version - " + version);
10011001
IOHandler()->enqueue(IOTask(&series.iterations, pOpen));
10021002

1003-
readAttributes();
1003+
readAttributes( ReadMode::IgnoreExisting );
10041004
/*
10051005
* __step__ changes over steps, so reread that.
10061006
*/
1007-
series.iterations.readAttributes( /* reread = */ true );
1007+
series.iterations.readAttributes( ReadMode::OverrideExisting );
10081008
/* obtain all paths inside the basepath (i.e. all iterations) */
10091009
Parameter< Operation::LIST_PATHS > pList;
10101010
IOHandler()->enqueue(IOTask(&series.iterations, pList));

src/backend/Attributable.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,30 +152,39 @@ AttributableImpl::flushAttributes()
152152
}
153153

154154
void
155-
AttributableImpl::readAttributes( bool reread )
155+
AttributableImpl::readAttributes( ReadMode mode )
156156
{
157+
auto & attri = get();
157158
Parameter< Operation::LIST_ATTS > aList;
158159
IOHandler()->enqueue(IOTask(this, aList));
159160
IOHandler()->flush();
160161
std::vector< std::string > written_attributes = attributes();
161162

163+
/* std::set_difference requires sorted ranges */
164+
std::sort(aList.attributes->begin(), aList.attributes->end());
165+
std::sort(written_attributes.begin(), written_attributes.end());
166+
162167
std::set< std::string > tmpAttributes;
163-
if( reread )
164-
{
165-
tmpAttributes = std::set< std::string >(
166-
aList.attributes->begin(),
167-
aList.attributes->end() );
168-
}
169-
else
168+
switch( mode )
170169
{
171-
/* std::set_difference requires sorted ranges */
172-
std::sort(aList.attributes->begin(), aList.attributes->end());
173-
std::sort(written_attributes.begin(), written_attributes.end());
174-
170+
case ReadMode::IgnoreExisting:
171+
// reread: aList - written_attributes
175172
std::set_difference(
176173
aList.attributes->begin(), aList.attributes->end(),
177174
written_attributes.begin(), written_attributes.end(),
178175
std::inserter(tmpAttributes, tmpAttributes.begin()));
176+
break;
177+
case ReadMode::OverrideExisting:
178+
tmpAttributes = std::set< std::string >(
179+
aList.attributes->begin(),
180+
aList.attributes->end() );
181+
break;
182+
case ReadMode::FullyReread:
183+
attri.m_attributes.clear();
184+
tmpAttributes = std::set< std::string >(
185+
aList.attributes->begin(),
186+
aList.attributes->end() );
187+
break;
179188
}
180189

181190
using DT = Datatype;

src/backend/PatchRecordComponent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ PatchRecordComponent::read()
115115
else
116116
throw std::runtime_error("Unexpected Attribute datatype for 'unitSI'");
117117

118-
readAttributes(); // this will set dirty() = false
118+
readAttributes( ReadMode::FullyReread ); // this will set dirty() = false
119119
}
120120

121121
bool

0 commit comments

Comments
 (0)