Exemplo n.º 1
0
 RefTester(hid_t id) : obj(id) {
     if (H5Iis_valid(id)) {
         ref = H5Iget_ref(id);
     } else {
         ref = 0;
     }
 }
Exemplo n.º 2
0
 void check(nix::hdf5::BaseHDF5* wrapped = nullptr) {
     CPPUNIT_ASSERT_EQUAL(H5Iget_ref(obj), ref);
     if (wrapped) {
         CPPUNIT_ASSERT_EQUAL(obj, wrapped->h5id());
         CPPUNIT_ASSERT_EQUAL(ref, wrapped->refCount());
     }
 }
Exemplo n.º 3
0
//--------------------------------------------------------------------------
// Function:    IdComponent::getCounter
///\brief       Returns the reference counter for a given id.
///\return      Reference count
// Programmer   Binh-Minh Ribler - May 2005
//--------------------------------------------------------------------------
int IdComponent::getCounter(const hid_t obj_id) const
{
    int counter = 0;
    if (p_valid_id(obj_id))
    {
        counter = H5Iget_ref(obj_id);
        if (counter < 0)
            throw IdComponentException(inMemFunc("incRefCount"), "getting object ref count failed - negative");
    }
    return (counter);
}
Exemplo n.º 4
0
//--------------------------------------------------------------------------
// Function:	IdComponent::decRefCount
///\brief	Decrement reference counter for a given id.
// Programmer	Binh-Minh Ribler - May 2005
// Modification:
//		Added the check for ref counter to give a little more info
//		on why H5Idec_ref fails in some cases - BMR 5/19/2005
//--------------------------------------------------------------------------
void IdComponent::decRefCount(const hid_t obj_id) const
{
    if (p_valid_id(obj_id))
	if (H5Idec_ref(obj_id) < 0)
	    if (H5Iget_ref(obj_id) <= 0)
		throw IdComponentException(inMemFunc("decRefCount"),
					"object ref count is 0 or negative");
	    else
		throw IdComponentException(inMemFunc("decRefCount"),
					"decrementing object ref count failed");
}
Exemplo n.º 5
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Iget_ref
 * Signature: (J)I
 */
JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Iget_1ref
    (JNIEnv *env, jclass clss, jlong obj_id)
{
    int retVal = -1;

    retVal = H5Iget_ref((hid_t)obj_id);
    if (retVal < 0)
        h5libraryError(env);

    return (jint)retVal;
} /* end Java_hdf_hdf5lib_H5_H5Iget_1ref */
Exemplo n.º 6
0
void TestH5::testDataSpace() {

    std::vector<hsize_t> dims = {4, 6};
    hid_t ds = H5Screate_simple(static_cast<int>(dims.size()), dims.data(), nullptr);
    nix::hdf5::DataSpace space(ds);

    nix::NDSize es = space.extent();
    CPPUNIT_ASSERT_EQUAL(es.size(), dims.size());
    CPPUNIT_ASSERT_EQUAL(es[0], dims[0]);
    CPPUNIT_ASSERT_EQUAL(es[1], dims[1]);

    CPPUNIT_ASSERT_EQUAL(1, H5Iget_ref(ds));
    space.close();
}
Exemplo n.º 7
0
void TestH5::testDataType() {
    namespace h5x = nix::hdf5::h5x;

    hid_t t_int = H5Tcopy(H5T_NATIVE_INT);
    hid_t t_dbl = H5Tcopy(H5T_NATIVE_DOUBLE);

    CPPUNIT_ASSERT(t_int > 0);
    CPPUNIT_ASSERT(t_dbl > 0);

    test_refcounting<h5x::DataType>(t_int, t_dbl);

    CPPUNIT_ASSERT_EQUAL(1, H5Iget_ref(t_int));
    CPPUNIT_ASSERT_EQUAL(1, H5Iget_ref(t_dbl));

    H5Tclose(t_int);
    H5Tclose(t_dbl);
    
    h5x::DataType v_str = h5x::DataType::makeStrType();
    CPPUNIT_ASSERT_EQUAL(true, v_str.isVariableString());

    h5x::DataType str_255 = h5x::DataType::makeStrType(255);
    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(255), str_255.size());

}
Exemplo n.º 8
0
Arquivo: H5If.c Projeto: ElaraFX/hdf5
/****if* H5If/h5iget_ref_c
 * NAME
 *  h5iget_ref_c
 * PURPOSE
 *  Call H5Iget_ref to retrieve object's reference count
 * INPUTS
 *  obj_id - object identifier
 * OUTPUTS
 *  ref_count - Reference count of ID
 * RETURNS
 *  current reference count on success, -1 on failure
 * AUTHOR
 *  Quincey Koziol
 *  Tuesday, December  9, 2003
 *
 * SOURCE
*/
int_f
h5iget_ref_c(hid_t_f *obj_id, int_f *ref_count)
/******/
{
     int ret_value;

     /*
      * Call H5Iget_ref function
      */
     if ((ret_value = H5Iget_ref(*obj_id)) < 0)
         HGOTO_DONE(FAIL);

    /* Set output & return values */
    *ref_count=ret_value;
    ret_value=0;

done:
      return ret_value;
}
Exemplo n.º 9
0
void FileHDF5::close() {

    if (!isOpen())
        return;

    data.close();
    metadata.close();
    root.close();

    unsigned types = H5F_OBJ_GROUP|H5F_OBJ_DATASET|H5F_OBJ_DATATYPE;

    ssize_t obj_count = H5Fget_obj_count(hid, types);

    if (obj_count < 0) {
        throw H5Exception("FileHDF5::close(): Could not get object count");
    }

    std::vector<hid_t> objs(static_cast<size_t>(obj_count));

    if (obj_count > 0) {
        obj_count = H5Fget_obj_ids(hid, types, objs.size(), objs.data());

        if (obj_count < 0) {
            throw H5Exception("FileHDF5::close(): Could not get objs");
        }
    }

    for (auto obj : objs) {
        int ref_count = H5Iget_ref(obj);

        for (int j = 0; j < ref_count; j++) {
            H5Oclose(obj);
        }
    }

    H5Object::close();
}
Exemplo n.º 10
0
void TestH5::testBase() {
    CPPUNIT_ASSERT(h5group.isValid());

    nix::hdf5::Group g_invalid{};
    CPPUNIT_ASSERT_EQUAL(false, g_invalid.isValid());
    CPPUNIT_ASSERT_THROW(g_invalid.check("Error"), nix::hdf5::H5Exception);

    // check check, heh
    CPPUNIT_ASSERT_THROW(check_h5_arg_name("foo/bar"), std::invalid_argument);

    // check HTri

    typedef nix::hdf5::HTri::value_type tri_type;

    nix::hdf5::HTri htri_true(static_cast<tri_type >(1));
    nix::hdf5::HTri htri_false(static_cast<tri_type >(0));
    nix::hdf5::HTri htri_error(static_cast<tri_type >(-1));

    CPPUNIT_ASSERT_EQUAL(static_cast<tri_type >(1), htri_true.value);
    CPPUNIT_ASSERT_EQUAL(true, htri_true.result());
    CPPUNIT_ASSERT_EQUAL(false, htri_true.isError());
    CPPUNIT_ASSERT_EQUAL(false, !htri_true);
    CPPUNIT_ASSERT_EQUAL(true, htri_true.check("Error"));

    CPPUNIT_ASSERT_EQUAL(static_cast<tri_type >(0), htri_false.value);
    CPPUNIT_ASSERT_EQUAL(false, htri_false.result());
    CPPUNIT_ASSERT_EQUAL(false, htri_false.isError());
    CPPUNIT_ASSERT_EQUAL(true, !htri_false);
    CPPUNIT_ASSERT_EQUAL(false, htri_false.check("Error"));

    CPPUNIT_ASSERT_EQUAL(static_cast<tri_type >(-1), htri_error.value);
    CPPUNIT_ASSERT_EQUAL(false, htri_error.result());
    CPPUNIT_ASSERT_EQUAL(true, htri_error.isError());
    CPPUNIT_ASSERT_EQUAL(true, !htri_error);
    CPPUNIT_ASSERT_THROW(htri_error.check("Error"), nix::hdf5::H5Exception);

    // check HErr

    typedef nix::hdf5::HErr::value_type err_type;

    nix::hdf5::HErr herr_success(static_cast<err_type>(1));
    nix::hdf5::HErr herr_fail(static_cast<err_type>(-1));

    CPPUNIT_ASSERT_EQUAL(static_cast<tri_type >(1), herr_success.value);
    CPPUNIT_ASSERT_EQUAL(false, herr_success.isError());
    CPPUNIT_ASSERT_EQUAL(false, !herr_success);
    CPPUNIT_ASSERT_EQUAL(true, herr_success.check("Error"));

    CPPUNIT_ASSERT_EQUAL(static_cast<tri_type >(-1), herr_fail.value);
    CPPUNIT_ASSERT_EQUAL(true, herr_fail.isError());
    CPPUNIT_ASSERT_EQUAL(true, !herr_fail);
    CPPUNIT_ASSERT_THROW(herr_fail.check("Error"), nix::hdf5::H5Error);

    nix::hdf5::HErr herr_default;
    CPPUNIT_ASSERT_EQUAL(true, herr_default.isError());

    //check BaseHDF5
    hid_t gcpl = H5Pcreate(H5P_GROUP_CREATE);
    hid_t dcpl = H5Pcreate(H5P_DATASET_CREATE);

    CPPUNIT_ASSERT(gcpl > 0);
    CPPUNIT_ASSERT(dcpl > 0);

    test_refcounting<nix::hdf5::BaseHDF5>(gcpl, dcpl);

    CPPUNIT_ASSERT_EQUAL(1, H5Iget_ref(gcpl));
    CPPUNIT_ASSERT_EQUAL(1, H5Iget_ref(dcpl));

    //ref counting
    hid_t ga = H5Gopen(h5file, "/", H5P_DEFAULT);
    hid_t gb = H5Gopen(h5file, "/h5", H5P_DEFAULT);

    CPPUNIT_ASSERT(ga > 0);
    CPPUNIT_ASSERT(gb > 0);

    test_refcounting<nix::hdf5::BaseHDF5>(ga, gb);

    CPPUNIT_ASSERT_EQUAL(1, H5Iget_ref(ga));
    CPPUNIT_ASSERT_EQUAL(1, H5Iget_ref(gb));

    test_refcounting<nix::hdf5::LocID>(ga, gb);

    CPPUNIT_ASSERT_EQUAL(1, H5Iget_ref(ga));
    CPPUNIT_ASSERT_EQUAL(1, H5Iget_ref(gb));

    H5Gclose(ga);
    H5Gclose(gb);

    //name()
    std::string name = h5group.name();

    CPPUNIT_ASSERT_EQUAL(std::string("/h5"), name);
    CPPUNIT_ASSERT_EQUAL(std::string{}, g_invalid.name());

    //FIXME: this should be somewhere lese

    size_t sz_a = 10;
    CPPUNIT_ASSERT_EQUAL(sz_a, nix::check::fits_in_size_t(sz_a, "OOB"));

    //this is a bit of a hack to get a size that will be bigger then
    //size_t's max value on 64bit systems
    double sz_b = static_cast<double>(std::numeric_limits<size_t>::max()) * 2.0;
    CPPUNIT_ASSERT_THROW(nix::check::fits_in_size_t(sz_b, "OOB"), nix::OutOfBounds);
}