From 40b13c74457cc4fbe97a746bb58bedc3e0732445 Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Wed, 15 Feb 2017 09:01:05 -0600 Subject: Purpose: Add new C++ wrappers Description: Added wrappers for H5Pset_file_space and H5Pget_file_space // Sets the strategy and the threshold value that the library will // will employ in managing file space. void setFileSpace(H5F_file_space_type_t strategy, hsize_t threshold) const; // Returns the strategy that the library uses in managing file space. H5F_file_space_type_t getFileSpaceStrategy() const; // Returns the threshold value that the library uses in tracking free // space sections. hsize_t getFileSpaceThreshold() const; Platforms tested: Linux/32 2.6 (jam) Linux/64 (jelly) Darwin (osx1010test) --- c++/src/H5FcreatProp.cpp | 63 +++++++++++++++++++++++++++++++++++++ c++/src/H5FcreatProp.h | 11 +++++++ c++/test/tfile.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 152 insertions(+), 4 deletions(-) diff --git a/c++/src/H5FcreatProp.cpp b/c++/src/H5FcreatProp.cpp index 5a99dba..1d9bfd4 100644 --- a/c++/src/H5FcreatProp.cpp +++ b/c++/src/H5FcreatProp.cpp @@ -295,6 +295,69 @@ unsigned FileCreatPropList::getIstorek() const } //-------------------------------------------------------------------------- +// Function: FileCreatPropList::setFileSpace +///\brief Sets the strategy and the threshold value that the library +/// will employ in managing file space. +///\param ik - IN: Symbol table tree rank +///\param lk - IN: Symbol table node size +///\exception H5::PropListIException +///\par Description +/// If the given strategy is zero, the property will not be +/// changed and the existing strategy will be retained. +/// If the given threshold value is zero, the property will not be +/// changed and the existing threshold will be retained. +// Programmer Binh-Minh Ribler - Feb, 2017 +//-------------------------------------------------------------------------- +void FileCreatPropList::setFileSpace(H5F_file_space_type_t strategy, hsize_t threshold) const +{ + herr_t ret_value = H5Pset_file_space(id, strategy, threshold); + if( ret_value < 0 ) + { + throw PropListIException("FileCreatPropList::setFileSpace", + "H5Pset_file_space failed"); + } +} + +//-------------------------------------------------------------------------- +// Function: FileCreatPropList::getFileSpaceStrategy +///\brief Returns the strategy that the library uses in managing file space. +///\return The strategy value +///\exception H5::PropListIException +// Programmer Binh-Minh Ribler - Feb, 2017 +//-------------------------------------------------------------------------- +H5F_file_space_type_t FileCreatPropList::getFileSpaceStrategy() const +{ + H5F_file_space_type_t strategy = H5F_FILE_SPACE_ALL; + herr_t ret_value = H5Pget_file_space(id, &strategy, NULL); + if (ret_value < 0) + { + throw PropListIException("FileCreatPropList::getFileSpaceStrategy", + "H5Pget_file_space for strategry failed"); + } + return(strategy); +} + +//-------------------------------------------------------------------------- +// Function: FileCreatPropList::getFileSpaceThreshold +///\brief Returns the threshold value that the library uses in tracking +/// free space sections. +///\return The threshold value +///\exception H5::PropListIException +// Programmer Binh-Minh Ribler - Feb, 2017 +//-------------------------------------------------------------------------- +hsize_t FileCreatPropList::getFileSpaceThreshold() const +{ + hsize_t threshold = 0; + herr_t ret_value = H5Pget_file_space(id, NULL, &threshold); + if (ret_value < 0) + { + throw PropListIException("FileCreatPropList::getFileSpaceThreshold", + "H5Pget_file_space for threshold failed"); + } + return(threshold); +} + +//-------------------------------------------------------------------------- // Function: FileCreatPropList destructor ///\brief Noop destructor. // Programmer Binh-Minh Ribler - 2000 diff --git a/c++/src/H5FcreatProp.h b/c++/src/H5FcreatProp.h index 1ac925e..cadff8b 100644 --- a/c++/src/H5FcreatProp.h +++ b/c++/src/H5FcreatProp.h @@ -65,6 +65,17 @@ class H5_DLLCPP FileCreatPropList : public PropList { // indexing chunked datasets. void setIstorek( unsigned ik ) const; + // Sets the strategy and the threshold value that the library will + // will employ in managing file space. + void setFileSpace(H5F_file_space_type_t strategy, hsize_t threshold) const; + + // Returns the strategy that the library uses in managing file space. + H5F_file_space_type_t getFileSpaceStrategy() const; + + // Returns the threshold value that the library uses in tracking free + // space sections. + hsize_t getFileSpaceThreshold() const; + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("FileCreatPropList"); } diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp index f1844b6..f836ac0 100644 --- a/c++/test/tfile.cpp +++ b/c++/test/tfile.cpp @@ -411,6 +411,9 @@ static void test_file_size() // use C test utility routine to close property list. H5Pclose(fapl_id); + herr_t ret = H5Pclose(fapl_id); + if (ret < 0) + issue_fail_msg("test_file_size()", __LINE__, __FILE__, "H5Pclose failed"); } // test_file_size() @@ -734,9 +737,7 @@ static void test_libver_bounds() /*------------------------------------------------------------------------- * Function: test_commonfg * - * Purpose: Verify that a file created and modified with the - * specified libver bounds has the specified object header - * versions for the right objects. + * Purpose: Verify that H5File works as a root group. * * Return: None * @@ -795,6 +796,77 @@ static void test_commonfg() } /* end test_commonfg() */ +const H5std_string FILE7("tfile7.h5"); +/*------------------------------------------------------------------------- + * Function: test_filespace_info + * + * Purpose: Verify that setting and retrieving the file space strategy + * and free space section threshold work correctly. + * + * Return: None + * + * Programmer: Binh-Minh Ribler + * February, 2017 + * + *------------------------------------------------------------------------- + */ +static void test_filespace_info() +{ + // Output message about test being performed + SUBTEST("File space information"); + + hid_t fapl_id = h5_fileaccess(); // in h5test.c, returns a file access template + hsize_t in_threshold = 2; // Free space section threshold to set */ + hsize_t out_threshold = 0; // Free space section threshold to get */ + // File space handling strategy + H5F_file_space_type_t in_strategy = H5F_FILE_SPACE_ALL; + // File space handling strategy + H5F_file_space_type_t out_strategy = H5F_FILE_SPACE_DEFAULT; + + try { + // Use the file access template id to create a file access prop. + // list object to pass in H5File::H5File + FileAccPropList fapl(fapl_id); + + /* Create file-creation proplist */ + FileCreatPropList fcpl; + + /* Set file space strategy and free space section threshold */ + fcpl.setFileSpace(in_strategy, in_threshold); + + // Create a file using default properties. + H5File file7(FILE7, H5F_ACC_TRUNC, fcpl); + + /* Close the file */ + file7.close(); + + /* Re-open the file */ + file7.openFile(FILE7, H5F_ACC_RDWR, fapl); + + /* Get the file's creation property */ + FileCreatPropList fcpl2 = file7.getCreatePlist(); + + /* Get and verify the file space info from the creation property list */ + out_strategy = fcpl2.getFileSpaceStrategy(); + verify_val(static_cast(out_strategy), static_cast(in_strategy), "FileCreatPropList::getFileSpaceStrategy", __LINE__, __FILE__); + + out_threshold = fcpl2.getFileSpaceThreshold(); + verify_val(static_cast(out_threshold), static_cast(in_threshold), "FileCreatPropList::getFileSpaceThreshold", __LINE__, __FILE__); + + PASSED(); + } // end of try block + + catch (Exception& E) + { + issue_fail_msg("test_filespace_info()", __LINE__, __FILE__, E.getCDetailMsg()); + } + // Close file access template. + herr_t ret = H5Pclose(fapl_id); + if (ret < 0) + issue_fail_msg("test_filespace_info()", __LINE__, __FILE__, "H5Pclose failed"); + +} /* test_filespace_info() */ + /*------------------------------------------------------------------------- * Function: test_file * @@ -821,7 +893,8 @@ void test_file() test_file_name(); // Test getting file's name test_file_attribute(); // Test file attribute feature test_libver_bounds(); // Test format version - test_commonfg(); + test_commonfg(); // Test H5File as a root group + test_filespace_info(); // Test file space info } // test_file() @@ -849,4 +922,5 @@ void cleanup_file() HDremove(FILE4.c_str()); HDremove(FILE5.c_str()); HDremove(FILE6.c_str()); + HDremove(FILE7.c_str()); } // cleanup_file -- cgit v0.12 From f51f05ec20f5b585bd0f49f088d402a2f3410044 Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Wed, 15 Feb 2017 09:15:06 -0600 Subject: Description: Fixed small typos Platform tested: Jam (very minor) --- c++/src/H5FcreatProp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c++/src/H5FcreatProp.cpp b/c++/src/H5FcreatProp.cpp index 1d9bfd4..a51f83d 100644 --- a/c++/src/H5FcreatProp.cpp +++ b/c++/src/H5FcreatProp.cpp @@ -332,7 +332,7 @@ H5F_file_space_type_t FileCreatPropList::getFileSpaceStrategy() const if (ret_value < 0) { throw PropListIException("FileCreatPropList::getFileSpaceStrategy", - "H5Pget_file_space for strategry failed"); + "H5Pget_file_space for strategy failed"); } return(strategy); } -- cgit v0.12 From 5f759d6d9f804d99572f605f9d9933c897ef3671 Mon Sep 17 00:00:00 2001 From: Binh-Minh Ribler Date: Thu, 16 Feb 2017 00:35:44 -0600 Subject: Description: Fixed and added function comments. Platform tested: Jam (very minor) --- c++/src/H5FcreatProp.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/c++/src/H5FcreatProp.cpp b/c++/src/H5FcreatProp.cpp index a51f83d..ed6064f 100644 --- a/c++/src/H5FcreatProp.cpp +++ b/c++/src/H5FcreatProp.cpp @@ -298,14 +298,22 @@ unsigned FileCreatPropList::getIstorek() const // Function: FileCreatPropList::setFileSpace ///\brief Sets the strategy and the threshold value that the library /// will employ in managing file space. -///\param ik - IN: Symbol table tree rank -///\param lk - IN: Symbol table node size +///\param strategy - IN: Strategy for file space management +///\param threshold - IN: Free-space section threshold. The library +/// default is 1, which is to track all free-space sections. ///\exception H5::PropListIException ///\par Description /// If the given strategy is zero, the property will not be /// changed and the existing strategy will be retained. /// If the given threshold value is zero, the property will not be /// changed and the existing threshold will be retained. +/// Valid values of \a libver_low are as follows: +/// \li \c H5F_FILE_SPACE_ALL (Default) +/// \li \c H5F_FILE_SPACE_ALL_PERSIST +/// \li \c H5F_FILE_SPACE_AGGR_VFD +/// \li \c H5F_FILE_SPACE_VFD +/// For information, please see the C layer Reference Manual at: +/// https://support.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetFileSpace // Programmer Binh-Minh Ribler - Feb, 2017 //-------------------------------------------------------------------------- void FileCreatPropList::setFileSpace(H5F_file_space_type_t strategy, hsize_t threshold) const -- cgit v0.12