Exemplo n.º 1
0
void BaseTestReadOnly::testRead() {
    File file = File::open("test_read_only.h5", FileMode::ReadOnly);

    Section section = file.getSection(section_id);
    Block block = file.getBlock(block_id);
    DataArray data_array = block.getDataArray(data_array_id);
    Dimension dim = data_array.getDimension(dim_index);
    SampledDimension dim_sampled = data_array.getDimension(dim_sampled_index).asSampledDimension();
    RangeDimension dim_range = data_array.getDimension(dim_range_index).asRangeDimension();
    SetDimension dim_set = data_array.getDimension(dim_set_index).asSetDimension();
    Tag tag = block.getTag(tag_id);
    MultiTag mtag = block.getMultiTag(mtag_id);
    Feature feature = tag.getFeature(feature_id);
    Property property = section.getProperty(property_id);

    // TODO use assertions here
    s << block.id() << block.name();
    s << data_array.id() << data_array.name();
    s << tag.id() << tag.name();
    s << mtag.id() << mtag.name();
    s << feature.id();
    s << property.id() << property.name();
    s << dim.index();
    s << dim_sampled.index();
    s << dim_range.index();
    s << dim_set.index();
    
    file.close();
}
Exemplo n.º 2
0
DataView retrieveFeatureData(const Tag &tag, size_t feature_index) {
    if (tag.featureCount() == 0) {
        throw nix::OutOfBounds("There are no features associated with this tag!", 0);
    }
    if (feature_index > tag.featureCount()) {
        throw nix::OutOfBounds("Feature index out of bounds.", 0);
    }
    Feature feat = tag.getFeature(feature_index);
    DataArray data = feat.data();
    if (data == nix::none) {
        throw nix::UninitializedEntity();
        //return NDArray(nix::DataType::Float,{0});
    }
    if (feat.linkType() == nix::LinkType::Tagged) {
        NDSize offset, count;
        getOffsetAndCount(tag, data, offset, count);
        if (!positionAndExtentInData(data, offset, count)) {
            throw nix::OutOfBounds("Requested data slice out of the extent of the Feature!", 0);
        }
        DataView io = DataView(data, count, offset);
        return io;
    }
    // for untagged and indexed return the full data
    NDSize offset(data.dataExtent().size(), 0);
    DataView io = DataView(data, data.dataExtent(), offset);
    return io;
}