IODA
HH.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * (C) Copyright 2020-2021 UCAR
4  *
5  * This software is licensed under the terms of the Apache Licence Version 2.0
6  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
7  */
8 /*! \defgroup ioda_cxx_engines_pub_HH HDF5 Engine
9  * \brief HDF5 Engine
10  * \ingroup ioda_cxx_engines_pub
11  *
12  * @{
13  * \file HH.h
14  * \brief HDF5 engine
15  */
16 
17 #include <string>
18 #include <utility>
19 
20 #include "../defs.h"
21 #include "Capabilities.h"
22 #include "Factory.h"
23 
24 namespace ioda {
25 class Group;
26 
27 namespace Engines {
28 /// \brief Functions that are helpful in creating a new ioda::Group that is backed by HDF5.
29 namespace HH {
30 /// \brief HDF5 library format versions
31 /// \ingroup ioda_cxx_engines_pub_HH
32 enum class HDF5_Version {
33  Earliest, ///< Use the earliest possible HDF5 format for storing objects.
34  V18, ///< Use the latest HDF5 v1.8 format for storing objects.
35  V110, ///< Use the latest HDF5 v1.10 format for storing objects.
36  V112, ///< Use the latest HDF5 v1.12 format for storing objects.
37  Latest ///< Use the latest possible HDF5 format for storing objects.
38 };
39 /// \ingroup ioda_cxx_engines_pub_HH
40 typedef std::pair<HDF5_Version, HDF5_Version> HDF5_Version_Range;
41 /// \ingroup ioda_cxx_engines_pub_HH
43 
44 /// \brief Convenience function to generate a random file name.
45 /// \see createMemoryFile
46 /// \ingroup ioda_cxx_engines_pub_HH
47 IODA_DL std::string genUniqueName();
48 
49 /// \brief Create a ioda::Group backed by an HDF5 file.
50 /// \ingroup ioda_cxx_engines_pub_HH
51 /// \param filename is the file name.
52 /// \param mode is the creation mode.
53 /// \param compat is the range of HDF5 versions that should be able to access this file.
54 IODA_DL Group createFile(const std::string& filename, BackendCreateModes mode,
56 
57 /// \brief Open a ioda::Group backed by an HDF5 file.
58 /// \ingroup ioda_cxx_engines_pub_HH
59 /// \param filename is the file name.
60 /// \param mode is the access mode.
61 /// \param compat is the range of HDF5 versions that should be able to access this file.
62 IODA_DL Group openFile(const std::string& filename, BackendOpenModes mode,
64 
65 /// \brief Create a ioda::Group backed by the HDF5 in-memory-store.
66 /// \ingroup ioda_cxx_engines_pub_HH
67 /// \param filename is the name of the file if it gets flushed
68 /// (written) to disk. Otherwise, it is a unique identifier.
69 /// If this id is reused, then we are re-opening the store.
70 /// \param mode is the creation mode. This only matters if
71 /// the file is flushed to disk.
72 /// \param flush_on_close instructs us to flush the memory
73 /// image to the disk when done.
74 /// If false, then the image is never written to disk.
75 /// \param increment_len_bytes is the length (in bytes) of
76 /// the initial memory image. As the image grows larger,
77 /// then additional memory allocations will be performed.
78 /// \param compat is the range of HDF5 versions that should be able to access this file.
79 IODA_DL Group createMemoryFile(const std::string& filename,
80  BackendCreateModes mode, // = BackendCreateModes::Fail_If_Exists,
81  bool flush_on_close = false, size_t increment_len_bytes = 1000000,
83 
84 /// \brief Map an HDF5 file in memory and open a ioda::Group.
85 /// \ingroup ioda_cxx_engines_pub_HH
86 /// \param filename is the name of the file to be opened.
87 /// \param mode is the access mode.
88 /// \param flush_on_close instructs us to flush the memory image
89 /// to the disk when done. If false, then the image is never written to disk.
90 /// \param increment_len_bytes is the length (in bytes) of the initial
91 /// memory image. As the image grows larger, then additional memory
92 /// allocations will be performed of increment_len bytes.
93 /// \param compat is the range of HDF5 versions that should be able to access this file.
94 ///
95 /// \details
96 /// While using openMemoryFile to open an existing file, if
97 /// flush_on_close is set to 1 and the mode is set to
98 /// BackendOpenModes::Read_Write, any change to the file contents are
99 /// saved to the file when the file is closed. If flush_on_close is set
100 /// to 0 and the flags for mode is set to BackendOpenModes::Read_Write,
101 /// any change to the file contents will be lost when the file is closed.
102 /// If the mode for openMemoryFile is set to BackendOpenModes::Read_Only,
103 /// no change to the file is allowed either in memory or on file.
104 IODA_DL Group openMemoryFile(const std::string& filename,
106  bool flush_on_close = false, size_t increment_len_bytes = 1000000,
108 
109 /// \brief Get capabilities of the HDF5 file-backed engine
110 /// \ingroup ioda_cxx_engines_pub_HH
112 
113 /// \brief Get capabilities of the HDF5 memory-backed engine
114 /// \ingroup ioda_cxx_engines_pub_HH
116 } // namespace HH
117 } // namespace Engines
118 } // namespace ioda
119 
120 /// @}
Structs that describe backend capabilities.
Definitions for setting up backends with file and memory I/O.
Groups are a new implementation of ObsSpaces.
Definition: Group.h:159
#define IODA_DL
A preprocessor tag that indicates that a symbol is to be exported/imported.
Definition: defs.h:110
IODA_DL Group createFile(const std::string &filename, BackendCreateModes mode, HDF5_Version_Range compat=defaultVersionRange())
Create a ioda::Group backed by an HDF5 file.
Definition: HH.cpp:113
IODA_DL HDF5_Version_Range defaultVersionRange()
Definition: HH.cpp:77
IODA_DL Group openFile(const std::string &filename, BackendOpenModes mode, HDF5_Version_Range compat=defaultVersionRange())
Open a ioda::Group backed by an HDF5 file.
Definition: HH.cpp:135
IODA_DL Capabilities getCapabilitiesFileEngine()
Get capabilities of the HDF5 file-backed engine.
Definition: HH.cpp:178
IODA_DL std::string genUniqueName()
Convenience function to generate a random file name.
Definition: HH.cpp:50
HDF5_Version
HDF5 library format versions.
Definition: HH.h:32
IODA_DL Capabilities getCapabilitiesInMemoryEngine()
Get capabilities of the HDF5 memory-backed engine.
Definition: HH.cpp:194
IODA_DL Group openMemoryFile(const std::string &filename, BackendOpenModes mode=BackendOpenModes::Read_Only, bool flush_on_close=false, size_t increment_len_bytes=1000000, HDF5_Version_Range compat=defaultVersionRange())
Map an HDF5 file in memory and open a ioda::Group.
Definition: HH.cpp:154
IODA_DL Group createMemoryFile(const std::string &filename, BackendCreateModes mode, bool flush_on_close=false, size_t increment_len_bytes=1000000, HDF5_Version_Range compat=defaultVersionRange())
Create a ioda::Group backed by the HDF5 in-memory-store.
Definition: HH.cpp:86
std::pair< HDF5_Version, HDF5_Version > HDF5_Version_Range
Definition: HH.h:40
@ Earliest
Use the earliest possible HDF5 format for storing objects.
@ V18
Use the latest HDF5 v1.8 format for storing objects.
@ V110
Use the latest HDF5 v1.10 format for storing objects.
@ Latest
Use the latest possible HDF5 format for storing objects.
@ V112
Use the latest HDF5 v1.12 format for storing objects.
BackendCreateModes
Definition: Factory.h:42
@ Read_Only
Open the file in read-only mode.
Struct defining what an engine can/cannot do.
Definition: Capabilities.h:47