ModelSpace
All Classes Namespaces Functions Variables Enumerations Pages
CsvLogger.h
1/******************************************************************************
2* Copyright (c) ATTX LLC 2024. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX, LLC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX, LLC.
15******************************************************************************/
16/*
17CSV Logger header file
18
19Author: Alex Reynolds
20*/
21#ifndef CSV_LOGGER_H
22#define CSV_LOGGER_H
23
24#include <fstream>
25
26#include "logging/SimLogger.h"
27
28namespace modelspace {
29
30 /// @brief Class for logging to CSV
31 ///
32 /// The CSV logger is a class that inherits from the base logger
33 /// class and manually configures it to write to CSV.
34 class CsvLogger : public clockwerk::SimLogger {
35 public:
36 /// Constructor for CSV logger -- wraps around logger constructor
37 CsvLogger(clockwerk::Executive &exec, const std::string &filename="output.csv", unsigned int buffer_size=1);
38 ~CsvLogger() {close();}
39
40 /// @brief Function to set the delimeter
41 /// @param delim The delimeter to separate file values
42 int delimeter(const std::string &delim);
43
44 /// @brief Function to set CSV logger filename
45 /// @param The filename to set. If no extension applies, auto-set to .csv
46 /// @return Error code corresponding to success/failure
47 int filename(std::string name);
48
49 /// @brief Function to close down the file -- logs remaining buffered data
50 /// and closes
51 int close();
52
53 /// @brief Function to set the precision of CSV logging
54 /// @param precision The precision to set logging to as # of decimal places
55 /// @return Error code corresponding to success/failure
56 int setPrecision(int precision);
57 protected:
58 /// @brief Function to create a CSV file for logging
59 int _createSetupFile();
60
61 /// @brief Function to write buffered data to CSV file
62 int _writeToFile();
63
64 /// Stream variable to write file to
65 std::ofstream _fout;
66
67 /// String to indicate delimeter -- set to comma by default
68 std::string _delimeter;
69
70 /// The precision of logging. Default is 20 places
71 int _precision = 20;
72 };
73
74}
75
76#endif
Central control mechanism to run simulations and software.
Definition Executive.h:43
Class for logging data to a file.
Definition SimLogger.h:67
Class for logging to CSV.
Definition CsvLogger.h:34
int _createSetupFile()
Function to create a CSV file for logging.
Definition CsvLogger.cpp:87
int _precision
The precision of logging. Default is 20 places.
Definition CsvLogger.h:71
int _writeToFile()
Function to write buffered data to CSV file.
Definition CsvLogger.cpp:130
CsvLogger(clockwerk::Executive &exec, const std::string &filename="output.csv", unsigned int buffer_size=1)
Constructor for CSV logger – wraps around logger constructor.
Definition CsvLogger.cpp:25
std::string _delimeter
String to indicate delimeter – set to comma by default.
Definition CsvLogger.h:68
int setPrecision(int precision)
Function to set the precision of CSV logging.
Definition CsvLogger.cpp:78
int delimeter(const std::string &delim)
Function to set the delimeter.
Definition CsvLogger.cpp:69
int close()
Function to close down the file – logs remaining buffered data and closes.
Definition CsvLogger.cpp:180
std::ofstream _fout
Stream variable to write file to.
Definition CsvLogger.h:65
int filename(std::string name)
Function to set CSV logger filename.
Definition CsvLogger.cpp:46
Class to propagate CR3BP dynamics in characteristic units.
Definition ConfigurationWriter.cpp:18