openPMD-api
ADIOS1IOHandlerImpl.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 #include "openPMD/auxiliary/Export.hpp"
25 #include "openPMD/config.hpp"
26 
27 #if openPMD_HAVE_ADIOS1
28 #include "openPMD/IO/AbstractIOHandlerImpl.hpp"
29 #include <adios_read.h>
30 #endif
31 
32 #include <future>
33 #include <memory>
34 #include <string>
35 #if openPMD_HAVE_ADIOS1
36 #include <unordered_map>
37 #include <unordered_set>
38 #endif
39 
40 namespace openPMD
41 {
42 #if openPMD_HAVE_ADIOS1
43 class OPENPMDAPI_EXPORT ADIOS1IOHandlerImpl : public AbstractIOHandlerImpl
44 {
45 public:
47  virtual ~ADIOS1IOHandlerImpl();
48 
49  virtual void init();
50 
51  std::future<void> flush();
52 
53  void
54  createFile(Writable *, Parameter<Operation::CREATE_FILE> const &) override;
55  void
56  createPath(Writable *, Parameter<Operation::CREATE_PATH> const &) override;
57  void createDataset(
59  void extendDataset(
61  void openFile(Writable *, Parameter<Operation::OPEN_FILE> const &) override;
62  void
63  closeFile(Writable *, Parameter<Operation::CLOSE_FILE> const &) override;
64  void availableChunks(
66  void openPath(Writable *, Parameter<Operation::OPEN_PATH> const &) override;
67  void openDataset(Writable *, Parameter<Operation::OPEN_DATASET> &) override;
68  void
69  deleteFile(Writable *, Parameter<Operation::DELETE_FILE> const &) override;
70  void
71  deletePath(Writable *, Parameter<Operation::DELETE_PATH> const &) override;
72  void deleteDataset(
74  void deleteAttribute(
75  Writable *, Parameter<Operation::DELETE_ATT> const &) override;
76  void writeDataset(
77  Writable *, Parameter<Operation::WRITE_DATASET> const &) override;
78  void writeAttribute(
79  Writable *, Parameter<Operation::WRITE_ATT> const &) override;
80  void readDataset(Writable *, Parameter<Operation::READ_DATASET> &) override;
81  void readAttribute(Writable *, Parameter<Operation::READ_ATT> &) override;
82  void listPaths(Writable *, Parameter<Operation::LIST_PATHS> &) override;
83  void
84  listDatasets(Writable *, Parameter<Operation::LIST_DATASETS> &) override;
85  void listAttributes(Writable *, Parameter<Operation::LIST_ATTS> &) override;
86 
87  virtual int64_t open_write(Writable *);
88  virtual ADIOS_FILE *open_read(std::string const &name);
89  void close(int64_t);
90  void close(ADIOS_FILE *);
91  int64_t initialize_group(std::string const &name);
92  void
93  flush_attribute(int64_t group, std::string const &name, Attribute const &);
94 
95 protected:
96  ADIOS_READ_METHOD m_readMethod;
97  std::unordered_map<Writable *, std::shared_ptr<std::string> > m_filePaths;
98  std::unordered_map<std::shared_ptr<std::string>, int64_t> m_groups;
99  std::unordered_map<std::shared_ptr<std::string>, bool> m_existsOnDisk;
100  std::unordered_map<std::shared_ptr<std::string>, int64_t>
101  m_openWriteFileHandles;
102  std::unordered_map<std::shared_ptr<std::string>, ADIOS_FILE *>
103  m_openReadFileHandles;
105  {
106  ADIOS_SELECTION *selection;
107  std::shared_ptr<void> data; // needed to avoid early freeing
108  };
109  std::unordered_map<ADIOS_FILE *, std::vector<ScheduledRead> >
110  m_scheduledReads;
111  std::unordered_map<int64_t, std::unordered_map<std::string, Attribute> >
112  m_attributeWrites;
118  int64_t GetFileHandle(Writable *);
119 }; // ADIOS1IOHandlerImpl
120 #else
121 class OPENPMDAPI_EXPORT ADIOS1IOHandlerImpl
122 {}; // ADIOS1IOHandlerImpl
123 #endif
124 } // namespace openPMD
Definition: ADIOS1IOHandlerImpl.hpp:104
Varidic datatype supporting at least all formats for attributes specified in the openPMD standard...
Definition: Attribute.hpp:51
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:122
Public definitions of openPMD-api.
Definition: Date.cpp:28
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:63
Definition: ADIOS1IOHandlerImpl.hpp:43
Definition: AbstractIOHandlerImpl.hpp:35