connection_data_logger.h
1 /*
2  * This file is part of SPORE.
3  *
4  * Copyright (C) 2016, the SPORE team (see AUTHORS).
5  *
6  * SPORE is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * SPORE is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with SPORE. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * For more information see: https://github.com/IGITUGraz/spore-nest-module
20  *
21  * File: connection_data_logger.h
22  * Author: Kappel
23  *
24  * Created on November 8, 2016, 11:57 AM
25  */
26 
27 #ifndef CONNECTION_DATA_LOGGER_H
28 #define CONNECTION_DATA_LOGGER_H
29 
30 #include <string>
31 #include <vector>
32 
33 #include "nest.h"
34 #include "dictdatum.h"
35 
36 
37 namespace spore
38 {
39 
44 {
45 public:
46  typedef nest::index recorder_port;
47 
50 
51  void get_status(DictionaryDatum& d, recorder_port port) const;
52  void set_status(const DictionaryDatum& d, recorder_port& port);
53  void clear();
54 
55 protected:
56 
60  struct RecorderData
61  {
62  RecorderData(size_t size);
63  void clear();
64 
65  std::vector<double> recorder_times_;
66  std::vector< std::vector<double> > recorder_values_;
67  double interval_;
68  };
69 
70  recorder_port add_recordable_connection();
71 
72  std::vector< RecorderData* > recorder_data_;
73  std::vector< Name > recorder_names_;
74 };
75 
79 template<typename ConnectionType>
81 {
82 public:
83  typedef double ( ConnectionType::*DataAccessFct )() const;
84 
85  void register_recordable_variable(const Name& name, DataAccessFct data_access_fct);
86  void record(double time, ConnectionType const& host, recorder_port port);
87 
88 private:
89  std::vector< DataAccessFct > data_access_fct_;
90 };
91 
92 
93 //
94 // ConnectionDataLogger implementation.
95 //
96 
103 template<typename ConnectionType>
105  DataAccessFct data_access_fct)
106 {
107  recorder_names_.push_back(name);
108  data_access_fct_.push_back(data_access_fct);
109 }
110 
119 template<typename ConnectionType>
121  ConnectionType const& host,
122  recorder_port port)
123 {
124  if (port == nest::invalid_index)
125  return;
126 
127  assert(port < recorder_data_.size());
128  ConnectionDataLoggerBase::RecorderData &recorder = *recorder_data_[port];
129 
130  if (recorder.interval_ == 0)
131  return;
132 
133  if (recorder.recorder_times_.empty() || (recorder.recorder_times_.back() + recorder.interval_ <= time_step))
134  {
135  recorder.recorder_times_.push_back(time_step);
136 
137  for (size_t i = 0; i < recorder.recorder_values_.size(); i++)
138  {
139  recorder.recorder_values_[i].push_back(((host).*(data_access_fct_[i]))());
140  }
141  }
142 }
143 
144 }
145 
146 #endif
RecorderData(size_t size)
Definition: connection_data_logger.cpp:146
void set_status(const DictionaryDatum &d, recorder_port &port)
Definition: connection_data_logger.cpp:86
Generic version of data logger for connections.
Definition: connection_data_logger.h:80
void register_recordable_variable(const Name &name, DataAccessFct data_access_fct)
Definition: connection_data_logger.h:104
void record(double time, ConnectionType const &host, recorder_port port)
Definition: connection_data_logger.h:120
recorder_port add_recordable_connection()
Definition: connection_data_logger.cpp:115
void get_status(DictionaryDatum &d, recorder_port port) const
Definition: connection_data_logger.cpp:63
~ConnectionDataLoggerBase()
Definition: connection_data_logger.cpp:47
Global namespace holding all classes of the SPORE NEST module.
Definition: circular_buffer.h:31
void clear()
Definition: connection_data_logger.cpp:157
ConnectionDataLoggerBase()
Definition: connection_data_logger.cpp:40
Base class to all data loggers for connections.
Definition: connection_data_logger.h:43
Data structure that holds the recorded data.
Definition: connection_data_logger.h:60
void clear()
Definition: connection_data_logger.cpp:127