kspaceFirstOrder3D-OMP  1.2
The C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
CuboidOutputStream.h
Go to the documentation of this file.
1 /**
2  * @file CuboidOutputStream.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 classes responsible for storing output quantities based on the
10  * cuboid sensor mask into the output HDF5 file.
11  *
12  * @version kspaceFirstOrder3D 2.16
13  *
14  * @date 26 August 2017, 16:55 (created) \n
15  * 04 September 2017, 11:10 (revised)
16  *
17  * @copyright Copyright (C) 2017 Jiri Jaros and Bradley Treeby.
18  *
19  * This file is part of the C++ extension of the [k-Wave Toolbox](http://www.k-wave.org).
20  *
21  * This file is part of the k-Wave. k-Wave is free software: you can redistribute it and/or modify it under the terms
22  * of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the
23  * License, or (at your option) any later version.
24  *
25  * k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
26  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
27  * more details.
28  *
29  * You should have received a copy of the GNU Lesser General Public License along with k-Wave.
30  * If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/).
31  */
32 
33 #ifndef CUBOID_OUTPUT_STREAM_H
34 #define CUBOID_OUTPUT_STREAM_H
35 
36 #include <vector>
37 
39 
40 
41 /**
42  * @class CuboidOutputStream
43  * @brief Output stream for quantities sampled by a cuboid corner sensor mask.
44  *
45  * Output stream for quantities sampled by a cuboid corner sensor mask. This class writes data into separated datasets
46  * (one per cuboid) under a given dataset in the HDF5 file (time-series as well as aggregations).
47  *
48  */
50 {
51  public:
52  /// Default constructor not allowed
53  CuboidOutputStream() = delete;
54 
55  /**
56  * @brief Constructor links the HDF5 dataset, SourceMatrix, and SensorMask together.
57  *
58  * @param [in] file - HDF5 file to write the output to.
59  * @param [in] groupName - The name of the HDF5 group. This group contains datasets for particular cuboids.
60  * @param [in] sourceMatrix - Source matrix to be sampled.
61  * @param [in] sensorMask - Sensor mask with the cuboid coordinates.
62  * @param [in] reduceOp - Reduction operator.
63  * @param [in] bufferToReuse - If there is a memory space to be reused, provide a pointer.
64  */
66  MatrixName& groupName,
67  const RealMatrix& sourceMatrix,
68  const IndexMatrix& sensorMask,
69  const ReduceOperator ReduceOp,
70  float* bufferToReuse = nullptr);
71 
72  /// Copy constructor is not allowed.
73  CuboidOutputStream(const CuboidOutputStream&) = delete;
74 
75  /**
76  * @brief Destructor.
77  *
78  * If the file is still opened, it applies the post processing and flush the data.
79  * Then, the object memory is freed and the object destroyed.
80  */
81  virtual ~CuboidOutputStream();
82 
83  /// operator= is not allowed.
85 
86  /// Create a HDF5 stream and allocate data for it.
87  virtual void create();
88 
89  /// Reopen the output stream after restart and reload data.
90  virtual void reopen();
91 
92  /// Sample data into buffer and apply reduction, or flush to disk - based on a sensor mask.
93  virtual void sample();
94 
95  /// Apply post-processing on the buffer and flush it to the file.
96  virtual void postProcess();
97 
98  /// Checkpoint the stream and close.
99  virtual void checkpoint();
100 
101  /// Close stream (apply post-processing if necessary, flush data and close).
102  virtual void close();
103 
104  protected:
105  /**
106  * @struct CuboidInfo
107  * @brief This structure information about a HDF5 dataset (one cuboid).
108  */
109  struct CuboidInfo
110  {
111  /// Id of the dataset storing the given cuboid.
112  hid_t cuboidId;
113  /// Having a single buffer for all cuboids, where this one starts.
115  };
116 
117  /**
118  * @brief Create a new dataset for a given cuboid specified by index (order).
119  * @param [in] cuboidIdx - Index of the cuboid in the sensor mask.
120  * @return Handle to the HDF5 dataset.
121  */
122  virtual hid_t createCuboidDataset(const size_t cuboidIdx);
123 
124  /**
125  * @brief Sample aggregated values.
126  * @tparam reduceOp - Reduction operator
127  */
128  template<BaseOutputStream::ReduceOperator reduceOp>
129  void sampleAggregated();
130 
131  /// Flush the buffer to the file.
132  virtual void flushBufferToFile();
133 
134  /// Sensor mask to sample data.
136 
137  /// Handle to a HDF5 dataset.
138  hid_t mGroup;
139 
140  /// vector keeping handles and positions of all cuboids.
141  std::vector<CuboidInfo> mCuboidsInfo;
142 
143  /// Timestep to store (N/A for aggregated).
145 
146 };// end of CuboidOutputStream
147 //----------------------------------------------------------------------------------------------------------------------
148 
149 #endif /* CUBOID_OUTPUT_STREAM_H */
150 
The class for real matrices.
Definition: RealMatrix.h:47
std::vector< CuboidInfo > mCuboidsInfo
vector keeping handles and positions of all cuboids.
virtual ~CuboidOutputStream()
Destructor.
virtual void flushBufferToFile()
Flush the buffer to the file.
CuboidOutputStream()=delete
Default constructor not allowed.
const IndexMatrix & mSensorMask
Sensor mask to sample data.
virtual void sample()
Sample data into buffer and apply reduction, or flush to disk - based on a sensor mask...
void sampleAggregated()
Sample aggregated values.
virtual void close()
Close stream (apply post-processing if necessary, flush data and close).
CuboidOutputStream & operator=(const CuboidOutputStream &)=delete
operator= is not allowed.
hid_t mGroup
Handle to a HDF5 dataset.
Class wrapping the HDF5 routines.
Definition: Hdf5File.h:490
hid_t cuboidId
Id of the dataset storing the given cuboid.
const std::string MatrixName
Datatype for matrix names.
Definition: MatrixNames.h:39
size_t mSampledTimeStep
Timestep to store (N/A for aggregated).
virtual void checkpoint()
Checkpoint the stream and close.
virtual void postProcess()
Apply post-processing on the buffer and flush it to the file.
virtual void create()
Create a HDF5 stream and allocate data for it.
size_t startingPossitionInBuffer
Having a single buffer for all cuboids, where this one starts.
ReduceOperator
How to aggregate data.
virtual hid_t createCuboidDataset(const size_t cuboidIdx)
Create a new dataset for a given cuboid specified by index (order).
virtual void reopen()
Reopen the output stream after restart and reload data.
The header file of the class saving RealMatrix data into the output HDF5 file.
This structure information about a HDF5 dataset (one cuboid).
The class for 64b unsigned integers (indices). It is used for linear and cuboid corners masks to get ...
Definition: IndexMatrix.h:47
Abstract base class for output data streams (sampled data).
Output stream for quantities sampled by a cuboid corner sensor mask.