Rivet API documentation

Rivet 4.1.3
RivetHDF5.hh
1// -*- C++ -*-
2#ifndef RIVET_RivetHDF5_HH
3#define RIVET_RivetHDF5_HH
4#include "Rivet/Config/RivetCommon.hh"
5#include "Rivet/Tools/RivetPaths.hh"
6
7#include "Rivet/Config/RivetConfig.hh"
8#ifdef WITH_YODA_HIGHFIVE
9 #include "YODA/highfive/H5File.hpp"
10#else
11 #include "highfive/H5File.hpp"
12 #define YODA_H5 HighFive
13#endif
14
15namespace Rivet {
16 namespace H5 {
17
18
19 using namespace YODA_H5;
20
21
23 inline YODA_H5::File readFile(const string& filename) {
24 const string filepath = findAnalysisDataFile(filename);
25 if (filepath.empty()) throw IOError("Failed to load HDF5 file " + filename);
26 try {
27 return YODA_H5::File(filepath, YODA_H5::File::ReadOnly);
28 }
29 catch (...) {
30 throw IOError("Failed to load HDF5 file " + filename);
31 }
32 }
33
34
36 template <typename T>
37 inline bool readData(const string& filename, const string& dsname, T& rtndata) {
38 try {
39 YODA_H5::File h5file = readFile(filename);
40 DataSet dataset = h5file.getDataSet(dsname);
41 dataset.read(rtndata);
42 }
43 catch (...) {
44 return false;
45 }
46 return true;
47 }
48
49
51 template <typename T>
52 inline T readData(const string& filename, const string& dsname) {
53 T rtn;
54 readData(filename, dsname, rtn);
55 return rtn;
56 }
57
58
59 }
60}
61
62#endif
std::string findAnalysisDataFile(const std::string &filename, const std::vector< std::string > &pathprepend=std::vector< std::string >(), const std::vector< std::string > &pathappend=std::vector< std::string >())
Find the first file of the given name in the general data file search dirs.
Definition LHCbCommon.hh:9