hdf5_reader.h
1 #pragma once
2 
3 #include <tuple>
4 #include <vector>
5 
6 #include <bbp/sonata/selection.h>
7 #include <highfive/H5File.hpp>
8 
9 namespace bbp {
10 namespace sonata {
11 
13 template <class T>
15 {
16  public:
17  virtual ~Hdf5PluginRead1DInterface() = default;
18 
23  virtual std::vector<T> readSelection(const HighFive::DataSet& dset,
24  const Selection& selection) const = 0;
25 };
26 
27 template <class T>
29 {
30  public:
31  virtual ~Hdf5PluginRead2DInterface() = default;
32 
37  virtual std::vector<std::array<uint64_t, 2>> readSelection(const HighFive::DataSet& dset,
38  const Selection& xsel,
39  const Selection& ysel) const = 0;
40 };
41 
42 template <class T, class U>
44 
49 template <class... Ts, class... Us>
50 class Hdf5PluginInterface<std::tuple<Ts...>, std::tuple<Us...>>
51  : virtual public Hdf5PluginRead1DInterface<Ts>...,
52  virtual public Hdf5PluginRead2DInterface<Us>...
53 {
54  public:
58  virtual HighFive::File openFile(const std::string& path) const = 0;
59 };
60 
121 class SONATA_API Hdf5Reader
122 {
123  public:
124  // The issue here is that on a mac `size_t` is different from
125  // `{,u}int{8,16,32,64}_t` but not on the other two OSes.
126  using supported_1D_types = std::tuple<uint8_t,
127  uint16_t,
128  uint32_t,
129  uint64_t,
130  int8_t,
131  int16_t,
132  int32_t,
133  int64_t,
134  float,
135  double,
136 #ifdef __APPLE__
137  size_t,
138 #endif
139  std::string>;
140 
141  using supported_2D_types = std::tuple<std::array<uint64_t, 2>>;
142 
144  Hdf5Reader();
145 
148 
153  template <class T>
154  std::vector<T> readSelection(const HighFive::DataSet& dset, const Selection& selection) const {
155  return static_cast<const Hdf5PluginRead1DInterface<T>&>(*impl).readSelection(dset,
156  selection);
157  }
158 
163  HighFive::File openFile(const std::string& filename) const;
164 
169  template <class T>
170  std::vector<T> readSelection(const HighFive::DataSet& dset,
171  const Selection& xsel,
172  const Selection& ysel) const {
173  return static_cast<const Hdf5PluginRead2DInterface<T>&>(*impl).readSelection(dset,
174  xsel,
175  ysel);
176  }
177 
178  private:
179  std::shared_ptr<Hdf5PluginInterface<supported_1D_types, supported_2D_types>> impl;
180 };
181 
182 } // namespace sonata
183 } // namespace bbp
bbp::sonata::Hdf5PluginRead1DInterface::readSelection
virtual std::vector< T > readSelection(const HighFive::DataSet &dset, const Selection &selection) const =0
bbp::sonata::Hdf5PluginRead2DInterface
Definition: hdf5_reader.h:28
bbp::sonata::Hdf5Reader::readSelection
std::vector< T > readSelection(const HighFive::DataSet &dset, const Selection &selection) const
Definition: hdf5_reader.h:154
bbp::sonata::Hdf5PluginRead1DInterface
Interface for implementing readSelection<T>(dset, selection).
Definition: hdf5_reader.h:14
bbp::sonata::Hdf5PluginInterface
Definition: hdf5_reader.h:43
bbp::sonata::Hdf5PluginRead2DInterface::readSelection
virtual std::vector< std::array< uint64_t, 2 > > readSelection(const HighFive::DataSet &dset, const Selection &xsel, const Selection &ysel) const =0
bbp::sonata::Selection
Definition: selection.h:12
bbp::sonata::Hdf5Reader
Definition: hdf5_reader.h:121
bbp::sonata::Hdf5Reader::readSelection
std::vector< T > readSelection(const HighFive::DataSet &dset, const Selection &xsel, const Selection &ysel) const
Definition: hdf5_reader.h:170