Skip to content

Commit

Permalink
relay: preserve creation order for hdf5 i/o
Browse files Browse the repository at this point in the history
relay write functions enable creation order tracking
relay read functions use creation order indices if available
  • Loading branch information
cyrush committed Apr 22, 2016
1 parent 2e58997 commit bc50a02
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 24 deletions.
43 changes: 32 additions & 11 deletions src/libs/relay/relay_hdf5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,16 +519,19 @@ check_if_conduit_object_is_compatible_with_hdf5_tree(const Node &node,
// check if the HDF5 group has child with same name
// as the node's child

hid_t h5_child_id = H5Oopen(hdf5_id,
hid_t h5_child_obj = H5Oopen(hdf5_id,
itr.path().c_str(),
H5P_DEFAULT);

if( CONDUIT_HDF5_VALID_ID(h5_child_id) )
if( CONDUIT_HDF5_VALID_ID(h5_child_obj) )
{
// if a child does exist, we need to make sure the child is
// compatible with the conduit node
res = check_if_conduit_node_is_compatible_with_hdf5_tree(child,
h5_child_id);
h5_child_obj);

CONDUIT_CHECK_HDF5_ERROR(H5Oclose(h5_child_obj),
"Failed to close HDF5 Object: " << h5_child_obj);
}

// no child exists with this name, we are ok (it can be created
Expand Down Expand Up @@ -1047,7 +1050,7 @@ read_hdf5_group_into_conduit_node(hid_t hdf5_group_id,

hid_t h5_gc_plist = H5Gget_create_plist(hdf5_group_id);

if( CONDUIT_HDF5_VALID_ID(h5_status) )
if( CONDUIT_HDF5_VALID_ID(h5_gc_plist) )
{
unsigned int h5_gc_flags = 0;
h5_status = H5Pget_link_creation_order(h5_gc_plist,
Expand Down Expand Up @@ -1246,25 +1249,41 @@ hdf5_write(const Node &node,
const std::string &file_path,
const std::string &hdf5_path)
{
herr_t h5_status = 0;
// preserve creation order
hid_t h5_file_plist = H5Pcreate(H5P_FILE_CREATE);

CONDUIT_CHECK_HDF5_ERROR(h5_file_plist,
"Failed to create H5P_FILE_CREATE property "
<< " list");


herr_t h5_status = H5Pset_link_creation_order(h5_file_plist,
( H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED) );

CONDUIT_CHECK_HDF5_ERROR(h5_status,
"Failed to set creation order options for property "
<< "list");

// open the hdf5 file for writing
hid_t h5_file_id = H5Fcreate(file_path.c_str(),
H5F_ACC_TRUNC,
H5P_DEFAULT,
h5_file_plist,
H5P_DEFAULT);

CONDUIT_CHECK_HDF5_ERROR(h5_file_id,
"Error opening HDF5 file for writing: "
<< file_path);

CONDUIT_CHECK_HDF5_ERROR(H5Pclose(h5_file_plist),
"Failed to close HDF5 H5P_GROUP_CREATE "
<< "property list: " << h5_file_plist);

hdf5_write(node,
h5_file_id,
hdf5_path);

// close the hdf5 file
h5_status = H5Fclose(h5_file_id);
CONDUIT_CHECK_HDF5_ERROR(h5_status,
CONDUIT_CHECK_HDF5_ERROR(H5Fclose(h5_file_id),
"Error closing HDF5 file: " << file_path);
}

Expand Down Expand Up @@ -1427,8 +1446,7 @@ hdf5_read(const std::string &file_path,
node);

// close the hdf5 file
h5_status = H5Fclose(h5_file_id);
CONDUIT_CHECK_HDF5_ERROR(h5_status,
CONDUIT_CHECK_HDF5_ERROR(H5Fclose(h5_file_id),
"Error closing HDF5 file: " << file_path);
}
//---------------------------------------------------------------------------//
Expand All @@ -1446,11 +1464,14 @@ hdf5_read(hid_t hdf5_id,
H5P_DEFAULT);

CONDUIT_CHECK_HDF5_ERROR(h5_child_obj,
"Error fetching HDF5 object from: "
"Failed to fetch HDF5 object from: "
<< hdf5_id << ":" << hdf5_path);

read_hdf5_tree_into_conduit_node(h5_child_obj,dest);

CONDUIT_CHECK_HDF5_ERROR(H5Oclose(h5_child_obj),
"Failed to close HDF5 Object: " << h5_child_obj);

// enable hdf5 error stack
}

Expand Down
89 changes: 76 additions & 13 deletions src/tests/relay/t_relay_io_hdf5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ using namespace conduit::relay;


//-----------------------------------------------------------------------------
TEST(conduit_io_hdf5, conduit_hdf5_write_read_by_file_name)
TEST(conduit_relay_io_hdf5, conduit_hdf5_write_read_by_file_name)
{
uint32 a_val = 20;
uint32 b_val = 8;
Expand Down Expand Up @@ -125,7 +125,7 @@ TEST(conduit_io_hdf5, conduit_hdf5_write_read_by_file_name)
//-----------------------------------------------------------------------------
// This variant tests when a caller code has already opened a HDF5 file
// and has a handle ready.
TEST(conduit_io_hdf5, conduit_hdf5_write_read_by_file_handle)
TEST(conduit_relay_io_hdf5, conduit_hdf5_write_read_by_file_handle)
{
uint32 a_val = 20;
uint32 b_val = 8;
Expand Down Expand Up @@ -197,7 +197,7 @@ TEST(conduit_io_hdf5, conduit_hdf5_write_read_by_file_handle)
}

//-----------------------------------------------------------------------------
TEST(conduit_io_hdf5, conduit_hdf5_write_read_special_paths)
TEST(conduit_relay_io_hdf5, conduit_hdf5_write_read_special_paths)
{
uint32 a_val = 20;
uint32 b_val = 8;
Expand Down Expand Up @@ -240,7 +240,7 @@ TEST(conduit_io_hdf5, conduit_hdf5_write_read_special_paths)


//-----------------------------------------------------------------------------
TEST(conduit_io_hdf5, conduit_hdf5_write_read_string)
TEST(conduit_relay_io_hdf5, conduit_hdf5_write_read_string)
{
uint32 a_val = 20;

Expand All @@ -267,7 +267,7 @@ TEST(conduit_io_hdf5, conduit_hdf5_write_read_string)
}

//-----------------------------------------------------------------------------
TEST(conduit_io_hdf5, conduit_hdf5_write_read_array)
TEST(conduit_relay_io_hdf5, conduit_hdf5_write_read_array)
{
Node n_in(DataType::float64(10));

Expand All @@ -293,10 +293,24 @@ TEST(conduit_io_hdf5, conduit_hdf5_write_read_array)
EXPECT_EQ(val_in[i],val_out[i]);
}

}
//-----------------------------------------------------------------------------
TEST(conduit_relay_io_hdf5, conduit_hdf5_read_dataset_from_handle)
{
EXPECT_TRUE(false);

}

//-----------------------------------------------------------------------------
TEST(conduit_io_hdf5, conduit_hdf5_write_to_existing_dset)
TEST(conduit_relay_io_hdf5, conduit_hdf5_read_group_from_handle)
{
EXPECT_TRUE(false);

}


//-----------------------------------------------------------------------------
TEST(conduit_relay_io_hdf5, conduit_hdf5_write_to_existing_dset)
{
Node n_in(DataType::uint32(2));

Expand Down Expand Up @@ -333,20 +347,40 @@ TEST(conduit_io_hdf5, conduit_hdf5_write_to_existing_dset)

// check that the second set of values are the ones we get back

Node n_out;
Node n_read;

io::hdf5_read("tout_hdf5_wr_existing_dset.hdf5:myarray",n_read);

uint32_array val = n_read.value();

io::hdf5_read("tout_hdf5_wr_existing_dset.hdf5:myarray",n_out);
EXPECT_EQ(val[0],3);
EXPECT_EQ(val[1],4);

uint32_array val_out = n_out.value();
Node n_w2;
n_w2["myarray"].set_external(n_read);
n_w2["a/b/c"].set_uint64(123);

EXPECT_EQ(val_out[0],3);
EXPECT_EQ(val_out[1],4);
// this should be compatible
io::hdf5_write(n_w2,"tout_hdf5_wr_existing_dset.hdf5");

n_read.reset();

io::hdf5_read("tout_hdf5_wr_existing_dset.hdf5",n_read);


uint32_array myarray_val = n_read["myarray"].value();

uint64 a_b_c_val = n_read["a/b/c"].value();

EXPECT_EQ(myarray_val[0],3);
EXPECT_EQ(myarray_val[1],4);
EXPECT_EQ(a_b_c_val,123);


}

//-----------------------------------------------------------------------------
TEST(conduit_io_hdf5, conduit_hdf5_write_read_leaf_arrays)
TEST(conduit_relay_io_hdf5, conduit_hdf5_write_read_leaf_arrays)
{
Node n;

Expand All @@ -364,7 +398,36 @@ TEST(conduit_io_hdf5, conduit_hdf5_write_read_leaf_arrays)
n["v_float64"].set(DataType::float64(5));

n["v_string"].set("my_string");



int8 *v_int8_ptr = n["v_int8"].value();
int16 *v_int16_ptr = n["v_int16"].value();
int32 *v_int32_ptr = n["v_int32"].value();
int64 *v_int64_ptr = n["v_int64"].value();

uint8 *v_uint8_ptr = n["v_uint8"].value();
uint16 *v_uint16_ptr = n["v_uint16"].value();
uint32 *v_uint32_ptr = n["v_uint32"].value();
uint64 *v_uint64_ptr = n["v_uint64"].value();

float32 *v_float32_ptr = n["v_float32"].value();
float64 *v_float64_ptr = n["v_float64"].value();

for(index_t i=0; i < 5; i++)
{
v_int8_ptr[i] = -8;
v_int16_ptr[i] = -16;
v_int32_ptr[i] = -32;
v_int64_ptr[i] = -64;

v_uint8_ptr[i] = 8;
v_uint16_ptr[i] = 16;
v_uint32_ptr[i] = 32;
v_uint64_ptr[i] = 64;

v_float32_ptr[i] = 32.0;
v_float64_ptr[i] = 64.0;
}

n.print_detailed();

Expand Down

0 comments on commit bc50a02

Please sign in to comment.