Coverage Report

Created: 2025-07-11 06:33

/src/bag/api/bag_interleavedlegacylayer.cpp
Line
Count
Source (jump to first uncovered line)
1
2
#include "bag_hdfhelper.h"
3
#include "bag_interleavedlegacylayer.h"
4
#include "bag_interleavedlegacylayerdescriptor.h"
5
#include "bag_private.h"
6
7
#include <array>
8
#include <H5Cpp.h>
9
10
11
namespace BAG {
12
13
//! Constructor
14
/*
15
\param dataset
16
    The BAG Dataset this layer belongs to.
17
\param descriptor
18
    The descriptor of this layer.
19
\param pH5dataSet
20
    The HDF5 DataSet that stores this interleaved layer.
21
*/
22
InterleavedLegacyLayer::InterleavedLegacyLayer(
23
    Dataset& dataset,
24
    InterleavedLegacyLayerDescriptor& descriptor,
25
    std::unique_ptr<::H5::DataSet, DeleteH5dataSet> pH5dataSet)
26
0
    : Layer(dataset, descriptor)
27
0
    , m_pH5dataSet(std::move(pH5dataSet))
28
0
{
29
0
}
30
31
//! Open an existing interleaved layer.
32
/*!
33
\param dataset
34
    The BAG Dataset this layer belongs to.
35
\param descriptor
36
    The descriptor of this layer.
37
*/
38
std::shared_ptr<InterleavedLegacyLayer> InterleavedLegacyLayer::open(
39
    Dataset& dataset,
40
    InterleavedLegacyLayerDescriptor& descriptor)
41
0
{
42
0
    const auto& h5file = dataset.getH5file();
43
0
    const auto& path = descriptor.getInternalPath();
44
0
    auto h5dataSet = std::unique_ptr<::H5::DataSet, DeleteH5dataSet>(
45
0
        new ::H5::DataSet{h5file.openDataSet(path)},
46
0
        DeleteH5dataSet{});
47
48
    // Read the min/max attribute values.
49
0
    const auto possibleMinMax = dataset.getMinMax(descriptor.getLayerType(), path);
50
0
    if (std::get<0>(possibleMinMax))
51
0
        descriptor.setMinMax(std::get<1>(possibleMinMax),
52
0
            std::get<2>(possibleMinMax));
53
54
0
    return std::make_shared<InterleavedLegacyLayer>(dataset,
55
0
        descriptor, std::move(h5dataSet));
56
0
}
57
58
59
//! \copydoc Layer::read
60
UInt8Array InterleavedLegacyLayer::readProxy(
61
    uint32_t rowStart,
62
    uint32_t columnStart,
63
    uint32_t rowEnd,
64
    uint32_t columnEnd) const
65
0
{
66
0
    auto pDescriptor =
67
0
        std::dynamic_pointer_cast<const InterleavedLegacyLayerDescriptor>(
68
0
            this->getDescriptor());
69
0
    if (!pDescriptor)
70
0
        throw InvalidDescriptor{};
71
72
0
    const auto rows = (rowEnd - rowStart) + 1;
73
0
    const auto columns = (columnEnd - columnStart) + 1;
74
0
    const std::array<hsize_t, kRank> count{rows, columns};
75
0
    const std::array<hsize_t, kRank> offset{rowStart, columnStart};
76
77
    // Query the file for the specified rows and columns.
78
0
    const auto h5fileSpace = m_pH5dataSet->getSpace();
79
0
    h5fileSpace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data());
80
81
    // Initialize the output buffer.
82
0
    const auto bufferSize = pDescriptor->getReadBufferSize(rows, columns);
83
0
    UInt8Array buffer{bufferSize};
84
85
    // Prepare the memory space.
86
0
    const ::H5::DataSpace h5memSpace{kRank, count.data(), count.data()};
87
88
    // Set up the type.
89
0
    const auto h5dataType = createH5compType(pDescriptor->getLayerType(),
90
0
        pDescriptor->getGroupType());
91
92
0
    m_pH5dataSet->read(buffer.data(), h5dataType, h5memSpace, h5fileSpace);
93
94
0
    return buffer;
95
0
}
96
97
//! \copydoc Layer::writeAttributes
98
void InterleavedLegacyLayer::writeAttributesProxy() const
99
0
{
100
    // Writing Interleaved layers not supported.
101
0
}
102
103
//! \copydoc Layer::write
104
void InterleavedLegacyLayer::writeProxy(
105
    uint32_t /*rowStart*/,
106
    uint32_t /*columnStart*/,
107
    uint32_t /*rowEnd*/,
108
    uint32_t /*columnEnd*/,
109
    const uint8_t* /*buffer*/)
110
0
{
111
    // Writing Interleaved layers not supported.
112
0
}
113
114
}   //namespace BAG
115