Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:19:07

0001 // TRENTO: Reduced Thickness Event-by-event Nuclear Topology
0002 // Copyright 2015 Jonah E. Bernhard, J. Scott Moreland
0003 // TRENTO3D: Three-dimensional extension of TRENTO by Weiyao Ke
0004 // MIT License
0005 
0006 #ifndef HDF5_UTILS_H
0007 #define HDF5_UTILS_H
0008 
0009 #include <string>
0010 
0011 #ifdef TRENTO_HDF5
0012 #include <H5Cpp.h>
0013 // This macro was introduced in v1.8.7.  Define it manually for older versions.
0014 #ifndef H5_VERSION_GE
0015 #define H5_VERSION_GE(Maj,Min,Rel) \
0016        (((H5_VERS_MAJOR==Maj) && (H5_VERS_MINOR==Min) && (H5_VERS_RELEASE>=Rel)) || \
0017         ((H5_VERS_MAJOR==Maj) && (H5_VERS_MINOR>Min)) || \
0018         (H5_VERS_MAJOR>Maj))
0019 #endif
0020 #endif
0021 
0022 #include "fwd_decl.h"
0023 
0024 namespace trento {
0025 
0026 namespace hdf5 {
0027 
0028 // Determine if a filename is an HDF5 file based on the extension.
0029 bool filename_is_hdf5(const fs::path& path);
0030 bool filename_is_hdf5(const std::string& path);
0031 
0032 #ifdef TRENTO_HDF5
0033 
0034 // Open an HDF5 file object.
0035 // Throw std::invalid_argument if the file does not exist or is not valid HDF5.
0036 H5::H5File try_open_file(
0037     const std::string& path, unsigned int flags = H5F_ACC_RDONLY);
0038 
0039 // Map C types to corresponding HDF5 datatypes.
0040 // See section "predefined datatypes" in the HDF5 docs.
0041 using H5::PredType;
0042 template <typename T> inline const PredType& type();
0043 template <> inline const PredType& type<int>()           { return PredType::NATIVE_INT; }
0044 template <> inline const PredType& type<unsigned long>() { return PredType::NATIVE_UINT; }
0045 template <> inline const PredType& type<long int>()      { return PredType::NATIVE_LONG; }
0046 template <> inline const PredType& type<long long int>() { return PredType::NATIVE_LLONG; }
0047 template <> inline const PredType& type<float>()         { return PredType::NATIVE_FLOAT; }
0048 template <> inline const PredType& type<double>()        { return PredType::NATIVE_DOUBLE; }
0049 template <> inline const PredType& type<long double>()   { return PredType::NATIVE_LDOUBLE; }
0050 
0051 // Construct an HDF5 "simple" dataspace from a generic container.
0052 // It must contain values of type "hsize_t" to match the H5::DataSpace ctor.
0053 template <typename Container>
0054 inline typename std::enable_if<
0055   std::is_same<typename Container::value_type, hsize_t>::value,
0056   H5::DataSpace
0057 >::type
0058 make_dataspace(const Container& shape) {
0059   return H5::DataSpace{shape.size(), shape.data()};
0060 }
0061 
0062 #endif  // TRENTO_HDF5
0063 
0064 }  // namespace hdf5
0065 
0066 }  // namespace trento
0067 
0068 #endif  // HDF5_UTILS_H