openPMD-api
HDF5IOHandlerImpl.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/config.hpp"
24 #if openPMD_HAVE_HDF5
25 # include "openPMD/IO/AbstractIOHandlerImpl.hpp"
26 
27 # include "openPMD/auxiliary/JSON.hpp"
28 # include "openPMD/auxiliary/Option.hpp"
29 
30 # include <hdf5.h>
31 # include <unordered_map>
32 # include <unordered_set>
33 #endif
34 
35 
36 namespace openPMD
37 {
38 #if openPMD_HAVE_HDF5
40  {
41  public:
42  HDF5IOHandlerImpl(AbstractIOHandler*, nlohmann::json config);
43  ~HDF5IOHandlerImpl() override;
44 
50  void openFile(Writable*, Parameter< Operation::OPEN_FILE > const&) override;
52  void openPath(Writable*, Parameter< Operation::OPEN_PATH > const&) override;
65 
66  std::unordered_map< Writable*, std::string > m_fileNames;
67  std::unordered_map< std::string, hid_t > m_fileNamesWithID;
68 
69  std::unordered_set< hid_t > m_openFileIDs;
70 
71  hid_t m_datasetTransferProperty;
72  hid_t m_fileAccessProperty;
73 
74  // h5py compatible types for bool and complex
75  hid_t m_H5T_BOOL_ENUM;
76  hid_t m_H5T_CFLOAT;
77  hid_t m_H5T_CDOUBLE;
78  hid_t m_H5T_CLONG_DOUBLE;
79 
80  private:
81  auxiliary::TracingJSON m_config;
82  std::string m_chunks = "auto";
83  struct File
84  {
85  std::string name;
86  hid_t id;
87  };
89  }; // HDF5IOHandlerImpl
90 #else
91  class HDF5IOHandlerImpl
92  {
93  }; // HDF5IOHandlerImpl
94 #endif
95 
96 } // openPMD
openPMD::Parameter< Operation::CLOSE_FILE >
Definition: IOTask.hpp:149
openPMD::Parameter< Operation::LIST_ATTS >
Definition: IOTask.hpp:514
openPMD::Writable
Layer to mirror structure of logical data and persistent data in file.
Definition: Writable.hpp:64
openPMD::HDF5IOHandlerImpl::openPath
void openPath(Writable *, Parameter< Operation::OPEN_PATH > const &) override
Open all contained groups in a path, possibly recursively.
Definition: HDF5IOHandler.cpp:597
openPMD::HDF5IOHandlerImpl::availableChunks
void availableChunks(Writable *, Parameter< Operation::AVAILABLE_CHUNKS > &) override
Report chunks that are available for loading from the dataset represented by this writable.
Definition: HDF5IOHandler.cpp:472
openPMD::HDF5IOHandlerImpl::openDataset
void openDataset(Writable *, Parameter< Operation::OPEN_DATASET > &) override
Open an existing dataset and determine its datatype and extent.
Definition: HDF5IOHandler.cpp:638
openPMD::Parameter< Operation::READ_DATASET >
Definition: IOTask.hpp:373
openPMD::HDF5IOHandlerImpl::listPaths
void listPaths(Writable *, Parameter< Operation::LIST_PATHS > &) override
List all paths/sub-groups inside a group, non-recursively.
Definition: HDF5IOHandler.cpp:1775
openPMD::HDF5IOHandlerImpl::deleteAttribute
void deleteAttribute(Writable *, Parameter< Operation::DELETE_ATT > const &) override
Delete an existing attribute.
Definition: HDF5IOHandler.cpp:859
openPMD::Parameter< Operation::DELETE_FILE >
Definition: IOTask.hpp:163
openPMD::Parameter< Operation::WRITE_ATT >
Definition: IOTask.hpp:467
openPMD::HDF5IOHandlerImpl::writeDataset
void writeDataset(Writable *, Parameter< Operation::WRITE_DATASET > const &) override
Write a chunk of data into an existing dataset.
Definition: HDF5IOHandler.cpp:887
openPMD::HDF5IOHandlerImpl::listDatasets
void listDatasets(Writable *, Parameter< Operation::LIST_DATASETS > &) override
List all datasets inside a group, non-recursively.
Definition: HDF5IOHandler.cpp:1809
openPMD::Parameter< Operation::AVAILABLE_CHUNKS >
Definition: IOTask.hpp:555
openPMD::Parameter< Operation::CREATE_FILE >
Definition: IOTask.hpp:108
openPMD::Parameter< Operation::DELETE_PATH >
Definition: IOTask.hpp:233
openPMD::Parameter< Operation::WRITE_DATASET >
Definition: IOTask.hpp:344
openPMD::HDF5IOHandlerImpl::createDataset
void createDataset(Writable *, Parameter< Operation::CREATE_DATASET > const &) override
Create a new dataset of given type, extent and storage properties.
Definition: HDF5IOHandler.cpp:262
openPMD::Parameter< Operation::LIST_PATHS >
Definition: IOTask.hpp:249
openPMD::AbstractIOHandler
Interface for communicating between logical and physically persistent data.
Definition: AbstractIOHandler.hpp:98
openPMD::Parameter< Operation::LIST_DATASETS >
Definition: IOTask.hpp:402
openPMD::auxiliary::Option
Simple Option type based on variantSrc::variant.
Definition: Option.hpp:47
openPMD::HDF5IOHandlerImpl
Definition: HDF5IOHandlerImpl.hpp:39
openPMD::HDF5IOHandlerImpl::createPath
void createPath(Writable *, Parameter< Operation::CREATE_PATH > const &) override
Create all necessary groups for a path, possibly recursively.
Definition: HDF5IOHandler.cpp:199
openPMD::HDF5IOHandlerImpl::openFile
void openFile(Writable *, Parameter< Operation::OPEN_FILE > const &) override
Open an existing file assuming it conforms to openPMD.
Definition: HDF5IOHandler.cpp:533
openPMD::HDF5IOHandlerImpl::readAttribute
void readAttribute(Writable *, Parameter< Operation::READ_ATT > &) override
Read the value of an existing attribute.
Definition: HDF5IOHandler.cpp:1345
openPMD::HDF5IOHandlerImpl::deleteFile
void deleteFile(Writable *, Parameter< Operation::DELETE_FILE > const &) override
Delete an existing file from physical storage.
Definition: HDF5IOHandler.cpp:742
openPMD::AbstractIOHandlerImpl
Definition: AbstractIOHandlerImpl.hpp:35
openPMD::HDF5IOHandlerImpl::writeAttribute
void writeAttribute(Writable *, Parameter< Operation::WRITE_ATT > const &) override
Create a single attribute and fill the value, possibly overwriting an existing attribute.
Definition: HDF5IOHandler.cpp:983
openPMD
Public definitions of openPMD-api.
Definition: Date.cpp:29
openPMD::Parameter< Operation::EXTEND_DATASET >
Definition: IOTask.hpp:291
openPMD::Parameter< Operation::DELETE_ATT >
Definition: IOTask.hpp:451
openPMD::Parameter< Operation::OPEN_DATASET >
Definition: IOTask.hpp:307
openPMD::HDF5IOHandlerImpl::closeFile
void closeFile(Writable *, Parameter< Operation::CLOSE_FILE > const &) override
Close the file corresponding with the writable and release file handles.
Definition: HDF5IOHandler.cpp:577
openPMD::Parameter< Operation::DELETE_DATASET >
Definition: IOTask.hpp:328
openPMD::Parameter< Operation::CREATE_DATASET >
Definition: IOTask.hpp:266
openPMD::Parameter< Operation::CREATE_PATH >
Definition: IOTask.hpp:179
openPMD::HDF5IOHandlerImpl::extendDataset
void extendDataset(Writable *, Parameter< Operation::EXTEND_DATASET > const &) override
Increase the extent of an existing dataset.
Definition: HDF5IOHandler.cpp:421
openPMD::auxiliary::TracingJSON
Extend nlohmann::json with tracing of which keys have been accessed by operator[]().
Definition: JSON.hpp:52
openPMD::HDF5IOHandlerImpl::deletePath
void deletePath(Writable *, Parameter< Operation::DELETE_PATH > const &) override
Delete all objects within an existing path.
Definition: HDF5IOHandler.cpp:773
openPMD::Parameter< Operation::OPEN_PATH >
Definition: IOTask.hpp:217
openPMD::Parameter< Operation::OPEN_FILE >
Definition: IOTask.hpp:126
openPMD::Parameter< Operation::READ_ATT >
Definition: IOTask.hpp:486
openPMD::HDF5IOHandlerImpl::listAttributes
void listAttributes(Writable *, Parameter< Operation::LIST_ATTS > &) override
List all attributes associated with an object.
Definition: HDF5IOHandler.cpp:1842
openPMD::HDF5IOHandlerImpl::createFile
void createFile(Writable *, Parameter< Operation::CREATE_FILE > const &) override
Create a new file in physical storage, possibly overriding an existing file.
Definition: HDF5IOHandler.cpp:161
openPMD::HDF5IOHandlerImpl::readDataset
void readDataset(Writable *, Parameter< Operation::READ_DATASET > &) override
Read a chunk of data from an existing dataset.
Definition: HDF5IOHandler.cpp:1256
openPMD::HDF5IOHandlerImpl::deleteDataset
void deleteDataset(Writable *, Parameter< Operation::DELETE_DATASET > const &) override
Delete an existing dataset.
Definition: HDF5IOHandler.cpp:816