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/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 
63 enum class FlushLevel : unsigned char
64 {
70  UserFlush,
87 };
88 
89 
99 {
100 public:
101 #if openPMD_HAVE_MPI
102  AbstractIOHandler(std::string path, Access at, MPI_Comm)
103  : directory{std::move(path)},
104  m_backendAccess{at},
105  m_frontendAccess{at}
106  { }
107 #endif
108  AbstractIOHandler(std::string path, Access at)
109  : directory{std::move(path)},
110  m_backendAccess{at},
111  m_frontendAccess{at}
112  { }
113  virtual ~AbstractIOHandler() = default;
114 
119  virtual void enqueue(IOTask const& iotask)
120  {
121  m_work.push(iotask);
122  }
123 
128  virtual std::future< void > flush() = 0;
129 
131  virtual std::string backendName() const = 0;
132 
133  std::string const directory;
134  Access const m_backendAccess;
135  Access const m_frontendAccess;
136  std::queue< IOTask > m_work;
137  FlushLevel m_flushLevel = FlushLevel::InternalFlush;
138 }; // AbstractIOHandler
139 
140 } // namespace openPMD
openPMD::FlushLevel::UserFlush
@ UserFlush
Flush operation that was triggered by user code.
openPMD::FlushLevel::InternalFlush
@ InternalFlush
Default mode, used when flushes are triggered internally, e.g.
openPMD::AbstractIOHandler
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:98
openPMD::AbstractIOHandler::flush
virtual std::future< void > flush()=0
Process operations in queue according to FIFO.
openPMD
Public definitions of openPMD-api.
Definition: Date.cpp:29
openPMD::AbstractIOHandler::backendName
virtual std::string backendName() const =0
The currently used backend.
openPMD::IOTask
Self-contained description of a single IO operation.
Definition: IOTask.hpp:589
openPMD::FlushLevel::SkeletonOnly
@ SkeletonOnly
Restricted mode, ensures to set up the openPMD hierarchy (as far as defined so far) in the backend.
openPMD::Access
Access
File access mode to use during IO.
Definition: Access.hpp:28
openPMD::AbstractIOHandler::enqueue
virtual void enqueue(IOTask const &iotask)
Add provided task to queue according to FIFO.
Definition: AbstractIOHandler.hpp:119
openPMD::unsupported_data_error
Definition: AbstractIOHandler.hpp:50
openPMD::no_such_file_error
Definition: AbstractIOHandler.hpp:41
openPMD::FlushLevel
FlushLevel
Determine what items should be flushed upon Series::flush()
Definition: AbstractIOHandler.hpp:63