SST 12.1.0
Structural Simulation Toolkit
statoutputtxt.h
1// Copyright 2009-2022 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-2022, 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
22namespace SST {
23namespace Statistics {
24
25
27{
28public:
29 /** Construct a StatOutputTxt
30 * @param outputParameters - Parameters used for this Statistic Output
31 */
32 StatisticOutputTextBase(Params& outputParameters);
33
34protected:
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
81protected:
83
84 bool m_outputTopHeader;
85 bool m_outputInlineHeader;
86 bool m_outputSimTime;
87 bool m_outputRank;
88 bool m_useCompression;
89
90private:
91 bool openFile();
92 void closeFile();
93 int print(const char* fmt, ...);
94
95private:
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
137
138/**
139 \class StatisticOutputTxt
140
141 The class for statistics output to a text file.
142*/
144{
145public:
149 "sst",
150 "statoutputtxt",
151 SST_ELI_ELEMENT_VERSION(1,0,0),
152 "Output to text file"
153 )
154
155 /** Construct a StatOutputTxt
156 * @param outputParameters - Parameters used for this Statistic Output
157 */
158 StatisticOutputTxt(Params& outputParameters);
159
160protected:
161 StatisticOutputTxt() { ; } // For serialization
162
163private:
164 /**
165 Returns whether or not this outputter outputs to a file
166 */
167 bool outputsToFile() override { return true; }
168
169 /**
170 Returns whether or not this outputter supports compression.
171 Only checked if the class also writes to a file
172 */
173 bool supportsCompression() override
174 {
175#ifdef HAVE_LIBZ
176 return true;
177#else
178 return false;
179#endif
180 }
181
182 /**
183 Function that gets the end of the first line of help message
184 */
185 std::string getUsageInfo() override { return "a text file"; }
186
187 /**
188 Returns a prefix that will start each new output entry
189 */
190 std::string getStartOutputPrefix() override { return ""; }
191
192 /**
193 These functions return the default value for the associated
194 flags. These are implemented by the child class so that each
195 final class can control how the defaults work.
196 */
197 bool getOutputTopHeaderDefault() override { return false; }
198 bool getOutputInlineHeaderDefault() override { return true; }
199 bool getOutputSimTimeDefault() override { return true; }
200 bool getOutputRankDefault() override { return true; }
201
202 std::string getDefaultFileName() override { return "./StatisticOutput.txt"; }
203};
204
205/**
206 \class StatisticOutputConsole
207
208 The class for statistics output to the console.
209*/
211{
212public:
216 "sst",
217 "statoutputconsole",
218 SST_ELI_ELEMENT_VERSION(1,0,0),
219 "Output to console"
220 )
221
222 /** Construct a StatOutputTxt
223 * @param outputParameters - Parameters used for this Statistic Output
224 */
225 StatisticOutputConsole(Params& outputParameters);
226
227protected:
228 StatisticOutputConsole() { ; } // For serialization
229
230private:
231 /**
232 Returns whether or not this outputter outputs to a file
233 */
234 bool outputsToFile() override { return false; }
235
236 /**
237 Returns whether or not this outputter supports compression.
238 Only checked if the class also writes to a file
239 */
240 bool supportsCompression() override { return false; }
241
242 /**
243 Function that gets the end of the first line of help message
244 */
245 std::string getUsageInfo() override { return "the console"; }
246
247 /**
248 Returns a prefix that will start each new output entry
249 */
250 std::string getStartOutputPrefix() override { return " "; }
251
252 /**
253 These functions return the default value for the associated
254 flags. These are implemented by the child class so that each
255 final class can control how the defaults work.
256 */
257 bool getOutputTopHeaderDefault() override { return false; }
258 bool getOutputInlineHeaderDefault() override { return true; }
259 bool getOutputSimTimeDefault() override { return false; }
260 bool getOutputRankDefault() override { return false; }
261};
262
263} // namespace Statistics
264} // namespace SST
265
266#endif // SST_CORE_STATAPI_STATOUTPUTTXT_H
Parameter store.
Definition: params.h:56
Forms the base class for statistics gathering within SST.
Definition: statbase.h:64
Definition: statoutput.h:143
The class for statistics output to the console.
Definition: statoutputtxt.h:211
SST_ELI_REGISTER_DERIVED(StatisticOutput, StatisticOutputConsole, "sst", "statoutputconsole", SST_ELI_ELEMENT_VERSION(1, 0, 0), "Output to console") StatisticOutputConsole(Params &outputParameters)
Construct a StatOutputTxt.
Definition: statoutputtxt.h:27
void printUsage() override
Print out usage for this Statistic Output.
Definition: statoutputtxt.cc:60
void endOfSimulation() override
Indicate to Statistic Output that simulation ended.
Definition: statoutputtxt.cc:142
void outputField(fieldHandle_t fieldHandle, int32_t data) override
Implementation functions for output.
Definition: statoutputtxt.cc:198
void implStartOutputEntries(StatisticBase *statistic) override
Implementation function for the start of output.
Definition: statoutputtxt.cc:150
void startOfSimulation() override
Indicate to Statistic Output that simulation started.
Definition: statoutputtxt.cc:80
void implStopOutputEntries() override
Implementation function for the end of output.
Definition: statoutputtxt.cc:190
bool checkOutputParameters() override
Perform a check of provided parameters.
Definition: statoutputtxt.cc:25
The class for statistics output to a text file.
Definition: statoutputtxt.h:144
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.
Forms the base class for statistics output generation within the SST core.
Definition: statoutput.h:50