NEURON
phase3.cpp
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2024 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================
7 */
8 #include <algorithm>
9 
10 #include "coreneuron/io/phase3.hpp"
11 // Where nrn2core_get_dat3_secmapping_ is declared with extern "C" to avoid symbol name mangling
12 // caused by dual ABI for std::string
14 
15 void (*nrn2core_get_dat3_cell_count_)(int& cell_count);
16 void (*nrn2core_get_dat3_cellmapping_)(int i, int& gid, int& nsec, int& nseg, int& n_seclist);
18  int i_sec,
19  std::string& sclname,
20  int& nsec,
21  int& nseg,
22  size_t& total_lfp_factors,
23  int& n_electrodes,
24  std::vector<int>& data_sec,
25  std::vector<int>& data_seg,
26  std::vector<double>& data_lfp);
27 
28 namespace coreneuron {
30  int count = 0;
31  F.read_mapping_cell_count(&count);
32  /** for every neuron */
33  for (int i = 0; i < count; i++) {
34  int gid, nsec, nseg, nseclist;
35  // read counts
36  F.read_mapping_count(&gid, &nsec, &nseg, &nseclist);
37  CellMapping* cmap = new CellMapping(gid);
38  // read section-segment mapping for every section list
39  for (int j = 0; j < nseclist; j++) {
40  SecMapping* smap = new SecMapping();
41  F.read_mapping_info(smap, ntmapping, cmap);
42  cmap->add_sec_map(smap);
43  }
44  ntmapping->add_cell_mapping(cmap);
45  }
46 }
47 
49  int count;
51  /** for every neuron */
52  for (int i = 0; i < count; i++) {
53  int gid;
54  int t_sec;
55  int t_seg;
56  int nseclist;
57  nrn2core_get_dat3_cellmapping_(i, gid, t_sec, t_seg, nseclist);
58  auto cmap = new CellMapping(gid);
59  for (int j = 0; j < nseclist; j++) {
60  std::string sclname;
61  int n_sec;
62  int n_seg;
63  int n_electrodes;
64  size_t total_lfp_factors;
65  std::vector<int> data_sec;
66  std::vector<int> data_seg;
67  std::vector<double> data_lfp;
69  j,
70  sclname,
71  n_sec,
72  n_seg,
73  total_lfp_factors,
74  n_electrodes,
75  data_sec,
76  data_seg,
77  data_lfp);
78  auto smap = new SecMapping();
79  smap->name = sclname;
80  for (int i_seg = 0; i_seg < n_seg; i_seg++) {
81  smap->add_segment(data_sec[i_seg], data_seg[i_seg]);
82  ntmapping->add_segment_id(data_seg[i_seg]);
83  int factor_offset = i_seg * n_electrodes;
84  if (total_lfp_factors > 0) {
85  // Abort if the factors contains a NaN
86  nrn_assert(count_if(data_lfp.begin(), data_lfp.end(), [](double d) {
87  return std::isnan(d);
88  }) == 0);
89  std::vector<double> segment_factors(data_lfp.begin() + factor_offset,
90  data_lfp.begin() + factor_offset +
91  n_electrodes);
92  cmap->add_segment_lfp_factor(data_seg[i_seg], segment_factors);
93  }
94  }
95  cmap->add_sec_map(smap);
96  }
97  ntmapping->add_cell_mapping(cmap);
98  }
99 }
100 
101 } // namespace coreneuron
void read_mapping_cell_count(int *count)
Reads number of cells in parsing file.
int read_mapping_info(T *mapinfo, NrnThreadMappingInfo *ntmapping, CellMapping *cmap)
Parse a neuron section segment mapping.
void read_mapping_count(int *gid, int *nsec, int *nseg, int *nseclist)
Parse a neuron mapping count entries.
void read_file(FileHandler &F, NrnThreadMappingInfo *ntmapping)
Definition: phase3.cpp:29
void read_direct(NrnThreadMappingInfo *ntmapping)
Definition: phase3.cpp:48
#define i
Definition: md1redef.h:19
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
#define nrn_assert(x)
assert()-like macro, independent of NDEBUG status
Definition: nrn_assert.h:33
size_t j
void(* nrn2core_get_dat3_cell_count_)(int &cell_count)
Definition: phase3.cpp:15
void(* nrn2core_get_dat3_cellmapping_)(int i, int &gid, int &nsec, int &nseg, int &n_seclist)
Definition: phase3.cpp:16
void(* nrn2core_get_dat3_secmapping_)(int i_c, int i_sec, std::string &sclname, int &nsec, int &nseg, size_t &total_lfp_factors, int &n_electrodes, std::vector< int > &data_sec, std::vector< int > &data_seg, std::vector< double > &data_lfp)
Definition: phase3.cpp:17
Compartment mapping information for a cell.
void add_sec_map(SecMapping *s)
add new SecMapping
Compartment mapping information for NrnThread.
void add_cell_mapping(CellMapping *c)
add mapping information of new cell
void add_segment_id(const int segment_id)
add a new segment
Section to segment mapping.