NEST  2.6.0,not_revisioned_source_dir@0
multimeter.h
Go to the documentation of this file.
1 /*
2  * multimeter.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 MULTIMETER_H
24 #define MULTIMETER_H
25 
26 #include <vector>
27 
28 #include "recording_device.h"
29 #include "name.h"
30 #include "node.h"
31 #include "connection.h"
32 #include "dictutils.h"
33 #include "exceptions.h"
34 #include "sibling_container.h"
35 
36 /*BeginDocumentation
37 Name: multimeter - Device to record analog data from neurons.
38 Synopsis: multimeter Create
39 
40 Description:
41 A multimeter records a user-defined set of state variables from connected nodes to memory,
42 file or stdout.
43 
44 The multimeter must be configured with the list of variables to record
45 from, otherwise it will not record anything. The /recordables property
46 of a neuron model shows which quantities can be recorded with a multimeter.
47 A single multimeter should only record from neurons of the same basic
48 type (e.g. /iaf_cond_alpha and any user-defined models derived from it
49 using CopyModel). If the defaults or status dictionary of a model neuron
50 does not contain a /recordables entry, it is not ready for use with
51 multimeter.
52 
53 By default, multimeters record values once per ms. Set the parameter /interval to
54 change this. The recording interval cannot be smaller than the resolution.
55 
56 Results are returned in the /events entry of the status dictionary. For
57 each recorded quantity, a vector of doubles is returned. The vector has the
58 same name as the /recordable. If /withtime is set, times are given in the
59 /times vector in /events.
60 
61 Accumulator mode:
62 Multimeter can operate in accumulator mode. In this case, values for all recorded
63 variables are added across all recorded nodes (but kept separate in time). This can
64 be useful to record average membrane potential in a population.
65 
66 To activate accumulator mode, either set /to_accumulator to true, or set
67 /record_to [ /accumulator ]. In accumulator mode, you cannot record to file,
68 to memory, to screen, with GID or with weight. You must activate accumulator mode
69 before simulating. Accumulator data is never written to file. You must extract it
70 from the device using GetStatus.
71 
72 Note:
73  - The set of variables to record and the recording interval must be set
74  BEFORE the multimeter is connected to any node, and cannot be changed
75  afterwards.
76  - A multimeter cannot be frozen.
77  - If you record with multimeter in accumulator mode and some of the nodes
78  you record from and others are not, data will only be collected from the
79  unfrozen nodes. Most likely, this will lead to confusing results, so
80  you should not use multimeter with frozen nodes.
81 
82 Parameters:
83  The following parameters can be set in the status dictionary:
84  interval double - Recording interval in ms
85  record_from array - Array containing the names of variables to record
86  from, obtained from the /recordables entry of the
87  model from which one wants to record
88 
89 Examples:
90 SLI ] /iaf_cond_alpha Create /n Set
91 SLI ] n /recordables get ==
92 [/V_m /g_ex /g_in /t_ref_remaining]
93 SLI ] /multimeter Create /mm Set
94 SLI ] mm << /interval 0.5 /record_from [/V_m /g_ex /g_in] >> SetStatus
95 SLI ] mm n Connect
96 SLI ] 10 Simulate
97 SLI ] mm /events get info
98 --------------------------------------------------
99 Name Type Value
100 --------------------------------------------------
101 g_ex doublevectortype <doublevectortype>
102 g_in doublevectortype <doublevectortype>
103 senders intvectortype <intvectortype>
104 times doublevectortype <doublevectortype>
105 t_ref_remaining doublevectortype <doublevectortype>
106 V_m doublevectortype <doublevectortype>
107 --------------------------------------------------
108 Total number of entries: 6
109 
110 
111 Sends: DataLoggingRequest
112 
113 FirstVersion: 2009-04-01
114 
115 Author: Hans Ekkehard Plesser
116 
117 SeeAlso: Device, RecordingDevice
118 */
119 
120 namespace nest {
121 
122  class Network;
123 
157  class Multimeter : public Node {
158 
159  public:
160  Multimeter();
161  Multimeter(const Multimeter&);
162 
167  bool has_proxies() const { return false; }
168 
173  using Node::handle;
175 
177 
178  void handle(DataLoggingReply&);
179 
180  void get_status(DictionaryDatum &) const;
181  void set_status(const DictionaryDatum &) ;
182 
183  protected:
184  void init_state_(Node const&);
185  void init_buffers_();
186  void calibrate();
187  void finalize();
188 
196  void update(Time const&, const long_t, const long_t);
197 
198  private:
199 
204  bool is_active(Time const & T) const;
205 
212  void print_value_(const std::vector<double_t>&);
213 
220  void add_data_(DictionaryDatum&) const;
221 
222  // ------------------------------------------------------------
223 
225 
226  // ------------------------------------------------------------
227 
228  struct Buffers_;
229 
230  struct Parameters_ {
232  std::vector<Name> record_from_;
233 
234  Parameters_();
235  Parameters_(const Parameters_&);
236  void get(DictionaryDatum&) const;
237  void set(const DictionaryDatum&, const Buffers_&);
238  };
239 
240  // ------------------------------------------------------------
241 
242  struct State_ {
253  std::vector<std::vector<double_t> > data_;
254  };
255 
256  // ------------------------------------------------------------
257 
258  struct Buffers_ {
263  Buffers_();
264 
266  };
267 
268  // ------------------------------------------------------------
269 
270  struct Variables_ {
278 
286  };
287 
288  // ------------------------------------------------------------
289 
294  };
295 
296 
297  inline
299  {
300  // get the data from the device
301  device_.get_status(d);
302 
303  // we need to add analog data to the events dictionary
304  DictionaryDatum dd = getValue<DictionaryDatum>(d, names::events);
305  add_data_(dd);
306 
307  // if we are the device on thread 0, also get the data from the
308  // siblings on other threads
309  if (get_thread() == 0)
310  {
311  const SiblingContainer* siblings = network()->get_thread_siblings(get_gid());
312  std::vector<Node*>::const_iterator sibling;
313  for (sibling = siblings->begin() + 1; sibling != siblings->end(); ++sibling)
314  (*sibling)->get_status(d);
315  }
316 
317  P_.get(d);
318  }
319 
320  inline
322  {
323  // protect Multimeter from being frozen
324  bool freeze = false;
325  if ( updateValue<bool>(d, names::frozen, freeze) && freeze )
326  throw BadProperty("Multimeter cannot be frozen.");
327 
328  Parameters_ ptmp = P_;
329  ptmp.set(d, B_);
330 
331  // Set properties in device. As a side effect, this will clear data_,
332  // if /clear_events set in d
333  device_.set_status(d, S_.data_);
334 
335  P_ = ptmp;
336  }
337 
338 
339 } // Namespace
340 
341 #endif
Time interval_
recording interval, in ms
Definition: multimeter.h:231
bool has_proxies() const
Definition: multimeter.h:167
SiblingContainer class.
Definition: sibling_container.h:46
Definition: multimeter.h:242
Definition: lockptrdatum.h:40
void calibrate()
Re-calculate dependent parameters of the node.
Definition: multimeter.cpp:127
bool new_request_
Flag active till first DataLoggingReply during an update() call processed.
Definition: multimeter.h:277
const Name d("d")
Specific to Izhikevich 2003.
Definition: nest_names.h:83
Declarations for base class Node.
const Name frozen("frozen")
Node parameter.
Definition: nest_names.h:142
void handle(DataLoggingReply &)
Handler for universal data logging request.
Definition: multimeter.cpp:166
void get_status(DictionaryDatum &) const
Definition: sibling_container.h:61
std::vector< std::vector< double_t > > data_
Recorded data.
Definition: multimeter.h:253
long_t rport
Connection port number to distinguish incoming connections, also called receiver port.
Definition: nest.h:147
void print_value_(const std::vector< double_t > &)
"Print" one value to file or screen, depending on settings in RecordingDevice.
Definition: multimeter.cpp:223
void update(Time const &, const long_t, const long_t)
Collect and output membrane potential information.
Definition: multimeter.cpp:139
const Name events("events")
Recorder parameter.
Definition: nest_names.h:125
Parameters_()
Definition: multimeter.cpp:56
State_ S_
Definition: multimeter.h:291
void init_state_(Node const &)
Private function to initialize the state of a node to model defaults.
Definition: multimeter.cpp:115
void set(const DictionaryDatum &, const Buffers_ &)
Definition: multimeter.cpp:82
Multimeter()
Definition: multimeter.cpp:28
void add_data_(DictionaryDatum &) const
Add recorded data to dictionary.
Definition: multimeter.cpp:235
size_t current_request_data_start_
Index to first S_.data_ entry for currently processed request.
Definition: multimeter.h:285
Base class for all recording devices.
Definition: recording_device.h:214
Provide logged data through request transmitting reference.
Definition: event.h:563
Definition: nest_time.h:130
Buffers_ B_
Definition: multimeter.h:292
bool has_targets_
Definition: multimeter.h:265
void get_status(DictionaryDatum &) const
Definition: multimeter.h:298
vector< Node * >::iterator begin()
Return iterator to the first child node.
Definition: sibling_container.h:133
void init_buffers_()
Private function to initialize the buffers of a node.
Definition: multimeter.cpp:122
Variables_ V_
Definition: multimeter.h:293
std::vector< Name > record_from_
which data to record
Definition: multimeter.h:232
Definition: multimeter.h:270
Exception to be thrown if a status parameter is incomplete or inconsistent.
Definition: exceptions.h:420
long_t port
Connection port number to distinguis outgoing connections.
Definition: nest.h:155
void finalize()
Finalize node.
Definition: multimeter.cpp:134
virtual void handle(SpikeEvent &e)
Handle incoming spike events.
Definition: node.cpp:198
bool is_active(Time const &T) const
Indicate if recording device is active.
Definition: multimeter.cpp:254
General analog data recorder.
Definition: multimeter.h:157
virtual port handles_test_event(SpikeEvent &, rport receptor_type)
Check if the node can handle a particular event and receptor type.
Definition: node.cpp:203
Definition: multimeter.h:258
RecordingDevice device_
Definition: multimeter.h:224
unsigned char synindex
Unsigned char type for enumerations of synapse types.
Definition: nest.h:115
Parameters_ P_
Definition: multimeter.h:290
vector< Node * >::iterator end()
Return iterator to the end of the child-list.
Definition: sibling_container.h:139
Base class for all NEST network objects.
Definition: node.h:96
Buffers_()
Does this multimeter have targets? Placed here since it is implementation detail. ...
Definition: multimeter.cpp:68
void set_status(const DictionaryDatum &)
Definition: multimeter.h:321
port send_test_event(Node &, rport, synindex, bool)
Send an event to the receiving_node passed as an argument.
Definition: multimeter.cpp:46
long long_t
Integer number with at least 32 bit.
Definition: nest.h:96
Definition: multimeter.h:230