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