/src/bag/api/bag_interleavedlegacylayer.cpp
Line | Count | Source |
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 | std::array<hsize_t, 2> dims; |
55 | 0 | h5dataSet->getSpace().getSimpleExtentDims(dims.data(), nullptr); |
56 | 0 | descriptor.setDims(dims[0], dims[1]); |
57 | |
|
58 | 0 | return std::make_shared<InterleavedLegacyLayer>(dataset, |
59 | 0 | descriptor, std::move(h5dataSet)); |
60 | 0 | } |
61 | | |
62 | | |
63 | | //! \copydoc Layer::read |
64 | | UInt8Array InterleavedLegacyLayer::readProxy( |
65 | | uint32_t rowStart, |
66 | | uint32_t columnStart, |
67 | | uint32_t rowEnd, |
68 | | uint32_t columnEnd) const |
69 | 0 | { |
70 | 0 | auto pDescriptor = |
71 | 0 | std::dynamic_pointer_cast<const InterleavedLegacyLayerDescriptor>( |
72 | 0 | this->getDescriptor()); |
73 | 0 | if (!pDescriptor) |
74 | 0 | throw InvalidDescriptor{}; |
75 | | |
76 | 0 | const auto rows = (rowEnd - rowStart) + 1; |
77 | 0 | const auto columns = (columnEnd - columnStart) + 1; |
78 | 0 | const std::array<hsize_t, kRank> count{rows, columns}; |
79 | 0 | const std::array<hsize_t, kRank> offset{rowStart, columnStart}; |
80 | | |
81 | | // Query the file for the specified rows and columns. |
82 | 0 | const auto h5fileSpace = m_pH5dataSet->getSpace(); |
83 | 0 | h5fileSpace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data()); |
84 | | |
85 | | // Initialize the output buffer. |
86 | 0 | const auto bufferSize = pDescriptor->getReadBufferSize(rows, columns); |
87 | 0 | UInt8Array buffer{bufferSize}; |
88 | | |
89 | | // Prepare the memory space. |
90 | 0 | const ::H5::DataSpace h5memSpace{kRank, count.data(), count.data()}; |
91 | | |
92 | | // Set up the type. |
93 | 0 | const auto h5dataType = createH5compType(pDescriptor->getLayerType(), |
94 | 0 | pDescriptor->getGroupType()); |
95 | |
|
96 | 0 | m_pH5dataSet->read(buffer.data(), h5dataType, h5memSpace, h5fileSpace); |
97 | |
|
98 | 0 | return buffer; |
99 | 0 | } |
100 | | |
101 | | //! \copydoc Layer::writeAttributes |
102 | | void InterleavedLegacyLayer::writeAttributesProxy() const |
103 | 0 | { |
104 | | // Writing Interleaved layers not supported. |
105 | 0 | } |
106 | | |
107 | | //! \copydoc Layer::write |
108 | | void InterleavedLegacyLayer::writeProxy( |
109 | | uint32_t /*rowStart*/, |
110 | | uint32_t /*columnStart*/, |
111 | | uint32_t /*rowEnd*/, |
112 | | uint32_t /*columnEnd*/, |
113 | | const uint8_t* /*buffer*/) |
114 | 0 | { |
115 | | // Writing Interleaved layers not supported. |
116 | 0 | } |
117 | | |
118 | | } //namespace BAG |
119 | | |