Logo Search packages:      
Sourcecode: jhdf version File versions  Download package

HObject ncsa::hdf::object::h5::H5File::get ( String  path  )  throws Exception [inline, virtual]

Gets the HObject with the specified path from the file.

This method returns the specified object from the file associated with this FileFormat instance.

If the specified object is a group, groups and datasets that are members of the group will be accessible via the returned HObject instance. The exact contents of the returned HObject instance depends on whether or not open() was called previously for this file.

  • If the file was opened prior to this method call, the complete tree of objects under the group will be accessible via the returned HObject instance.
  • If the file was not opened prior to this method call, only the members immediately under the group will be accessible via the returned HOBject instance.

The decision to have different behaviors was made to give users some control over the "cost" of the method. In many cases, a user wants only one level of a tree, and the performance penalty for loading the entire hierarchy of objects in a large and complex file can be significant. In the case where open() has already been called, the HObject instances have already been created in memory and can be returned quickly. If open() has not been called, this method creates the HObject instances before returning the requested HObject.

For example, say we have the following structure in our file:

        /g0                      Group
        /g0/dataset_comp         Dataset {50, 10}
        /g0/dataset_int          Dataset {50, 10}
        /g0/g00                  Group
        /g0/g00/dataset_float    Dataset {50, 10}
        /g0/g01                  Group
        /g0/g01/dataset_string   Dataset {50, 10}
  • If open() is called before get(), the full structure of file is loaded into memory. The call get("/g0") returns the instance for /g0 with the information necessary to access /g0/dataset_comp, /g0/dataset_int, /g0/g00, /g0/g00/dataset_float, /g0/g01, and /g0/g01/dataset_string.
  • If open() is not called before get(), only the objects immediately under the specified group are accessible via the returned HObject instance. In this example, the call get("/go") returns the instance for /g0 with the information necessary to access /g0/dataset_comp, /g0/dataset_int, /g0/g00, and /g0/g01.

path Full path of the data object to be returned.
The object if it exists in the file; otherwise null.
Exception If there are unexpected problems in trying to retrieve the object. The exceptions thrown vary depending on the implementing class.

Implements ncsa::hdf::object::FileFormat.

Definition at line 916 of file H5File.java.

References ncsa::hdf::object::Group::addToMemberList(), ncsa::hdf::object::FileFormat::fid, findObject(), getDataset(), getGroup(), ncsa::hdf::hdf5lib::HDF5GroupInfo::getType(), open(), and rootNode.

