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  /** number of sections in section list */
15  int nsec;
16 
17  /** name of section list */
18  std::string name;
19 
20  /** list of segments */
21  std::vector<int> segments;
22 
23  /** list sections associated with each segment */
24  std::vector<int> sections;
25 
26  SecMapping(int n, std::string s)
27  : nsec(n)
28  , name(s) {}
29 
30  size_t size() {
31  return segments.size();
32  }
33 };
34 
35 /** @brief Compartment mapping information for a cell
36  *
37  * A cell can have multiple section list types like
38  * soma, axon, apic, dend etc. User will add these
39  * section lists using HOC interface.
40  */
41 struct CellMapping {
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  /** list of cells mapping */
90  std::vector<CellMapping*> mapping;
91 
92  /** @brief number of cells */
93  size_t size() {
94  return mapping.size();
95  }
96 
97  /** @brief after writing NrnThread to file we remove
98  * all previous mapping information, free memory.
99  */
100  void clear() {
101  for (size_t i = 0; i < mapping.size(); i++) {
102  delete mapping[i];
103  }
104  mapping.clear();
105  }
106 
107  /** @brief memory cleanup */
109  for (size_t i = 0; i < mapping.size(); i++) {
110  delete mapping[i];
111  }
112  }
113 
114  /** @brief get cell mapping information for given gid
115  * if exist otherwise return NULL.
116  */
118  for (int i = 0; i < mapping.size(); i++) {
119  if (mapping[i]->gid == gid)
120  return mapping[i];
121  }
122  return NULL;
123  }
124 
125  /** @brief add section mapping information for given gid
126  * if cell is not peviously added, create new cell mapping.
127  */
128  void add_sec_mapping(int gid, SecMapping* s) {
130 
131  if (cm == NULL) {
132  CellMapping* c = new CellMapping(gid, s);
133  mapping.push_back(c);
134  } else {
135  cm->secmapping.push_back(s);
136  }
137  }
138 };
139 
140 void nrn_write_mapping_info(const char*, int, NrnMappingInfo&);
141 
142 #endif // NRN_SECTION_MAPPING
double cm
Definition: coord.h:49
#define c
#define i
Definition: md1redef.h:12
int const size_t const size_t n
Definition: nrngsl.h:11
void nrn_write_mapping_info(const char *, int, NrnMappingInfo &)
dump mapping information to gid_3.dat file
Definition: nrncore_io.cpp:540
#define g
Definition: passive0.cpp:21
#define NULL
Definition: sptree.h:16
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
int nsec
number of sections in section list
std::vector< int > sections
list sections associated with each segment
SecMapping(int n, std::string s)