NEST main@caf0ae8
 
Loading...
Searching...
No Matches
recording_backend_ascii.h
Go to the documentation of this file.
1/*
2 * recording_backend_ascii.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_ASCII_H
24#define RECORDING_BACKEND_ASCII_H
25
26// C++ includes:
27#include <fstream>
28
29#include "recording_backend.h"
30
31/* BeginUserDocs: NOINDEX
32
33Short description
34+++++++++++++++++
35
36Recording backend `ascii` - Write data to plain text files
37
38Description
39~~~~~~~~~~~
40
41The `ascii` recording backend writes collected data persistently to a
42plain text ASCII file. It can be used for small to medium sized
43simulations, where the ease of a simple data format outweighs the
44benefits of high-performance output operations.
45
46This backend will open one file per recording device per thread on
47each MPI process. This can cause a high load on the file system in
48large simulations. This backend can become prohibitively inefficient,
49particularly on machines with distributed filesystems. In case you
50experience such scaling problems, the :doc:`recording backend for
51SIONlib </models/recording_backend_sionlib>` may be a possible alternative.
52
53Filenames of data files are determined according to the following
54pattern:
55
56::
57
58 data_path/data_prefix(label|model_name)-node_id-vp.file_extension
59
60The properties ``data_path`` and ``data_prefix`` are global kernel
61properties. They can, for example, be set during repetitive simulation
62protocols to separate the data originating from individual runs. The
63``label`` replaces the model name component if it is set to a non-empty
64string. ``node_id`` and ``vp`` denote the zero-padded global ID and virtual
65process of the recorder writing the file. The filename ends in a dot
66and the ``file_extension``.
67
68The life of a file starts with the call to ``Prepare`` and ends with
69the call to ``Cleanup``. Data that is produced during successive calls
70to ``Run`` in between a pair of ``Prepare`` and ``Cleanup`` calls will
71be written to the same file, while the call to ``Run`` will flush all
72data to the file, so it is available for immediate inspection.
73
74If the file name already exists when creating a new recording, the
75call to ``Prepare`` will fail with a ``FileExists`` error. To overwrite
76the old file, the kernel property ``overwrite_files`` can be set to
77``True`` using the corresponding kernel attribute. An alternative way
78for avoiding name clashes is to set the kernel attributes
79``data_path`` or ``data_prefix``, to write to a different file.
80
81Data format
82~~~~~~~~~~~
83
84Any file written by the `ascii` recording backend starts with an
85informational header. The first header line contains the NEST version,
86with which the file was created, followed by the version of the
87recording backend in the second. The third line describes the data by
88means of the field names for the different columns. All lines of the
89header start with a `#` character.
90
91The first field of each record written is the node ID of the neuron
92the event originated from, i.e., the *source* of the event. This is
93followed by the time of the measurement, the recorded floating point
94values and the recorded integer values.
95
96The format of the time field depends on the value of the property
97``time_in_steps``. If set to *false* (which is the default), time is
98written as a single floating point number representing the simulation
99time in ms. If ``time_in_steps`` is *true*, the time of the event is
100written as a pair of values consisting of the integer simulation time
101step in units of the simulation resolution and the negative floating
102point offset in ms from the next integer grid point.
103
104.. note::
105
106 The number of decimal places for all decimal numbers written can be
107 controlled using the recorder property ``precision``.
108
109Parameter summary
110~~~~~~~~~~~~~~~~~
111
112file_extension
113 A string (default: *"dat"*) that specifies the file name extension,
114 without leading dot. The generic default was chosen, because the
115 exact type of data cannot be known a priori.
116
117filenames
118 A list of the filenames where data is recorded to. This list has one
119 entry per local thread and is a read-only property.
120
121label
122 A string (default: *""*) that replaces the model name component in
123 the filename if it is set.
124
125precision
126 An integer (default: *3*) that controls the number of decimal places
127 used to write decimal numbers to the output file.
128
129time_in_steps
130 A Boolean (default: *false*) specifying whether to write time in
131 steps, i.e., in integer multiples of the simulation resolution plus
132 a floating point number for the negative offset from the next grid
133 point in ms, or just the simulation time in ms. This property
134 cannot be set after Simulate has been called.
135
136EndUserDocs */
137
138namespace nest
139{
140
152{
153public:
154 const static unsigned int ASCII_REC_BACKEND_VERSION;
155
157
158 ~RecordingBackendASCII() throw() override;
159
160 void initialize() override;
161
162 void finalize() override;
163
164 void enroll( const RecordingDevice& device, const Dictionary& params ) override;
165
166 void disenroll( const RecordingDevice& device ) override;
167
168 void set_value_names( const RecordingDevice& device,
169 const std::vector< std::string >& double_value_names,
170 const std::vector< std::string >& long_value_names ) override;
171
172 void prepare() override;
173
174 void cleanup() override;
175
176 void pre_run_hook() override;
177
181 void post_run_hook() override;
182
183 void post_step_hook() override;
184
185 void write( const RecordingDevice&, const Event&, const std::vector< double >&, const std::vector< long >& ) override;
186
187 void set_status( const Dictionary& ) override;
188 void get_status( Dictionary& ) const override;
189
190 void check_device_status( const Dictionary& ) const override;
191 void get_device_defaults( Dictionary& ) const override;
192 void get_device_status( const RecordingDevice& device, Dictionary& ) const override;
193
194private:
195 const std::string compute_vp_node_id_string_( const RecordingDevice& device ) const;
196
198 {
199 DeviceData() = delete;
200 DeviceData( std::string, std::string );
201 void set_value_names( const std::vector< std::string >&, const std::vector< std::string >& );
202 void open_file();
203 void write( const Event&, const std::vector< double >&, const std::vector< long >& );
204 void flush_file();
205 void close_file();
206 void get_status( Dictionary& ) const;
207 void set_status( const Dictionary& );
208
209 private:
212 std::string modelname_;
213 std::string vp_node_id_string_;
214 std::string file_extension_;
215 std::string label_;
216 std::ofstream file_;
217 std::vector< std::string > double_value_names_;
218 std::vector< std::string > long_value_names_;
219
220 std::string compute_filename_() const;
221 };
222
223 typedef std::vector< std::map< size_t, DeviceData > > data_map;
225};
226
227} // namespace
228
229#endif /* #ifndef RECORDING_BACKEND_ASCII_H */
Dictionary class for interface to Python and C++ API.
Definition dictionary.h:213
Encapsulate information sent between nodes.
Definition event.h:103
ASCII specialization of the RecordingBackend interface.
Definition recording_backend_ascii.h:152
void get_device_defaults(Dictionary &) const override
Return the per-device defaults by writing it to the given params dictionary.
Definition recording_backend_ascii.cpp:207
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_ascii.cpp:94
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_ascii.cpp:200
void initialize() override
Definition recording_backend_ascii.cpp:50
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_ascii.cpp:214
void post_run_hook() override
Flush files after a single call to Run.
Definition recording_backend_ascii.cpp:113
~RecordingBackendASCII() override
Definition recording_backend_ascii.cpp:45
data_map device_data_
Definition recording_backend_ascii.h:224
void prepare() override
Prepare the backend at begin of the NEST Simulate function.
Definition recording_backend_ascii.cpp:176
void pre_run_hook() override
Initialize global backend-specific data structures.
Definition recording_backend_ascii.cpp:107
void cleanup() override
Clean up the backend at the end of a user level call to the NEST Simulate function.
Definition recording_backend_ascii.cpp:131
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_ascii.cpp:143
void finalize() override
Definition recording_backend_ascii.cpp:57
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_ascii.cpp:188
void enroll(const RecordingDevice &device, const Dictionary &params) override
Enroll a RecordingDevice with the RecordingBackend.
Definition recording_backend_ascii.cpp:63
void get_status(Dictionary &) const override
Return the status of the recording backend by writing it to the given params dictionary.
Definition recording_backend_ascii.cpp:194
std::vector< std::map< size_t, DeviceData > > data_map
Definition recording_backend_ascii.h:223
RecordingBackendASCII()
Definition recording_backend_ascii.cpp:41
void disenroll(const RecordingDevice &device) override
Disenroll a RecordingDevice from the RecordingBackend.
Definition recording_backend_ascii.cpp:81
static const unsigned int ASCII_REC_BACKEND_VERSION
Definition recording_backend_ascii.h:154
void post_step_hook() override
Do work required at the end of each simulation step.
Definition recording_backend_ascii.cpp:125
const std::string compute_vp_node_id_string_(const RecordingDevice &device) const
Definition recording_backend_ascii.cpp:161
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_ascii.h:198
std::string label_
The label of the device.
Definition recording_backend_ascii.h:215
std::string file_extension_
File name extension without leading ".".
Definition recording_backend_ascii.h:214
std::string vp_node_id_string_
The vp and node ID component of the filename.
Definition recording_backend_ascii.h:213
std::string modelname_
File name up to but not including the ".".
Definition recording_backend_ascii.h:212
std::vector< std::string > double_value_names_
names for values of type double
Definition recording_backend_ascii.h:217
bool time_in_steps_
Should time be recorded in steps (ms if false)
Definition recording_backend_ascii.h:211
std::vector< std::string > long_value_names_
names for values of type long
Definition recording_backend_ascii.h:218
std::ofstream file_
File stream to use for the device.
Definition recording_backend_ascii.h:216
long precision_
Number of decimal places used when writing decimal values.
Definition recording_backend_ascii.h:210