NEURON
bbsavestate.h
Go to the documentation of this file.
1 #pragma once
3 
4 struct Object;
5 struct Section;
6 struct Node;
7 struct Prop;
8 struct Point_process;
9 
10 // base class to allow either counting, reading, writing files, buffers, etc.
11 // All the BBSaveState methods take a BBSS_IO subclass and are merely iterators
12 class BBSS_IO {
13  public:
14  enum Type { IN, OUT, CNT };
15  BBSS_IO();
16  virtual ~BBSS_IO() {}
17  virtual void i(int& j, int chk = 0) = 0;
18  virtual void d(int n, double& p) = 0;
19  virtual void d(int n, double* p) = 0;
20  virtual void d(int n, double** p) = 0;
21  virtual void d(int n, neuron::container::data_handle<double> h) = 0;
22  virtual void s(char* cp, int chk = 0) = 0;
23  virtual Type type() = 0;
24  virtual void skip(int) {} // only when reading
25 };
26 
27 class BBSaveState {
28  public:
29  BBSaveState();
30  virtual ~BBSaveState();
31  virtual void apply(BBSS_IO* io);
33 
34  int counts(int** gids, int** counts);
35  void core();
36  void init();
37  void finish();
38  void gids();
39  void gid2buffer(int gid, char* buffer, int size);
40  void buffer2gid(int gid, char* buffer, int size);
41  void gidobj(int basegid);
42  void gidobj(int spgid, Object*);
43  void cell(Object*);
44  int cellsize(Object*);
46  void section(Section*);
47  int sectionsize(Section*);
48  void seccontents(Section*);
49  void node(Node*);
50  void node01(Section*, Node*);
51  void v_vext(Node*);
52  void mech(Prop*);
54  void possible_presyn(int gid);
55 
56  void mk_base2spgid();
57  void mk_pp2de();
58  void mk_presyn_info();
59  void del_pp2de();
60 };
61 
62 /** BBSaveState API
63  * See save_test_bin and restore_test_bin for an example of the use of this
64  * following interface. Note in particular the use in restore_test_bin of a
65  * prior clear_event_queue() in order to allow bbss_buffer_counts to pass an
66  * assert during the restore process.
67  */
68 
69 /** First call to return the information needed to make the other calls. Returns
70  * a pointer used by the other methods. Caller is reponsible for freeing (using
71  * free() and not delete []) the returned gids and sizes arrays when finished.
72  * The sizes array and global_size are needed for the caller to construct
73  * proper buffer sizes to pass to bbss_save_global and bbss_save for filling
74  * in. The size of these arrays is returned in *len. They are not needed for
75  * restoring (since the caller is passing already filled in buffers that are
76  * read by bbss_restore_global and bbss_restore. The gids returned are base
77  * gids. It is the callers responsibility to somehow concatenate buffers with
78  * the same gid (from different hosts) either after save or before restore and
79  * preserve the piece count of the number of concatenated buffers for each base
80  * gid. Global_size will only be non_zero for host 0.
81  */
82 void* bbss_buffer_counts(int* len, int** gids, int** sizes, int* global_size);
83 
84 /** Call only on host 0 with a buffer of size equal to the global_size returned
85  * from the bbss_buffer_counts call on host 0 sz is the size of the buffer
86  * (for error checking only, buffer+sz is out of bounds)
87  */
88 void bbss_save_global(void* bbss, char* buffer, int sz);
89 
90 /** Call on all hosts with the buffer contents returned from the call to
91  * bbss_save_global. This must be called prior to any calls to bbss_restore sz
92  * is the size of the buffer (error checking only). This also does some other
93  * important restore initializations.
94  */
95 void bbss_restore_global(void* bbss, char* buffer, int sz);
96 
97 /** Call this for each item of the gids from bbss_buffer_counts along with a
98  * buffer of size from the corresponding sizes array. The buffer will be filled
99  * in with savestate information. The gid may be the same on different hosts,
100  * in which case it is the callers responsibility to concatentate buffers at
101  * some point to allow calling of bbss_restore. sz is the size of the buffer
102  * (error checking only).
103  */
104 void bbss_save(void* bbss, int gid, char* buffer, int sz);
105 
106 /** Call this for each item of the gids from bbss_buffer_counts, the number of
107  * buffers that were concatenated for the gid, and the concatenated buffer (the
108  * concatenated buffer does NOT contain npiece as the first value in the char*
109  * buffer pointer). sz is the size of the buffer (error checking only).
110  */
111 void bbss_restore(void* bbss, int gid, int npiece, char* buffer, int sz);
112 
113 /** At the end of the save process, call this to cleanup. When this call
114  * returns, bbss will be invalid.
115  */
116 void bbss_save_done(void* bbss);
117 
118 /** At the end of the restore process, call this to do some extra setting up and
119  * cleanup. When this call returns, bbss will be invalid.
120  */
121 void bbss_restore_done(void* bbss);
static BBSaveState * bbss
void bbss_restore(void *bbss, int gid, int npiece, char *buffer, int sz)
Call this for each item of the gids from bbss_buffer_counts, the number of buffers that were concaten...
void bbss_restore_done(void *bbss)
At the end of the restore process, call this to do some extra setting up and cleanup.
void * bbss_buffer_counts(int *len, int **gids, int **sizes, int *global_size)
BBSaveState API See save_test_bin and restore_test_bin for an example of the use of this following in...
void bbss_restore_global(void *bbss, char *buffer, int sz)
Call on all hosts with the buffer contents returned from the call to bbss_save_global.
void bbss_save_done(void *bbss)
At the end of the save process, call this to cleanup.
void bbss_save(void *bbss, int gid, char *buffer, int sz)
Call this for each item of the gids from bbss_buffer_counts along with a buffer of size from the corr...
void bbss_save_global(void *bbss, char *buffer, int sz)
Call only on host 0 with a buffer of size equal to the global_size returned from the bbss_buffer_coun...
virtual Type type()=0
virtual void d(int n, double &p)=0
virtual void d(int n, double *p)=0
virtual void s(char *cp, int chk=0)=0
virtual void d(int n, double **p)=0
virtual ~BBSS_IO()
Definition: bbsavestate.h:16
virtual void skip(int)
Definition: bbsavestate.h:24
virtual void d(int n, neuron::container::data_handle< double > h)=0
virtual void i(int &j, int chk=0)=0
virtual void apply(BBSS_IO *io)
void node01(Section *, Node *)
void mk_presyn_info()
void mech(Prop *)
void node(Node *)
void del_pp2de()
void possible_presyn(int gid)
void cell(Object *)
void mk_base2spgid()
void v_vext(Node *)
int cellsize(Object *)
void gid2buffer(int gid, char *buffer, int size)
void netrecv_pp(Point_process *)
BBSS_IO * f
Definition: bbsavestate.h:32
void section_exist_info(Section *)
void gidobj(int basegid)
int sectionsize(Section *)
virtual ~BBSaveState()
void buffer2gid(int gid, char *buffer, int size)
void seccontents(Section *)
int counts(int **gids, int **counts)
void section(Section *)
int const size_t const size_t n
Definition: nrngsl.h:10
size_t p
size_t j
Definition: section.h:105
Definition: hocdec.h:173
A point process is computed just like regular mechanisms.
Definition: section_fwd.hpp:77
Definition: section.h:231