kspaceFirstOrder3D-OMP  1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
Hdf5FileHeader.h
Go to the documentation of this file.
1 /**
2  * @file Hdf5FileHeader.h
3  *
4  * @author Jiri Jaros \n
5  * Faculty of Information Technology \n
6  * Brno University of Technology \n
7  * jarosjir@fit.vutbr.cz
8  *
9  * @brief The header file containing the class processing file headers.
10  * Detail about the file header are described below.
11  *
12  * @version kspaceFirstOrder3D 2.16
13  *
14  * @date 24 August 2017, 09:51 (created) \n
15  * 29 August 2017, 10:00 (revised)
16  *
17  * @section Hdf5FileHeader HDF5 File Header Structure
18  *
19  *The header includes following information
20  *
21  * \verbatim
22 +----------------------------------------------------------------------------------------------------------------------+
23 | Input File / Checkpoint File Header |
24 +----------------------------------------------------------------------------------------------------------------------+
25 | created_by Short description of the tool that created this file |
26 | creation_date Date when the file was created |
27 | file_description Short description of the content of the file (e.g. simulation name) |
28 | file_type Type of the file (input) |
29 | major_version Major version of the file definition (1) |
30 | minor_version Minor version of the file definition (1) |
31 +----------------------------------------------------------------------------------------------------------------------+
32  \endverbatim
33  *
34  * \verbatim
35 +----------------------------------------------------------------------------------------------------------------------+
36 | Output File Header |
37 +----------------------------------------------------------------------------------------------------------------------+
38 | created_by Short description of the tool that created this file |
39 | creation_date Date when the file was created |
40 | file_description Short description of the content of the file (e.g. simulation name) |
41 | file_type Type of the file (output) |
42 | major_version Major version of the file definition (1) |
43 | minor_version Minor version of the file definition (1) |
44 +----------------------------------------------------------------------------------------------------------------------+
45 | host_names List of hosts (computer names) the simulation was executed on |
46 | number_of_cpu_cores Number of CPU cores used for the simulation |
47 | data_loading_phase_execution_time Time taken to load data from the file |
48 | pre-processing_phase_execution_time Time taken to pre-process data |
49 | simulation_phase_execution_time Time taken to run the simulation |
50 | post-processing_phase_execution_time Time taken to complete the post-processing phase |
51 | total_execution_time Total execution time |
52 | peak_core_memory_in_use Peak memory required per core during the simulation |
53 | total_memory_in_use Total Peak memory in use |
54 +----------------------------------------------------------------------------------------------------------------------+
55  \endverbatim
56  *
57  *
58  * @copyright Copyright (C) 2017 Jiri Jaros and Bradley Treeby.
59  *
60  * This file is part of the C++ extension of the [k-Wave Toolbox](http://www.k-wave.org).
61  *
62  * This file is part of the k-Wave. k-Wave is free software: you can redistribute it and/or modify it under the terms
63  * of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the
64  * License, or (at your option) any later version.
65  *
66  * k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
67  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
68  * more details.
69  *
70  * You should have received a copy of the GNU Lesser General Public License along with k-Wave.
71  * If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
72  */
73 
74 #ifndef HDF5_FILE_HEADER_H
75 #define HDF5_FILE_HEADER_H
76 
77 #include <map>
78 
79 #include <Hdf5/Hdf5File.h>
80 #include <Utils/DimensionSizes.h>
81 #include <Utils/MatrixNames.h>
82 
83 /**
84  * @class Hdf5FileHeader
85  * @brief Class for HDF5 file header.
86  * @details This class manages all information that can be stored in the input output or checkpoint
87  * file header.
88  */
90 {
91  public:
92 
93  /**
94  * @enum FileHeaderItems
95  * @brief List of all header items.
96  * @details List of all header items.
97  * @todo In the future, we should add number of GPUs, peak GPU memory.
98  */
99  enum class FileHeaderItems
100  {
101  /// Code that created the file.
102  kCreatedBy = 0,
103  /// When the file was created.
104  kCreationDate = 1,
105  /// Description of the file (e.g. simulation).
106  kFileDescription = 2,
107  /// Major file version.
108  kMajorVersion = 3,
109  /// Minor file version.
110  kMinorVersion = 4,
111  /// File type.
112  kFileType = 5,
113  /// Machines the code were executed on.
114  kHostName = 6,
115  /// Total amount of memory consumed by the code.
117  /// Peak memory consumption (by process).
119  /// Total execution time.
121  /// Time to load data in.
122  kDataLoadTime = 10,
123  /// Time to preprocess data.
124  kPreProcessingTime = 11,
125  /// Simulation time.
126  kSimulationTime = 12,
127  /// Time to postprocess data.
128  kPostProcessingTime = 13,
129  /// Number of cores the simulation was executed.
130  kNumberOfCores = 14
131  };
132 
133  /**
134  * @enum FileType
135  * @brief HDF5 file type.
136  * @details HDF5 file type.
137  */
138  enum class FileType
139  {
140  /// Input file.
141  kInput = 0,
142  /// Output file.
143  kOutput = 1,
144  /// Checkpoint file.
145  kCheckpoint = 2,
146  /// Unknown file.
147  kUnknown = 3
148  };
149 
150  /**
151  * @enum FileVersion
152  * @brief HDF5 file version.
153  * @details HDF5 file version.
154  */
155  enum class FileVersion
156  {
157  /// Version 1.0.
158  kVersion10 = 0,
159  /// Version 1.1.
160  kVersion11 = 1,
161  /// Version unknown.
162  kVersionUnknown = 2
163  };
164 
165 
166  /// Constructor.
167  Hdf5FileHeader();
168  /**
169  * @brief Copy constructor.
170  * @param [in] src - Source object.
171  */
172  Hdf5FileHeader(const Hdf5FileHeader& src);
173  /// Destructor.
174  ~Hdf5FileHeader();
175 
176  /**
177  * @brief Read header from the input file.
178  *
179  * @param [in, out] inputFile - Input file handle.
180  * @throw ios:failure - If error happens.
181  */
182  void readHeaderFromInputFile(Hdf5File& inputFile);
183  /**
184  * @brief Read header from output file (necessary for checkpoint-restart).
185  *
186  * Read only execution times (the others are read from the input file, or calculated based on the very last
187  * leg of the simulation). This function is called only if checkpoint-restart is enabled.
188  *
189  * @param [in, out] outputFile - Output file handle.
190  * @throw ios:failure - If error happens.
191  */
192  void readHeaderFromOutputFile(Hdf5File& outputFile);
193  /**
194  * @brief Read the file header form the checkpoint file.
195  *
196  * We need the header to verify the file version and type.
197  * @param [in, out] checkpointFile - Checkpoint file handle.
198  * @throw ios:failure - If error happens.
199  */
200  void readHeaderFromCheckpointFile(Hdf5File& checkpointFile);
201 
202  /**
203  * @brief Write header into the output file.
204  *
205  * @param [in,out] outputFile - Output file handle.
206  * @throw ios:failure - If error happens.
207  */
208  void writeHeaderToOutputFile(Hdf5File& outputFile);
209  /**
210  * @brief Write header to the output file (only a subset of all possible fields are written).
211  *
212  * @param [in, out] checkpointFile - Checkpoint file handle.
213  * @throw ios:failure - If error happens.
214  */
215  void writeHeaderToCheckpointFile(Hdf5File& checkpointFile);
216 
217  /**
218  * @brief Set code name.
219  * @param [in] codeName - Code version.
220  */
221  void setCodeName(const std::string& codeName)
222  {
224  };
225 
226  /// Set creation time.
227  void setActualCreationTime();
228 
229  /**
230  * @brief Get string representing of current Major version of the file.
231  * @return Current major file version.
232  */
233  static std::string getFileMajorVersion()
234  {
235  return kMajorFileVersionsNames[0];
236  };
237  /**
238  * @brief Get string representing of current Minor version of the file.
239  * @return Current minor file version.
240  */
241  static std::string getFileMinorVersion()
242  {
243  return kMinorFileVersionsNames[1];
244  };
245 
246  /// Set major file version.
248  {
250  };
251  /// Set minor file version.
253  {
255  };
256 
257  /**
258  * @brief Get file version as an enum.
259  * @return File version as an enum.
260  */
262 
263  /**
264  * @brief Check major file version.
265  * @return true - If the file version is supported.
266  */
268  {
270  };
271  /**
272  * @brief Check minor file version.
273  * @return true - If the file version is supported.
274  */
276  {
278  };
279 
280  /**
281  * @brief Get File type.
282  * @return File type.
283  */
285  /**
286  * @brief Set File type.
287  * @param [in] fileType - File type.
288  */
289  void setFileType(const Hdf5FileHeader::FileType fileType);
290 
291  /// Set host name.
292  void setHostName();
293  /**
294  * @brief Set memory consumption.
295  * @param [in] totalMemory - Total memory consumption.
296  */
297  void setMemoryConsumption(const size_t totalMemory);
298 
299  /**
300  * @brief Set execution times in file header.
301  *
302  * @param [in] totalTime - Total time.
303  * @param [in] loadTime - Time to load data.
304  * @param [in] preProcessingTime - Preprocessing time.
305  * @param [in] simulationTime - Simulation time.
306  * @param [in] postprocessingTime - Post processing time.
307  */
308  void setExecutionTimes(const double totalTime,
309  const double loadTime,
310  const double preProcessingTime,
311  const double simulationTime,
312  const double postprocessingTime);
313  /**
314  * @brief Get execution times stored in the output file header.
315  *
316  * @param [out] totalTime - Total time.
317  * @param [out] loadTime - Time to load data.
318  * @param [out] preProcessingTime - Preprocessing time.
319  * @param [out] simulationTime - Simulation time.
320  * @param [out] postprocessingTime - Post processing time.
321  */
322  void getExecutionTimes(double& totalTime,
323  double& loadTime,
324  double& preProcessingTime,
325  double& simulationTime,
326  double& postprocessingTime);
327  /// Set number of cores.
328  void setNumberOfCores();
329 
330  private:
331 
332  /// map for the header values.
333  std::map<FileHeaderItems, std::string> mHeaderValues;
334  /// map for the header names.
335  static std::map<FileHeaderItems, std::string> sHeaderNames;
336 
337  ///String representation of different file types.
338  static const std::string kFileTypesNames[];
339  /// String representations of Major file versions.
340  static const std::string kMajorFileVersionsNames[];
341  /// String representations of Major file versions.
342  static const std::string kMinorFileVersionsNames[];
343 
344 };// Hdf5FileHeader
345 //----------------------------------------------------------------------------------------------------------------------
346 
347 
348 #endif /* HDF5_FILE_HEADER_H */
349 
Description of the file (e.g. simulation).
void setMemoryConsumption(const size_t totalMemory)
Set memory consumption.
The header file containing the HDF5 related classes.
void setMinorFileVersion()
Set minor file version.
Total amount of memory consumed by the code.
void setHostName()
Set host name.
static const std::string kFileTypesNames[]
String representation of different file types.
FileType
HDF5 file type.
void writeHeaderToOutputFile(Hdf5File &outputFile)
Write header into the output file.
~Hdf5FileHeader()
Destructor.
void setMajorFileVersion()
Set major file version.
static std::string getFileMajorVersion()
Get string representing of current Major version of the file.
static std::string getFileMinorVersion()
Get string representing of current Minor version of the file.
void setCodeName(const std::string &codeName)
Set code name.
Hdf5FileHeader()
Constructor.
void getExecutionTimes(double &totalTime, double &loadTime, double &preProcessingTime, double &simulationTime, double &postprocessingTime)
Get execution times stored in the output file header.
Machines the code were executed on.
std::map< FileHeaderItems, std::string > mHeaderValues
map for the header values.
void readHeaderFromCheckpointFile(Hdf5File &checkpointFile)
Read the file header form the checkpoint file.
bool checkMinorFileVersion()
Check minor file version.
FileVersion getFileVersion()
Get file version as an enum.
FileVersion
HDF5 file version.
Peak memory consumption (by process).
static std::map< FileHeaderItems, std::string > sHeaderNames
map for the header names.
static const std::string kMajorFileVersionsNames[]
String representations of Major file versions.
Class wrapping the HDF5 routines.
Definition: Hdf5File.h:490
void setActualCreationTime()
Set creation time.
void readHeaderFromInputFile(Hdf5File &inputFile)
Read header from the input file.
Class for HDF5 file header.
The header file storing names of all variables.
void setExecutionTimes(const double totalTime, const double loadTime, const double preProcessingTime, const double simulationTime, const double postprocessingTime)
Set execution times in file header.
void readHeaderFromOutputFile(Hdf5File &outputFile)
Read header from output file (necessary for checkpoint-restart).
void writeHeaderToCheckpointFile(Hdf5File &checkpointFile)
Write header to the output file (only a subset of all possible fields are written).
The header file containing the structure with 3D dimension sizes.
Hdf5FileHeader::FileType getFileType()
Get File type.
static const std::string kMinorFileVersionsNames[]
String representations of Major file versions.
bool checkMajorFileVersion()
Check major file version.
void setFileType(const Hdf5FileHeader::FileType fileType)
Set File type.
Number of cores the simulation was executed.
FileHeaderItems
List of all header items.
void setNumberOfCores()
Set number of cores.