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