STIR  6.2.0
InputStreamWithRecordsFromHDF5.h
Go to the documentation of this file.
1 //
2 //
15 /*
16  Copyright (C) 2016-2018, 2020-2021 University College London
17  Copyright (C) 2016-2019, University of Leeds
18  Copyright (C) 2016-2018, University of Hull
19 
20  This file is part of STIR.
21 
22  SPDX-License-Identifier: Apache-2.0
23 
24  See STIR/LICENSE.txt for details
25 */
26 
27 #ifndef __stir_IO_InputStreamWithRecordsFromHDF5_H__
28 #define __stir_IO_InputStreamWithRecordsFromHDF5_H__
29 
30 #include "stir/shared_ptr.h"
31 #include "stir/Succeeded.h"
32 #include "stir/IO/GEHDF5Wrapper.h"
33 #include "boost/shared_array.hpp"
34 #include <string>
35 #include <iostream>
36 #include <vector>
37 
38 START_NAMESPACE_STIR
39 
40 namespace GE
41 {
42 namespace RDF_HDF5
43 {
44 
46 
73 template <class RecordT>
75 {
76 public:
77  typedef std::vector<std::streampos>::size_type SavedPosition;
79 
81  // explicit
82  // InputStreamWithRecordsFromHDF5(const shared_ptr<H5::DataSet>& ,
83  // const std::size_t size_of_record_signature,
84  // const std::size_t max_size_of_record);
85 
86  explicit InputStreamWithRecordsFromHDF5(const std::string& filename,
87  const std::size_t size_of_record_signature,
88  const std::size_t max_size_of_record);
89 
90  virtual ~InputStreamWithRecordsFromHDF5() {}
91 
92  inline virtual Succeeded get_next_record(RecordT& record);
93 
94  virtual Succeeded set_up();
95 
97  inline Succeeded reset();
98 
100 
103  inline SavedPosition save_get_position();
104 
106  inline Succeeded set_get_position(const SavedPosition&);
107 
109 
113  inline std::vector<std::streampos> get_saved_get_positions() const;
115 
120  inline void set_saved_get_positions(const std::vector<std::streampos>&);
121 
122 private:
123  shared_ptr<GEHDF5Wrapper> input_sptr;
124 
125  boost::shared_array<char> data_sptr;
126 
127  uint64_t m_list_size = 0;
128 
129  std::streampos starting_stream_position;
130  mutable std::streampos current_offset;
131  std::vector<std::streampos> saved_get_positions;
132 
133  const std::string m_filename;
134  const std::size_t size_of_record_signature;
135  const std::size_t max_size_of_record;
136 
138  void read_data(char* output, const std::streampos offset, const hsize_t size) const;
139  // members for buffering
140 
141  boost::shared_array<char> buffer;
142  std::size_t max_buffer_size;
144  mutable std::size_t buffer_size;
145  mutable std::streampos start_of_buffer_offset;
146  void fill_buffer(const std::streampos offset) const;
147 };
148 
149 } // namespace RDF_HDF5
150 } // namespace GE
151 END_NAMESPACE_STIR
152 
154 
155 #endif
Declaration of class stir::Succeeded.
Implementation of class stir::GE::RDF_HDF5::InputStreamWithRecordsFromHDF5.
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast (or corresponding b...
A helper class to read data from a hdf5 file.
Definition: InputStreamWithRecordsFromHDF5.h:74
Succeeded read_data(IStreamT &s, Array< num_dimensions, elemT > &data, const ByteOrder byte_order=ByteOrder::native)
Read the data of an Array from file.
Definition: read_data.inl:63
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.