openPMD-api
Writable.hpp
1 /* Copyright 2017-2021 Fabian Koller
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/IO/AbstractIOHandler.hpp"
24 
25 #include <memory>
26 #include <string>
27 #include <vector>
28 
29 // expose private and protected members for invasive testing
30 #ifndef OPENPMD_private
31 #define OPENPMD_private private:
32 #endif
33 
34 namespace openPMD
35 {
36 namespace test
37 {
38  struct TestHelper;
39 } // namespace test
40 class AbstractFilePosition;
41 class AbstractIOHandler;
42 struct ADIOS2FilePosition;
43 template <typename FilePositionType>
45 template <typename>
46 class Span;
47 
48 namespace internal
49 {
50  class AttributableData;
51  class SeriesData;
52 } // namespace internal
53 
64 class Writable final
65 {
66  friend class internal::AttributableData;
67  friend class internal::SeriesData;
68  friend class Attributable;
69  template <typename T_elem>
70  friend class BaseRecord;
71  template <typename T_elem>
72  friend class BaseRecordInterface;
73  template <typename T, typename T_key, typename T_container>
74  friend class Container;
75  friend class Iteration;
76  friend class Mesh;
77  friend class ParticleSpecies;
78  friend class Series;
79  friend class Record;
80  friend class AbstractIOHandlerImpl;
81  template <typename>
82  friend class CommonADIOS1IOHandlerImpl;
83  friend class ADIOS1IOHandlerImpl;
84  friend class ParallelADIOS1IOHandlerImpl;
85  friend class ADIOS2IOHandlerImpl;
86  friend class HDF5IOHandlerImpl;
87  friend class ParallelHDF5IOHandlerImpl;
88  friend class AbstractIOHandlerImplCommon<ADIOS2FilePosition>;
89  friend class JSONIOHandlerImpl;
90  friend struct test::TestHelper;
91  friend std::string concrete_h5_file_position(Writable *);
92  friend std::string concrete_bp1_file_position(Writable *);
93  template <typename>
94  friend class Span;
95 
96 private:
98 
99 public:
100  ~Writable();
101 
102  Writable(Writable const &other) = delete;
103  Writable(Writable &&other) = delete;
104  Writable &operator=(Writable const &other) = delete;
105  Writable &operator=(Writable &&other) = delete;
106 
114  void seriesFlush(std::string backendConfig = "{}");
115 
116  // clang-format off
117 OPENPMD_private
118  // clang-format on
119 
120  void seriesFlush(internal::FlushParams);
121  /*
122  * These members need to be shared pointers since distinct instances of
123  * Writable may share them.
124  */
125  std::shared_ptr<AbstractFilePosition> abstractFilePosition = nullptr;
126  /*
127  * shared_ptr since the IOHandler is shared by multiple Writable instances.
128  * optional to make it possible to release the IOHandler, without first
129  * having to destroy every single Writable.
130  * unique_ptr since AbstractIOHandler is an abstract class.
131  */
132  std::shared_ptr<std::optional<std::unique_ptr<AbstractIOHandler>>>
133  IOHandler = nullptr;
134  internal::AttributableData *attributable = nullptr;
135  Writable *parent = nullptr;
136  bool dirty = true;
143  std::vector<std::string> ownKeyWithinParent;
159  bool written = false;
160 };
161 } // namespace openPMD
Definition: CommonADIOS1IOHandler.hpp:50
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:126
Definition: ADIOS2IOHandler.hpp:108
Definition: JSONIOHandlerImpl.hpp:151
Implementation for the root level of the openPMD hierarchy.
Definition: Series.hpp:186
Definition: ParallelHDF5IOHandlerImpl.hpp:37
Public definitions of openPMD-api.
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:64
Definition: Record.hpp:32
Data members for Series.
Definition: Series.hpp:67
Definition: Attributable.hpp:56
Definition: ADIOS1IOHandlerImpl.hpp:42
Definition: BaseRecord.hpp:58
Parameters recursively passed through the openPMD hierarchy when flushing.
Definition: AbstractIOHandler.hpp:84
Definition: Writable.hpp:44
Subset of C++20 std::span class template.
Definition: Writable.hpp:46
Definition: ParticleSpecies.hpp:33
Container for N-dimensional, homogeneous Records.
Definition: Mesh.hpp:40
Map-like container that enforces openPMD requirements and handles IO.
Definition: Container.hpp:131
Definition: HDF5IOHandlerImpl.hpp:38
Definition: AbstractIOHandlerImpl.hpp:35
std::vector< std::string > ownKeyWithinParent
If parent is not null, then this is a vector of keys such that: &(*parent)[key_1]...[key_n] == this (Noti...
Definition: Writable.hpp:143
Definition: ParallelADIOS1IOHandlerImpl.hpp:43
Layer to manage storage of attributes associated with file objects.
Definition: Attributable.hpp:93