kspaceFirstOrder3D-OMP  1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
BaseOutputStream.h
Go to the documentation of this file.
1 /**
2  * @file BaseOutputStream.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 of the class saving RealMatrix data into the output HDF5 file.
10  *
11  * @version kspaceFirstOrder3D 2.16
12  *
13  * @date 11 July 2012, 10:30 (created) \n
14  * 04 September 2017, 11:10 (revised)
15  *
16  * @copyright Copyright (C) 2017 Jiri Jaros and Bradley Treeby.
17  *
18  * This file is part of the C++ extension of the [k-Wave Toolbox](http://www.k-wave.org).
19  *
20  * This file is part of the k-Wave. k-Wave is free software: you can redistribute it and/or modify it under the terms
21  * of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the
22  * License, or (at your option) any later version.
23  *
24  * k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
25  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
26  * more details.
27  *
28  * You should have received a copy of the GNU Lesser General Public License along with k-Wave.
29  * If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
30  */
31 
32 #ifndef BASE_OUTPUT_STREAM_H
33 #define BASE_OUTPUT_STREAM_H
34 
35 
38 #include <Hdf5/Hdf5File.h>
39 
40 /**
41  * @class BaseOutputStream
42  * @brief Abstract base class for output data streams (sampled data).
43  *
44  * Data are sampled based on the the sensor mask and the reduction operator. The sampled data is stored in the output
45  * HDF5 file.
46  */
48 {
49  public:
50 
51  /**
52  * @enum ReduceOperator
53  * @brief How to aggregate data.
54  */
55  enum class ReduceOperator
56  {
57  /// Store actual data (time series).
58  kNone,
59  /// Calculate root mean square.
60  kRms,
61  /// Store maximum.
62  kMax,
63  /// Store minimum.
64  kMin
65  };
66 
67  /// Default constructor not allowed.
68  BaseOutputStream() = delete;
69 
70  /**
71  * @brief Constructor
72  *
73  * There is no sensor mask by default to support both sensor mask and whole domain sampling.
74  * The constructor links the HDF5 dataset, source (sampled matrix) and the reduction operator together. The
75  * constructor DOES NOT allocate memory because the size of the sensor mask is not known at the time the instance
76  * of the class is being created.
77  *
78  * @param [in] file - Handle to the output HDF5 file.
79  * @param [in] rootObjectName - The root object that stores the sample data (dataset or group).
80  * @param [in] sourceMatrix - The source matrix (only real matrices are supported).
81  * @param [in] reduceOp - Reduction operator.
82  * @param [in] bufferToReuse - An external buffer can be used to line up the grid points.
83  */
85  MatrixName& rootObjectName,
86  const RealMatrix& sourceMatrix,
87  const ReduceOperator reduceOp,
88  float* bufferToReuse = nullptr);
89 
90  /// Copy constructor not allowed.
92  /**
93  * @brief Destructor.
94  *
95  * If the file is still opened, it applies the post processing and flush the data.
96  * Then, the object memory is freed and the object destroyed.
97  */
98  virtual ~BaseOutputStream() {};
99 
100  /// Operator = not allowed (we don't want any data movements).
102 
103  /// Create a HDF5 stream and allocate data for it.
104  virtual void create() = 0;
105 
106  /// Reopen the output stream after restart.
107  virtual void reopen() = 0;
108 
109  /// Sample data into buffer, apply reduction or flush to disk - based on a sensor mask.
110  virtual void sample() = 0;
111 
112  /// Apply post-processing on the buffer and flush it to the file.
113  virtual void postProcess();
114 
115  /// Checkpoint the stream.
116  virtual void checkpoint() = 0;
117 
118  /// Close stream (apply post-processing if necessary, flush data and close).
119  virtual void close() = 0;
120 
121  protected:
122 
123  /**
124  * @brief Allocate memory using proper memory alignment.
125  * @throw std::bad_alloc - If there's not enough memory.
126  * @warning This can routine is not used in the base class (should be used in derived ones).
127  */
128  virtual void allocateMemory();
129  /**
130  * @brief Free memory.
131  * @warning This can routine is not used in the base class (should be used in derived ones).
132  */
133  virtual void freeMemory();
134 
135  /// Handle to HDF5 output file.
137  /// HDF5 group/dataset in the output file where to store data in.
138  std::string mRootObjectName;
139  /// Source matrix to be sampled.
141  /// Reduction operator.
143 
144  /// if true, the container reuses another matrix as scratch place, e.g. Temp_1_RS3D, Temp_2_RS3D, Temp_3_RS3D.
146  /// Buffer size.
147  size_t mBufferSize;
148  /// Temporary buffer for store - only if Buffer Reuse = false!
149  float* mStoreBuffer;
150 
151  /// chunk size of 4MB in number of float elements.
152  static constexpr size_t kChunkSize4MB = 1048576;
153 };// end of BaseOutputStream
154 //----------------------------------------------------------------------------------------------------------------------
155 
156 #endif /* BASE_OUTPUT_STREAM_H */
Calculate root mean square.
The class for real matrices.
Definition: RealMatrix.h:47
virtual void freeMemory()
Free memory.
virtual ~BaseOutputStream()
Destructor.
std::string mRootObjectName
HDF5 group/dataset in the output file where to store data in.
The header file containing the HDF5 related classes.
const ReduceOperator mReduceOp
Reduction operator.
virtual void close()=0
Close stream (apply post-processing if necessary, flush data and close).
The header file containing the class for real matrices.
virtual void allocateMemory()
Allocate memory using proper memory alignment.
virtual void sample()=0
Sample data into buffer, apply reduction or flush to disk - based on a sensor mask.
virtual void postProcess()
Apply post-processing on the buffer and flush it to the file.
Store actual data (time series).
Class wrapping the HDF5 routines.
Definition: Hdf5File.h:490
size_t mBufferSize
Buffer size.
The header file containing the class for 64b integer matrices.
const std::string MatrixName
Datatype for matrix names.
Definition: MatrixNames.h:39
Hdf5File & mFile
Handle to HDF5 output file.
const RealMatrix & mSourceMatrix
Source matrix to be sampled.
virtual void reopen()=0
Reopen the output stream after restart.
float * mStoreBuffer
Temporary buffer for store - only if Buffer Reuse = false!
ReduceOperator
How to aggregate data.
BaseOutputStream & operator=(const BaseOutputStream &src)
Operator = not allowed (we don&#39;t want any data movements).
BaseOutputStream()=delete
Default constructor not allowed.
static constexpr size_t kChunkSize4MB
chunk size of 4MB in number of float elements.
Abstract base class for output data streams (sampled data).
virtual void create()=0
Create a HDF5 stream and allocate data for it.
virtual void checkpoint()=0
Checkpoint the stream.
bool mBufferReuse
if true, the container reuses another matrix as scratch place, e.g. Temp_1_RS3D, Temp_2_RS3D, Temp_3_RS3D.