Skip to content

Commit f883f8e

Browse files
Update examples (#1371)
* Update examples Mainly Series::close, Iteration::close, Series::writeIterations, Series::readIterations, READ_LINEAR * Fix: Python bindings use copy return value policies * Fix: Use explicit ::close() call in WriteIterations
1 parent 0028647 commit f883f8e

35 files changed

+289
-63
lines changed

examples/10_streaming_read.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ int main()
3939
extents[i] = rc.getExtent();
4040
}
4141

42+
// The iteration can be closed in order to help free up resources.
43+
// The iteration's content will be flushed automatically.
44+
// An iteration once closed cannot (yet) be reopened.
4245
iteration.close();
4346

4447
for (size_t i = 0; i < 3; ++i)
@@ -55,6 +58,14 @@ int main()
5558
}
5659
}
5760

61+
/* The files in 'series' are still open until the object is destroyed, on
62+
* which it cleanly flushes and closes all open file handles.
63+
* When running out of scope on return, the 'Series' destructor is called.
64+
* Alternatively, one can call `series.close()` to the same effect as
65+
* calling the destructor, including the release of file handles.
66+
*/
67+
series.close();
68+
5869
return 0;
5970
#else
6071
std::cout << "The streaming example requires that openPMD has been built "

examples/10_streaming_read.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,10 @@
5353
print("dim: {}".format(dim))
5454
chunk = loadedChunks[i]
5555
print(chunk)
56+
57+
# The files in 'series' are still open until the object is destroyed, on
58+
# which it cleanly flushes and closes all open file handles.
59+
# When running out of scope on return, the 'Series' destructor is called.
60+
# Alternatively, one can call `series.close()` to the same effect as
61+
# calling the destructor, including the release of file handles.
62+
series.close()

examples/10_streaming_write.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ int main()
4545
iteration.close();
4646
}
4747

48+
/* The files in 'series' are still open until the object is destroyed, on
49+
* which it cleanly flushes and closes all open file handles.
50+
* When running out of scope on return, the 'Series' destructor is called.
51+
* Alternatively, one can call `series.close()` to the same effect as
52+
* calling the destructor, including the release of file handles.
53+
*/
54+
series.close();
55+
4856
return 0;
4957
#else
5058
std::cout << "The streaming example requires that openPMD has been built "

examples/10_streaming_write.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,10 @@
8080
# If not closing an iteration explicitly, it will be implicitly closed
8181
# upon creating the next iteration.
8282
iteration.close()
83+
84+
# The files in 'series' are still open until the object is destroyed, on
85+
# which it cleanly flushes and closes all open file handles.
86+
# When running out of scope on return, the 'Series' destructor is called.
87+
# Alternatively, one can call `series.close()` to the same effect as
88+
# calling the destructor, including the release of file handles.
89+
series.close()

examples/11_particle_dataframe.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,5 @@
9696
idx_max * E.grid_spacing + E.grid_global_offset)
9797
print("maximum intensity I={} at index={} z={}mu".format(
9898
Intensity_max, idx_max, pos_max[2]))
99+
100+
s.close()

examples/12_span_write.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ void span_write(std::string const &filename)
8484
}
8585
iteration.close();
8686
}
87+
88+
/* The files in 'series' are still open until the object is destroyed, on
89+
* which it cleanly flushes and closes all open file handles.
90+
* When running out of scope on return, the 'Series' destructor is called.
91+
# Alternatively, one can call `series.close()` to the same effect as
92+
# calling the destructor, including the release of file handles.
93+
*/
94+
series.close();
8795
}
8896

8997
int main()

examples/12_span_write.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ def span_write(filename):
2727
j += 1
2828
iteration.close()
2929

30+
# The files in 'series' are still open until the object is destroyed, on
31+
# which it cleanly flushes and closes all open file handles.
32+
# When running out of scope on return, the 'Series' destructor is called.
33+
# Alternatively, one can call `series.close()` to the same effect as
34+
# calling the destructor, including the release of file handles.
35+
series.close()
36+
3037

3138
if __name__ == "__main__":
3239
for ext in io.file_extensions:

examples/13_write_dynamic_configuration.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,13 @@ chunks = "auto"
128128
iteration.close();
129129
}
130130

131+
/* The files in 'series' are still open until the object is destroyed, on
132+
* which it cleanly flushes and closes all open file handles.
133+
* When running out of scope on return, the 'Series' destructor is called.
134+
* Alternatively, one can call `series.close()` to the same effect as
135+
* calling the destructor, including the release of file handles.
136+
*/
137+
series.close();
138+
131139
return 0;
132140
}

examples/13_write_dynamic_configuration.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ def main():
146146
# upon creating the next iteration.
147147
iteration.close()
148148

149+
# The files in 'series' are still open until the object is destroyed, on
150+
# which it cleanly flushes and closes all open file handles.
151+
# When running out of scope on return, the 'Series' destructor is called.
152+
# Alternatively, one can call `series.close()` to the same effect as
153+
# calling the destructor, including the release of file handles.
154+
series.close()
155+
149156

150157
if __name__ == "__main__":
151158
main()

examples/1_structure.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ int main()
3939
* to the openPMD standard. Creation of new elements happens on access
4040
* inside the tree-like structure. Required attributes are initialized to
4141
* reasonable defaults for every object. */
42-
ParticleSpecies electrons = series.iterations[1].particles["electrons"];
42+
ParticleSpecies electrons =
43+
series.writeIterations()[1].particles["electrons"];
4344

4445
/* Data to be moved from memory to persistent storage is structured into
4546
* Records, each holding an unbounded number of RecordComponents. If a
@@ -59,9 +60,17 @@ int main()
5960
electrons["positionOffset"]["x"].resetDataset(dataset);
6061
electrons["positionOffset"]["x"].makeConstant(22.0);
6162

63+
// The iteration can be closed in order to help free up resources.
64+
// The iteration's content will be flushed automatically.
65+
// An iteration once closed cannot (yet) be reopened.
66+
series.writeIterations()[1].close();
67+
6268
/* The files in 'series' are still open until the object is destroyed, on
6369
* which it cleanly flushes and closes all open file handles.
6470
* When running out of scope on return, the 'Series' destructor is called.
71+
* Alternatively, one can call `series.close()` to the same effect as
72+
* calling the destructor, including the release of file handles.
6573
*/
74+
series.close();
6675
return 0;
6776
}

0 commit comments

Comments
 (0)