population.h
1 /*************************************************************************
2  * Copyright (C) 2018-2020 Blue Brain Project
3  *
4  * This file is part of 'libsonata', distributed under the terms
5  * of the GNU Lesser General Public License version 3.
6  *
7  * See top-level COPYING.LESSER and COPYING files for details.
8  *************************************************************************/
9 
10 #pragma once
11 
12 #include "common.h"
13 
14 #include <cstdint>
15 #include <functional>
16 #include <memory> // std::shared_ptr, std::unique_ptr
17 #include <set>
18 #include <string>
19 #include <utility> // std::move
20 #include <vector>
21 
22 #include <bbp/sonata/hdf5_reader.h>
23 #include <bbp/sonata/selection.h>
24 
25 namespace bbp {
26 namespace sonata {
27 
28 class SONATA_API Population
29 {
30  public:
34  std::string name() const;
35 
39  uint64_t size() const;
40 
44  Selection selectAll() const;
45 
49  const std::set<std::string>& attributeNames() const;
50 
57  const std::set<std::string>& enumerationNames() const;
58 
73  template <typename T>
74  std::vector<T> getAttribute(const std::string& name, const Selection& selection) const;
75 
90  template <typename T>
91  std::vector<T> getAttribute(const std::string& name,
92  const Selection& selection,
93  const T& defaultValue) const;
94 
106  template <typename T>
107  std::vector<T> getEnumeration(const std::string& name, const Selection& selection) const;
108 
116  std::vector<std::string> enumerationValues(const std::string& name) const;
117 
125  std::string _attributeDataType(const std::string& name,
126  bool translate_enumeration = false) const;
127 
131  const std::set<std::string>& dynamicsAttributeNames() const;
132 
141  template <typename T>
142  std::vector<T> getDynamicsAttribute(const std::string& name, const Selection& selection) const;
143 
152  template <typename T>
153  std::vector<T> getDynamicsAttribute(const std::string& name,
154  const Selection& selection,
155  const T& defaultValue) const;
156 
164  std::string _dynamicsAttributeDataType(const std::string& name) const;
165 
166  template <typename T>
167  Selection filterAttribute(const std::string& name, std::function<bool(const T)> pred) const;
168 
169  protected:
170  Population(const std::string& h5FilePath,
171  const std::string& csvFilePath,
172  const std::string& name,
173  const std::string& prefix,
174  const Hdf5Reader& hdf5_reader);
175 
176  Population(const Population&) = delete;
177 
178  Population(Population&&) noexcept;
179 
180  virtual ~Population() noexcept;
181 
182  struct Impl;
183  std::unique_ptr<Impl> impl_;
184 };
185 
186 template <>
187 std::vector<std::string> Population::getAttribute<std::string>(const std::string& name,
188  const Selection& selection) const;
189 
190 //--------------------------------------------------------------------------------------------------
191 
195 template <typename Population>
196 class SONATA_API PopulationStorage
197 {
198  public:
199  PopulationStorage(const std::string& h5FilePath);
200  PopulationStorage(const std::string& h5FilePath, const std::string& csvFilePath);
201  PopulationStorage(const std::string& h5FilePath, const Hdf5Reader& hdf5_reader);
202  PopulationStorage(const std::string& h5FilePath,
203  const std::string& csvFilePath,
204  const Hdf5Reader& hdf5_reader);
205 
206  PopulationStorage(const PopulationStorage&) = delete;
207 
208  PopulationStorage(PopulationStorage&&) noexcept;
209 
210  ~PopulationStorage() noexcept;
211 
215  std::set<std::string> populationNames() const;
216 
222  std::shared_ptr<Population> openPopulation(const std::string& name) const;
223 
224  protected:
225  struct Impl;
226  std::unique_ptr<Impl> impl_;
227 };
228 
229 //--------------------------------------------------------------------------------------------------
230 
231 } // namespace sonata
232 } // namespace bbp
bbp::sonata::Population
Definition: population.h:42
bbp::sonata::PopulationStorage
Definition: population.h:210