openPMD-api
AbstractIOHandler.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/IO/Access.hpp"
25 #include "openPMD/IO/Format.hpp"
26 #include "openPMD/IO/IOTask.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 
39 namespace openPMD
40 {
41 class no_such_file_error : public std::runtime_error
42 {
43 public:
44  no_such_file_error(std::string const& what_arg)
45  : std::runtime_error(what_arg)
46  { }
47  virtual ~no_such_file_error() { }
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 
69 {
70 public:
71 #if openPMD_HAVE_MPI
72  AbstractIOHandler(std::string path, Access at, MPI_Comm)
73  : directory{std::move(path)},
74  m_backendAccess{at},
75  m_frontendAccess{at}
76  { }
77 #endif
78  AbstractIOHandler(std::string path, Access at)
79  : directory{std::move(path)},
80  m_backendAccess{at},
81  m_frontendAccess{at}
82  { }
83  virtual ~AbstractIOHandler() = default;
84 
89  virtual void enqueue(IOTask const& iotask)
90  {
91  m_work.push(iotask);
92  }
93 
98  virtual std::future< void > flush() = 0;
99 
101  virtual std::string backendName() const = 0;
102 
103  std::string const directory;
104  Access const m_backendAccess;
105  Access const m_frontendAccess;
106  std::queue< IOTask > m_work;
107 }; // AbstractIOHandler
108 
109 } // namespace openPMD
Self-contained description of a single IO operation.
Definition: IOTask.hpp:550
Access
File access mode to use during IO.
Definition: Access.hpp:28
Definition: AbstractIOHandler.hpp:50
virtual void enqueue(IOTask const &iotask)
Add provided task to queue according to FIFO.
Definition: AbstractIOHandler.hpp:89
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:68
Definition: AbstractIOHandler.hpp:41
Public definitions of openPMD-api.
Definition: Date.cpp:29