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