openPMD-api
RecordComponent.hpp
1 /* Copyright 2017-2021 Fabian Koller, Axel Huebl and Franz Poeschel
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/Dataset.hpp"
24 #include "openPMD/auxiliary/ShareRaw.hpp"
25 #include "openPMD/backend/BaseRecordComponent.hpp"
26 
27 #include <array>
28 #include <cmath>
29 #include <limits>
30 #include <memory>
31 #include <queue>
32 #include <sstream>
33 #include <stdexcept>
34 #include <string>
35 #include <type_traits>
36 #include <vector>
37 
38 // expose private and protected members for invasive testing
39 #ifndef OPENPMD_protected
40 #define OPENPMD_protected protected
41 #endif
42 
43 namespace openPMD
44 {
45 namespace traits
46 {
55  template <typename T>
57  {
58  static constexpr bool value = false;
59  };
60 
61  template <typename T_Value>
62  struct IsContiguousContainer<std::vector<T_Value> >
63  {
64  static constexpr bool value = true;
65  };
66 
67  template <typename T_Value, std::size_t N>
68  struct IsContiguousContainer<std::array<T_Value, N> >
69  {
70  static constexpr bool value = true;
71  };
72 } // namespace traits
73 
74 template <typename T>
76 
78 {
79  template <typename T, typename T_key, typename T_container>
80  friend class Container;
81  friend class Iteration;
82  friend class ParticleSpecies;
83  template <typename T_elem>
84  friend class BaseRecord;
85  friend class Record;
86  friend class Mesh;
87  template <typename>
88  friend class DynamicMemoryView;
89 
90 public:
91  enum class Allocation
92  {
93  USER,
94  API,
95  AUTO
96  }; // Allocation
97 
98  RecordComponent &setUnitSI(double);
99 
119  RecordComponent &resetDataset(Dataset);
120 
121  uint8_t getDimensionality() const;
122  Extent getExtent() const;
123 
132  template <typename T>
133  RecordComponent &makeConstant(T);
134 
143  template <typename T>
144  RecordComponent &makeEmpty(uint8_t dimensions);
145 
154  RecordComponent &makeEmpty(Datatype dt, uint8_t dimensions);
155 
163  bool empty() const;
164 
172  template <typename T>
173  std::shared_ptr<T> loadChunk(Offset = {0u}, Extent = {-1u});
174 
185  template <typename T>
186  void loadChunk(std::shared_ptr<T>, Offset, Extent);
187 
188  template <typename T>
189  void storeChunk(std::shared_ptr<T>, Offset, Extent);
190 
191  template <typename T_ContiguousContainer>
192  typename std::enable_if<
194  storeChunk(T_ContiguousContainer &, Offset = {0u}, Extent = {-1u});
195 
226  template <typename T, typename F>
227  DynamicMemoryView<T> storeChunk(Offset, Extent, F &&createBuffer);
228 
233  template <typename T>
234  DynamicMemoryView<T> storeChunk(Offset, Extent);
235 
236  static constexpr char const *const SCALAR = "\vScalar";
237 
238  virtual ~RecordComponent() = default;
239 
240  OPENPMD_protected:
241  RecordComponent();
242 
243  void readBase();
244 
245  std::shared_ptr<std::queue<IOTask> > m_chunks;
246  std::shared_ptr<Attribute> m_constantValue;
247  std::shared_ptr<bool> m_isEmpty = std::make_shared<bool>(false);
248  // User has extended the dataset, but the EXTEND task must yet be flushed
249  // to the backend
250  std::shared_ptr<bool> m_hasBeenExtended = std::make_shared<bool>(false);
251 
252 private:
253  void flush(std::string const &, internal::FlushParams const &);
254  virtual void read();
255 
262  RecordComponent &makeEmpty(Dataset d);
263 
272  bool dirtyRecursive() const;
273 
274 protected:
283  std::shared_ptr<std::string> m_name = std::make_shared<std::string>();
284 
285 }; // RecordComponent
286 } // namespace openPMD
287 
288 #include "RecordComponent.tpp"
Definition: Dataset.hpp:35
Logical compilation of data from one snapshot (e.g.
Definition: Iteration.hpp:40
Emulate in the C++17 concept ContiguousContainer.
Definition: RecordComponent.hpp:56
STL namespace.
Datatype
Concrete datatype of an object available at runtime.
Definition: Datatype.hpp:45
Definition: RecordComponent.hpp:77
Public definitions of openPMD-api.
Definition: Date.cpp:28
Definition: Record.hpp:32
Definition: BaseRecord.hpp:35
Parameters recursively passed through the openPMD hierarchy when flushing.
Definition: AbstractIOHandler.hpp:103
A view into a buffer that might be reallocated at some points and thus has changing base pointers ove...
Definition: RecordComponent.hpp:75
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:105
Definition: BaseRecordComponent.hpp:33