SST  13.0.0
StructuralSimulationToolkit
statoutputcsv.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_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 namespace SST {
23 namespace Statistics {
24 
25 /**
26  \class StatisticOutputCSV
27 
28  The class for statistics output to a comma separated file.
29 */
31 {
32 public:
36  "sst",
37  "statoutputcsv",
38  SST_ELI_ELEMENT_VERSION(1,0,0),
39  "Output directly to console screen"
40  )
41 
42  /** Construct a StatOutputCSV
43  * @param outputParameters - Parameters used for this Statistic Output
44  */
45  StatisticOutputCSV(Params& outputParameters);
46 
47 protected:
48  /** Perform a check of provided parameters
49  * @return True if all required parameters and options are acceptable
50  */
51  bool checkOutputParameters() override;
52 
53  /** Print out usage for this Statistic Output */
54  void printUsage() override;
55 
56  /** Indicate to Statistic Output that simulation started.
57  * Statistic output may perform any startup code here as necessary.
58  */
59  void startOfSimulation() override;
60 
61  /** Indicate to Statistic Output that simulation ended.
62  * Statistic output may perform any shutdown code here as necessary.
63  */
64  void endOfSimulation() override;
65 
66  /** Implementation function for the start of output.
67  * This will be called by the Statistic Processing Engine to indicate that
68  * a Statistic is about to send data to the Statistic Output for processing.
69  * @param statistic - Pointer to the statistic object than the output can
70  * retrieve data from.
71  */
72  void implStartOutputEntries(StatisticBase* statistic) override;
73 
74  /** Implementation function for the end of output.
75  * This will be called by the Statistic Processing Engine to indicate that
76  * a Statistic is finished sending data to the Statistic Output for processing.
77  * The Statistic Output can perform any output related functions here.
78  */
79  void implStopOutputEntries() override;
80 
81  /** Implementation functions for output.
82  * These will be called by the statistic to provide Statistic defined
83  * data to be output.
84  * @param fieldHandle - The handle to the registered statistic field.
85  * @param data - The data related to the registered field to be output.
86  */
87  void outputField(fieldHandle_t fieldHandle, int32_t data) override;
88  void outputField(fieldHandle_t fieldHandle, uint32_t data) override;
89  void outputField(fieldHandle_t fieldHandle, int64_t data) override;
90  void outputField(fieldHandle_t fieldHandle, uint64_t data) override;
91  void outputField(fieldHandle_t fieldHandle, float data) override;
92  void outputField(fieldHandle_t fieldHandle, double data) override;
93 
94  /** True if this StatOutput can handle StatisticGroups */
95  virtual bool acceptsGroups() const override { return true; }
96 
97 protected:
98  StatisticOutputCSV() { ; } // For serialization
99 
100 private:
101  bool openFile();
102  void closeFile();
103  int print(const char* fmt, ...);
104 
105 private:
106 #ifdef HAVE_LIBZ
107  gzFile m_gzFile;
108 #endif
109  FILE* m_hFile;
110  std::vector<std::string> m_OutputBufferArray;
111  std::string m_Separator;
112  std::string m_FilePath;
113  std::string m_currentComponentName;
114  std::string m_currentStatisticName;
115  std::string m_currentStatisticSubId;
116  std::string m_currentStatisticType;
117  bool m_outputTopHeader;
118  bool m_outputSimTime;
119  bool m_outputRank;
120  bool m_useCompression;
121 };
122 
123 } // namespace Statistics
124 } // namespace SST
125 
126 #endif // SST_CORE_STATAPI_STATOUTPUTCSV_H
void implStartOutputEntries(StatisticBase *statistic) override
Implementation function for the start of output.
Definition: statoutputcsv.cc:176
Forms the base class for statistics output generation within the SST core.
Definition: statoutput.h:49
Forms the base class for statistics gathering within SST.
Definition: statbase.h:63
void endOfSimulation() override
Indicate to Statistic Output that simulation ended.
Definition: statoutputcsv.cc:169
Definition: action.cc:18
void startOfSimulation() override
Indicate to Statistic Output that simulation started.
Definition: statoutputcsv.cc:85
The class for statistics output to a comma separated file.
Definition: statoutputcsv.h:30
void implStopOutputEntries() override
Implementation function for the end of output.
Definition: statoutputcsv.cc:192
virtual bool acceptsGroups() const override
True if this StatOutput can handle StatisticGroups.
Definition: statoutputcsv.h:95
Definition: statoutput.h:142
bool checkOutputParameters() override
Perform a check of provided parameters.
Definition: statoutputcsv.cc:32
void printUsage() override
Print out usage for this Statistic Output.
Definition: statoutputcsv.cc:70
Parameter store.
Definition: params.h:55
void outputField(fieldHandle_t fieldHandle, int32_t data) override
Implementation functions for output.
Definition: statoutputcsv.cc:230
SST_ELI_REGISTER_DERIVED(StatisticOutput, StatisticOutputCSV, "sst", "statoutputcsv", SST_ELI_ELEMENT_VERSION(1, 0, 0), "Output directly to console screen") StatisticOutputCSV(Params &outputParameters)
Construct a StatOutputCSV.