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  /** Number of electrodes per segment */
30 
31  SecMapping(int n, std::string s)
32  : nsec(n)
33  , name(s) {}
34 
35  size_t size() {
36  return segments.size();
37  }
38 };
39 
40 /** @brief Compartment mapping information for a cell
41  *
42  * A cell can have multiple section list types like
43  * soma, axon, apic, dend etc. User will add these
44  * section lists using HOC interface.
45  */
46 struct CellMapping {
47  /** gid of a cell */
48  int gid;
49 
50  /** list of section lists (like soma, axon, apic) */
51  std::vector<SecMapping*> secmapping;
52 
54  gid = g;
55  secmapping.push_back(s);
56  }
57 
58  /** @brief total number of sections in a cell */
59  int num_sections() {
60  int nsec = 0;
61  for (size_t i = 0; i < secmapping.size(); i++) {
62  nsec += secmapping[i]->nsec;
63  }
64  return nsec;
65  }
66 
67  /** @brief total number of segments in a cell */
68  int num_segments() {
69  int nseg = 0;
70  for (size_t i = 0; i < secmapping.size(); i++) {
71  nseg += secmapping[i]->segments.size();
72  }
73  return nseg;
74  }
75 
76  /** @brief number of section lists */
77  size_t size() {
78  return secmapping.size();
79  }
80 
82  for (size_t i = 0; i < secmapping.size(); i++) {
83  delete secmapping[i];
84  }
85  }
86 };
87 
88 /** @brief Compartment mapping information for NrnThread
89  *
90  * NrnThread could have more than one cell in cellgroup
91  * and we store this in vector.
92  */
94  /** list of cells mapping */
95  std::vector<CellMapping*> mapping;
96 
97  /** @brief number of cells */
98  size_t size() {
99  return mapping.size();
100  }
101 
102  /** @brief after writing NrnThread to file we remove
103  * all previous mapping information, free memory.
104  */
105  void clear() {
106  for (size_t i = 0; i < mapping.size(); i++) {
107  delete mapping[i];
108  }
109  mapping.clear();
110  }
111 
112  /** @brief memory cleanup */
114  for (size_t i = 0; i < mapping.size(); i++) {
115  delete mapping[i];
116  }
117  }
118 
119  /** @brief get cell mapping information for given gid
120  * if exist otherwise return NULL.
121  */
123  for (int i = 0; i < mapping.size(); i++) {
124  if (mapping[i]->gid == gid)
125  return mapping[i];
126  }
127  return NULL;
128  }
129 
130  /** @brief add section mapping information for given gid
131  * if cell is not peviously added, create new cell mapping.
132  */
133  void add_sec_mapping(int gid, SecMapping* s) {
135 
136  if (cm == NULL) {
137  CellMapping* c = new CellMapping(gid, s);
138  mapping.push_back(c);
139  } else {
140  cm->secmapping.push_back(s);
141  }
142  }
143 };
144 
145 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:531
#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
int num_electrodes
Number of electrodes per segment.
std::vector< int > segments
list of segments
std::vector< double > seglfp_factors
list of lfp factors associated with each segment
int nsec
number of sections in section list
std::vector< int > sections
list sections associated with each segment
SecMapping(int n, std::string s)