1 /*
2 * io_manager.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 IO_MANAGER_H
24 #define IO_MANAGER_H
25
26 // C++ includes:
27 #include <string>
28
29 // Includes from libnestutil:
30 #include "manager_interface.h"
31
32 #include "recording_backend.h"
33 #include "stimulation_backend.h"
34
35 namespace nest
36 {
37
38 /*
39 IOManager: Handles data storage files from spike recorders and
40 multimeters to file system(s)/memory/output. Distinct from logging
41 for error streams.
42 */
43 class IOManager : public ManagerInterface
44 {
45 public:
46 void initialize() override; // called from meta-manager to construct
47 void finalize() override; // called from meta-manger to reinit
48 void change_num_threads( thread ) override;
49
50 void set_status( const DictionaryDatum& ) override; // set parameters
51 void get_status( DictionaryDatum& ) override; // get parameters
52
53 IOManager(); // Construct only by meta-manager
54 ~IOManager() override;
55
56 /**
57 * The prefix for files written by devices.
58 * The prefix must not contain any part of a path.
59 * @see get_data_dir(), overwrite_files()
60 */
61 const std::string& get_data_prefix() const;
62
63 /**
64 * The path for files written by devices.
65 * It may be the empty string (use current directory).
66 * @see get_data_prefix(), overwrite_files()
67 */
68 const std::string& get_data_path() const;
69
70 /**
71 * Indicate if existing data files should be overwritten.
72 * @return true if existing data files should be overwritten by devices.
73 * Default: false.
74 */
75 bool overwrite_files() const;
76
77 /**
78 * Clean up in all registered recording backends after a single call to run by
79 * calling the backends' post_run_hook() functions
80 */
81 void post_run_hook();
82 void pre_run_hook();
83
84 /**
85 * Clean up in all registered recording backends after a single simulation
86 * step by calling the backends' post_step_hook() functions
87 */
88 void post_step_hook();
89
90 /**
91 * Finalize all registered recording backends after a call to
92 * SimulationManager::simulate() or SimulationManager::cleanup() by
93 * calling the backends' finalize() functions
94 */
95 void cleanup() override;
96 void prepare() override;
97
98 template < class RBT >
99 void register_recording_backend( Name );
100 template < class RBT >
101 void register_stimulation_backend( Name );
102
103 bool is_valid_recording_backend( const Name& ) const;
104 bool is_valid_stimulation_backend( const Name& ) const;
105
106 void
107 write( const Name&, const RecordingDevice&, const Event&, const std::vector< double >&, const std::vector< long >& );
108
109 void enroll_recorder( const Name&, const RecordingDevice&, const DictionaryDatum& );
110 void enroll_stimulator( const Name&, StimulationDevice&, const DictionaryDatum& );
111
112 void set_recording_value_names( const Name& backend_name,
113 const RecordingDevice& device,
114 const std::vector< Name >& double_value_names,
115 const std::vector< Name >& long_value_names );
116
117 void check_recording_backend_device_status( const Name&, const DictionaryDatum& );
118 void get_recording_backend_device_defaults( const Name&, DictionaryDatum& );
119 void get_recording_backend_device_status( const Name&, const RecordingDevice&, DictionaryDatum& );
120
121 private:
122 void set_data_path_prefix_( const DictionaryDatum& );
123 void register_recording_backends_();
124 void register_stimulation_backends_();
125
126 std::string data_path_; //!< Path for all files written by devices
127 std::string data_prefix_; //!< Prefix for all files written by devices
128 bool overwrite_files_; //!< If true, overwrite existing data files.
129
130 /**
131 * A mapping from names to registered recording backends.
132 */
133 std::map< Name, RecordingBackend* > recording_backends_;
134 /**
135 * A mapping from names to registered stimulation backends
136 */
137 std::map< Name, StimulationBackend* > stimulation_backends_;
138 };
139
140 } // namespace nest
141
142 inline const std::string&
get_data_path()143 nest::IOManager::get_data_path() const
144 {
145 return data_path_;
146 }
147
148 inline const std::string&
get_data_prefix()149 nest::IOManager::get_data_prefix() const
150 {
151 return data_prefix_;
152 }
153
154 inline bool
overwrite_files()155 nest::IOManager::overwrite_files() const
156 {
157 return overwrite_files_;
158 }
159
160
161 #endif /* IO_MANAGER_H */
162