openPMD-api
CommonADIOS1IOHandler.hpp
1 /* Copyright 2017-2021 Fabian Koller 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/config.hpp"
24 
25 #if openPMD_HAVE_ADIOS1
26 
27 #include "openPMD/IO/ADIOS/ADIOS1Auxiliary.hpp"
28 #include "openPMD/IO/ADIOS/ADIOS1FilePosition.hpp"
29 #include "openPMD/IO/AbstractIOHandler.hpp"
30 #include "openPMD/IO/AbstractIOHandlerImpl.hpp"
31 #include "openPMD/auxiliary/DerefDynamicCast.hpp"
32 #include "openPMD/auxiliary/Filesystem.hpp"
33 #include "openPMD/auxiliary/JSON_internal.hpp"
34 #include "openPMD/auxiliary/Memory.hpp"
35 #include "openPMD/auxiliary/StringManip.hpp"
36 
37 #include <adios.h>
38 #include <adios_read.h>
39 
40 #include <future>
41 #include <memory>
42 #include <string>
43 #include <unordered_map>
44 #include <unordered_set>
45 #include <utility>
46 
47 namespace openPMD
48 {
49 template <typename ChildClass> // CRT pattern
51 {
52 public:
53  void
56  void
58  void createDataset(
60  void extendDataset(
63  void
65  void availableChunks(
67  void openPath(Writable *, Parameter<Operation::OPEN_PATH> const &) override;
69  void
71  void
73  void deleteDataset(
75  void deleteAttribute(
76  Writable *, Parameter<Operation::DELETE_ATT> const &) override;
77  void
79  void writeAttribute(
80  Writable *, Parameter<Operation::WRITE_ATT> const &) override;
84  void
87  void
89 
90  void close(int64_t);
91  void close(ADIOS_FILE *);
92  void
93  flush_attribute(int64_t group, std::string const &name, Attribute const &);
94 
95 protected:
96  template <typename... Args>
97  CommonADIOS1IOHandlerImpl(Args &&...args)
98  : AbstractIOHandlerImpl{std::forward<Args>(args)...}
99  {}
100 
101  ADIOS_READ_METHOD m_readMethod;
102  std::unordered_map<Writable *, std::shared_ptr<std::string> > m_filePaths;
103  std::unordered_map<std::shared_ptr<std::string>, int64_t> m_groups;
104  std::unordered_map<std::shared_ptr<std::string>, bool> m_existsOnDisk;
105  std::unordered_map<std::shared_ptr<std::string>, int64_t>
106  m_openWriteFileHandles;
107  std::unordered_map<std::shared_ptr<std::string>, ADIOS_FILE *>
108  m_openReadFileHandles;
110  {
111  ADIOS_SELECTION *selection;
112  std::shared_ptr<void> data; // needed to avoid early freeing
113  };
114  std::unordered_map<ADIOS_FILE *, std::vector<ScheduledRead> >
115  m_scheduledReads;
116  std::unordered_map<int64_t, std::unordered_map<std::string, Attribute> >
117  m_attributeWrites;
118  // config options
119  std::string m_defaultTransform;
125  int64_t GetFileHandle(Writable *);
126 
127  void initJson(json::TracingJSON);
128 }; // ParallelADIOS1IOHandlerImpl
129 } // namespace openPMD
130 
131 #endif
Extend nlohmann::json with tracing of which keys have been accessed by operator[]().
Definition: JSON_internal.hpp:67
void deleteDataset(Writable *, Parameter< Operation::DELETE_DATASET > const &) override
Delete an existing dataset.
void extendDataset(Writable *, Parameter< Operation::EXTEND_DATASET > const &) override
Increase the extent of an existing dataset.
void deleteFile(Writable *, Parameter< Operation::DELETE_FILE > const &) override
Delete an existing file from physical storage.
Definition: CommonADIOS1IOHandler.hpp:50
void readAttribute(Writable *, Parameter< Operation::READ_ATT > &) override
Read the value of an existing attribute.
void createFile(Writable *, Parameter< Operation::CREATE_FILE > const &) override
Create a new file in physical storage, possibly overriding an existing file.
void deleteAttribute(Writable *, Parameter< Operation::DELETE_ATT > const &) override
Delete an existing attribute.
void deregister(Writable *, Parameter< Operation::DEREGISTER > const &) override
Notify the backend that the Writable has been / will be deallocated.
void writeAttribute(Writable *, Parameter< Operation::WRITE_ATT > const &) override
Create a single attribute and fill the value, possibly overwriting an existing attribute.
void listAttributes(Writable *, Parameter< Operation::LIST_ATTS > &) override
List all attributes associated with an object.
void createPath(Writable *, Parameter< Operation::CREATE_PATH > const &) override
Create all necessary groups for a path, possibly recursively.
Definition: CommonADIOS1IOHandler.hpp:109
void openDataset(Writable *, Parameter< Operation::OPEN_DATASET > &) override
Open an existing dataset and determine its datatype and extent.
void closeFile(Writable *, Parameter< Operation::CLOSE_FILE > const &) override
Close the file corresponding with the writable and release file handles.
void deletePath(Writable *, Parameter< Operation::DELETE_PATH > const &) override
Delete all objects within an existing path.
void listDatasets(Writable *, Parameter< Operation::LIST_DATASETS > &) override
List all datasets inside a group, non-recursively.
void availableChunks(Writable *, Parameter< Operation::AVAILABLE_CHUNKS > &) override
Report chunks that are available for loading from the dataset represented by this writable...
Varidic datatype supporting at least all formats for attributes specified in the openPMD standard...
Definition: Attribute.hpp:54
void checkFile(Writable *, Parameter< Operation::CHECK_FILE > &) override
Check if the file specified by the parameter is already present on disk.
Public definitions of openPMD-api.
int64_t GetFileHandle(Writable *)
Call this function to get adios file id for a Writable.
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:64
void writeDataset(Writable *, Parameter< Operation::WRITE_DATASET > &) override
Write a chunk of data into an existing dataset.
void openPath(Writable *, Parameter< Operation::OPEN_PATH > const &) override
Open all contained groups in a path, possibly recursively.
void listPaths(Writable *, Parameter< Operation::LIST_PATHS > &) override
List all paths/sub-groups inside a group, non-recursively.
void openFile(Writable *, Parameter< Operation::OPEN_FILE > &) override
Open an existing file assuming it conforms to openPMD.
Definition: AbstractIOHandlerImpl.hpp:35
void createDataset(Writable *, Parameter< Operation::CREATE_DATASET > const &) override
Create a new dataset of given type, extent and storage properties.
void readDataset(Writable *, Parameter< Operation::READ_DATASET > &) override
Read a chunk of data from an existing dataset.