yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.1.0
YODA::H5DataSetReader Class Reference

Helper class to extract information from YODA_H5::DataSets. More...

#include <H5Utils.h>

Public Member Functions

 H5DataSetReader ()
 Nullary constructor.
 
 H5DataSetReader (const YODA_H5::File &h5file, const string &label)
 
void skip (size_t len) noexcept
 Move internal cursor by len elements.
 
template<typename T = size_t>
next () noexcept
 Load next item and increment cursor.
 
template<typename T >
vector< T > read () noexcept
 Method to read and return the entire 1D dataset.
 
template<typename T >
vector< T > read (size_t len) noexcept
 Method to read a subset of the 1D dataset.
 
template<typename T >
vector< T > readSlice (size_t len) noexcept
 Method to read a subset of the 1D dataset.
 
template<typename T >
vector< T > readAt (size_t row, size_t len) noexcept
 Method to read a subset of the 1D dataset starting from row row.
 
template<typename T = size_t>
vector< T > readAttribute (const string &label) const noexcept
 Method to read an attribute decorated onto this dataset.
 

Detailed Description

Helper class to extract information from YODA_H5::DataSets.

Definition at line 66 of file H5Utils.h.

Constructor & Destructor Documentation

◆ H5DataSetReader() [1/2]

YODA::H5DataSetReader::H5DataSetReader ( )
inline

Nullary constructor.

Definition at line 70 of file H5Utils.h.

70{ }

◆ H5DataSetReader() [2/2]

YODA::H5DataSetReader::H5DataSetReader ( const YODA_H5::File &  h5file,
const string &  label 
)
inline

Definition at line 73 of file H5Utils.h.

74 : _nrows(0), _thisrow(0), _ncols(0), _thiscol(0), _ds(nullptr) {
75 _ds = std::make_unique<YODA_H5::DataSet>(h5file.getDataSet(label));
76 const auto& dims = _ds->getDimensions();
77 _nrows = dims.at(0);
78 if (dims.size() > 1) _ncols = dims.at(1);
79 }

Member Function Documentation

◆ next()

template<typename T = size_t>
T YODA::H5DataSetReader::next ( )
inlinenoexcept

Load next item and increment cursor.

Definition at line 86 of file H5Utils.h.

86 {
87 T item;
88 _ds->select({_thisrow++}, {1}).read(item);
89 return item;
90 }
vector< T > read() noexcept
Method to read and return the entire 1D dataset.
Definition H5Utils.h:94

References read().

◆ read() [1/2]

template<typename T >
vector< T > YODA::H5DataSetReader::read ( )
inlinenoexcept

Method to read and return the entire 1D dataset.

Definition at line 94 of file H5Utils.h.

94 {
95 if (_nrows == 0) return vector<T>{};
96 vector<T> data; data.reserve(_nrows);
97 _ds->select({0}, {_nrows}).read(data);
98 return data;
99 }

References read().

Referenced by next(), read(), read(), and readSlice().

◆ read() [2/2]

template<typename T >
vector< T > YODA::H5DataSetReader::read ( size_t  len)
inlinenoexcept

Method to read a subset of the 1D dataset.

Definition at line 103 of file H5Utils.h.

103 {
104 if (len == 0) return {};
105 vector<T> data; data.reserve(len);
106 _ds->select({_thisrow}, {len}).read(data);
107 _thisrow += len;
108 return data;
109 }

References read().

◆ readAt()

template<typename T >
vector< T > YODA::H5DataSetReader::readAt ( size_t  row,
size_t  len 
)
inlinenoexcept

Method to read a subset of the 1D dataset starting from row row.

Definition at line 134 of file H5Utils.h.

134 {
135 _thisrow = row;
136 return read<T>(len);
137 }

◆ readAttribute()

template<typename T = size_t>
vector< T > YODA::H5DataSetReader::readAttribute ( const string &  label) const
inlinenoexcept

Method to read an attribute decorated onto this dataset.

Definition at line 141 of file H5Utils.h.

141 {
142 vector<T> data;
143 _ds->getAttribute(label).read(data);
144 return data;
145 }

◆ readSlice()

template<typename T >
vector< T > YODA::H5DataSetReader::readSlice ( size_t  len)
inlinenoexcept

Method to read a subset of the 1D dataset.

Definition at line 113 of file H5Utils.h.

113 {
114 if (len == 0) return {};
115 vector<T> data; data.reserve(len);
116 while (len) {
117 vector<vector<T>> tmp;
118 size_t ncols = std::min(len, _ncols - _thiscol);
119 size_t nrows = 1+(ncols-1)/_ncols; // C-style ceil
120 _ds->select({_thisrow,_thiscol}, {nrows,ncols}).read(tmp);
121 for (size_t i=0; i < tmp.size(); ++i) {
122 data.insert(data.end(), std::make_move_iterator(std::begin(tmp[i])),
123 std::make_move_iterator(std::end(tmp[i])));
124 }
125 if ((_thiscol + ncols) == _ncols) ++_thisrow;
126 _thiscol = (_thiscol + ncols) % _ncols;
127 len -= ncols;
128 }
129 return data;
130 }

References read().

◆ skip()

void YODA::H5DataSetReader::skip ( size_t  len)
inlinenoexcept

Move internal cursor by len elements.

Definition at line 82 of file H5Utils.h.

82{ _thisrow += len; }

The documentation for this class was generated from the following file: