SST  6.1.0
StructuralSimulationToolkit
statoutputhdf5.h
1 // Copyright 2009-2016 Sandia Corporation. Under the terms
2 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2016, Sandia Corporation
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 _H_SST_CORE_STATISTICS_OUTPUTHDF5
13 #define _H_SST_CORE_STATISTICS_OUTPUTHDF5
14 
15 #include "sst/core/sst_types.h"
16 
17 #include <sst/core/statapi/statoutput.h>
18 
19 #include "H5Cpp.h"
20 #include <map>
21 #include <string>
22 
23 namespace SST {
24 namespace Statistics {
25 
26 /**
27  \class StatisticOutputHDF5
28 
29  The class for statistics output to a comma separated file.
30 */
32 {
33 public:
34  /** Construct a StatOutputHDF5
35  * @param outputParameters - Parameters used for this Statistic Output
36  */
37  StatisticOutputHDF5(Params& outputParameters);
38 
39 protected:
40  /** Perform a check of provided parameters
41  * @return True if all required parameters and options are acceptable
42  */
43  bool checkOutputParameters();
44 
45  /** Print out usage for this Statistic Output */
46  void printUsage();
47 
48  void implStartRegisterFields(StatisticBase *stat);
49  void implRegisteredField(fieldHandle_t fieldHandle);
50  void implStopRegisterFields();
51 
52  /** Indicate to Statistic Output that simulation started.
53  * Statistic output may perform any startup code here as necessary.
54  */
55  void startOfSimulation();
56 
57  /** Indicate to Statistic Output that simulation ended.
58  * Statistic output may perform any shutdown code here as necessary.
59  */
60  void endOfSimulation();
61 
62  /** Implementation function for the start of output.
63  * This will be called by the Statistic Processing Engine to indicate that
64  * a Statistic is about to send data to the Statistic Output for processing.
65  * @param statistic - Pointer to the statistic object than the output can
66  * retrieve data from.
67  */
68  void implStartOutputEntries(StatisticBase* statistic);
69 
70  /** Implementation function for the end of output.
71  * This will be called by the Statistic Processing Engine to indicate that
72  * a Statistic is finished sendind data to the Statistic Output for processing.
73  * The Statisic Output can perform any output related functions here.
74  */
75  void implStopOutputEntries();
76 
77  /** Implementation functions for output.
78  * These will be called by the statistic to provide Statistic defined
79  * data to be output.
80  * @param fieldHandle - The handle to the registered statistic field.
81  * @param data - The data related to the registered field to be output.
82  */
83  void implOutputField(fieldHandle_t fieldHandle, int32_t data);
84  void implOutputField(fieldHandle_t fieldHandle, uint32_t data);
85  void implOutputField(fieldHandle_t fieldHandle, int64_t data);
86  void implOutputField(fieldHandle_t fieldHandle, uint64_t data);
87  void implOutputField(fieldHandle_t fieldHandle, float data);
88  void implOutputField(fieldHandle_t fieldHandle, double data);
89 
90 protected:
91  StatisticOutputHDF5() {;} // For serialization
92 
93 private:
94 
95  typedef union {
96  int32_t i32;
97  uint32_t u32;
98  int64_t i64;
99  uint64_t u64;
100  float f;
101  double d;
102  } StatData_u;
103 
104  class StatisticInfo {
105  StatisticBase *statistic;
106  std::vector<fieldHandle_t> indexMap;
107  std::vector<StatData_u> currentData;
108  std::vector<fieldType_t> typeList;
109  std::vector<std::string> fieldNames;
110 
111  H5::DataSet *dataset;
112  H5::CompType *memType;
113  H5::H5File *file;
114 
115  hsize_t nEntries;
116 
117  public:
118  StatisticInfo(StatisticBase *stat, H5::H5File *file) : statistic(stat), file(file), nEntries(0) { }
119  ~StatisticInfo() {
120  if ( dataset ) delete dataset;
121  if ( memType ) delete memType;
122  }
123  void registerSimTime();
125  void finalizeRegistration();
126 
127  void startNewEntry();
128  StatData_u& getFieldLoc(fieldHandle_t fieldHandle);
129  void finishEntry();
130  };
131 
132 
133  H5::H5File* m_hFile;
134  StatisticInfo* m_currentStatistic;
135  std::map<StatisticBase*, StatisticInfo*> m_statistics;
136 
137 
138  StatisticInfo* initStatistic(StatisticBase* statistic);
139  StatisticInfo* getStatisticInfo(StatisticBase* statistic);
140 };
141 
142 } //namespace Statistics
143 } //namespace SST
144 
145 #endif
void implStopOutputEntries()
Implementation function for the end of output.
Definition: statoutputhdf5.cc:110
void endOfSimulation()
Indicate to Statistic Output that simulation ended.
Definition: statoutputhdf5.cc:96
The class for representing Statistic Output Fields
Definition: statfieldinfo.h:32
bool checkOutputParameters()
Perform a check of provided parameters.
Definition: statoutputhdf5.cc:30
Forms the base class for statistics output generation within the SST core.
Definition: statoutput.h:47
fieldHandle_t registerField(const char *fieldName)
Register a field to be output (templated function)
Definition: statoutput.h:84
Forms the base class for statistics gathering within SST.
Definition: statbase.h:36
Definition: action.cc:17
void printUsage()
Print out usage for this Statistic Output.
Definition: statoutputhdf5.cc:58
void implOutputField(fieldHandle_t fieldHandle, int32_t data)
Implementation functions for output.
Definition: statoutputhdf5.cc:117
The class for statistics output to a comma separated file.
Definition: statoutputhdf5.h:31
Parameter store.
Definition: params.h:44
void startOfSimulation()
Indicate to Statistic Output that simulation started.
Definition: statoutputhdf5.cc:91
void implStartOutputEntries(StatisticBase *statistic)
Implementation function for the start of output.
Definition: statoutputhdf5.cc:104