Example #1
0
    void DCDataSet::createReference(hid_t refGroup,
            hid_t srcGroup,
            DCDataSet &srcDataSet,
            Dimensions count,
            Dimensions offset,
            Dimensions stride)
    throw (DCException)
    {
        if (opened)
            throw DCException(getExceptionString("createReference: dataset is already open"));

        if (checkExistence && H5Lexists(refGroup, name.c_str(), H5P_LINK_ACCESS_DEFAULT))
            throw DCException(getExceptionString("createReference: this reference already exists"));

        getLogicalSize().set(count);
        this->ndims = srcDataSet.getNDims();

        count.swapDims(this->ndims);
        offset.swapDims(this->ndims);
        stride.swapDims(this->ndims);

        // select region hyperslab in source dataset
        if (H5Sselect_hyperslab(srcDataSet.getDataSpace(), H5S_SELECT_SET,
                offset.getPointer(), stride.getPointer(),
                count.getPointer(), NULL) < 0 ||
                H5Sselect_valid(srcDataSet.getDataSpace()) <= 0)
            throw DCException(getExceptionString("createReference: failed to select hyperslap for reference"));

        if (H5Rcreate(&regionRef, srcGroup, srcDataSet.getName().c_str(), H5R_DATASET_REGION,
                srcDataSet.getDataSpace()) < 0)
            throw DCException(getExceptionString("createReference: failed to create region reference"));

        hsize_t ndims = 1;
        dataspace = H5Screate_simple(1, &ndims, NULL);
        if (dataspace < 0)
            throw DCException(getExceptionString("createReference: failed to create dataspace for reference"));

        dataset = H5Dcreate(refGroup, name.c_str(), H5T_STD_REF_DSETREG,
                dataspace, H5P_DEFAULT, dsetProperties, H5P_DEFAULT);

        if (dataset < 0)
            throw DCException(getExceptionString("createReference: failed to create dataset for reference"));

        if (H5Dwrite(dataset, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL,
                dsetWriteProperties, &regionRef) < 0)
            throw DCException(getExceptionString("createReference: failed to write reference"));

        isReference = true;
        opened = true;
    }
Example #2
0
    void DCDataSet::write(Dimensions srcBuffer, Dimensions srcStride,
            Dimensions srcOffset, Dimensions srcData,
            Dimensions dstOffset, const void* data)
    throw (DCException)
    {
        log_msg(2, "DCDataSet::write (%s)", name.c_str());

        if (!opened)
            throw DCException(getExceptionString("write: Dataset has not been opened/created"));

        log_msg(3,
                " ndims = %llu\n"
                " logical_size = %s\n"
                " physical_size = %s\n"
                " src_buffer = %s\n"
                " src_stride = %s\n"
                " src_data = %s\n"
                " src_offset = %s\n"
                " dst_offset = %s\n",
                (long long unsigned) ndims,
                getLogicalSize().toString().c_str(),
                getPhysicalSize().toString().c_str(),
                srcBuffer.toString().c_str(),
                srcStride.toString().c_str(),
                srcData.toString().c_str(),
                srcOffset.toString().c_str(),
                dstOffset.toString().c_str());

        // swap dimensions if necessary
        srcBuffer.swapDims(ndims);
        srcStride.swapDims(ndims);
        srcData.swapDims(ndims);
        srcOffset.swapDims(ndims);
        dstOffset.swapDims(ndims);

        // dataspace to read from
        hid_t dsp_src;

        if (getLogicalSize().getScalarSize() != 0)
        {
            dsp_src = H5Screate_simple(ndims, srcBuffer.getPointer(), NULL);
            if (dsp_src < 0)
                throw DCException(getExceptionString("write: Failed to create source dataspace"));

            if (H5Sselect_hyperslab(dsp_src, H5S_SELECT_SET, srcOffset.getPointer(),
                    srcStride.getPointer(), srcData.getPointer(), NULL) < 0 ||
                    H5Sselect_valid(dsp_src) <= 0)
                throw DCException(getExceptionString("write: Invalid source hyperslap selection"));

            if (srcData.getScalarSize() == 0)
                H5Sselect_none(dsp_src);

            // dataspace to write to
            if (H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, dstOffset.getPointer(),
                    NULL, srcData.getPointer(), NULL) < 0 ||
                    H5Sselect_valid(dataspace) <= 0)
                throw DCException(getExceptionString("write: Invalid target hyperslap selection"));

            if (!data || (srcData.getScalarSize() == 0))
            {
                H5Sselect_none(dataspace);
                data = NULL;
            }

            // write data to the dataset

            if (H5Dwrite(dataset, this->datatype, dsp_src, dataspace, dsetWriteProperties, data) < 0)
                throw DCException(getExceptionString("write: Failed to write dataset"));

            H5Sclose(dsp_src);
        }
    }
