rivet is hosted by Hepforge, IPPP Durham
Rivet 4.0.0
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#include "highfive/H5File.hpp"
7
8namespace Rivet {
9 namespace H5 {
10
11
12 using namespace HighFive;
13
14
16 inline HighFive::File readFile(const string& filename) {
17 const string filepath = findAnalysisDataFile(filename);
18 if (filepath.empty()) throw IOError("Failed to load HDF5 file " + filename);
19 try {
20 return HighFive::File(filepath, HighFive::File::ReadOnly);
21 } catch (...) {
22 throw IOError("Failed to load HDF5 file " + filename);
23 }
24 }
25
26
28 template <typename T>
29 inline bool readData(const string& filename, const string& dsname, T& rtndata) {
30 try {
31 HighFive::File h5file = readFile(filename);
32 DataSet dataset = h5file.getDataSet(dsname);
33 dataset.read(rtndata);
34 } catch (...) {
35 return false;
36 }
37 return true;
38 }
39
40
42 template <typename T>
43 inline T readData(const string& filename, const string& dsname) {
44 T rtn;
45 readData(filename, dsname, rtn);
46 return rtn;
47 }
48
49
50 }
51}
52
53#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 MC_CENT_PPB_Projections.hh:10