openPMD-api
AbstractIOHandler.hpp
1 /* Copyright 2017-2021 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/IO/Access.hpp"
24 #include "openPMD/IO/Format.hpp"
25 #include "openPMD/IO/IOTask.hpp"
26 #include "openPMD/config.hpp"
27 
28 #if openPMD_HAVE_MPI
29 #include <mpi.h>
30 #endif
31 
32 #include <future>
33 #include <memory>
34 #include <queue>
35 #include <stdexcept>
36 #include <string>
37 
38 namespace openPMD
39 {
40 class no_such_file_error : public std::runtime_error
41 {
42 public:
43  no_such_file_error(std::string const &what_arg)
44  : std::runtime_error(what_arg)
45  {}
46  virtual ~no_such_file_error()
47  {}
48 };
49 
50 class unsupported_data_error : public std::runtime_error
51 {
52 public:
53  unsupported_data_error(std::string const &what_arg)
54  : std::runtime_error(what_arg)
55  {}
56  virtual ~unsupported_data_error()
57  {}
58 };
59 
64 // do not write `enum class FlushLevel : unsigned char` here since NVHPC
65 // does not compile it correctly
66 enum class FlushLevel
67 {
73  UserFlush,
94 };
95 
96 namespace internal
97 {
103  struct FlushParams
104  {
106  };
107 
108  /*
109  * To be used for reading
110  */
111  constexpr FlushParams defaultFlushParams{};
112 } // namespace internal
113 
123 {
124 public:
125 #if openPMD_HAVE_MPI
126  AbstractIOHandler(std::string path, Access at, MPI_Comm)
127  : directory{std::move(path)}, m_backendAccess{at}, m_frontendAccess{at}
128  {}
129 #endif
130  AbstractIOHandler(std::string path, Access at)
131  : directory{std::move(path)}, m_backendAccess{at}, m_frontendAccess{at}
132  {}
133  virtual ~AbstractIOHandler() = default;
134 
140  virtual void enqueue(IOTask const &iotask)
141  {
142  m_work.push(iotask);
143  }
144 
150  virtual std::future<void> flush(internal::FlushParams const &) = 0;
151 
153  virtual std::string backendName() const = 0;
154 
155  std::string const directory;
156  Access const m_backendAccess;
157  Access const m_frontendAccess;
158  std::queue<IOTask> m_work;
159 }; // AbstractIOHandler
160 
161 } // namespace openPMD
FlushLevel
Determine what items should be flushed upon Series::flush()
Definition: AbstractIOHandler.hpp:66
Self-contained description of a single IO operation.
Definition: IOTask.hpp:615
Access
File access mode to use during IO.
Definition: Access.hpp:27
Only creates/opens files, nothing more.
Definition: AbstractIOHandler.hpp:50
virtual void enqueue(IOTask const &iotask)
Add provided task to queue according to FIFO.
Definition: AbstractIOHandler.hpp:140
Restricted mode, ensures to set up the openPMD hierarchy (as far as defined so far) in the backend...
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:122
Definition: AbstractIOHandler.hpp:40
Public definitions of openPMD-api.
Definition: Date.cpp:28
Parameters recursively passed through the openPMD hierarchy when flushing.
Definition: AbstractIOHandler.hpp:103
Default mode, used when flushes are triggered internally, e.g.
Flush operation that was triggered by user code.