STIR  6.2.0
GEHDF5Wrapper.h
Go to the documentation of this file.
1 /* Copyright (C) 2017-2019, University of Leeds
2  Copyright (C) 2018 University of Hull
3  Copyright (C) 2018-2020, University College London
4  This file is part of STIR.
5 
6  SPDX-License-Identifier: Apache-2.0
7 
8  See STIR/LICENSE.txt for details
9 */
10 #ifndef __stir_IO_GEHDF5Wrapper_H__
11 #define __stir_IO_GEHDF5Wrapper_H__
12 
24 #include "stir/shared_ptr.h"
25 #include "stir/ExamInfo.h"
26 #include "stir/ProjDataInfo.h"
27 #include "stir/Scanner.h"
28 #include "stir/Succeeded.h"
29 #include "stir/Array.h"
30 
31 #include "H5Cpp.h"
32 
33 #include <string>
34 
35 START_NAMESPACE_STIR
36 
37 namespace GE
38 {
39 
40 namespace RDF_HDF5
41 {
42 
50 {
51 public:
53 
54  static bool check_GE_signature(const std::string& filename);
55 
57 
58  static bool check_GE_signature(H5::H5File& file);
59 
60  GEHDF5Wrapper();
61 
62  explicit GEHDF5Wrapper(const std::string& filename);
63 
64  // bool is_list_file(const std::string& filename);
65 
67  bool is_list_file() const;
68 
69  bool is_sino_file() const;
70 
71  bool is_geo_file() const;
72 
73  bool is_norm_file() const;
74 
75  Succeeded open(const std::string& filename);
76 
77  Succeeded initialise_listmode_data();
78 
79  Succeeded initialise_singles_data();
80 
82 
86  Succeeded initialise_proj_data(const unsigned int view_num);
88 
90  Succeeded initialise_geo_factors_data(const unsigned int slice_num);
91 
92  Succeeded initialise_efficiency_factors();
93 
95  /* \param[output] output: has to be pre-allocated and of the correct size
96  \param[in] offset: start in listmode data (in number of bytes)
97  \param[in]: size to read (in number of bytes)
98  */
99  Succeeded read_list_data(char* output, const std::streampos offset, const hsize_t size) const;
100 
102 
103  Succeeded read_singles(Array<1, unsigned int>& output, const unsigned int current_id);
104 
105  Succeeded read_sinogram(Array<3, unsigned char>& output,
106  const std::array<hsize_t, 3>& offset = { 0, 0, 0 },
107  const std::array<hsize_t, 3>& stride = { 1, 1, 1 });
108 
109  // PW Here I added the get_from_2d_dataset which must read the hyperslab and memory space for 2D array
110  // with specific offset, count, stride and block. This dataset is read from this memory space and then
111  // into a 1D output array.
112  Succeeded read_geometric_factors(Array<1, unsigned int>& output,
113  const std::array<hsize_t, 2>& offset = { 0, 0 },
114  const std::array<hsize_t, 2>& count = { 0, 0 },
115  const std::array<hsize_t, 2>& stride = { 1, 1 });
116 
117  Succeeded read_efficiency_factors(Array<1, float>& output,
118  const std::array<hsize_t, 2>& offset = { 0, 0 },
119  const std::array<hsize_t, 2>& stride = { 1, 1 });
120 
121  inline H5::DataSet* get_dataset_ptr() const;
122 
123  inline hsize_t get_dataset_size() const;
124 
125  inline unsigned int get_geo_dims() const;
126 
127  unsigned int get_num_singles_samples();
128  // inline TimeFrameDefinitions* get_timeframe_definitions() const;
129 
131 
133  inline shared_ptr<ExamInfo> get_exam_info_sptr() const;
134 
135  inline shared_ptr<Scanner> get_scanner_sptr() const;
136 
137  inline shared_ptr<const ProjDataInfo> get_proj_data_info_sptr() const;
138 
140  inline const H5::H5File& get_file() const;
141 
142  ~GEHDF5Wrapper() {}
143 
144  std::uint32_t read_dataset_uint32(const std::string& dataset_name);
145  std::int32_t read_dataset_int32(const std::string& dataset_name);
146 
147 protected:
150  {
151  ACQ_HEAD_FIRST = 0,
152  ACQ_FEET_FIRST = 1
153  };
156  {
157  ACQ_SUPINE = 0,
158  ACQ_PRONE = 1,
159  ACQ_LEFT_DECUB = 2,
160  ACQ_RIGHT_DECUB = 3
161  };
162 
163  void initialise_proj_data_info_from_HDF5();
164  void initialise_exam_info();
165 
166  shared_ptr<ProjDataInfo> proj_data_info_sptr;
167  shared_ptr<ExamInfo> exam_info_sptr;
168 
169 private:
170  Succeeded check_file();
171 
172  unsigned int check_geo_type();
173  shared_ptr<Scanner> get_scanner_from_HDF5();
174 
175  H5::H5File file;
176 
177  shared_ptr<H5::DataSet> m_dataset_sptr;
178 
179  H5::DataSpace m_dataspace;
180 
181  std::uint64_t m_list_size = 0;
182  int m_dataset_list_Ndims;
183  unsigned int m_num_singles_samples;
184 
185  bool is_list = false;
186  bool is_sino = false;
187  bool is_geo = false;
188  bool is_norm = false;
189 
190  // There are two types of geometry that behave very differently. We need to know which type it is.
191  // In essence, the options are 2D (2) or 3D (3). In 2D, all transaxial values are the same.
192  unsigned int geo_dims = 0;
193  std::string m_address;
194 
195  unsigned int rdf_ver = 0;
196 
197  hsize_t m_size_of_record_signature = 0;
198 
199  hsize_t m_max_size_of_record = 0;
200 
201  hsize_t m_NX_SUB = 0; // hyperslab dimensions
202  hsize_t m_NY_SUB = 0;
203  hsize_t m_NZ_SUB = 0;
204 
205  static const int m_max_dataset_dims = 5;
206 #if 0
207  // AB: todo these are never used.
208  hsize_t m_NX = 0; // output buffer dimensions
209  hsize_t m_NY = 0;
210  hsize_t m_NZ = 0;
211 #endif
212 };
213 
214 } // namespace RDF_HDF5
215 } // namespace GE
216 END_NAMESPACE_STIR
217 
218 #include "stir/IO/GEHDF5Wrapper.inl"
219 
220 #endif
Declaration of class stir::Succeeded.
This file declares the class stir::ExamInfo.
Declaration of class stir::ProjDataInfo.
AcqPatientPositions
enum for encoding patient orientation in the RDF file
Definition: GEHDF5Wrapper.h:155
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast (or corresponding b...
A class that extracts and reads the necessary data from GE HDF5 input files.
Definition: GEHDF5Wrapper.h:49
defines the Array class for multi-dimensional (numeric) arrays
Declaration of class stir::Scanner.
This class defines multi-dimensional (numeric) arrays.
Definition: Array.h:73
AcqPatientEntries
enum for encoding head/feet first in the RDF file
Definition: GEHDF5Wrapper.h:149
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition: Succeeded.h:43
Declaration of class stir::GE::RDF_HDF5::GEHDF5Wrapper.