• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

BlueBrain / libsonata / 6862333260

14 Nov 2023 10:28AM UTC coverage: 93.271% (-0.7%) from 93.955%
6862333260

Pull #307

github

1uc
Implement `Hdf5Reader` API and default.

This commit introduces the API for an Hdf5Reader. This reader abstracts the
process of opening HDF5 files, and reading an `libsonata.Selection` from a
dataset.

The default reader calls the existing `_readSelection`.
Pull Request #307: Inject dataset reading via `Hdf5Reader`.

113 of 129 new or added lines in 11 files covered. (87.6%)

10 existing lines in 3 files now uncovered.

1885 of 2021 relevant lines covered (93.27%)

80.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/src/hdf5_reader.hpp
1
#pragma once
2

3
#include "population.hpp"
4
#include "read_bulk.hpp"
5
#include "read_canonical_selection.hpp"
6

7
namespace bbp {
8
namespace sonata {
9

10
namespace detail {
11
template <class Range>
12
HighFive::HyperSlab _makeHyperslab(const std::vector<Range>& ranges) {
164✔
13
    HighFive::HyperSlab slab;
164✔
14
    for (const auto& range : ranges) {
356✔
15
        size_t i_begin = std::get<0>(range);
192✔
16
        size_t i_end = std::get<1>(range);
192✔
17
        slab |= HighFive::RegularHyperSlab({i_begin}, {i_end - i_begin});
192✔
18
    }
19

20
    return slab;
164✔
21
}
22
}  // namespace detail
23

24

25
template <class T>
26
class Hdf5PluginRead1DDefault: virtual public Hdf5PluginRead1DInterface<T>
27
{
28
  public:
29
    std::vector<T> readSelection(const HighFive::DataSet& dset,
166✔
30
                                 const Selection& selection) const override {
31
        if (selection.ranges().empty()) {
166✔
32
            return {};
2✔
33
        }
34

35
        return dset.select(detail::_makeHyperslab(selection.ranges()))
164✔
36
            .template read<std::vector<T>>();
164✔
37
    }
38
};
39

40
template <class T>
41
class Hdf5PluginRead2DDefault: virtual public Hdf5PluginRead2DInterface<T>
42
{
43
  private:
44
    using AltRanges = std::vector<std::array<uint64_t, 2>>;
45

46
  public:
NEW
47
    std::vector<T> readSelection(const HighFive::DataSet& dset,
×
48
                                 const Selection& xsel,
49
                                 const Selection& ysel) const override {
NEW
50
        return readSelectionImpl(dset, xsel.ranges(), ysel.ranges());
×
51
    }
52

NEW
53
    std::vector<T> readSelection(const HighFive::DataSet& dset,
×
54
                                 const AltRanges& xsel,
55
                                 const Selection& ysel) const override {
NEW
56
        return readSelectionImpl(dset, xsel, ysel.ranges());
×
57
    }
58

59
    std::vector<T> readSelection(const HighFive::DataSet& dset,
58✔
60
                                 const Selection& xsel,
61
                                 const AltRanges& ysel) const override {
62
        return readSelectionImpl(dset, xsel.ranges(), ysel);
58✔
63
    }
64

65
    std::vector<T> readSelection(const HighFive::DataSet& dset,
58✔
66
                                 const AltRanges& xsel,
67
                                 const AltRanges& ysel) const override {
68
        return readSelectionImpl(dset, xsel, ysel);
58✔
69
    }
70

71
  private:
72
    template <class XRange, class YRange>
73
    std::vector<T> readSelectionImpl(const HighFive::DataSet& dset,
116✔
74
                                     const std::vector<XRange>& xsel,
75
                                     const std::vector<YRange>& ysel) const {
76
        return detail::readCanonicalSelection<T>(dset, xsel, ysel);
116✔
77
    }
78
};
79

80
template <class T, class U>
81
class Hdf5PluginDefault;
82

83
template <class... Ts, class... Us>
84
class Hdf5PluginDefault<std::tuple<Ts...>, std::tuple<Us...>>
85
    : virtual public Hdf5PluginInterface<std::tuple<Ts...>, std::tuple<Us...>>,
86
      virtual public Hdf5PluginRead1DDefault<Ts>...,
87
      virtual public Hdf5PluginRead2DDefault<Us>...
88
{
89
  private:
90
    using AltRanges = std::vector<std::array<uint64_t, 2>>;
91

92
  public:
93
    HighFive::File openFile(const std::string& path) const override {
68✔
94
        return HighFive::File(path);
68✔
95
    }
96
};
97

98

99
}  // namespace sonata
100
}  // namespace bbp
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc