NEURON
nrnsection_mapping.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
6 /** @brief Section to segment mapping
7  *
8  * For a section list (of particulat type), store mapping
9  * of section to segment. Note that the section is repeated
10  * when there are multiple segments in a section.
11  */
12 struct SecMapping {
13  /** number of sections in section list */
14  int nsec;
15 
16  /** name of section list */
17  std::string name;
18 
19  /** list of segments */
20  std::vector<int> segments;
21 
22  /** list sections associated with each segment */
23  std::vector<int> sections;
24 
25  /** list of lfp factors associated with each segment */
26  std::vector<double> seglfp_factors;
27 
28  /** Electrode offsets as partial sums (CSR-style).
29  * For a single report with N electrodes: [0, N].
30  * Empty when no electrodes are associated. */
31  std::vector<size_t> electrode_offsets;
32 
33  SecMapping(int n, std::string s)
34  : nsec(n)
35  , name(s) {}
36 
37  size_t size() {
38  return segments.size();
39  }
40 };
41 
42 /** @brief Compartment mapping information for a cell
43  *
44  * A cell can have multiple section list types like
45  * soma, axon, apic, dend etc. User will add these
46  * section lists using HOC interface.
47  */
48 struct CellMapping {
49  /** gid of a cell */
50  int gid;
51 
52  /** list of section lists (like soma, axon, apic) */
53  std::vector<SecMapping*> secmapping;
54 
56  gid = g;
57  secmapping.push_back(s);
58  }
59 
60  /** @brief total number of sections in a cell */
61  int num_sections() {
62  int nsec = 0;
63  for (size_t i = 0; i < secmapping.size(); i++) {
64  nsec += secmapping[i]->nsec;
65  }
66  return nsec;
67  }
68 
69  /** @brief total number of segments in a cell */
70  int num_segments() {
71  int nseg = 0;
72  for (size_t i = 0; i < secmapping.size(); i++) {
73  nseg += secmapping[i]->segments.size();
74  }
75  return nseg;
76  }
77 
78  /** @brief number of section lists */
79  size_t size() {
80  return secmapping.size();
81  }
82 
84  for (size_t i = 0; i < secmapping.size(); i++) {
85  delete secmapping[i];
86  }
87  }
88 };
89 
90 /** @brief Compartment mapping information for NrnThread
91  *
92  * NrnThread could have more than one cell in cellgroup
93  * and we store this in vector.
94  */
96  /** list of cells mapping */
97  std::vector<CellMapping*> mapping;
98 
99  /** @brief number of cells */
100  size_t size() {
101  return mapping.size();
102  }
103 
104  /** @brief after writing NrnThread to file we remove
105  * all previous mapping information, free memory.
106  */
107  void clear() {
108  for (size_t i = 0; i < mapping.size(); i++) {
109  delete mapping[i];
110  }
111  mapping.clear();
112  }
113 
114  /** @brief memory cleanup */
116  for (size_t i = 0; i < mapping.size(); i++) {
117  delete mapping[i];
118  }
119  }
120 
121  /** @brief get cell mapping information for given gid
122  * if exist otherwise return NULL.
123  */
125  for (int i = 0; i < mapping.size(); i++) {
126  if (mapping[i]->gid == gid)
127  return mapping[i];
128  }
129  return NULL;
130  }
131 
132  /** @brief add section mapping information for given gid
133  * if cell is not peviously added, create new cell mapping.
134  */
135  void add_sec_mapping(int gid, SecMapping* s) {
137 
138  if (cm == NULL) {
139  CellMapping* c = new CellMapping(gid, s);
140  mapping.push_back(c);
141  } else {
142  cm->secmapping.push_back(s);
143  }
144  }
145 };
146 
147 void nrn_write_mapping_info(const char*, int, NrnMappingInfo&);
double cm
Definition: coord.h:48
#define i
Definition: md1redef.h:19
static int c
Definition: hoc.cpp:169
int const size_t const size_t n
Definition: nrngsl.h:10
s
Definition: multisend.cpp:521
void nrn_write_mapping_info(const char *, int, NrnMappingInfo &)
dump mapping information to gid_3.dat file
Definition: nrncore_io.cpp:546
#define NULL
Definition: spdefs.h:105
Compartment mapping information for a cell.
std::vector< SecMapping * > secmapping
list of section lists (like soma, axon, apic)
int num_sections()
total number of sections in a cell
CellMapping(int g, SecMapping *s)
int num_segments()
total number of segments in a cell
size_t size()
number of section lists
int gid
gid of a cell
Compartment mapping information for NrnThread.
size_t size()
number of cells
std::vector< CellMapping * > mapping
list of cells mapping
~NrnMappingInfo()
memory cleanup
void clear()
after writing NrnThread to file we remove all previous mapping information, free memory.
CellMapping * get_cell_mapping(int gid)
get cell mapping information for given gid if exist otherwise return NULL.
void add_sec_mapping(int gid, SecMapping *s)
add section mapping information for given gid if cell is not peviously added, create new cell mapping...
Section to segment mapping.
std::string name
name of section list
std::vector< int > segments
list of segments
std::vector< double > seglfp_factors
list of lfp factors associated with each segment
std::vector< size_t > electrode_offsets
Electrode offsets as partial sums (CSR-style).
int nsec
number of sections in section list
std::vector< int > sections
list sections associated with each segment
SecMapping(int n, std::string s)