-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdataset_op.h
More file actions
204 lines (168 loc) · 6.34 KB
/
Copy pathdataset_op.h
File metadata and controls
204 lines (168 loc) · 6.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*******************************************************************************
* Copyright (C) 2015-2025 Commissariat a l'energie atomique et aux energies alternatives (CEA)
* Copyright (C) 2021-2022 Institute of Bioorganic Chemistry Polish Academy of Science (PSNC)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of CEA nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#ifndef DECL_HDF5_DATASET_OP_H_
#define DECL_HDF5_DATASET_OP_H_
#include <hdf5.h>
#ifdef H5_HAVE_PARALLEL
#include <mpi.h>
#endif
#include <string>
#include <unordered_map>
#include <paraconf.h>
#include <pdi/pdi_fwd.h>
#include <pdi/context.h>
#include <pdi/expression.h>
#include "attribute_op.h"
#include "collision_policy.h"
#include "dataset_explicit_type.h"
#include "selection.h"
namespace decl_hdf5 {
/** A Dataset_op represents an operation on a dataset: creating it and a read or
* write.
*/
class Dataset_op
{
public:
/** an I/O direction (read or write)
*/
enum Direction {
READ,
WRITE
};
private:
/// What to do when dataset already exists (default = OVERWRITE)
Collision_policy m_collision_policy;
/// direction of the transfer (read or write)
Direction m_direction;
/// the type of MPI-I/O parallel pointer (default = COLLECTIVE)
H5FD_mpio_xfer_t m_mpio = H5FD_MPIO_COLLECTIVE;
/// the name of the dataset where to transfer
PDI::Expression m_dataset;
/// the name of the value to transfer
std::string m_value;
/// a condition to check before doing the transfer
PDI::Expression m_when;
#ifdef H5_HAVE_PARALLEL
/// a communicator for parallel HDF5 (only for data triggered)
PDI::Expression m_communicator;
#endif
/// a selection in-memory
Selection m_memory_selection;
/// a selection in-dataset
Selection m_dataset_selection;
/// chunking property set from yaml
PDI::Expression m_chunking;
/// deflate property set from yaml
PDI::Expression m_deflate;
/// fletcher property set from yaml
PDI::Expression m_fletcher;
/// attributes of this dataset
std::vector<Attribute_op> m_attributes;
/** Creates dataset plist to pass to H5D_create
*
* \param ctx the context in which to operate
* \param dataset_type type of the dataset
* \param dataset_name name of the dataset
*
* \return dataset creation plist hid_t
*/
hid_t dataset_creation_plist(PDI::Context& ctx, const PDI::Datatype* dataset_type, const std::string& dataset_name);
public:
/** Builds a Dataset_op from its yaml config
*
* \param dir the operation direction
* \param name the value name
* \param default_when the default "when" clause as read from the file level (optional)
* \param file_collision_policy the collision policy string
*/
Dataset_op(Direction dir, std::string name, PDI::Expression default_when, Collision_policy file_collision_policy = Collision_policy::WRITE_INTO);
/** Builds a Dataset_op from its yaml config
*
* \param dir the operation direction
* \param name the value name
* \param default_when the default "when" clause as read from the file level (optional)
* \param tree the configuration tree
* \param collision_policy the collision policy string
*/
Dataset_op(
Direction dir,
std::string name,
PDI::Expression default_when,
PC_tree_t tree,
Collision_policy collision_policy = Collision_policy::WRITE_INTO
);
/** Accesses the direction of the transfer (read or write).
*
* \return The direction of the transfer (read or write)
*/
Direction direction() { return m_direction; }
/** Accesses the name of the value to transfer.
*
* \return The name of the value to transfer
*/
std::string value() const { return m_value; }
/** Accesses the name of the dataset where to transfer.
*
* \return The name of the dataset where to transfer
*/
const PDI::Expression& dataset() const { return m_dataset; }
/** Accesses the condition to check before doing the transfer.
*
* \return The condition to check before doing the transfer
*/
const PDI::Expression& when() const { return m_when; }
#ifdef H5_HAVE_PARALLEL
/** Accesses the communicator for parallel HDF5 (only for data triggered).
*
* \return The communicator for parallel HDF5 (only for data triggered)
*/
const PDI::Expression& communicator() const { return m_communicator; }
#endif
/** Set deflate dataset level
*
* \param ctx the context in which to operate
* \param level level of the deflate
*/
void deflate(PDI::Context& ctx, PDI::Expression level);
/** Set fletcher dataset
*
* \param ctx the context in which to operate
* \param value turn on fletcher if true, turn off if false
*/
void fletcher(PDI::Context& ctx, PDI::Expression value);
/** Executes the requested operation.
*
* \param ctx the context in which to operate
* \param h5_file the already opened HDF5 file id
* \param use_mpio whether the hdf5 read/write is parallel
* \param dsets the vector of the explicitly typed datasets defined in Yaml file.
*/
void execute(PDI::Context& ctx, hid_t h5_file, bool use_mpio, const std::vector<Dataset_explicit_type>& dsets);
private:
void do_read(PDI::Context& ctx, hid_t h5_file, hid_t read_lst);
void do_write(PDI::Context& ctx, hid_t h5_file, hid_t xfer_lst, const std::vector<Dataset_explicit_type>& dsets);
};
} // namespace decl_hdf5
#endif // DECL_HDF5_DATASET_OP_H_