HOPS
HOPS class reference
MHO_HDF5ConversionHelpers.hh
Go to the documentation of this file.
1 #ifndef MHO_HDF5ConversionHelpers_HH__
2 #define MHO_HDF5ConversionHelpers_HH__
3 
4 #include "MHO_ClassIdentity.hh"
7 
8 #include "MHO_Axis.hh"
9 #include "MHO_AxisPack.hh"
10 #include "MHO_ObjectTags.hh"
11 #include "MHO_ScalarContainer.hh"
12 #include "MHO_TableContainer.hh"
13 #include "MHO_Taggable.hh"
14 #include "MHO_VectorContainer.hh"
15 
16 #include <sstream>
17 
18 #include "hdf5.h"
19 #include "hdf5_hl.h"
20 
21 #include "MHO_NumpyTypeCode.hh"
22 #include "MHO_HDF5TypeCode.hh"
23 #include "MHO_HDF5Attributes.hh"
24 #include "MHO_HDF5Datasets.hh"
25 
26 namespace hops
27 {
28 
39 inline void json_to_hdf5_attributes(const mho_json& j, hid_t parent_group)
40 {
41  for(auto it = j.begin(); it != j.end(); ++it)
42  {
43  const std::string& key = it.key();
44  const mho_json& value = it.value();
45 
46  if( value.is_object() )
47  {
48  hid_t subgroup = H5Gcreate(parent_group, key.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
49  json_to_hdf5_attributes(value, subgroup);
50  H5Gclose(subgroup);
51  }
52  else if ( value.is_array() && value.size() != 0)
53  {
54  if( !(value.begin()->is_object()) )
55  {
56  make_attribute(key, value, parent_group);
57  }
58  else
59  {
60  hid_t array_group = H5Gcreate(parent_group, key.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
61  int idx = 0;
62  for (const auto& elem : value)
63  {
64  std::string item_name = std::to_string(idx++);
65  hid_t item_group = H5Gcreate(array_group, item_name.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
66  json_to_hdf5_attributes(elem, item_group);
67  H5Gclose(item_group);
68  }
69  H5Gclose(array_group);
70  }
71  }
72  else
73  {
74  make_attribute(key, value, parent_group);
75  }
76  }
77 }
78 
79 
80 
81 } // namespace hops
82 
83 #endif
nlohmann::json mho_json
Definition: MHO_JSONHeaderWrapper.hh:5
Definition: MHO_ChannelLabeler.hh:17
void make_attribute(const std::string &key, XValueType value, hid_t parent_dataset_id)
Definition: MHO_HDF5Attributes.hh:38
void json_to_hdf5_attributes(const mho_json &j, hid_t parent_group)
Definition: MHO_HDF5ConversionHelpers.hh:39
Definition: vex.h:175