2
3
4
5
6
7
8
9
10
11
12
13
14
15
17
18
19
20
28#include "data_management/GraphTreeObject.h"
29#include "core/clockwerkerrors.h"
30#include "core/Matrix.hpp"
31#include "architecture/EventLogger.h"
35 enum vector_select_e {
71 SimLogger(
Executive &executive,
const std::string &filename=
"output.csv",
unsigned int buffer_size=1);
76 int bufferSize(
unsigned int buffer_size);
80 int filename(
const std::string &name);
83 std::string
outDir() {
return _output_directory;}
84 int outDir(
const std::string &directory);
89 virtual int setup(
const std::string &file_name) {
return NO_ERROR;}
98 int addParameter(
GraphTreeObject ¶meter,
const std::string ¶m_name,
99 bool recursive =
false);
108 int addParameter(
const std::string ¶meter,
const std::string ¶m_name,
109 bool recursive =
false);
129 int writeHeaders(
const int &val) {_group_idx.push_back(-1); _headers.push_back(_current_name);
return NO_ERROR;}
130 int writeHeaders(
const unsigned int &val) {_group_idx.push_back(-1); _headers.push_back(_current_name);
return NO_ERROR;}
131 int writeHeaders(
const double &val) {_group_idx.push_back(-1); _headers.push_back(_current_name);
return NO_ERROR;}
133 int writeHeaders(
void* val) {_group_idx.push_back(-1); _headers.push_back(_current_name);
return NO_ERROR;}
134 int writeHeaders(
const std::string &val) {_group_idx.push_back(-1); _headers.push_back(_current_name);
return NO_ERROR;}
136 template <
typename T>
int writeHeaders(
const std::vector<T> &val);
137 template <
typename T,
long unsigned int N>
int writeHeaders(
const std::array<T, N> &val);
139 template <
typename T,
unsigned int R,
unsigned int C>
int writeHeaders(
const Matrix<T, R, C> &val);
147 int writeToBuffer(
const int &val);
148 int writeToBuffer(
const long unsigned int &val);
149 int writeToBuffer(
const float &val);
150 int writeToBuffer(
const double &val);
151 int writeToBuffer(
const std::string &val);
152 int writeToBuffer(
void* val);
158 template <
typename T>
int writeToBuffer(
const std::vector<T> &val);
159 template <
typename T,
long unsigned int N>
int writeToBuffer(
const std::array<T, N> &val);
161 template <
typename T,
unsigned int R,
unsigned int C>
int writeToBuffer(
const Matrix<T, R, C> &val);
181 std::vector<std::string> _log_names;
182 std::string _current_name;
186 std::string _output_directory;
198 unsigned int _buffer_write_idx = 0;
199 unsigned int _buffer_read_idx = 0;
200 std::vector<std::vector<
bool>> _bool_vector;
202 std::vector<std::vector<
long unsigned int>>
_uint_vector;
209 unsigned int _seq_idx = 0;
210 std::vector<std::string> _headers;
211 std::vector<
unsigned int> _sequence;
212 std::vector<vector_select_e> _type;
220 long unsigned int size;
223 std::vector<
int> _group_idx;
231 template <
typename T>
232 int SimLogger::writeToBuffer(
const std::vector<T> &val) {
235 for(
unsigned int i = 0; i < val.size(); i++) {
236 err = writeToBuffer(val[i]);
244 template <
typename T,
long unsigned int N>
245 int SimLogger::writeToBuffer(
const std::array<T, N> &val) {
248 for(
unsigned int i = 0; i < N; i++) {
249 err = writeToBuffer(val[i]);
257 template <
typename T,
unsigned int R,
unsigned int C>
261 for(i = 0; i < R; i++) {
262 for(j = 0; j < C; j++) {
263 err = writeToBuffer(val.values[i][j]);
272 template <
typename T>
273 int SimLogger::writeHeaders(
const std::vector<T> &val) {
276 _groups.push_back({val.size(), _current_name});
278 for(
unsigned int i = 0; i < val.size(); i++) {
279 _headers.push_back(_current_name +
"_" + std::to_string(i));
280 _group_idx.push_back(
_groups.size() - 1);
285 template <
typename T,
long unsigned int N>
286 int SimLogger::writeHeaders(
const std::array<T, N> &val) {
289 _groups.push_back({val.size(), _current_name});
291 for(
unsigned int i = 0; i < N; i++) {
292 _headers.push_back(_current_name +
"_" + std::to_string(i));
293 _group_idx.push_back(
_groups.size() - 1);
298 template <
typename T,
unsigned int R,
unsigned int C>
302 _groups.push_back({R*C, _current_name});
305 for(i = 0; i < R; i++) {
306 for(j = 0; j < C; j++) {
309 _headers.push_back(_current_name +
"_" + std::to_string(i));
310 _group_idx.push_back(
_groups.size() - 1);
313 _headers.push_back(_current_name +
"_" + std::to_string(i) +
"_" + std::to_string(j));
314 _group_idx.push_back(
_groups.size() - 1);
Central control mechanism to run simulations and software.
Definition Executive.h:43
Base class for object organization.
Definition GraphTreeObject.h:87
Matrix math implementation.
Definition Matrix.hpp:54
Class for logging data to a file.
Definition SimLogger.h:67
std::vector< std::vector< long unsigned int > > _uint_vector
1
Definition SimLogger.h:202
virtual int _createSetupFile()
Function to create a file, in whatever format is chosen, for logging.
Definition SimLogger.h:174
std::vector< std::vector< int > > _int_vector
0
Definition SimLogger.h:201
virtual int lockForLogging()
Function to lock the file for logging once all parameters have been defined. Generates headers and cr...
Definition SimLogger.cpp:125
log_level_e _local_log_level
Our local log level – allows a higher log level locally than the overall system.
Definition SimLogger.h:227
Executive * exc
Handle to the executive object – used for event logging, etc.
Definition SimLogger.h:168
std::string outDir()
Functions to get and set output directory.
Definition SimLogger.h:83
std::string filename()
Functions to get and set filename.
Definition SimLogger.h:79
std::vector< std::vector< float > > _float_vector
2
Definition SimLogger.h:203
virtual int log()
Function to log data to buffer. Flushes buffer to file when full.
Definition SimLogger.cpp:178
int writeToBuffer(const bool &val)
Overloaded function to write data to the buffer. Should not be called directly by the user – is reser...
Definition SimLogger.cpp:277
std::vector< std::vector< std::string > > _string_vector
4
Definition SimLogger.h:205
virtual int close()
Function to close down the file – logs remaining buffered data and closes.
Definition SimLogger.cpp:216
std::vector< GraphTreeObject * > _logged_nodes
A vector to hold all graph tree object pointers.
Definition SimLogger.h:180
bool _locked
5
Definition SimLogger.h:208
std::string _filename
String for the filename.
Definition SimLogger.h:185
unsigned int bufferSize()
Functions to get and set buffer size.
Definition SimLogger.h:75
void logLevel(log_level_e new_level)
Function to set the local model log level.
Definition SimLogger.h:165
std::vector< Group > _groups
Set to -1 if variable is not part of group.
Definition SimLogger.h:224
unsigned int _buffer_size
Ok, so this is important. At the end of the day, every variable resolves somehow into a basic type,...
Definition SimLogger.h:197
virtual int _writeToFile()
Function to write buffered data to file.
Definition SimLogger.h:177
std::vector< std::vector< double > > _double_vector
3
Definition SimLogger.h:204
void _fillBuffers()
Function to set all buffers to full size.
Definition SimLogger.cpp:233
#define NO_ERROR
Definition clockwerkerrors.h:31
Grouping methods – for some variables, such as arrays and vectors, we may want to lump all of the dat...
Definition SimLogger.h:219
std::string group_name
The size of the group.
Definition SimLogger.h:221