Example #3
0
    void DCDataSet::read(Dimensions dstBuffer,
            Dimensions dstOffset,
            Dimensions srcSize,
            Dimensions srcOffset,
            Dimensions& sizeRead,
            uint32_t& srcNDims,
            void* dst)
    throw (DCException)
    {
        log_msg(2, "DCDataSet::read (%s)", name.c_str());

        if (!opened)
            throw DCException(getExceptionString("read: Dataset has not been opened/created"));

        if (dstBuffer.getScalarSize() == 0)
            dstBuffer.set(srcSize);

        // dst buffer is allowed to be NULL
        // in this case, only the size of the dataset is returned
        // if the dataset is empty, return just its size as there is nothing to read
        if ((dst != NULL) && (getNDims() > 0))
        {
            log_msg(3,
                    " ndims = %llu\n"
                    " logical_size = %s\n"
                    " physical_size = %s\n"
                    " dstBuffer = %s\n"
                    " dstOffset = %s\n"
                    " srcSize = %s\n"
                    " srcOffset = %s\n",
                    (long long unsigned) ndims,
                    getLogicalSize().toString().c_str(),
                    getPhysicalSize().toString().c_str(),
                    dstBuffer.toString().c_str(),
                    dstOffset.toString().c_str(),
                    srcSize.toString().c_str(),
                    srcOffset.toString().c_str());

            dstBuffer.swapDims(ndims);
            dstOffset.swapDims(ndims);
            srcSize.swapDims(ndims);
            srcOffset.swapDims(ndims);

            hid_t dst_dataspace = H5Screate_simple(ndims, dstBuffer.getPointer(), NULL);
            if (dst_dataspace < 0)
                throw DCException(getExceptionString("read: Failed to create target dataspace"));

            if (H5Sselect_hyperslab(dst_dataspace, H5S_SELECT_SET, dstOffset.getPointer(), NULL,
                    srcSize.getPointer(), NULL) < 0 ||
                    H5Sselect_valid(dst_dataspace) <= 0)
                throw DCException(getExceptionString("read: Target dataspace hyperslab selection is not valid!"));

            if (H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, srcOffset.getPointer(), NULL,
                    srcSize.getPointer(), NULL) < 0 ||
                    H5Sselect_valid(dataspace) <= 0)
                throw DCException(getExceptionString("read: Source dataspace hyperslab selection is not valid!"));

            if (srcSize.getScalarSize() == 0)
                H5Sselect_none(dataspace);
            
            if (H5Dread(dataset, this->datatype, dst_dataspace, dataspace, dsetReadProperties, dst) < 0)
                throw DCException(getExceptionString("read: Failed to read dataset"));

            H5Sclose(dst_dataspace);

            srcSize.swapDims(ndims);
        }

        // swap dimensions if necessary
        sizeRead.set(srcSize);
        srcNDims = this->ndims;

        log_msg(3, " returns ndims = %llu", (long long unsigned) ndims);
        log_msg(3, " returns sizeRead = %s", sizeRead.toString().c_str());
    }