Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hdf5_utils.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file hdf5_utils.cxx
1 // TRENTO: Reduced Thickness Event-by-event Nuclear Topology
2 // Copyright 2015 Jonah E. Bernhard, J. Scott Moreland
3 // TRENTO3D: Three-dimensional extension of TRENTO by Weiyao Ke
4 // MIT License
5 
6 #include "hdf5_utils.h"
7 
8 #include <stdexcept>
9 
10 #include <boost/filesystem.hpp>
11 
12 namespace trento {
13 
14 namespace hdf5 {
15 
17  if (!path.has_extension())
18  return false;
19 
20  auto hdf5_exts = {".hdf5", ".hdf", ".hd5", ".h5"};
21  auto result = std::find(hdf5_exts.begin(), hdf5_exts.end(), path.extension());
22 
23  return result != hdf5_exts.end();
24 }
25 
27  return filename_is_hdf5(fs::path{path});
28 }
29 
30 #ifdef TRENTO_HDF5
31 
32 H5::H5File try_open_file(const std::string& path, unsigned int flags) {
33  if (!fs::exists(path))
34  throw std::invalid_argument{"file '" + path + "' does not exist"};
35 
36  if (!H5::H5File::isHdf5(path))
37  throw std::invalid_argument{"'" + path + "' is not a valid HDF5 file"};
38 
39  return H5::H5File{path, flags};
40 }
41 
42 #endif // TRENTO_HDF5
43 
44 } // namespace hdf5
45 
46 } // namespace trento