NEURON
sonata_report_handler.cpp
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================
7 */
8 
14 #ifdef ENABLE_SONATA_REPORTS
15 #include "bbp/sonata/reports.h"
16 #endif // ENABLE_SONATA_REPORTS
17 
18 namespace coreneuron {
19 
21  double dt,
22  double tstop,
23  double delay) {
24 #ifdef ENABLE_SONATA_REPORTS
25  sonata_set_atomic_step(dt);
26 #endif // ENABLE_SONATA_REPORTS
27  ReportHandler::create_report(report_conf, dt, tstop, delay);
28 }
29 
30 #ifdef ENABLE_SONATA_REPORTS
31 void SonataReportHandler::register_section_report(const NrnThread& nt,
32  const ReportConfiguration& report_conf,
33  const VarsToReport& vars_to_report,
34  bool is_soma_target) {
35  register_report(nt, report_conf, vars_to_report);
36 }
37 
38 void SonataReportHandler::register_custom_report(const NrnThread& nt,
39  const ReportConfiguration& report_conf,
40  const VarsToReport& vars_to_report) {
41  register_report(nt, report_conf, vars_to_report);
42 }
43 
44 std::pair<std::string, int> SonataReportHandler::get_population_info(int gid) {
45  if (m_spikes_info.population_info.empty()) {
46  return std::make_pair("All", 0);
47  }
48  std::pair<std::string, int> prev = m_spikes_info.population_info.front();
49  for (const auto& name_offset: m_spikes_info.population_info) {
50  std::string pop_name = name_offset.first;
51  int pop_offset = name_offset.second;
52  if (pop_offset > gid) {
53  break;
54  }
55  prev = name_offset;
56  }
57  return prev;
58 }
59 
60 void SonataReportHandler::register_report(const NrnThread& nt,
61  const ReportConfiguration& report_conf,
62  const VarsToReport& vars_to_report) {
63  const auto type_str = to_string(report_conf.type);
64  sonata_create_report(report_conf.output_path.data(),
65  report_conf.start,
66  report_conf.stop,
67  report_conf.report_dt,
68  report_conf.unit.data(),
69  type_str.data());
70  sonata_set_report_max_buffer_size_hint(report_conf.output_path.data(), report_conf.buffer_size);
71 
72  for (const auto& kv: vars_to_report) {
73  uint64_t gid = kv.first;
74  const std::vector<VarWithMapping>& vars = kv.second;
75  if (!vars.size())
76  continue;
77 
78  const auto& pop_info = get_population_info(gid);
79  std::string population_name = pop_info.first;
80  int population_offset = pop_info.second;
81  sonata_add_node(report_conf.output_path.data(),
82  population_name.data(),
83  population_offset,
84  gid);
85  sonata_set_report_max_buffer_size_hint(report_conf.output_path.data(),
86  report_conf.buffer_size);
87  for (const auto& variable: vars) {
88  sonata_add_element(report_conf.output_path.data(),
89  population_name.data(),
90  gid,
91  variable.id,
92  variable.var_value);
93  }
94  }
95 }
96 #endif // ENABLE_SONATA_REPORTS
97 } // Namespace coreneuron
virtual void create_report(ReportConfiguration &config, double dt, double tstop, double delay)
void create_report(ReportConfiguration &config, double dt, double tstop, double delay) override
Item * prev(Item *item)
Definition: list.cpp:94
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
std::string to_string(EnumT e, const std::array< std::pair< EnumT, std::string_view >, N > &mapping, const std::string_view enum_name)
Converts an enum value to its corresponding string representation.
Definition: nrnreport.hpp:102
Represent main neuron object computed by single thread.
Definition: multicore.h:58
std::vector< std::pair< std::string, int > > population_info
Definition: nrnreport.hpp:86