NEST main@caf0ae8
 
Loading...
Searching...
No Matches
recording_backend_memory.h
Go to the documentation of this file.
1/*
2 * recording_backend_memory.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef RECORDING_BACKEND_MEMORY_H
24#define RECORDING_BACKEND_MEMORY_H
25
26// Includes from nestkernel:
27#include "recording_backend.h"
28
29/* BeginUserDocs: NOINDEX
30
31Short description
32+++++++++++++++++
33
34Recording backend `memory` - Store data in main memory
35
36Description
37~~~~~~~~~~~
38
39When a recording device sends data to the ``memory`` backend, it is
40stored internally in efficient vectors. These vectors are made
41available to the user level in the device's status dictionary under
42the key ``events``.
43
44The ``events`` dictionary always contains the global IDs of the source
45nodes of the recorded data in the field ``sender``. It also always
46contains the time of the recording. Depending on the setting of the
47property ``time_in_steps``, this time can be stored in two different
48formats:
49
50- If ``time_in_steps`` is `false` (which is the default), the time is
51 stored as a single floating point number in the field ``times``,
52 interpreted as the simulation time in ms
53
54- If ``time_in_steps`` is `true`, the time is stored as a pair
55 consisting of the integer number of simulation time steps in units
56 of the simulation resolution in ``times`` and the negative offset from
57 the next such grid point as a floating point number in ms in
58 ``offset``.
59
60All additional data collected or sampled by the recording device is
61contained in the ``events`` dictionary in arrays. These data are named
62based on the recordable they came from and with the appropriate data
63type (either integer or floating point).
64
65The number of events that were collected by the ``memory`` backend can
66be read out of the `n_events` entry in the status dictionary of the
67recording device. To delete data from memory, `n_events` can be set to
680. Other values cannot be set.
69
70Parameter summary
71~~~~~~~~~~~~~~~~~
72
73events
74 A dictionary containing the recorded data in the form of one numeric
75 array for each quantity measured. It always has the sender global
76 IDs of recorded events under the key ``senders`` and the time of the
77 recording, the format of which depends on the setting of
78 ``time_in_steps``.
79
80n_events
81 The number of events collected or sampled since the last reset of
82 `n_events`. By setting `n_events` to 0, all events recorded so far
83 will be discarded from memory.
84
85time_in_steps
86 A Boolean (default: *false*) specifying whether to store time in
87 steps, i.e., in integer multiples of the simulation resolution
88 (under the key ``times`` of the ``events`` dictionary) plus a
89 floating point number for the negative offset from the next grid
90 point in ms (under key ``offset``), or just the simulation time in
91 ms under key ``times``. This property cannot be set after Simulate
92 has been called.
93
94EndUserDocs */
95
96namespace nest
97{
98
115{
116public:
118 ~RecordingBackendMemory() throw() override;
119
120 void initialize() override;
121 void finalize() override;
122
123 void enroll( const RecordingDevice& device, const Dictionary& params ) override;
124
125 void disenroll( const RecordingDevice& device ) override;
126
127 void set_value_names( const RecordingDevice& device,
128 const std::vector< std::string >& double_value_names,
129 const std::vector< std::string >& long_value_names ) override;
130
131 void prepare() override;
132
133 void cleanup() override;
134
135 void write( const RecordingDevice&, const Event&, const std::vector< double >&, const std::vector< long >& ) override;
136
137 void pre_run_hook() override;
138
139 void post_run_hook() override;
140
141 void post_step_hook() override;
142
143 void set_status( const Dictionary& ) override;
144
145 void get_status( Dictionary& ) const override;
146
147 void check_device_status( const Dictionary& ) const override;
148 void get_device_defaults( Dictionary& ) const override;
149 void get_device_status( const RecordingDevice& device, Dictionary& ) const override;
150
151private:
153 {
154 DeviceData();
155 void set_value_names( const std::vector< std::string >&, const std::vector< std::string >& );
156 void push_back( const Event&, const std::vector< double >&, const std::vector< long >& );
157 void get_status( Dictionary& ) const;
158 void set_status( const Dictionary& );
159
160 private:
161 void clear();
162 std::vector< long > senders_;
163 std::vector< double > times_ms_;
164 std::vector< long > times_steps_;
165 std::vector< double > times_offset_;
166 std::vector< std::string > double_value_names_;
167 std::vector< std::string > long_value_names_;
168 std::vector< std::vector< double > > double_values_;
169 std::vector< std::vector< long > > long_values_;
171 };
172
173 typedef std::vector< std::map< size_t, DeviceData > > device_data_map;
175};
176
177} // namespace
178
179#endif /* #ifndef RECORDING_BACKEND_MEMORY_H */
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Encapsulate information sent between nodes.
Definition event.h:103
Memory specialization of the RecordingBackend interface.
Definition recording_backend_memory.h:115
~RecordingBackendMemory() override
Definition recording_backend_memory.cpp:36
void enroll(const RecordingDevice &device, const Dictionary &params) override
Enroll a RecordingDevice with the RecordingBackend.
Definition recording_backend_memory.cpp:53
void get_device_status(const RecordingDevice &device, Dictionary &) const override
Return the per-device status of the given recording device by writing it to the given params dictiona...
Definition recording_backend_memory.cpp:133
void pre_run_hook() override
Initialize global backend-specific data structures.
Definition recording_backend_memory.cpp:95
void post_run_hook() override
Clean up the backend at the end of a Run.
Definition recording_backend_memory.cpp:146
device_data_map device_data_
Definition recording_backend_memory.h:174
void set_value_names(const RecordingDevice &device, const std::vector< std::string > &double_value_names, const std::vector< std::string > &long_value_names) override
To make the names of recorded quantities known to the RecordingBackend, the vectors double_value_name...
Definition recording_backend_memory.cpp:82
void write(const RecordingDevice &, const Event &, const std::vector< double > &, const std::vector< long > &) override
Write the data from the event to the backend specific channel together with the values given.
Definition recording_backend_memory.cpp:107
void disenroll(const RecordingDevice &device) override
Disenroll a RecordingDevice from the RecordingBackend.
Definition recording_backend_memory.cpp:69
void get_device_defaults(Dictionary &) const override
Return the per-device defaults by writing it to the given params dictionary.
Definition recording_backend_memory.cpp:126
void prepare() override
Prepare the backend at begin of the NEST Simulate function.
Definition recording_backend_memory.cpp:170
void get_status(Dictionary &) const override
Return the status of the recording backend by writing it to the given params dictionary.
Definition recording_backend_memory.cpp:158
std::vector< std::map< size_t, DeviceData > > device_data_map
Definition recording_backend_memory.h:173
void initialize() override
Definition recording_backend_memory.cpp:41
void finalize() override
Definition recording_backend_memory.cpp:48
RecordingBackendMemory()
Definition recording_backend_memory.cpp:32
void set_status(const Dictionary &) override
Set the status of the recording backend using the key-value pairs contained in the params dictionary.
Definition recording_backend_memory.cpp:164
void post_step_hook() override
Do work required at the end of each simulation step.
Definition recording_backend_memory.cpp:152
void check_device_status(const Dictionary &) const override
Check if the given per-device properties are valid and usable by the backend.
Definition recording_backend_memory.cpp:119
void cleanup() override
Clean up the backend at the end of a user level call to the NEST Simulate function.
Definition recording_backend_memory.cpp:101
Abstract base class for all NESTio recording backends.
Definition recording_backend.h:67
Base class for all recording devices.
Definition recording_device.h:157
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
Definition recording_backend_memory.h:153
std::vector< std::string > long_value_names_
names for values of type long
Definition recording_backend_memory.h:167
std::vector< double > times_offset_
offsets of registered events if time_in_steps_
Definition recording_backend_memory.h:165
void push_back(const Event &, const std::vector< double > &, const std::vector< long > &)
Definition recording_backend_memory.cpp:194
std::vector< std::vector< long > > long_values_
recorded values of type long, one vector per value
Definition recording_backend_memory.h:169
std::vector< double > times_ms_
times of registered events in ms
Definition recording_backend_memory.h:163
void clear()
Definition recording_backend_memory.cpp:284
std::vector< std::string > double_value_names_
names for values of type double
Definition recording_backend_memory.h:166
void set_status(const Dictionary &)
Definition recording_backend_memory.cpp:263
void get_status(Dictionary &) const
Definition recording_backend_memory.cpp:221
std::vector< std::vector< double > > double_values_
recorded values of type double, one vector per value
Definition recording_backend_memory.h:168
std::vector< long > times_steps_
times of registered events in steps
Definition recording_backend_memory.h:164
std::vector< long > senders_
sender node IDs of the events
Definition recording_backend_memory.h:162
DeviceData()
Definition recording_backend_memory.cpp:177
void set_value_names(const std::vector< std::string > &, const std::vector< std::string > &)
Definition recording_backend_memory.cpp:183
bool time_in_steps_
Should time be recorded in steps (ms if false)
Definition recording_backend_memory.h:170