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

Helper class to extract AO information from a H5 file. More...

#include <H5Utils.h>

Public Member Functions

 H5FileManager (const YODA_H5::File &file)
 Constructor.
 
size_t version () const
 H5 YODA format version.
 
size_t size () const
 Number of AOs in this H5 file.
 
bool next ()
 Loads next AO from file.
 
const string & path () const
 Path of current AO.
 
const string & type () const
 Type of current AO.
 
vector< string > loadAnnotations () noexcept
 Serialized annotations of current AO.
 
vector< double > loadContent () noexcept
 Serialized content of current AO.
 
void skipCommon () noexcept
 Skips next set of annotations and content of current AO.
 
vector< size_t > loadMasks () noexcept
 Indices of masked bins in current AO.
 
void skipMasks () noexcept
 Skips next set of masked indices of current AO.
 
vector< string > loadSources () noexcept
 Labels of error sources of current AO.
 
void skipSources () noexcept
 Skips next set of error sources of current AO.
 
template<typename EdgeT >
vector< EdgeT > loadEdges () noexcept
 Returns next set of edges of type EdgeT.
 
template<typename EdgeT >
void skipEdges () noexcept
 Skips next set of edges of type EdgeT.
 

Static Public Attributes

static constexpr size_t AO_META = 2
 

Detailed Description

Helper class to extract AO information from a H5 file.

Definition at line 272 of file H5Utils.h.

Constructor & Destructor Documentation

◆ H5FileManager()

YODA::H5FileManager::H5FileManager ( const YODA_H5::File &  file)
inline

Constructor.

Definition at line 279 of file H5Utils.h.

280 : _index(-1), _cachepos(-1),
281 _labelindex(0), _h5file(file),
282 _aoinfo(file, "aoinfo"),
283 _layout(file, "sizeinfo"),
284 _content(file, "content"),
285 _annos(file, "annotations"),
286 _labels(H5DataSetReader(file, "labels").read<string>()) {
287
288 _meta = _aoinfo.readAttribute("meta");
289 if (_meta.size() < 2)
290 throw ReadError("No file metadata found!");
291
292 _annosizes = _layout.read<size_t>(_meta.at(1));
293 _datasizes = _layout.read<size_t>(_meta.at(1));
294 _labelsizes = _layout.read<size_t>(_layout.next());
295 }

Member Function Documentation

◆ loadAnnotations()

vector< string > YODA::H5FileManager::loadAnnotations ( )
inlinenoexcept

Serialized annotations of current AO.

Definition at line 333 of file H5Utils.h.

333 {
334 return _annos.readSlice<string>(_annosizes[_index]);
335 }

Referenced by YODA::AOReader< Counter >::mkFromH5(), YODA::AOReader< Estimate0D >::mkFromH5(), YODA::AOReader< ScatterND< N > >::mkFromH5(), YODA::AOReader< BinnedDbn< DbnN, AxisT... > >::mkFromH5(), and YODA::AOReader< BinnedEstimate< AxisT... > >::mkFromH5().

◆ loadContent()

vector< double > YODA::H5FileManager::loadContent ( )
inlinenoexcept

Serialized content of current AO.

Definition at line 338 of file H5Utils.h.

338 {
339 return _content.readSlice<double>(_datasizes[_index]);
340 }

Referenced by YODA::AOReader< Counter >::mkFromH5(), YODA::AOReader< Estimate0D >::mkFromH5(), YODA::AOReader< ScatterND< N > >::mkFromH5(), YODA::AOReader< BinnedDbn< DbnN, AxisT... > >::mkFromH5(), and YODA::AOReader< BinnedEstimate< AxisT... > >::mkFromH5().

◆ loadEdges()

template<typename EdgeT >
vector< EdgeT > YODA::H5FileManager::loadEdges ( )
inlinenoexcept

Returns next set of edges of type EdgeT.

Definition at line 385 of file H5Utils.h.

385 {
386
387 const string label = string("edges_") + TypeID<EdgeT>::name();
388 auto itr = datasets.find(label);
389 if (itr == datasets.end()) {
390 // put H5::DataSet into DataSet cache
391 datasets[label] = H5DataSetReader(_h5file, label);
392 itr = datasets.find(label);
393 }
394 return itr->second.read<EdgeT>(_layout.next());
395 }
static const char * name()

References YODA::TypeID< T >::name().

◆ loadMasks()

vector< size_t > YODA::H5FileManager::loadMasks ( )
inlinenoexcept

Indices of masked bins in current AO.

Definition at line 349 of file H5Utils.h.

349 {
350 return _layout.read<size_t>(_layout.next());
351 }

Referenced by YODA::AOReader< BinnedDbn< DbnN, AxisT... > >::mkFromH5(), and YODA::AOReader< BinnedEstimate< AxisT... > >::mkFromH5().

