2020 */
2121#pragma once
2222
23+ #include " openPMD/Error.hpp"
2324#include " openPMD/IO/AbstractIOHandler.hpp"
2425#include " openPMD/IO/Access.hpp"
2526#include " openPMD/IO/Format.hpp"
4041
4142#include < cstdint> // uint64_t
4243#include < deque>
44+ #include < functional>
4345#include < map>
46+ #include < memory>
4447#include < optional>
4548#include < set>
49+ #include < stdexcept>
4650#include < string>
51+ #include < tuple>
4752
4853// expose private and protected members for invasive testing
4954#ifndef OPENPMD_private
@@ -192,6 +197,9 @@ namespace internal
192197 */
193198 std::optional<ParsePreference> m_parsePreference;
194199
200+ std::optional<std::function<AbstractIOHandler *(Series &)>>
201+ m_deferred_initialization = std::nullopt ;
202+
195203 void close ();
196204 }; // SeriesData
197205
@@ -221,6 +229,18 @@ class Series : public Attributable
221229 explicit Series ();
222230
223231#if openPMD_HAVE_MPI
232+ /* *
233+ * @brief Construct a new Series
234+ *
235+ * For further details, refer to the documentation of the non-MPI overload.
236+ *
237+ * @param filepath The file path.
238+ * @param at Access mode.
239+ * @param comm The MPI communicator.
240+ * @param options Advanced backend configuration via JSON.
241+ * May be specified as a JSON-formatted string directly, or as a path
242+ * to a JSON textfile, prepended by an at sign '@'.
243+ */
224244 Series (
225245 std::string const &filepath,
226246 Access at,
@@ -229,13 +249,50 @@ class Series : public Attributable
229249#endif
230250
231251 /* *
232- * @brief Construct a new Series
233- *
234- * @param filepath The backend will be determined by the filepath extension.
252+ * @brief Construct a new Series.
253+ *
254+ * For details on access modes, JSON/TOML configuration and iteration
255+ * encoding, refer to:
256+ *
257+ * * https://openpmd-api.readthedocs.io/en/latest/usage/workflow.html#access-modes
258+ * * https://openpmd-api.readthedocs.io/en/latest/details/backendconfig.html
259+ * * https://openpmd-api.readthedocs.io/en/latest/usage/concepts.html#iteration-and-series
260+ *
261+ * In case of file-based iteration encoding, the file names for each
262+ * iteration are determined by an expansion pattern that must be specified.
263+ * It takes one out of two possible forms:
264+ *
265+ * 1. Simple form: %T is replaced with the iteration index, e.g.
266+ * `simData_%T.bp` becomes `simData_50.bp`.
267+ * 2. Padded form: e.g. %06T is replaced with the iteration index padded to
268+ * at least six digits. `simData_%06T.bp` becomes `simData_000050.bp`.
269+ *
270+ * The backend is determined:
271+ *
272+ * 1. Explicitly via the JSON/TOML parameter `backend`, e.g. `{"backend":
273+ * "adios2"}`.
274+ * 2. Otherwise implicitly from the filename extension, e.g.
275+ * `simData_%T.h5`.
276+ *
277+ * The filename extension can be replaced with a globbing pattern %E.
278+ * It will be replaced with an automatically determined file name extension:
279+ *
280+ * 1. In CREATE mode: The extension is set to a backend-specific default
281+ * extension. This requires that the backend is specified via JSON/TOML.
282+ * 2. In READ_ONLY, READ_WRITE and READ_LINEAR modes: These modes require
283+ * that files already exist on disk. The disk will be scanned for files
284+ * that match the pattern and the resulting file extension will be used.
285+ * If the result is ambiguous or no such file is found, an error is
286+ * raised.
287+ * 3. In APPEND mode: Like (2.), except if no matching file is found. In
288+ * that case, the procedure of (1.) is used, owing to the fact that
289+ * APPEND mode can be used to create new datasets.
290+ *
291+ * @param filepath The file path.
235292 * @param at Access mode.
236293 * @param options Advanced backend configuration via JSON.
237- * May be specified as a JSON-formatted string directly, or as a path
238- * to a JSON textfile, prepended by an at sign '@'.
294+ * May be specified as a JSON/TOML -formatted string directly, or as a
295+ * path to a JSON/TOML textfile, prepended by an at sign '@'.
239296 */
240297 Series (
241298 std::string const &filepath,
@@ -502,6 +559,7 @@ class Series : public Attributable
502559 * @return String of a pattern for data backend.
503560 */
504561 std::string backend () const ;
562+ std::string backend ();
505563
506564 /* * Execute all required remaining IO operations to write or read data.
507565 *
@@ -636,7 +694,20 @@ OPENPMD_private
636694 void parseJsonOptions (TracingJSON &options, ParsedInput &);
637695 bool hasExpansionPattern (std::string filenameWithExtension);
638696 bool reparseExpansionPattern (std::string filenameWithExtension);
639- void init (std::unique_ptr<AbstractIOHandler>, std::unique_ptr<ParsedInput>);
697+ template <typename ... MPI_Communicator>
698+ void init (
699+ std::string const &filepath,
700+ Access at,
701+ std::string const &options,
702+ MPI_Communicator &&...);
703+ template <typename TracingJSON>
704+ std::tuple<std::unique_ptr<ParsedInput>, TracingJSON> initIOHandler (
705+ std::string const &filepath,
706+ std::string const &options,
707+ Access at,
708+ bool resolve_generic_extension);
709+ void initSeries (
710+ std::unique_ptr<AbstractIOHandler>, std::unique_ptr<ParsedInput>);
640711 void initDefaults (IterationEncoding, bool initAll = false );
641712 /* *
642713 * @brief Internal call for flushing a Series.
@@ -688,7 +759,7 @@ OPENPMD_private
688759 * ReadIterations since those methods should be aware when the current step
689760 * is broken).
690761 */
691- std::optional<std::deque<IterationIndex_t> > readGorVBased (
762+ std::optional<std::deque<IterationIndex_t>> readGorVBased (
692763 bool do_always_throw_errors,
693764 bool init,
694765 std::set<IterationIndex_t> const &ignoreIterations = {});
@@ -758,7 +829,12 @@ OPENPMD_private
758829 * Returns the current content of the /data/snapshot attribute.
759830 * (We could also add this to the public API some time)
760831 */
761- std::optional<std::vector<IterationIndex_t> > currentSnapshot () const ;
832+ std::optional<std::vector<IterationIndex_t>> currentSnapshot () const ;
833+
834+ AbstractIOHandler *runDeferredInitialization ();
835+
836+ AbstractIOHandler *IOHandler ();
837+ AbstractIOHandler const *IOHandler () const ;
762838}; // Series
763839} // namespace openPMD
764840
0 commit comments