SST  15.1.0
StructuralSimulationToolkit
statoutputcsv.h
1 // Copyright 2009-2025 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2025, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_STATAPI_STATOUTPUTCSV_H
13 #define SST_CORE_STATAPI_STATOUTPUTCSV_H
14 
15 #include "sst/core/sst_types.h"
16 #include "sst/core/statapi/statoutput.h"
17 
18 #ifdef HAVE_LIBZ
19 #include <zlib.h>
20 #endif
21 
22 #include <cstdio>
23 #include <string>
24 #include <vector>
25 
26 namespace SST::Statistics {
27 
28 /**
29  \class StatisticOutputCSV
30 
31  The class for statistics output to a comma separated file.
32 */
34 {
35 public:
36  SST_ELI_REGISTER_DERIVED(
39  "sst",
40  "statoutputcsv",
41  SST_ELI_ELEMENT_VERSION(1,0,0),
42  "Output directly to console screen"
43  )
44 
45  SST_ELI_DOCUMENT_PARAMS(
46  { "separator", "Field separator", ", "},
47  { "filepath", "Filepath for the output file", "./StatisticOutput.csv"},
48  { "outputtopheader", "Whether to print a header at the top of the CSV output", "True" },
49  { "outputsimtime", "Whether to print the simulation time in the output", "True" },
50  { "outputrank", "Whether to print the rank in the output", "True" }
51  )
52 
53  /** Construct a StatOutputCSV
54  * @param outputParameters - Parameters used for this Statistic Output
55  */
56  explicit StatisticOutputCSV(Params& outputParameters);
57 
58  void serialize_order(SST::Core::Serialization::serializer& ser) override;
59  ImplementSerializable(SST::Statistics::StatisticOutputCSV)
60 
61 protected:
62  /** Perform a check of provided parameters
63  * @return True if all required parameters and options are acceptable
64  */
65  bool checkOutputParameters() override;
66 
67  /** Indicate to Statistic Output that simulation started.
68  * Statistic output may perform any startup code here as necessary.
69  */
70  void startOfSimulation() override;
71 
72  /** Indicate to Statistic Output that simulation ended.
73  * Statistic output may perform any shutdown code here as necessary.
74  */
75  void endOfSimulation() override;
76 
77  /** Implementation function for the start of output.
78  * This will be called by the Statistic Processing Engine to indicate that
79  * a Statistic is about to send data to the Statistic Output for processing.
80  * @param statistic - Pointer to the statistic object than the output can
81  * retrieve data from.
82  */
83  void implStartOutputEntries(StatisticBase* statistic) override;
84 
85  /** Implementation function for the end of output.
86  * This will be called by the Statistic Processing Engine to indicate that
87  * a Statistic is finished sending data to the Statistic Output for processing.
88  * The Statistic Output can perform any output related functions here.
89  */
90  void implStopOutputEntries() override;
91 
92  /** Implementation functions for output.
93  * These will be called by the statistic to provide Statistic defined
94  * data to be output.
95  * @param fieldHandle - The handle to the registered statistic field.
96  * @param data - The data related to the registered field to be output.
97  */
98  void outputField(fieldHandle_t fieldHandle, int32_t data) override;
99  void outputField(fieldHandle_t fieldHandle, uint32_t data) override;
100  void outputField(fieldHandle_t fieldHandle, int64_t data) override;
101  void outputField(fieldHandle_t fieldHandle, uint64_t data) override;
102  void outputField(fieldHandle_t fieldHandle, float data) override;
103  void outputField(fieldHandle_t fieldHandle, double data) override;
104 
105  /** True if this StatOutput can handle StatisticGroups */
106  virtual bool acceptsGroups() const override { return true; }
107 
108 protected:
109  StatisticOutputCSV() { ; } // For serialization
110 
111 private:
112  bool openFile();
113  void closeFile();
114  int print(const char* fmt, ...) __attribute__((format(printf, 2, 3)));
115 
116 private:
117 #ifdef HAVE_LIBZ
118  gzFile m_gzFile;
119 #endif
120  FILE* m_hFile;
121  std::vector<std::string> m_OutputBufferArray;
122  std::string m_Separator;
123  std::string m_FilePath;
124  std::string m_currentComponentName;
125  std::string m_currentStatisticName;
126  std::string m_currentStatisticSubId;
127  std::string m_currentStatisticType;
128  bool m_outputTopHeader;
129  bool m_outputSimTime;
130  bool m_outputRank;
131  bool m_useCompression;
132 };
133 
134 } // namespace SST::Statistics
135 
136 #endif // SST_CORE_STATAPI_STATOUTPUTCSV_H
void implStartOutputEntries(StatisticBase *statistic) override
Implementation function for the start of output.
Definition: statoutputcsv.cc:136
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:42
Forms the base class for statistics output generation within the SST core.
Definition: statoutput.h:52
Forms the base class for statistics gathering within SST.
Definition: statbase.h:49
void endOfSimulation() override
Indicate to Statistic Output that simulation ended.
Definition: statoutputcsv.cc:129
ImplementSerializable(SST::Statistics::StatisticOutputCSV) protected void startOfSimulation() override
Perform a check of provided parameters.
Definition: statoutputcsv.cc:60
The class for statistics output to a comma separated file.
Definition: statoutputcsv.h:33
virtual bool checkOutputParameters()=0
Have the Statistic Output check its parameters.
void implStopOutputEntries() override
Implementation function for the end of output.
Definition: statoutputcsv.cc:152
virtual bool acceptsGroups() const override
True if this StatOutput can handle StatisticGroups.
Definition: statoutputcsv.h:106
Definition: statoutput.h:170
Parameter store.
Definition: params.h:63
Definition: elementinfo.h:44
void outputField(fieldHandle_t fieldHandle, int32_t data) override
Implementation functions for output.
Definition: statoutputcsv.cc:192