SST  13.0.0
StructuralSimulationToolkit
statoutputtxt.h
1 // Copyright 2009-2023 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-2023, 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_STATOUTPUTTXT_H
13 #define SST_CORE_STATAPI_STATOUTPUTTXT_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 namespace SST {
23 namespace Statistics {
24 
25 
27 {
28 public:
29  /** Construct a StatOutputTxt
30  * @param outputParameters - Parameters used for this Statistic Output
31  */
32  StatisticOutputTextBase(Params& outputParameters);
33 
34 protected:
35  /** Perform a check of provided parameters
36  * @return True if all required parameters and options are acceptable
37  */
38  bool checkOutputParameters() override;
39 
40  /** Print out usage for this Statistic Output */
41  void printUsage() override;
42 
43  /** Indicate to Statistic Output that simulation started.
44  * Statistic output may perform any startup code here as necessary.
45  */
46  void startOfSimulation() override;
47 
48  /** Indicate to Statistic Output that simulation ended.
49  * Statistic output may perform any shutdown code here as necessary.
50  */
51  void endOfSimulation() override;
52 
53  /** Implementation function for the start of output.
54  * This will be called by the Statistic Processing Engine to indicate that
55  * a Statistic is about to send data to the Statistic Output for processing.
56  * @param statistic - Pointer to the statistic object than the output can
57  * retrieve data from.
58  */
59  void implStartOutputEntries(StatisticBase* statistic) override;
60 
61  /** Implementation function for the end of output.
62  * This will be called by the Statistic Processing Engine to indicate that
63  * a Statistic is finished sending data to the Statistic Output for processing.
64  * The Statistic Output can perform any output related functions here.
65  */
66  void implStopOutputEntries() override;
67 
68  /** Implementation functions for output.
69  * These will be called by the statistic to provide Statistic defined
70  * data to be output.
71  * @param fieldHandle - The handle to the registered statistic field.
72  * @param data - The data related to the registered field to be output.
73  */
74  void outputField(fieldHandle_t fieldHandle, int32_t data) override;
75  void outputField(fieldHandle_t fieldHandle, uint32_t data) override;
76  void outputField(fieldHandle_t fieldHandle, int64_t data) override;
77  void outputField(fieldHandle_t fieldHandle, uint64_t data) override;
78  void outputField(fieldHandle_t fieldHandle, float data) override;
79  void outputField(fieldHandle_t fieldHandle, double data) override;
80 
81 protected:
83 
84  bool m_outputTopHeader;
85  bool m_outputInlineHeader;
86  bool m_outputSimTime;
87  bool m_outputRank;
88  bool m_useCompression;
89 
90 private:
91  bool openFile();
92  void closeFile();
93  int print(const char* fmt, ...);
94 
95 private:
96 #ifdef HAVE_LIBZ
97  gzFile m_gzFile;
98 #endif
99  FILE* m_hFile;
100  std::string m_outputBuffer;
101  std::string m_FilePath;
102 
103  /**
104  Returns whether or not this outputter outputs to a file
105  */
106  virtual bool outputsToFile() = 0;
107 
108  /**
109  Returns whether or not this outputter supports compression.
110  Only checked if the class also writes to a file
111  */
112  virtual bool supportsCompression() = 0;
113 
114  /**
115  Function that gets the end of the first line of help message
116  */
117  virtual std::string getUsageInfo() = 0;
118 
119  /**
120  Returns a prefix that will start each new output entry
121  */
122  virtual std::string getStartOutputPrefix() = 0;
123 
124  /**
125  These functions return the default value for the associated
126  flags. These are implemented by the child class so that each
127  final class can control how the defaults work.
128  */
129  virtual bool getOutputTopHeaderDefault() = 0;
130  virtual bool getOutputInlineHeaderDefault() = 0;
131  virtual bool getOutputSimTimeDefault() = 0;
132  virtual bool getOutputRankDefault() = 0;
133 
134  virtual std::string getDefaultFileName() { return ""; }
135 
136  /** True if this StatOutput can handle StatisticGroups */
137  virtual bool acceptsGroups() const override { return true; }
138 };
139 
140 
141 /**
142  \class StatisticOutputTxt
143 
144  The class for statistics output to a text file.
145 */
147 {
148 public:
152  "sst",
153  "statoutputtxt",
154  SST_ELI_ELEMENT_VERSION(1,0,0),
155  "Output to text file"
156  )
157 
158  /** Construct a StatOutputTxt
159  * @param outputParameters - Parameters used for this Statistic Output
160  */
161  StatisticOutputTxt(Params& outputParameters);
162 
163 protected:
164  StatisticOutputTxt() { ; } // For serialization
165 
166 private:
167  /**
168  Returns whether or not this outputter outputs to a file
169  */
170  bool outputsToFile() override { return true; }
171 
172  /**
173  Returns whether or not this outputter supports compression.
174  Only checked if the class also writes to a file
175  */
176  bool supportsCompression() override
177  {
178 #ifdef HAVE_LIBZ
179  return true;
180 #else
181  return false;
182 #endif
183  }
184 
185  /**
186  Function that gets the end of the first line of help message
187  */
188  std::string getUsageInfo() override { return "a text file"; }
189 
190  /**
191  Returns a prefix that will start each new output entry
192  */
193  std::string getStartOutputPrefix() override { return ""; }
194 
195  /**
196  These functions return the default value for the associated
197  flags. These are implemented by the child class so that each
198  final class can control how the defaults work.
199  */
200  bool getOutputTopHeaderDefault() override { return false; }
201  bool getOutputInlineHeaderDefault() override { return true; }
202  bool getOutputSimTimeDefault() override { return true; }
203  bool getOutputRankDefault() override { return true; }
204 
205  std::string getDefaultFileName() override { return "./StatisticOutput.txt"; }
206 };
207 
208 /**
209  \class StatisticOutputConsole
210 
211  The class for statistics output to the console.
212 */
214 {
215 public:
219  "sst",
220  "statoutputconsole",
221  SST_ELI_ELEMENT_VERSION(1,0,0),
222  "Output to console"
223  )
224 
225  /** Construct a StatOutputTxt
226  * @param outputParameters - Parameters used for this Statistic Output
227  */
228  StatisticOutputConsole(Params& outputParameters);
229 
230 protected:
231  StatisticOutputConsole() { ; } // For serialization
232 
233 private:
234  /**
235  Returns whether or not this outputter outputs to a file
236  */
237  bool outputsToFile() override { return false; }
238 
239  /**
240  Returns whether or not this outputter supports compression.
241  Only checked if the class also writes to a file
242  */
243  bool supportsCompression() override { return false; }
244 
245  /**
246  Function that gets the end of the first line of help message
247  */
248  std::string getUsageInfo() override { return "the console"; }
249 
250  /**
251  Returns a prefix that will start each new output entry
252  */
253  std::string getStartOutputPrefix() override { return " "; }
254 
255  /**
256  These functions return the default value for the associated
257  flags. These are implemented by the child class so that each
258  final class can control how the defaults work.
259  */
260  bool getOutputTopHeaderDefault() override { return false; }
261  bool getOutputInlineHeaderDefault() override { return true; }
262  bool getOutputSimTimeDefault() override { return false; }
263  bool getOutputRankDefault() override { return false; }
264 };
265 
266 } // namespace Statistics
267 } // namespace SST
268 
269 #endif // SST_CORE_STATAPI_STATOUTPUTTXT_H
void implStopOutputEntries() override
Implementation function for the end of output.
Definition: statoutputtxt.cc:190
Definition: statoutputtxt.h:26
void implStartOutputEntries(StatisticBase *statistic) override
Implementation function for the start of output.
Definition: statoutputtxt.cc:150
Forms the base class for statistics output generation within the SST core.
Definition: statoutput.h:49
SST_ELI_REGISTER_DERIVED(StatisticOutput, StatisticOutputConsole, "sst", "statoutputconsole", SST_ELI_ELEMENT_VERSION(1, 0, 0), "Output to console") StatisticOutputConsole(Params &outputParameters)
Construct a StatOutputTxt.
Forms the base class for statistics gathering within SST.
Definition: statbase.h:63
Definition: action.cc:18
The class for statistics output to a text file.
Definition: statoutputtxt.h:146
void startOfSimulation() override
Indicate to Statistic Output that simulation started.
Definition: statoutputtxt.cc:80
void printUsage() override
Print out usage for this Statistic Output.
Definition: statoutputtxt.cc:60
Definition: statoutput.h:142
bool checkOutputParameters() override
Perform a check of provided parameters.
Definition: statoutputtxt.cc:25
void outputField(fieldHandle_t fieldHandle, int32_t data) override
Implementation functions for output.
Definition: statoutputtxt.cc:198
Parameter store.
Definition: params.h:55
SST_ELI_REGISTER_DERIVED(StatisticOutput, StatisticOutputTxt, "sst", "statoutputtxt", SST_ELI_ELEMENT_VERSION(1, 0, 0), "Output to text file") StatisticOutputTxt(Params &outputParameters)
Construct a StatOutputTxt.
void endOfSimulation() override
Indicate to Statistic Output that simulation ended.
Definition: statoutputtxt.cc:142
The class for statistics output to the console.
Definition: statoutputtxt.h:213