◆ loadSources()

vector< string > YODA::H5FileManager::loadSources ( )
inlinenoexcept

Labels of error sources of current AO.

Definition at line 359 of file H5Utils.h.

359 {
360
361 if (_cachepos < 0) { // fill label cache
362 _labelcache = _layout.read<size_t>(_labelsizes[_labelindex++]);
363 _cachepos = 0;
364 }
365
366 size_t len = _labelcache[_cachepos++];
367 if (len == 0) return {};
368
369 vector<size_t> indices(_labelcache.begin()+_cachepos, _labelcache.begin()+_cachepos+len);
370 vector<string> sources; sources.reserve(indices.size());
371 for (size_t idx : indices) {
372 sources.emplace_back(_labels[idx]);
373 }
374 _cachepos += len;
375 return sources;
376 }

Referenced by YODA::AOReader< Estimate0D >::mkFromH5(), and YODA::AOReader< BinnedEstimate< AxisT... > >::mkFromH5().

◆ next()

bool YODA::H5FileManager::next ( )
inline

Loads next AO from file.

Definition at line 308 of file H5Utils.h.

308 {
309 ++_index;
310 if ((size_t)_index == size()) return false;
311
312 _aodims = _aoinfo.readAt<string>(AO_META*_index, AO_META);
313 if (_aodims.empty()) {
314 throw ReadError("No AO information found!");
315 }
316
317 _cachepos = -1;
318
319 return true;
320 }
static constexpr size_t AO_META
Definition H5Utils.h:276
size_t size() const
Number of AOs in this H5 file.
Definition H5Utils.h:303

References AO_META, and size().

Referenced by YODA::ReaderH5::read().

◆ path()

◆ size()

size_t YODA::H5FileManager::size ( ) const
inline

Number of AOs in this H5 file.

Definition at line 303 of file H5Utils.h.

303 {
304 return _meta.at(1);
305 }

Referenced by next().

◆ skipCommon()

void YODA::H5FileManager::skipCommon ( )
inlinenoexcept

Skips next set of annotations and content of current AO.

Definition at line 343 of file H5Utils.h.

343 {
344 _annos.skip(_annosizes[_index]);
345 _content.skip(_datasizes[_index]);
346 }

Referenced by YODA::AOReaderBase::skip(), YODA::AOReader< Estimate0D >::skip(), YODA::AOReader< BinnedDbn< DbnN, AxisT... > >::skip(), and YODA::AOReader< BinnedEstimate< AxisT... > >::skip().

◆ skipEdges()

template<typename EdgeT >
void YODA::H5FileManager::skipEdges ( )
inlinenoexcept

Skips next set of edges of type EdgeT.

Definition at line 399 of file H5Utils.h.

399 {
400 const string label = string("edges_") + TypeID<EdgeT>::name();
401 auto itr = datasets.find(label);
402 if (itr == datasets.end()) {
403 // put H5::DataSet into DataSet cache
404 datasets[label] = H5DataSetReader(_h5file, label);
405 itr = datasets.find(label);
406 }
407 itr->second.skip(_layout.next());
408 }

References YODA::TypeID< T >::name().

◆ skipMasks()

void YODA::H5FileManager::skipMasks ( )
inlinenoexcept

Skips next set of masked indices of current AO.

Definition at line 354 of file H5Utils.h.

354 {
355 _layout.skip(_layout.next());
356 }

Referenced by YODA::AOReader< BinnedDbn< DbnN, AxisT... > >::skip(), and YODA::AOReader< BinnedEstimate< AxisT... > >::skip().

◆ skipSources()

void YODA::H5FileManager::skipSources ( )
inlinenoexcept

Skips next set of error sources of current AO.

Definition at line 379 of file H5Utils.h.

379 {
380 _layout.skip(_labelsizes[_labelindex++]);
381 }

Referenced by YODA::AOReader< Estimate0D >::skip(), and YODA::AOReader< BinnedEstimate< AxisT... > >::skip().

◆ type()

const string & YODA::H5FileManager::type ( ) const
inline

Type of current AO.

Definition at line 328 of file H5Utils.h.

328 {
329 return _aodims.at(1);
330 }

Referenced by YODA::ReaderH5::read().

◆ version()

size_t YODA::H5FileManager::version ( ) const
inline

H5 YODA format version.

Definition at line 298 of file H5Utils.h.

298 {
299 return _meta.at(0);
300 }

Member Data Documentation

◆ AO_META

constexpr size_t YODA::H5FileManager::AO_META = 2
staticconstexpr

Definition at line 276 of file H5Utils.h.

Referenced by next(), and YODA::WriterH5::writeAOS().


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