Referenced by ncsa::hdf::object::h5::H5Group::create(), test::unittests::H5TestFile::createTestFile(), test::object::TestH5Object::test_Dataset_byteToString(), test::object::TestH5Object::test_Group_getParent(), test::object::TestH5Object::test_Group_isRoot(), test::object::TestH5Object::test_H5CompoundDS_write_row_by_row(), test::object::TestH5Object::test_H5Datatype_toNative(), test::object::TestH5Object::test_H5File_copy(), test::object::TestH5Object::test_H5File_createCompoundDS(), test::object::TestH5Object::test_H5File_createImage(), test::object::TestH5Object::test_H5File_createLink(), test::object::TestH5Object::test_H5File_createScalarDS(), test::object::TestH5Object::test_H5File_getAttribute(), test::object::TestH5Object::test_H5File_open_relative_path(), test::object::TestH5Object::test_HDF5ScalarDS_str(), test::object::TestH5Object::test_HObject_getFID(), test::object::TestH5Object::test_HObject_getName(), test::unittests::H5BugFixTest::testBug847(), test::unittests::H5BugFixTest::testBug863(), test::unittests::H5ScalarDSTest::testCopy(), test::unittests::H5FileTest::testCopyHObjectGroup(), test::unittests::H5ScalarDSTest::testCreate(), test::unittests::H5GroupTest::testCreate(), test::unittests::H5FileTest::testCreateImageAttributes(), test::unittests::H5FileTest::testCreateObjects(), test::unittests::H5CompoundDSTest::testCreateStringGroupLongArrayStringArrayDatatypeArrayIntArrayObject(), test::unittests::H5FileTest::testDeleteHObject(), test::unittests::H5FileTest::testGet(), test::unittests::H5FileTest::testGetFromOpen(), test::unittests::H5ScalarDSTest::testGetPalette(), test::unittests::H5ScalarDSTest::testGetPaletteRefs(), test::unittests::H5FileTest::testH5FileStringInt(), test::unittests::H5GroupTest::testH5GroupFileFormatStringStringGroup(), test::unittests::H5GroupTest::testH5GroupFileFormatStringStringGroupLongArray(), test::unittests::H5ScalarDSTest::testInit(), test::unittests::H5CompoundDSTest::testInit(), test::unittests::H5FileTest::testOpen(), test::unittests::H5FileTest::testOpenInt(), test::unittests::H5ScalarDSTest::testRead(), test::unittests::H5ScalarDSTest::testReadPalette(), test::unittests::H5ScalarDSTest::testRemoveMetadata(), test::unittests::H5GroupTest::testRemoveMetadata(), test::unittests::H5DatatypeTest::testRemoveMetadata(), test::unittests::H5CompoundDSTest::testRemoveMetadata(), test::unittests::HObjectTest::testSetName(), test::unittests::H5ScalarDSTest::testSetName(), test::unittests::H5GroupTest::testSetName(), test::unittests::H5CompoundDSTest::testSetName(), test::unittests::H5FileTest::testUpdateReferenceDataset(), test::unittests::H5ScalarDSTest::testWriteMetadata(), test::unittests::H5GroupTest::testWriteMetadata(), test::unittests::H5DatatypeTest::testWriteMetadata(), test::unittests::H5CompoundDSTest::testWriteMetadata(), test::unittests::H5ScalarDSTest::testWriteObject(), test::unittests::H5CompoundDSTest::testWriteObject(), and test::unittests::H5ScalarDSTest::testWriteSubset().

        HObject obj = null;

        if ((path == null) || (path.length() <= 0)) {
            return null;
        // replace the wrong slash and get rid of "//"
        path = path.replace('\\', '/');
        path = "/"+path;
        path = path.replaceAll("//", "/");

        // the whole file tree is loaded. find the object in the tree
        if (rootNode != null) {
            obj = findObject(this, path);

        // found object in memory
        if (obj != null) {
            return obj;

        // open only the requested object
        String name=null, pPath=null;
        if (path.equals("/"))
            name = "/"; // the root
        } else
            // separate the parent path and the object name
            if (path.endsWith("/")) {
                path = path.substring(0, path.length()-2);
            int idx = path.lastIndexOf('/');
            name = path.substring(idx+1);
            if (idx == 0) {
                pPath = "/";
            } else {
                pPath = path.substring(0, idx);
        // do not open the full tree structure, only the file handler
        int fid_before_open = fid;
        fid = open(false);
        if (fid < 0) {
            return null;
        try {
            HDF5GroupInfo info = new HDF5GroupInfo();
            H5.H5Gget_objinfo(fid, path, false, info);
            int objType = info.getType();
            if (objType == HDF5Constants.H5G_DATASET) {
                int did = -1;
                try {
                    did = H5.H5Dopen(fid, path);
                    obj = getDataset(did, name, pPath); 
                finally { 
                    try { H5.H5Dclose(did); } catch (Exception ex) {} 
            else if (objType == HDF5Constants.H5G_GROUP) {
                int gid = -1;
                try {
                    gid = H5.H5Gopen(fid, path);
                    H5Group pGroup = null;
                    if (pPath != null) {
                        pGroup = new H5Group(this, null, pPath, null);
                        obj = getGroup(gid, name, pGroup);
                    } else {
                        obj = getGroup(gid, name, pGroup);
                } finally {
                    try { H5.H5Gclose(gid); } catch (Exception ex) {}
            else if (objType == HDF5Constants.H5G_TYPE) {
                obj = new H5Datatype( this, name, pPath);
        } catch (Exception ex) {
            obj = null;
        } finally {
            if ((fid_before_open<=0) && (obj ==null)) {
                // close the fid that is not attached to any object
                try { H5.H5Fclose(fid); } catch (Exception ex) {}
                fid = fid_before_open;

        return obj;

Generated by  Doxygen 1.6.0   Back to index