openPMD-api
Series.hpp
1 /* Copyright 2017-2020 Fabian Koller, Axel Huebl
2  *
3  * This file is part of openPMD-api.
4  *
5  * openPMD-api is free software: you can redistribute it and/or modify
6  * it under the terms of of either the GNU General Public License or
7  * the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * openPMD-api is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License and the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * and the GNU Lesser General Public License along with openPMD-api.
19  * If not, see <http://www.gnu.org/licenses/>.
20  */
21 #pragma once
22 
23 #include "openPMD/config.hpp"
24 #include "openPMD/auxiliary/Deprecated.hpp"
25 #include "openPMD/backend/Attributable.hpp"
26 #include "openPMD/backend/Container.hpp"
27 #include "openPMD/IO/AbstractIOHandler.hpp"
28 #include "openPMD/IO/Access.hpp"
29 #include "openPMD/IO/Format.hpp"
30 #include "openPMD/Iteration.hpp"
31 #include "openPMD/IterationEncoding.hpp"
32 #include "openPMD/version.hpp"
33 
34 #if openPMD_HAVE_MPI
35 # include <mpi.h>
36 #endif
37 
38 #include <string>
39 
40 // expose private and protected members for invasive testing
41 #ifndef OPENPMD_private
42 # define OPENPMD_private private
43 #endif
44 
45 
46 namespace openPMD
47 {
55 class Series : public Attributable
56 {
57  friend class Iteration;
58 
59 public:
60 #if openPMD_HAVE_MPI
61  Series(
62  std::string const & filepath,
63  Access at,
64  MPI_Comm comm,
65  std::string const & options = "{}" );
66 #endif
67 
68  Series(
69  std::string const & filepath,
70  Access at,
71  std::string const & options = "{}" );
72  ~Series();
73 
77  std::string openPMD() const;
83  Series& setOpenPMD(std::string const& openPMD);
84 
88  uint32_t openPMDextension() const;
94  Series& setOpenPMDextension(uint32_t openPMDextension);
95 
99  std::string basePath() const;
105  Series& setBasePath(std::string const& basePath);
106 
111  std::string meshesPath() const;
117  Series& setMeshesPath(std::string const& meshesPath);
118 
123  std::string particlesPath() const;
129  Series& setParticlesPath(std::string const& particlesPath);
130 
135  std::string author() const;
141  Series& setAuthor(std::string const& author);
142 
147  std::string software() const;
154  Series& setSoftware(std::string const& newName, std::string const& newVersion = std::string("unspecified"));
155 
160  std::string softwareVersion() const;
168  OPENPMDAPI_DEPRECATED("Set the version with the second argument of setSoftware()")
169  Series& setSoftwareVersion(std::string const& softwareVersion);
170 
175  std::string date() const;
181  Series& setDate(std::string const& date);
182 
187  std::string softwareDependencies() const;
193  Series& setSoftwareDependencies(std::string const& newSoftwareDependencies);
194 
199  std::string machine() const;
205  Series& setMachine(std::string const& newMachine);
206 
216  Series& setIterationEncoding(IterationEncoding iterationEncoding);
217 
221  std::string iterationFormat() const;
232  Series& setIterationFormat(std::string const& iterationFormat);
233 
237  std::string name() const;
238 
244  Series& setName(std::string const& name);
245 
252  std::string backend() const;
253 
256  void flush();
257 
259 
260 OPENPMD_private:
261  struct ParsedInput;
262  std::unique_ptr< ParsedInput > parseInput(std::string);
263  void init(std::shared_ptr< AbstractIOHandler >, std::unique_ptr< ParsedInput >);
264  void initDefaults();
265  template< typename IterationsContainer >
266  void flushFileBased( IterationsContainer && iterationsToFlush );
267  template< typename IterationsContainer >
268  void flushGroupBased( IterationsContainer && iterationsToFlush );
269  void flushMeshesPath();
270  void flushParticlesPath();
271  void readFileBased();
272  void readGroupBased();
273  void readBase();
274  void read();
275 
276  static constexpr char const * const BASEPATH = "/data/%T/";
277 
278  std::shared_ptr< IterationEncoding > m_iterationEncoding;
279  std::shared_ptr< std::string > m_name;
280  std::shared_ptr< Format > m_format;
281 
282  std::shared_ptr< std::string > m_filenamePrefix;
283  std::shared_ptr< std::string > m_filenamePostfix;
284  std::shared_ptr< int > m_filenamePadding;
285 }; // Series
286 } // namespace openPMD
Series & setOpenPMD(std::string const &openPMD)
Set the version of the enforced openPMD standard.
Definition: Series.cpp:135
std::string basePath() const
Definition: Series.cpp:155
Access
File access mode to use during IO.
Definition: Access.hpp:30
Series & setSoftwareDependencies(std::string const &newSoftwareDependencies)
Indicate dependencies of software that were used to create the file.
Definition: Series.cpp:273
std::string softwareDependencies() const
Definition: Series.cpp:267
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:35
Definition: Series.cpp:72
Series & setMachine(std::string const &newMachine)
Indicate the machine or relevant hardware that created the file.
Definition: Series.cpp:286
std::string meshesPath() const
Definition: Series.cpp:172
Series & setDate(std::string const &date)
Indicate the date of creation.
Definition: Series.cpp:260
Series & setName(std::string const &name)
Set the pattern for file names.
Definition: Series.cpp:346
Series & setBasePath(std::string const &basePath)
Set the common prefix for all data sets and sub-groups of a specific iteration.
Definition: Series.cpp:161
std::string machine() const
Definition: Series.cpp:280
std::string name() const
Definition: Series.cpp:340
std::string author() const
Definition: Series.cpp:214
std::string iterationFormat() const
Definition: Series.cpp:320
Root level of the openPMD hierarchy.
Definition: Series.hpp:55
void flush()
Execute all required remaining IO operations to write or read data.
Definition: Series.cpp:366
uint32_t openPMDextension() const
Definition: Series.cpp:142
std::string backend() const
The currently used backend.
Definition: Series.cpp:360
Series & setMeshesPath(std::string const &meshesPath)
Set the path to mesh records, relative(!) to basePath.
Definition: Series.cpp:178
Public definitions of openPMD-api.
Definition: Date.cpp:28
IterationEncoding iterationEncoding() const
Definition: Series.cpp:293
Series & setIterationFormat(std::string const &iterationFormat)
Set a pattern describing how to access single iterations in the raw file.
Definition: Series.cpp:326
Series & setSoftwareVersion(std::string const &softwareVersion)
Indicate the version of the software/code/simulation that created the file.
Definition: Series.cpp:247
Series & setIterationEncoding(IterationEncoding iterationEncoding)
Set the encoding style for multiple iterations in this series.
Definition: Series.cpp:299
IterationEncoding
Encoding scheme of an Iterations Series&#39;.
Definition: IterationEncoding.hpp:32
Series & setParticlesPath(std::string const &particlesPath)
Set the path to groups for each particle species, relative(!) to basePath.
Definition: Series.cpp:199
Series & setAuthor(std::string const &author)
Indicate the author and contact for the information in the file.
Definition: Series.cpp:220
std::string softwareVersion() const
Definition: Series.cpp:241
Series & setOpenPMDextension(uint32_t openPMDextension)
Set a 32-bit mask of applied extensions to the openPMD standard.
Definition: Series.cpp:148
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:70
std::string particlesPath() const
Definition: Series.cpp:193
std::string date() const
Definition: Series.cpp:254
Series & setSoftware(std::string const &newName, std::string const &newVersion=std::string("unspecified"))
Indicate the software/code/simulation that created the file.
Definition: Series.cpp:233
std::string openPMD() const
Definition: Series.cpp:129
std::string software() const
Definition: Series.cpp:227
Layer to manage storage of attributes associated with file objects.
Definition: Attributable.hpp:65