1 #ifndef MHO_ContainerHDF5Converter_HH__
2 #define MHO_ContainerHDF5Converter_HH__
62 fContainer =
dynamic_cast< XContainerType*
>(element);
71 if(fContainer !=
nullptr)
78 XContainerType* fContainer;
82 template<
typename XCheckType >
85 std::string class_name = MHO_ClassIdentity::ClassName< XCheckType >();
86 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XCheckType >().as_string();
93 template<
typename XCheckType = XContainerType >
94 typename std::enable_if< std::is_base_of< MHO_ScalarContainerBase, XCheckType >::value,
void >::type
95 ConstructHDF5(hid_t file_id, std::string group_prefix,
const XContainerType* obj)
97 std::string class_name = MHO_ClassIdentity::ClassName< XContainerType >();
98 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XContainerType >().as_string();
99 std::string object_uuid = obj->GetObjectUUID().as_string();
100 msg_debug(
"hdf5interface",
"creating scalar type for object with uuid: " << object_uuid << eom);
101 std::string item_group = group_prefix +
"/" + object_uuid;
103 if(H5Lexists(file_id, item_group.c_str(), H5P_DEFAULT) == 0)
105 hid_t group_id = H5Gcreate(file_id, item_group.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
108 msg_error(
"hdf5interface",
"failed to create HDF5 group: " << item_group << eom);
112 std::string name = item_group +
"/data";
114 hid_t dataset_id = -1;
115 herr_t
status = make_scalar_dataset< typename XContainerType::value_type >(
116 file_id, dataset_id, name, fContainer->GetValue());
123 template<
typename XCheckType = XContainerType >
124 typename std::enable_if< (std::is_base_of< MHO_VectorContainerBase, XCheckType >::value &&
125 !std::is_base_of< MHO_AxisBase, XCheckType >::value),
127 ConstructHDF5(hid_t file_id, std::string group_prefix,
const XContainerType* obj)
129 std::string class_name = MHO_ClassIdentity::ClassName< XContainerType >();
130 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XContainerType >().as_string();
131 std::string object_uuid = obj->GetObjectUUID().as_string();
132 msg_debug(
"hdf5interface",
"creating vector type for object with uuid: " << object_uuid << eom);
137 auto dim_array = fContainer->GetDimensionArray();
138 for(std::size_t i = 0; i < rank; i++)
140 dims[i] = dim_array[i];
142 std::string item_group = group_prefix +
"/" + object_uuid;
144 if(H5Lexists(file_id, item_group.c_str(), H5P_DEFAULT) == 0)
146 hid_t group_id = H5Gcreate(file_id, item_group.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
149 msg_error(
"hdf5interface",
"failed to create HDF5 group: " << item_group << eom);
153 std::string name = item_group +
"/data";
155 hid_t dataset_id = -1;
156 herr_t
status = make_dataset< typename XContainerType::value_type >(file_id, dataset_id, name, rank, dims,
165 template<
typename XCheckType = XContainerType >
166 typename std::enable_if< std::is_base_of< MHO_AxisBase, XCheckType >::value,
void >::type
167 ConstructHDF5(hid_t file_id, std::string group_prefix,
const XContainerType* obj)
169 std::string class_name = MHO_ClassIdentity::ClassName< XContainerType >();
170 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XContainerType >().as_string();
171 std::string object_uuid = obj->GetObjectUUID().as_string();
172 msg_debug(
"hdf5interface",
"creating axis type for object with uuid: " << object_uuid << eom);
177 auto dim_array = fContainer->GetDimensionArray();
178 for(std::size_t i = 0; i < rank; i++)
180 dims[i] = dim_array[i];
182 std::string item_group = group_prefix +
"/" + object_uuid;
184 if(H5Lexists(file_id, item_group.c_str(), H5P_DEFAULT) == 0)
186 hid_t group_id = H5Gcreate(file_id, item_group.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
189 msg_error(
"hdf5interface",
"failed to create HDF5 group: " << item_group << eom);
193 std::string name = item_group +
"/data";
195 hid_t dataset_id = -1;
196 herr_t
status = make_dataset< typename XContainerType::value_type >(file_id, dataset_id, name, rank, dims,
205 template<
typename XCheckType = XContainerType >
206 typename std::enable_if< std::is_base_of< MHO_TableContainerBase, XCheckType >::value,
void >::type
207 ConstructHDF5(hid_t file_id, std::string group_prefix,
const XContainerType* obj)
209 std::string class_name = MHO_ClassIdentity::ClassName< XContainerType >();
210 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XContainerType >().as_string();
211 std::string object_uuid = obj->GetObjectUUID().as_string();
212 msg_debug(
"hdf5interface",
"creating table type for object with uuid: " << object_uuid << eom);
215 hsize_t rank = XContainerType::rank::value;
216 hsize_t dims[XContainerType::rank::value];
217 auto dim_array = obj->GetDimensionArray();
218 for(std::size_t i = 0; i < rank; i++)
220 dims[i] = dim_array[i];
223 std::string item_group = group_prefix +
"/" + object_uuid;
225 if(H5Lexists(file_id, item_group.c_str(), H5P_DEFAULT) == 0)
227 hid_t group_id = H5Gcreate(file_id, item_group.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
230 msg_error(
"hdf5interface",
"failed to create HDF5 group: " << item_group << eom);
234 std::string name = item_group +
"/data";
236 hid_t dataset_id = -1;
237 herr_t
status = make_dataset< typename XContainerType::value_type >(file_id, dataset_id, name, rank, dims,
244 for(std::size_t idx = 0; idx < obj->GetRank(); idx++)
247 apply_at< typename XContainerType::axis_pack_tuple_type, AxisDumper >(*obj, idx, axis_dumper);
259 : fFileID(file_id), fDataSetID(ds_id), fParentName(parent), fParentMetadata(pmetadata){};
261 AxisDumper(): fFileID(-1), fDataSetID(-1), fParentName(
""){};
273 std::string class_name = MHO_ClassIdentity::ClassName< XAxisType >();
274 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< XAxisType >().as_string();
276 std::stringstream ssn;
277 ssn <<
"axis_" << fIndex;
278 std::string ax_name = ssn.str();
280 std::stringstream ss;
281 ss << fParentName <<
"/axis_";
283 std::string item_group = ss.str();
285 if(H5Lexists(fFileID, item_group.c_str(), H5P_DEFAULT) == 0)
287 hid_t group_id = H5Gcreate(fFileID, item_group.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
290 msg_error(
"hdf5interface",
"failed to create HDF5 group: " << item_group << eom);
294 std::string name = item_group +
"/data";
297 if(fParentMetadata.contains(ax_name))
299 mdata = fParentMetadata[ax_name];
301 msg_debug(
"hdf5interface",
"creating an axis object with name: " << name << eom);
304 std::size_t n =
axis.GetSize();
305 std::vector< typename XAxisType::value_type > axis_data;
306 for(std::size_t i = 0; i < n; i++)
308 axis_data.push_back(
axis.at(i));
313 hid_t dataset_id = -1;
314 herr_t
status = make_scale< typename XAxisType::value_type >(fFileID, fDataSetID, fIndex,
315 item_group, name, &axis_data, mdata);
325 std::string fParentName;
347 if(fContainer !=
nullptr)
356 std::string class_name = MHO_ClassIdentity::ClassName< MHO_ObjectTags >();
357 std::string class_uuid = MHO_ClassIdentity::GetUUIDFromClass< MHO_ObjectTags >().as_string();
359 msg_debug(
"hdf5interface",
"creating tag type for object with uuid: " << object_uuid << eom);
361 std::string item_group = group_prefix +
"/" + object_uuid;
363 if(H5Lexists(file_id, item_group.c_str(), H5P_DEFAULT) == 0)
365 hid_t group_id = H5Gcreate(file_id, item_group.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
368 msg_error(
"hdf5interface",
"failed to create HDF5 group: " << item_group << eom);
372 std::string name = item_group +
"/uuid_set";
376 std::vector< std::string > uuid_vec;
377 for(std::size_t i = 0; i < uvec.size(); i++)
379 uuid_vec.push_back(uvec[i].as_string());
383 mdata[
"class_name"] = class_name;
384 mdata[
"class_uuid"] = class_uuid;
385 hid_t dataset_id = -1;
389 if(mdata.contains(
"plot_data"))
391 std::string plot_group = item_group +
"/" +
"plot_data";
392 hid_t plot_group_id = H5Gcreate(file_id, plot_group.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
394 H5Gclose(plot_group_id);
402 if(mdata.contains(
"parameters"))
404 std::string param_group = item_group +
"/" +
"parameters";
405 hid_t param_group_id = H5Gcreate(file_id, param_group.c_str(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
407 H5Gclose(param_group_id);
420 MHO_ObjectTags* fContainer;
#define msg_debug(xKEY, xCONTENT)
Definition: MHO_Message.hh:291
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:238
int axis(char *y_axis, char *x_axis)
Definition: axis.c:22
Definition: MHO_ContainerHDF5Converter.hh:256
void SetFileID(hid_t file_id)
Definition: MHO_ContainerHDF5Converter.hh:266
~AxisDumper()
Definition: MHO_ContainerHDF5Converter.hh:262
AxisDumper(hid_t file_id, hid_t ds_id, const std::string &parent, const mho_json &pmetadata)
Definition: MHO_ContainerHDF5Converter.hh:258
void operator()(const XAxisType &axis)
Definition: MHO_ContainerHDF5Converter.hh:270
AxisDumper()
Definition: MHO_ContainerHDF5Converter.hh:261
void SetIndex(std::size_t idx)
Definition: MHO_ContainerHDF5Converter.hh:264
void SetDataSetID(hid_t ds_id)
Definition: MHO_ContainerHDF5Converter.hh:268
Converts a given ndarray-based container into a HDF5 representation - export only for now.
Definition: MHO_ContainerHDF5Converter.hh:56
MHO_ContainerHDF5Converter()
Definition: MHO_ContainerHDF5Converter.hh:58
std::enable_if< std::is_base_of< MHO_ScalarContainerBase, XCheckType >::value, void >::type ConstructHDF5(hid_t file_id, std::string group_prefix, const XContainerType *obj)
Definition: MHO_ContainerHDF5Converter.hh:95
virtual ~MHO_ContainerHDF5Converter()
Definition: MHO_ContainerHDF5Converter.hh:65
virtual void WriteToHDF5File(hid_t file_id, std::string group_prefix)
Definition: MHO_ContainerHDF5Converter.hh:69
MHO_ContainerHDF5Converter(MHO_ExtensibleElement *element)
Definition: MHO_ContainerHDF5Converter.hh:60
std::enable_if< std::is_base_of< MHO_AxisBase, XCheckType >::value, void >::type ConstructHDF5(hid_t file_id, std::string group_prefix, const XContainerType *obj)
Definition: MHO_ContainerHDF5Converter.hh:167
void ConstructHDF5(hid_t, std::string, const XCheckType *obj)
Definition: MHO_ContainerHDF5Converter.hh:83
virtual void SetObjectToConvert(MHO_Serializable *obj)
Definition: MHO_ContainerHDF5Converter.hh:67
std::enable_if<(std::is_base_of< MHO_VectorContainerBase, XCheckType >::value &&!std::is_base_of< MHO_AxisBase, XCheckType >::value), void >::type ConstructHDF5(hid_t file_id, std::string group_prefix, const XContainerType *obj)
Definition: MHO_ContainerHDF5Converter.hh:127
std::enable_if< std::is_base_of< MHO_TableContainerBase, XCheckType >::value, void >::type ConstructHDF5(hid_t file_id, std::string group_prefix, const XContainerType *obj)
Definition: MHO_ContainerHDF5Converter.hh:207
Class MHO_ExtensibleElement.
Definition: MHO_ExtensibleElement.hh:60
Definition: MHO_ContainerHDF5Converter.hh:40
virtual void SetObjectMetaData(const mho_json &mdata)
Definition: MHO_ContainerHDF5Converter.hh:47
virtual void SetObjectToConvert(MHO_Serializable *)=0
mho_json fMetaData
Definition: MHO_ContainerHDF5Converter.hh:52
virtual ~MHO_HDF5Converter()
Definition: MHO_ContainerHDF5Converter.hh:43
virtual void WriteToHDF5File(hid_t, std::string)=0
MHO_HDF5Converter()
Definition: MHO_ContainerHDF5Converter.hh:42
Class MHO_Serializable.
Definition: MHO_Serializable.hh:26
MHO_UUID GetObjectUUID() const
Getter for object uuid.
Definition: MHO_Serializable.hh:61
mho_json GetMetaDataAsJSON() const
Getter for all meta data stored in this object as a json object.
Definition: MHO_Taggable.hh:95
std::string as_string() const
Definition: MHO_UUID.hh:125
struct type_status status
Definition: fourfit3.c:53
Definition: MHO_AdhocFlagging.hh:18
herr_t make_string_vector_dataset(hid_t group_id, hid_t dataset_id, const std::string &name, const std::vector< std::string > *data, const mho_json &metadata)
Definition: MHO_HDF5Datasets.hh:261
void json_to_hdf5_attributes(const mho_json &j, hid_t parent_group)
Definition: MHO_HDF5ConversionHelpers.hh:38