STIR 6.4.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__
23
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#include <array>
35
36START_NAMESPACE_STIR
37
38namespace GE
39{
40
41namespace RDF_HDF5
42{
43
49
50class GEHDF5Wrapper
51{
52public:
54
55 static bool check_GE_signature(const std::string& filename);
56
58
59 static bool check_GE_signature(H5::H5File& file);
60
61 GEHDF5Wrapper();
62
63 explicit GEHDF5Wrapper(const std::string& filename);
64
65 // bool is_list_file(const std::string& filename);
66
68 bool is_list_file() const;
69
70 bool is_sino_file() const;
71
72 bool is_geo_file() const;
73
74 bool is_norm_file() const;
75
76 Succeeded open(const std::string& filename);
77
78 Succeeded initialise_listmode_data();
79
80 Succeeded initialise_singles_data();
81
83
87 Succeeded initialise_proj_data(const unsigned int view_num);
89
91 Succeeded initialise_geo_factors_data(const unsigned int slice_num);
92
93 Succeeded initialise_efficiency_factors();
94
96 /* \param[output] output: has to be pre-allocated and of the correct size
97 \param[in] offset: start in listmode data (in number of bytes)
98 \param[in]: size to read (in number of bytes)
99 */
100 Succeeded read_list_data(char* output, const std::streampos offset, const hsize_t size) const;
101
103
104 Succeeded read_singles(Array<1, unsigned int>& output, const unsigned int current_id);
105
106 Succeeded read_sinogram(Array<3, unsigned char>& output,
107 const std::array<hsize_t, 3>& offset = { 0, 0, 0 },
108 const std::array<hsize_t, 3>& stride = { 1, 1, 1 });
109
110 // PW Here I added the get_from_2d_dataset which must read the hyperslab and memory space for 2D array
111 // with specific offset, count, stride and block. This dataset is read from this memory space and then
112 // into a 1D output array.
113 Succeeded read_geometric_factors(Array<1, unsigned int>& output,
114 const std::array<hsize_t, 2>& offset = { 0, 0 },
115 const std::array<hsize_t, 2>& count = { 0, 0 },
116 const std::array<hsize_t, 2>& stride = { 1, 1 });
117
118 Succeeded read_efficiency_factors(Array<1, float>& output,
119 const std::array<hsize_t, 2>& offset = { 0, 0 },
120 const std::array<hsize_t, 2>& stride = { 1, 1 });
121
122 inline H5::DataSet* get_dataset_ptr() const;
123
124 inline hsize_t get_dataset_size() const;
125
126 inline unsigned int get_geo_dims() const;
127
128 unsigned int get_num_singles_samples();
129 // inline TimeFrameDefinitions* get_timeframe_definitions() const;
130
132
134 inline shared_ptr<ExamInfo> get_exam_info_sptr() const;
135
136 inline shared_ptr<Scanner> get_scanner_sptr() const;
137
138 inline shared_ptr<const ProjDataInfo> get_proj_data_info_sptr() const;
139
141 inline const H5::H5File& get_file() const;
142
143 ~GEHDF5Wrapper() {}
144
145 std::uint32_t read_dataset_uint32(const std::string& dataset_name);
146 std::int32_t read_dataset_int32(const std::string& dataset_name);
147
148protected:
151 {
152 ACQ_HEAD_FIRST = 0,
153 ACQ_FEET_FIRST = 1
154 };
155
157 {
158 ACQ_SUPINE = 0,
159 ACQ_PRONE = 1,
160 ACQ_LEFT_DECUB = 2,
161 ACQ_RIGHT_DECUB = 3
162 };
163
164 void initialise_proj_data_info_from_HDF5();
165 void initialise_exam_info();
166
167 shared_ptr<ProjDataInfo> proj_data_info_sptr;
168 shared_ptr<ExamInfo> exam_info_sptr;
169
170private:
171 Succeeded check_file();
172
173 unsigned int check_geo_type();
174 shared_ptr<Scanner> get_scanner_from_HDF5();
175
176 H5::H5File file;
177
178 shared_ptr<H5::DataSet> m_dataset_sptr;
179
180 H5::DataSpace m_dataspace;
181
182 std::uint64_t m_list_size = 0;
183 int m_dataset_list_Ndims;
184 unsigned int m_num_singles_samples;
185
186 bool is_list = false;
187 bool is_sino = false;
188 bool is_geo = false;
189 bool is_norm = false;
190
191 // There are two types of geometry that behave very differently. We need to know which type it is.
192 // In essence, the options are 2D (2) or 3D (3). In 2D, all transaxial values are the same.
193 unsigned int geo_dims = 0;
194 std::string m_address;
195
196 unsigned int rdf_ver = 0;
197
198 hsize_t m_size_of_record_signature = 0;
199
200 hsize_t m_max_size_of_record = 0;
201
202 hsize_t m_NX_SUB = 0; // hyperslab dimensions
203 hsize_t m_NY_SUB = 0;
204 hsize_t m_NZ_SUB = 0;
205
206 static const int m_max_dataset_dims = 5;
207#if 0
208 // AB: todo these are never used.
209 hsize_t m_NX = 0; // output buffer dimensions
210 hsize_t m_NY = 0;
211 hsize_t m_NZ = 0;
212#endif
213};
214
215} // namespace RDF_HDF5
216} // namespace GE
217END_NAMESPACE_STIR
218
220
221#endif
defines the stir::Array class for multi-dimensional (numeric) arrays
This file declares the class stir::ExamInfo.
Declaration of class stir::GE::RDF_HDF5::GEHDF5Wrapper.
Declaration of class stir::ProjDataInfo.
Declaration of class stir::Scanner.
Declaration of class stir::Succeeded.
This class defines multi-dimensional (numeric) arrays.
Definition Array.h:78
static bool check_GE_signature(const std::string &filename)
check signature to see if this is a GE RDF9 or higher file
Definition GEHDF5Wrapper.cxx:80
Succeeded initialise_geo_factors_data(const unsigned int slice_num)
Initialises data for reading geometric normalisation factors. Sets up reading addresses and inspect s...
Definition GEHDF5Wrapper.cxx:700
Succeeded read_singles(Array< 1, unsigned int > &output, const unsigned int current_id)
read singles at time slice current_id
Definition GEHDF5Wrapper.cxx:914
shared_ptr< ExamInfo > get_exam_info_sptr() const
Get shared pointer to exam info.
Definition GEHDF5Wrapper.inl:45
Succeeded read_list_data(char *output, const std::streampos offset, const hsize_t size) const
reads listmode event(s)
Definition GEHDF5Wrapper.cxx:783
Succeeded initialise_proj_data(const unsigned int view_num)
Initialises data for reading projections. Sets up reading addresses and inspect sizes.
Definition GEHDF5Wrapper.cxx:642
const H5::H5File & get_file() const
Definition GEHDF5Wrapper.inl:69
bool is_list_file() const
Checks if input file is a listmode file.
Definition GEHDF5Wrapper.cxx:114
AcqPatientPositions
enum for encoding patient orientation in the RDF file
Definition GEHDF5Wrapper.h:157
AcqPatientEntries
enum for encoding head/feet first in the RDF file
Definition GEHDF5Wrapper.h:151
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition Succeeded.h:44
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast into the stir names...