g4tools  5.4.0
Classes | Typedefs | Functions
tools::hdf5 Namespace Reference

Classes

class  group_exists_struct
 
class  ntuple
 
class  pages
 
class  store
 

Typedefs

typedef tools::histo::histo_data< double, unsigned int, unsigned int, double > histo_data_t
 

Functions

herr_t H5LT_get_attribute_mem (hid_t obj_id, const char *attr_name, hid_t mem_type_id, void *data)
 
herr_t find_attr (hid_t loc_id, const char *name, void *op_data)
 
herr_t H5LT_find_attribute (hid_t loc_id, const char *attr_name)
 
herr_t H5LT_get_attribute_disk (hid_t loc_id, const char *attr_name, void *attr_out)
 
herr_t group_exists_visit (hid_t a_id, const char *a_name, void *a_tag)
 
bool group_exists (hid_t a_file_id, const std::string &a_name)
 
bool write_std_map_ss (hid_t a_loc, const std::string &a_name, const std::map< std::string, std::string > &a_map, unsigned int=0, unsigned int=0)
 
bool read_std_map_ss (hid_t a_loc, const std::string &a_name, std::map< std::string, std::string > &a_map, unsigned int=0, unsigned int=0)
 
bool write_hdata (hid_t a_loc, const histo_data_t &a_hdata)
 
template<class HISTO >
bool write_histo (std::ostream &a_out, hid_t a_loc, const std::string &a_name, const HISTO &a_histo)
 
template<class PROFILE >
bool write_profile (std::ostream &a_out, hid_t a_loc, const std::string &a_name, const PROFILE &a_histo)
 
bool read_hdata (hid_t a_loc, histo_data_t &a_hdata)
 
template<class HISTO >
bool read_histo (std::ostream &a_out, hid_t a_loc, const std::string &a_name, HISTO *&a_histo, bool a_verb_class=true)
 
template<class PROFILE >
bool read_profile (std::ostream &a_out, hid_t a_loc, const std::string &a_name, PROFILE *&a_histo, bool a_verb_class=true)
 
bool read_class_version (std::ostream &a_out, hid_t a_loc, const std::string &a_name, std::string &a_class, int &a_version, bool a_verbose=true)
 
bool write_header (hid_t a_file, int a_version=1)
 
bool read_header (hid_t a_file, std::string &a_writer, int &a_data_schema_version)
 
hid_t to_T_file_type (char)
 
hid_t to_T_file_type (short)
 
hid_t to_T_file_type (int)
 
hid_t to_T_file_type (tools::int64)
 
hid_t to_T_file_type (float)
 
hid_t to_T_file_type (double)
 
hid_t to_T_file_type (unsigned char)
 
hid_t to_T_file_type (unsigned short)
 
hid_t to_T_file_type (unsigned int)
 
hid_t to_T_file_type (tools::uint64)
 
hid_t to_T_mem_type (char)
 
hid_t to_T_mem_type (short)
 
hid_t to_T_mem_type (int)
 
hid_t to_T_mem_type (tools::int64)
 
hid_t to_T_mem_type (float)
 
hid_t to_T_mem_type (double)
 
hid_t to_T_mem_type (unsigned char)
 
hid_t to_T_mem_type (unsigned short)
 
hid_t to_T_mem_type (unsigned int)
 
hid_t to_T_mem_type (tools::uint64)
 
template<class T >
bool write_array (hid_t a_loc, const std::string &a_name, hid_t a_file_type, hid_t a_mem_type, unsigned int a_chunked, unsigned int a_compress, unsigned int a_size, const T a_array[])
 
template<class T >
bool write_vlen (hid_t a_loc, const std::string &a_name, hid_t a_file_type, hid_t a_mem_type, unsigned int a_chunked, unsigned int a_compress, unsigned int a_size, const T a_array[])
 
template<class T >
bool write_sub_array (hid_t a_loc, const std::string &a_name, hid_t a_file_type, hid_t a_mem_type, bool a_create, unsigned int a_chunked, unsigned int a_compress, unsigned int a_size, unsigned int a_offset, unsigned int a_number, const T a_array[])
 
template<class T >
bool write_append_array_dataset (hid_t a_dataset, hid_t, hid_t a_mem_type, unsigned int a_number, const T a_array[])
 
template<class T >
bool write_append_vlen_dataset (hid_t a_dataset, hid_t, hid_t a_mem_type, unsigned int a_number, const T a_array[])
 
template<class T >
bool write_append_array (hid_t a_loc, const std::string &a_name, hid_t a_file_type, hid_t a_mem_type, unsigned int a_number, const T a_array[])
 
template<class T >
bool read_scalar (hid_t a_loc, const std::string &a_name, hid_t a_mem_type, T &a_data)
 
template<class T >
bool read_array (hid_t a_loc, const std::string &a_name, hid_t a_mem_type, unsigned int &a_size, T *&a_array, bool a_alloc=true)
 
template<class T >
bool read_sub_array (hid_t a_loc, const std::string &a_name, hid_t a_mem_type, unsigned int a_offset, unsigned int a_number, unsigned int &a_size, T *&a_array)
 
template<class T >
bool read_sub_vlen (hid_t a_loc, const std::string &a_name, hid_t a_mem_type, unsigned int a_offset, unsigned int &a_size, T *&a_array)
 
template<class TYPE >
bool read_scalar (hid_t a_loc, const std::string &a_name, TYPE &aValue)
 
template<class T >
bool read_std_vec (hid_t a_loc, const std::string &a_name, hid_t a_mem_type, std::vector< T > &a_vec)
 
template<class TYPE >
bool read_std_vec_vec (hid_t a_loc, const std::string &a_name, hid_t a_mem_type, std::vector< std::vector< TYPE > > &a_vec_vec)
 
template<class T >
bool read_struct (hid_t a_loc, const std::string &a_name, hid_t aReadType, T &a_data)
 
template<class TYPE >
bool write_scalar (hid_t a_loc, const std::string &a_name, const TYPE &aData)
 
template<class T >
bool write_struct (hid_t a_loc, const std::string &a_name, hid_t a_create_type, hid_t aWriteType, const T &aData)
 
template<class TYPE >
bool write_array (hid_t a_loc, const std::string &a_name, unsigned int a_size, const TYPE a_array[], unsigned int a_chunked=0, unsigned int a_compress=0)
 
template<class TYPE >
bool write_vlen (hid_t a_loc, const std::string &a_name, unsigned int a_size, const TYPE a_array[], unsigned int a_chunked=0, unsigned int a_compress=0)
 
template<class T >
bool write_std_vec (hid_t a_loc, const std::string &a_name, hid_t a_file_type, hid_t a_mem_type, unsigned int a_chunked, unsigned int a_compress, const std::vector< T > &a_vec)
 
template<class TYPE >
bool write_std_vec (hid_t a_loc, const std::string &a_name, const std::vector< TYPE > &a_array, unsigned int a_chunked=0, unsigned int a_compress=0)
 
template<class TYPE >
bool write_std_vec_vec (hid_t a_loc, const std::string &a_name, const std::vector< std::vector< TYPE > > &a_vec_vec, unsigned int=0, unsigned int=0)
 
template<class TYPE >
bool write_sub_array (hid_t a_loc, const std::string &a_name, unsigned int a_size, unsigned int a_offset, unsigned int a_number, const TYPE a_array[], bool a_create=true, unsigned int a_chunked=0, unsigned int a_compress=0)
 
template<class TYPE >
bool write_append_array_dataset (hid_t a_dataset, unsigned int a_number, const TYPE a_array[])
 
template<class TYPE >
bool write_append_vlen_dataset (hid_t a_dataset, unsigned int a_number, const TYPE a_array[])
 
template<class TYPE >
bool write_append_array (hid_t a_loc, const std::string &a_name, unsigned int a_number, const TYPE a_array[])
 
template<class TYPE >
bool read_array (hid_t a_loc, const std::string &a_name, unsigned int &a_size, TYPE *&a_array)
 
template<class TYPE >
bool read_std_vec (hid_t a_loc, const std::string &a_name, std::vector< TYPE > &a_vec)
 
template<class TYPE >
bool read_std_vec_vec (hid_t a_loc, const std::string &a_name, std::vector< std::vector< TYPE > > &a_vec_vec)
 
template<class TYPE >
bool read_sub_array (hid_t a_loc, const std::string &a_name, unsigned int a_offset, unsigned int a_number, unsigned int &a_size, TYPE *&a_array)
 
template<class TYPE >
bool read_sub_vlen (hid_t a_loc, const std::string &a_name, unsigned int a_offset, unsigned int &a_size, TYPE *&a_array)
 
bool read_bool (hid_t a_loc, const std::string &a_name, bool &aValue)
 
template<class TYPE >
bool write_scalar_atb (hid_t aDS, const std::string &a_name, const TYPE &aData)
 
bool check_sizes ()
 
int failure ()
 
hid_t string_datatype (size_t aSize)
 
hid_t str_datatype ()
 
hid_t basic_mem_type (hid_t a_file_type)
 
hid_t compound_mem_type (hid_t a_file_type)
 
bool read_atb (hid_t a_id, const std::string &a_name, std::string &a_data, unsigned int aSize=100)
 
bool read_atb (hid_t a_id, const std::string &a_name, unsigned int &a_data)
 
bool read_atb (hid_t a_id, const std::string &a_name, int &a_data)
 
hid_t H5T_STD_U8XX ()
 
hid_t H5T_STD_U32XX ()
 
hid_t H5T_STD_U64XX ()
 
hid_t H5T_STD_I8XX ()
 
hid_t H5T_STD_I16XX ()
 
hid_t H5T_STD_I32XX ()
 
hid_t H5T_STD_I64XX ()
 
hid_t H5T_IEEE_F32XX ()
 
hid_t H5T_IEEE_F64XX ()
 
bool dataset_vec_size (hid_t a_loc, const std::string &a_name, hsize_t &a_size)
 
bool write_atb (hid_t a_id, const std::string &a_name, const std::string &a_data)
 
bool write_bool (hid_t a_loc, const std::string &a_name, bool a_data)
 
bool write_string (hid_t a_loc, const std::string &a_name, const std::string &a_string)
 
bool write_string_dataset (hid_t a_loc, const std::string &a_name, unsigned int a_chunked, unsigned int a_compress, const std::string &a_string)
 
bool write_string_dataset (hid_t a_loc, const std::string &a_name, const std::string &a_string, unsigned int a_chunked=0, unsigned int a_compress=0)
 
bool write_append_string_dataset (hid_t a_dataset, const std::string &a_string)
 
bool write_array_string (hid_t a_loc, const std::string &a_name, const std::vector< std::string > &a_array)
 
bool write_object (hid_t a_loc, const std::string &a_name, hid_t a_file_type, char *a_data)
 
bool read_string (hid_t a_loc, const std::string &a_name, std::string &a_string)
 
bool read_sub_string (hid_t a_loc, const std::string &a_name, unsigned int a_offset, std::string &a_string)
 
bool read_object (hid_t a_loc, const std::string &a_name, size_t &a_size, char *&a_data)
 
bool read_array_string (hid_t a_loc, const std::string &a_name, std::vector< std::string > &a_array)
 

Typedef Documentation

◆ histo_data_t

typedef tools::histo::histo_data<double,unsigned int,unsigned int,double> tools::hdf5::histo_data_t

Definition at line 53 of file h2file.

Function Documentation

◆ basic_mem_type()

hid_t tools::hdf5::basic_mem_type ( hid_t  a_file_type)
inline

Definition at line 58 of file tools.

58  {
59  H5T_class_t mclass = H5Tget_class(a_file_type);
60  size_t msize = H5Tget_size(a_file_type);
61  if(mclass==H5T_INTEGER) {
62  H5T_sign_t msign = H5Tget_sign(a_file_type);
63  if(msize==1) {
64  if(msign==H5T_SGN_NONE) {
65  return H5Tcopy(H5T_NATIVE_UCHAR);
66  } else {
67  return H5Tcopy(H5T_NATIVE_CHAR);
68  }
69  } else if(msize==4) {
70  if(msign==H5T_SGN_NONE) {
71  return H5Tcopy(H5T_NATIVE_UINT);
72  } else {
73  return H5Tcopy(H5T_NATIVE_INT);
74  }
75  } else if(msize==8) { //for osc_file::header::fDate.
76  if(msign==H5T_SGN_NONE) {
77  return H5Tcopy(H5T_NATIVE_UINT64);
78  } else {
79  return H5Tcopy(H5T_NATIVE_INT64);
80  }
81  } else {
82  return failure();
83  }
84  } else if(mclass==H5T_FLOAT) {
85  if(msize==4) {
86  return H5Tcopy(H5T_NATIVE_FLOAT);
87  } else if(msize==8) {
88  return H5Tcopy(H5T_NATIVE_DOUBLE);
89  } else {
90  return failure();
91  }
92  } else if(mclass==H5T_STRING) {
93  return H5Tcopy(a_file_type);
94  }
95 
96  return failure();
97 }

◆ check_sizes()

bool tools::hdf5::check_sizes ( )
inline

Definition at line 14 of file tools.

14  {
15  if(sizeof(bool)!=1) return false;
16  if(sizeof(char)!=1) return false;
17  if(sizeof(short)!=2) return false;
18  if(sizeof(int)!=4) return false;
19  if(sizeof(float)!=4) return false;
20  if(sizeof(double)!=8) return false;
21  return true;
22 }

◆ compound_mem_type()

hid_t tools::hdf5::compound_mem_type ( hid_t  a_file_type)
inline

Definition at line 106 of file tools.

106  {
107  // FIXME : In principle H5T_get_native_type should do the job but it crashes.
108 
109  H5T_class_t t_class = H5Tget_class(a_file_type);
110  if(t_class!=H5T_COMPOUND) return failure();
111 
112  size_t sz = H5Tget_size(a_file_type);
113  //printf("debug : compound_mem_type : sz %lu\n",sz);
114 
115  hid_t mem_type = ::H5Tcreate(H5T_COMPOUND,sz);
116  if(mem_type<0) return failure();
117 
118  //FIXME : WARNING : is order the booked order ?
119 
120  int mn = H5Tget_nmembers(a_file_type);
121  std::vector<unsigned int> szs(mn);
122  //printf("debug : members : %d\n",mn);
123  for(int index=0;index<mn;index++) {
124  char* mname = H5Tget_member_name(a_file_type,index);
125  size_t moffset = H5Tget_member_offset(a_file_type,index);
126  hid_t mtype = H5Tget_member_type(a_file_type,index);
127  //printf("debug : members : %d (%d) : %s : begin\n",index,mn,mname);
128 
129  {H5T_class_t mclass = H5Tget_class(mtype);
130  if( (mclass==H5T_INTEGER) ||
131  (mclass==H5T_STRING) ||
132  (mclass==H5T_FLOAT) ) {
133  hid_t mmem_type = basic_mem_type(mtype);
134  if(mmem_type<0) {
135  ::H5Tclose(mtype);
136  if(mname) tools_H5free_memory(mname);
137  ::H5Tclose(mem_type);
138  return failure();
139  }
140  if(H5Tinsert(mem_type,mname,moffset,mmem_type)<0) {
141  ::H5Tclose(mmem_type);
142  ::H5Tclose(mtype);
143  if(mname) tools_H5free_memory(mname);
144  ::H5Tclose(mem_type);
145  return failure();
146  }
147  ::H5Tclose(mmem_type);
148 
149  } else if(mclass==H5T_ARRAY) {
150  int dimn = ::H5Tget_array_ndims(mtype); //Should be 1;
151  hsize_t* dims = new hsize_t[dimn];
152  int* perms = new int[dimn];
153  if(tools_H5Tget_array_dims(mtype,dims,perms)<0) {
154  delete [] dims;
155  delete [] perms;
156  ::H5Tclose(mtype);
157  if(mname) tools_H5free_memory(mname);
158  ::H5Tclose(mem_type);
159  return failure();
160  }
161  hid_t base_type = H5Tget_super(mtype);
162  if(base_type<0) {
163  delete [] dims;
164  delete [] perms;
165  ::H5Tclose(mtype);
166  if(mname) tools_H5free_memory(mname);
167  ::H5Tclose(mem_type);
168  return failure();
169  }
170  hid_t mmem_type = basic_mem_type(base_type);
171  if(mmem_type<0) {
172  delete [] dims;
173  delete [] perms;
174  ::H5Tclose(base_type);
175  ::H5Tclose(mtype);
176  if(mname) tools_H5free_memory(mname);
177  ::H5Tclose(mem_type);
178  return failure();
179  }
180  ::H5Tclose(base_type);
181  hid_t array_type = tools_H5Tarray_create(mmem_type,dimn,dims,perms);
182  delete [] dims;
183  delete [] perms;
184  if(array_type<0) {
185  ::H5Tclose(mmem_type);
186  ::H5Tclose(mtype);
187  if(mname) tools_H5free_memory(mname);
188  ::H5Tclose(mem_type);
189  return failure();
190  }
191  ::H5Tclose(mmem_type);
192 
193  if(H5Tinsert(mem_type,mname,moffset,array_type)<0) {
194  ::H5Tclose(array_type);
195  ::H5Tclose(mtype);
196  if(mname) tools_H5free_memory(mname);
197  ::H5Tclose(mem_type);
198  return failure();
199  }
200  ::H5Tclose(array_type);
201 
202  } else if(mclass==H5T_COMPOUND) {
203  hid_t mmem_type = compound_mem_type(mtype);
204  if(mem_type<0) {
205  ::H5Tclose(mtype);
206  if(mname) tools_H5free_memory(mname);
207  ::H5Tclose(mem_type);
208  return failure();
209  }
210  if(H5Tinsert(mem_type,mname,moffset,mmem_type)<0) {
211  ::H5Tclose(mmem_type);
212  ::H5Tclose(mtype);
213  if(mname) tools_H5free_memory(mname);
214  ::H5Tclose(mem_type);
215  return failure();
216  }
217  ::H5Tclose(mmem_type);
218  } else {
219  ::H5Tclose(mtype);
220  if(mname) tools_H5free_memory(mname);
221  ::H5Tclose(mem_type);
222  return failure();
223  }}
224  ::H5Tclose(mtype);
225  //printf("debug : compound_mem_type : %d (%d) : %s : end\n",index,mn,mname);
226  if(mname) tools_H5free_memory(mname);
227  }
228 
229  return mem_type;
230 }

◆ dataset_vec_size()

bool tools::hdf5::dataset_vec_size ( hid_t  a_loc,
const std::string &  a_name,
hsize_t &  a_size 
)
inline

Definition at line 276 of file tools.

276  {
277  hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
278  if(dataset<0) {
279  a_size = 0;
280  return false; // data set not found.
281  }
282 
283  hid_t file_space = H5Dget_space(dataset);
284  if(file_space<0) {
285  ::H5Dclose(dataset);
286  a_size = 0;
287  return false;
288  }
289 
290  int dimn = H5Sget_simple_extent_ndims(file_space);
291  if(dimn<0) {
292  ::H5Sclose(file_space);
293  ::H5Dclose(dataset);
294  a_size = 0;
295  return false;
296  }
297  if(dimn!=1) {
298  ::H5Sclose(file_space);
299  ::H5Dclose(dataset);
300  a_size = 0;
301  return false;
302  }
303  //printf("debug : read dimn %d\n",dimn);
304 
305  hsize_t dims[1];
306  {if(H5Sget_simple_extent_dims(file_space,dims,NULL)<0) {
307  ::H5Sclose(file_space);
308  ::H5Dclose(dataset);
309  a_size = 0;
310  return false;
311  }}
312 
313  ::H5Sclose(file_space);
314  ::H5Dclose(dataset);
315 
316  a_size = dims[0];
317  return true;
318 }

◆ failure()

int tools::hdf5::failure ( )
inline

Definition at line 24 of file tools.

24 {return -1;}

◆ find_attr()

herr_t tools::hdf5::find_attr ( hid_t  loc_id,
const char *  name,
void *  op_data 
)
inline

Definition at line 27 of file atb.

27  {
28  int ret = 0;
29  char *attr_name = (char*)op_data;
30  if( ::strcmp( name, attr_name ) == 0 ) ret = 1;
31  (void)loc_id;
32  return ret;
33 }

◆ group_exists()

bool tools::hdf5::group_exists ( hid_t  a_file_id,
const std::string &  a_name 
)
inline

Definition at line 41 of file group_exists.

41  {
42  group_exists_struct visitor(a_name);
43  ::H5Giterate(a_file_id,".",NULL,group_exists_visit,&visitor);
44  return visitor.m_found;
45 }

◆ group_exists_visit()

herr_t tools::hdf5::group_exists_visit ( hid_t  a_id,
const char *  a_name,
void *  a_tag 
)
inline

Definition at line 26 of file group_exists.

26  { //a_id = parent of a_name object.
27  group_exists_struct* visitor = (group_exists_struct*)a_tag;
28  H5G_stat_t statbuf;
29  ::H5Gget_objinfo(a_id,a_name,0,&statbuf);
30  switch(statbuf.type) {
31  case H5G_GROUP:{
32  if(a_name==visitor->m_what) {visitor->m_found=true;return 0;} //found
33  //::H5Giterate(a_id,a_name,NULL,group_exists_visit,visitor);
34  }break;
35  default:
36  break;
37  }
38  return 0;
39 }

◆ H5LT_find_attribute()

herr_t tools::hdf5::H5LT_find_attribute ( hid_t  loc_id,
const char *  attr_name 
)
inline

Definition at line 35 of file atb.

35  {
36  unsigned int attr_num;
37  attr_num = 0;
38  return tools_H5Aiterate( loc_id, &attr_num, find_attr, (void *)attr_name );
39 }

◆ H5LT_get_attribute_disk()

herr_t tools::hdf5::H5LT_get_attribute_disk ( hid_t  loc_id,
const char *  attr_name,
void *  attr_out 
)
inline

Definition at line 41 of file atb.

41  {
42  hid_t attr_id;
43  if ( ( attr_id = ::H5Aopen_name( loc_id, attr_name ) ) < 0 ) return -1;
44 
45  hid_t attr_type;
46  if ( (attr_type = ::H5Aget_type( attr_id )) < 0 ) {
47  ::H5Tclose( attr_type );
48  ::H5Aclose( attr_id );
49  return -1;
50  }
51 
52  if ( ::H5Aread( attr_id, attr_type, attr_out ) < 0 ) {
53  ::H5Tclose( attr_type );
54  ::H5Aclose( attr_id );
55  return -1;
56  }
57 
58  if ( ::H5Tclose( attr_type ) < 0 ) {
59  ::H5Tclose( attr_type );
60  ::H5Aclose( attr_id );
61  return -1;
62  }
63 
64  if ( ::H5Aclose( attr_id ) < 0 ) return -1;
65 
66  return 0;
67 
68 }

◆ H5LT_get_attribute_mem()

herr_t tools::hdf5::H5LT_get_attribute_mem ( hid_t  obj_id,
const char *  attr_name,
hid_t  mem_type_id,
void *  data 
)
inline

Definition at line 16 of file atb.

16  {
17  hid_t attr_id;
18  if ( ( attr_id = ::H5Aopen_name( obj_id, attr_name ) ) < 0 ) return -1;
19  if ( ::H5Aread( attr_id, mem_type_id, data ) < 0 ) {
20  ::H5Aclose( attr_id );
21  return -1;
22  }
23  if ( ::H5Aclose( attr_id ) < 0 ) return -1;
24  return 0;
25 }

◆ H5T_IEEE_F32XX()

hid_t tools::hdf5::H5T_IEEE_F32XX ( )
inline

Definition at line 273 of file tools.

273 {return H5T_IEEE_F32LE;}

◆ H5T_IEEE_F64XX()

hid_t tools::hdf5::H5T_IEEE_F64XX ( )
inline

Definition at line 274 of file tools.

274 {return H5T_IEEE_F64LE;}

◆ H5T_STD_I16XX()

hid_t tools::hdf5::H5T_STD_I16XX ( )
inline

Definition at line 270 of file tools.

270 {return H5T_STD_I16LE;}

◆ H5T_STD_I32XX()

hid_t tools::hdf5::H5T_STD_I32XX ( )
inline

Definition at line 271 of file tools.

271 {return H5T_STD_I32LE;}

◆ H5T_STD_I64XX()

hid_t tools::hdf5::H5T_STD_I64XX ( )
inline

Definition at line 272 of file tools.

272 {return H5T_STD_I64LE;}

◆ H5T_STD_I8XX()

hid_t tools::hdf5::H5T_STD_I8XX ( )
inline

Definition at line 269 of file tools.

269 {return H5T_STD_I8LE;}

◆ H5T_STD_U32XX()

hid_t tools::hdf5::H5T_STD_U32XX ( )
inline

Definition at line 267 of file tools.

267 {return H5T_STD_U32LE;}

◆ H5T_STD_U64XX()

hid_t tools::hdf5::H5T_STD_U64XX ( )
inline

Definition at line 268 of file tools.

268 {return H5T_STD_U64LE;}

◆ H5T_STD_U8XX()

hid_t tools::hdf5::H5T_STD_U8XX ( )
inline

Definition at line 266 of file tools.

266 {return H5T_STD_U8LE;}

◆ read_array() [1/2]

template<class T >
bool tools::hdf5::read_array ( hid_t  a_loc,
const std::string &  a_name,
hid_t  a_mem_type,
unsigned int &  a_size,
T *&  a_array,
bool  a_alloc = true 
)
inline

Definition at line 501 of file T_tools.

501  {
502  hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
503  if(dataset<0) {
504  a_size = 0;
505  if(a_alloc) a_array = 0;
506  return false; // data set not found.
507  }
508 
509  hid_t file_space = H5Dget_space(dataset);
510  if(file_space<0) {
511  ::H5Dclose(dataset);
512  a_size = 0;
513  if(a_alloc) a_array = 0;
514  return false;
515  }
516 
517  {int dimn = H5Sget_simple_extent_ndims(file_space);
518  if(dimn<0) {
519  ::H5Sclose(file_space);
520  ::H5Dclose(dataset);
521  a_size = 0;
522  if(a_alloc) a_array = 0;
523  return false;
524  }
525  if(dimn!=1) {
526  ::H5Sclose(file_space);
527  ::H5Dclose(dataset);
528  a_size = 0;
529  if(a_alloc) a_array = 0;
530  return false;
531  }
532  //printf("debug : read dimn %d\n",dimn);
533  }
534 
535  hsize_t dims[1];
536  {if(H5Sget_simple_extent_dims(file_space,dims,NULL)<0) {
537  ::H5Sclose(file_space);
538  ::H5Dclose(dataset);
539  a_size = 0;
540  if(a_alloc) a_array = 0;
541  return false;
542  }}
543 
544  a_size = (unsigned int)dims[0];
545  if(!a_size) {
546  ::H5Sclose(file_space);
547  ::H5Dclose(dataset);
548  a_size = 0;
549  if(a_alloc) a_array = 0;
550  return true; //It is ok.
551  }
552 
553  hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
554  if(mem_space<0) {
555  ::H5Sclose(file_space);
556  ::H5Dclose(dataset);
557  a_size = 0;
558  if(a_alloc) a_array = 0;
559  return false;
560  }
561 
562  if(a_alloc) a_array = new T[a_size];
563  if(H5Dread(dataset,a_mem_type,mem_space,file_space,H5P_DEFAULT,a_array)<0) {
564  if(a_alloc) delete [] a_array;
565  ::H5Sclose(mem_space);
566  ::H5Sclose(file_space);
567  ::H5Dclose(dataset);
568  a_size = 0;
569  if(a_alloc) a_array = 0;
570  return false;
571  }
572 
573 
574  ::H5Sclose(mem_space);
575  ::H5Sclose(file_space);
576  ::H5Dclose(dataset);
577 
578  return true;
579 }

◆ read_array() [2/2]

template<class TYPE >
bool tools::hdf5::read_array ( hid_t  a_loc,
const std::string &  a_name,
unsigned int &  a_size,
TYPE *&  a_array 
)
inline

Definition at line 1233 of file T_tools.

1233  {
1234  return read_array<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_size,a_array);
1235 }

◆ read_array_string()

bool tools::hdf5::read_array_string ( hid_t  a_loc,
const std::string &  a_name,
std::vector< std::string > &  a_array 
)
inline

Definition at line 995 of file tools.

995  {
996  a_array.clear();
997  hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
998  if(dataset<0) return false;
999 
1000  hid_t file_type = H5Dget_type(dataset);
1001  if(file_type<0) {
1002  ::H5Dclose(dataset);
1003  return false;
1004  }
1005 
1006  H5T_class_t t_class = H5Tget_class(file_type);
1007  if(t_class!=H5T_STRING) {
1008  ::H5Tclose(file_type);
1009  ::H5Dclose(dataset);
1010  return false;
1011  }
1012 
1013  size_t sz = H5Tget_size(file_type);
1014  ::H5Tclose(file_type);
1015  if(!sz) {
1016  ::H5Dclose(dataset);
1017  return false;
1018  }
1019 
1020  // We could have use file_type since, for string,
1021  // file type is the same than memory type.
1022  hid_t mem_type = string_datatype(sz);
1023  if(mem_type<0) {
1024  ::H5Dclose(dataset);
1025  return false;
1026  }
1027 
1028  char* buffer = new char[sz];
1029  herr_t stat = H5Dread(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,buffer);
1030  ::H5Tclose(mem_type);
1031  ::H5Dclose(dataset);
1032  if(stat<0) {
1033  delete [] buffer;
1034  return false;
1035  }
1036 
1037  if(!tools::buf2strings(sz,buffer,a_array)) {
1038  delete [] buffer;
1039  return false;
1040  }
1041 
1042  delete [] buffer;
1043  return true;
1044 }

◆ read_atb() [1/3]

bool tools::hdf5::read_atb ( hid_t  a_id,
const std::string &  a_name,
int &  a_data 
)
inline

Definition at line 260 of file tools.

260  {
261  if(!H5LT_find_attribute(a_id,a_name.c_str())) {a_data=0;return false;}
262  if(H5LT_get_attribute_mem(a_id,a_name.c_str(),H5T_NATIVE_INT,&a_data)<0) {a_data=0;return false;}
263  return true;
264 }

◆ read_atb() [2/3]

bool tools::hdf5::read_atb ( hid_t  a_id,
const std::string &  a_name,
std::string &  a_data,
unsigned int  aSize = 100 
)
inline

Definition at line 240 of file tools.

240  {
241  // From H5LT.c/H5LTget_attribute_string.
242  if(!H5LT_find_attribute(a_id,a_name.c_str())) {a_data.clear();return false;}
243  char* b = new char[aSize];
244  if(H5LT_get_attribute_disk(a_id,a_name.c_str(),b)<0) {
245  delete [] b;
246  a_data.clear();
247  return false;
248  }
249  a_data = std::string(b);
250  delete [] b;
251  return true;
252 }

◆ read_atb() [3/3]

bool tools::hdf5::read_atb ( hid_t  a_id,
const std::string &  a_name,
unsigned int &  a_data 
)
inline

Definition at line 254 of file tools.

254  {
255  if(!H5LT_find_attribute(a_id,a_name.c_str())) {a_data=0;return false;}
256  if(H5LT_get_attribute_mem(a_id,a_name.c_str(),H5T_NATIVE_UINT,&a_data)<0) {a_data=0;return false;}
257  return true;
258 }

◆ read_bool()

bool tools::hdf5::read_bool ( hid_t  a_loc,
const std::string &  a_name,
bool &  aValue 
)
inline

Definition at line 1264 of file T_tools.

1264  {
1265  unsigned char value = 0;
1266  if(!read_scalar<unsigned char>(a_loc,a_name,H5T_NATIVE_UCHAR,value)) {
1267  aValue = false;
1268  return false;
1269  }
1270  if((value!=0) && (value!=1)) {
1271  aValue = false;
1272  return false;
1273  }
1274  aValue = (value==1?true:false);
1275  return true;
1276 }

◆ read_class_version()

bool tools::hdf5::read_class_version ( std::ostream &  a_out,
hid_t  a_loc,
const std::string &  a_name,
std::string &  a_class,
int &  a_version,
bool  a_verbose = true 
)
inline

Definition at line 309 of file h2file.

310  {
311  hid_t id = tools_H5Gopen(a_loc,a_name.c_str());
312  if(id<0) {
313  if(a_verbose) a_out << "tools::hdf5::read_class_version : can't open group." << std::endl;
314  a_class.clear();
315  a_version = 0;
316  return false;
317  }
318 
319  if(!read_atb(id,"class",a_class)) {
320  if(a_verbose) a_out << "tools::hdf5::read_class_version : can't read_atb() class." << std::endl;
321  ::H5Gclose(id);
322  a_class.clear();
323  a_version = 0;
324  return false;
325  }
326 
327  if(!read_atb(id,"version",a_version)) {
328  if(a_verbose) a_out << "tools::hdf5::read_class_version : read_atb version failed." << std::endl;
329  ::H5Gclose(id);
330  a_class.clear();
331  a_version = 0;
332  return false;
333  }
334 
335  ::H5Gclose(id);
336  return true;
337 }

◆ read_hdata()

bool tools::hdf5::read_hdata ( hid_t  a_loc,
histo_data_t a_hdata 
)
inline

Definition at line 170 of file h2file.

170  {
171  if(!read_string(a_loc,"title",a_hdata.m_title)) return false;
172  if(!read_scalar<unsigned int>(a_loc,"dimension",a_hdata.m_dimension)) return false;
173  if(!read_scalar<unsigned int>(a_loc,"bin_number",a_hdata.m_bin_number)) return false;
174 
175  if(!read_std_vec<unsigned int>(a_loc,"bin_entries",a_hdata.m_bin_entries)) return false;
176  if(!read_std_vec<double>(a_loc,"bin_Sw",a_hdata.m_bin_Sw)) return false;
177  if(!read_std_vec<double>(a_loc,"bin_Sw2",a_hdata.m_bin_Sw2)) return false;
178 
179  if(!read_std_vec_vec<double>(a_loc,"bin_Sxw",a_hdata.m_bin_Sxw)) return false;
180  if(!read_std_vec_vec<double>(a_loc,"bin_Sx2w",a_hdata.m_bin_Sx2w)) return false;
181 
182  // axes :
183  {a_hdata.m_axes.resize(a_hdata.m_dimension);
184  std::string name,saxis;
185  for(unsigned int iaxis=0;iaxis<a_hdata.m_dimension;iaxis++) {
186  tools::num2s(iaxis,saxis);
187  name = "axis_"+saxis+"_";
188  histo_data_t::axis_t& _axis = a_hdata.m_axes[iaxis];
189  if(!read_scalar<unsigned int>(a_loc,name+"offset",_axis.m_offset)) return false;
190  if(!read_scalar<unsigned int>(a_loc,name+"number_of_bins",_axis.m_number_of_bins)) return false;
191  if(!read_scalar<double>(a_loc,name+"minimum_value",_axis.m_minimum_value)) return false;
192  if(!read_scalar<double>(a_loc,name+"maximum_value",_axis.m_maximum_value)) return false;
193  if(!read_scalar<bool>(a_loc,name+"fixed",_axis.m_fixed)) return false;
194  if(!read_scalar<double>(a_loc,name+"bin_width",_axis.m_bin_width)) return false;
195  if(!read_std_vec<double>(a_loc,name+"edges",_axis.m_edges)) return false;
196  }}
197 
198  // etc :
199  if(!read_std_vec<double>(a_loc,"in_range_plane_Sxyw",a_hdata.m_in_range_plane_Sxyw)) return false;
200 
201  // m_annotations :
202  if(!read_std_map_ss(a_loc,"annotations",a_hdata.m_annotations)) return false;
203 
204  return true;
205 }

◆ read_header()

bool tools::hdf5::read_header ( hid_t  a_file,
std::string &  a_writer,
int &  a_data_schema_version 
)
inline

Definition at line 22 of file header.

22  {
23  hid_t header = tools_H5Gopen(a_file,"header");
24  if(header<0) {a_writer.clear();a_data_schema_version=0;return false;}
25  if(!read_atb(header,"writer",a_writer)) {::H5Gclose(header);a_writer.clear();a_data_schema_version=0;return false;}
26  if(!read_atb(header,"data_schema_version",a_data_schema_version)) {
27  ::H5Gclose(header);
28  a_writer.clear();a_data_schema_version=0;
29  return false;
30  }
31  ::H5Gclose(header);
32  return true;
33 }

◆ read_histo()

template<class HISTO >
bool tools::hdf5::read_histo ( std::ostream &  a_out,
hid_t  a_loc,
const std::string &  a_name,
HISTO *&  a_histo,
bool  a_verb_class = true 
)
inline

Definition at line 208 of file h2file.

208  {
209  a_histo = 0;
210 
211  //if(::H5Gget_objinfo(a_loc,a_name.c_str(),0,NULL)<0) {return false;}
212 
213  hid_t histo = tools_H5Gopen(a_loc,a_name.c_str());
214  if(histo<0) {
215  a_out << "tools::hdf5::read_histo : can't open group." << std::endl;
216  return false;
217  }
218 
219  std::string sclass;
220  if(!read_atb(histo,"class",sclass)) {
221  a_out << "tools::hdf5::read_histo : can't read_atb() class." << std::endl;
222  ::H5Gclose(histo);
223  return false;
224  }
225 
226  if(sclass!=HISTO::s_class()) {
227  if(a_verb_class) {
228  a_out << "tools::hdf5::read_histo :"
229  << " read class " << tools::sout(sclass) << " not " << tools::sout(HISTO::s_class()) << std::endl;
230  }
231  ::H5Gclose(histo);
232  return false;
233  }
234 
235  int v;
236  if(!read_atb(histo,"version",v)) {
237  a_out << "tools::hdf5::read_histo : read_atb version failed." << std::endl;
238  ::H5Gclose(histo);
239  return false;
240  }
241 
242  histo_data_t hdata;
243 
244  if(!read_hdata(histo,hdata)) {::H5Gclose(histo);return false;}
245 
246  ::H5Gclose(histo);
247 
248  hdata.update_fast_getters();
249 
250  a_histo = new HISTO;
251  a_histo->copy_from_data(hdata);
252  a_histo->not_a_profile(); //trick to be sure to use this function on an histo and not a profile.
253  return true;
254 }

◆ read_object()

bool tools::hdf5::read_object ( hid_t  a_loc,
const std::string &  a_name,
size_t &  a_size,
char *&  a_data 
)
inline

Definition at line 909 of file tools.

909  {
910  hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
911  if(dataset<0) {
912  a_size = 0;
913  a_data = 0;
914  return false;
915  }
916 
917  hid_t file_type = H5Dget_type(dataset);
918  if(file_type<0) {
919  ::H5Dclose(dataset);
920  a_size = 0;
921  a_data = 0;
922  return false;
923  }
924 
925  H5T_class_t t_class = H5Tget_class(file_type);
926  if(t_class!=H5T_COMPOUND) {
927  ::H5Tclose(file_type);
928  ::H5Dclose(dataset);
929  a_size = 0;
930  a_data = 0;
931  return false;
932  }
933 
934  size_t sz = H5Tget_size(file_type);
935  if(!sz) {
936  ::H5Tclose(file_type);
937  ::H5Dclose(dataset);
938  a_size = 0;
939  a_data = 0;
940  return false;
941  }
942 
943  hid_t mem_type = compound_mem_type(file_type);
944  if(mem_type<0) {
945  ::H5Tclose(file_type);
946  ::H5Dclose(dataset);
947  a_size = 0;
948  a_data = 0;
949  return false;
950  }
951 
952  ::H5Tclose(file_type);
953 
954  hid_t dataspace = H5Dget_space(dataset);
955  if(dataspace<0) {
956  ::H5Tclose(mem_type);
957  ::H5Dclose(dataset);
958  a_size = 0;
959  a_data = 0;
960  return false;
961  }
962 
963  hid_t scalar = ::H5Screate(H5S_SCALAR);
964  if(scalar<0) {
965  ::H5Sclose(dataspace);
966  ::H5Tclose(mem_type);
967  ::H5Dclose(dataset);
968  a_size = 0;
969  a_data = 0;
970  return false;
971  }
972 
973  char* buffer = new char[sz];
974  if(H5Dread(dataset,mem_type,scalar,dataspace,H5P_DEFAULT,buffer)<0) {
975  delete [] buffer;
976  ::H5Sclose(scalar);
977  ::H5Sclose(dataspace);
978  ::H5Tclose(mem_type);
979  ::H5Dclose(dataset);
980  a_size = 0;
981  a_data = 0;
982  return false;
983  }
984 
985  ::H5Sclose(scalar);
986  ::H5Sclose(dataspace);
987  ::H5Tclose(mem_type);
988  ::H5Dclose(dataset);
989 
990  a_size = sz;
991  a_data = buffer;
992  return true;
993 }

◆ read_profile()

template<class PROFILE >
bool tools::hdf5::read_profile ( std::ostream &  a_out,
hid_t  a_loc,
const std::string &  a_name,
PROFILE *&  a_histo,
bool  a_verb_class = true 
)
inline

Definition at line 257 of file h2file.

257  {
258  a_histo = 0;
259 
260  hid_t histo = tools_H5Gopen(a_loc,a_name.c_str());
261  if(histo<0) {
262  a_out << "tools::hdf5::read_profile : can't open group." << std::endl;
263  return false;
264  }
265 
266  std::string sclass;
267  if(!read_atb(histo,"class",sclass)) {
268  a_out << "tools::hdf5::read_profile : can't read_atb() class." << std::endl;
269  ::H5Gclose(histo);
270  return false;
271  }
272 
273  if(sclass!=PROFILE::s_class()) {
274  if(a_verb_class) {
275  a_out << "tools::hdf5::read_profile :"
276  << " read class " << tools::sout(sclass) << " not " << tools::sout(PROFILE::s_class()) << std::endl;
277  }
278  ::H5Gclose(histo);
279  return false;
280  }
281 
282  int v;
283  if(!read_atb(histo,"version",v)) {
284  a_out << "tools::hdf5::read_profile : read_atb version failed." << std::endl;
285  ::H5Gclose(histo);
286  return false;
287  }
288 
289  typename PROFILE::pd_t pdata;
290 
291  if(!read_hdata(histo,pdata)) {::H5Gclose(histo);return false;}
292 
293  if(!read_bool(histo,"is_profile",pdata.m_is_profile)) {::H5Gclose(histo);return false;}
294  if(!read_std_vec<double>(histo,"bin_Svw",pdata.m_bin_Svw)) {::H5Gclose(histo);return false;}
295  if(!read_std_vec<double>(histo,"bin_Sv2w",pdata.m_bin_Sv2w)) {::H5Gclose(histo);return false;}
296  if(!read_bool(histo,"cut_v",pdata.m_cut_v)) {::H5Gclose(histo);return false;}
297  if(!read_scalar<double>(histo,"min_v",pdata.m_min_v)) {::H5Gclose(histo);return false;}
298  if(!read_scalar<double>(histo,"max_v",pdata.m_max_v)) {::H5Gclose(histo);return false;}
299 
300  ::H5Gclose(histo);
301 
302  pdata.update_fast_getters();
303 
304  a_histo = new PROFILE;
305  a_histo->copy_from_data(pdata);
306  return true;
307 }

◆ read_scalar() [1/2]

template<class T >
bool tools::hdf5::read_scalar ( hid_t  a_loc,
const std::string &  a_name,
hid_t  a_mem_type,
T &  a_data 
)
inline

Definition at line 469 of file T_tools.

469  {
470  hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
471  if(dataset<0) return false;
472 
473  hid_t file_space = H5Dget_space(dataset);
474  if(file_space<0) {
475  ::H5Dclose(dataset);
476  return false;
477  }
478 
479  hid_t mem_space = ::H5Screate(H5S_SCALAR);
480  if(mem_space<0) {
481  ::H5Sclose(file_space);
482  ::H5Dclose(dataset);
483  return false;
484  }
485 
486  if(H5Dread(dataset,a_mem_type,mem_space,file_space,H5P_DEFAULT,&a_data)<0) {
487  ::H5Sclose(mem_space);
488  ::H5Sclose(file_space);
489  ::H5Dclose(dataset);
490  return false;
491  }
492 
493  ::H5Sclose(mem_space);
494  ::H5Sclose(file_space);
495  ::H5Dclose(dataset);
496 
497  return true;
498 }

◆ read_scalar() [2/2]

template<class TYPE >
bool tools::hdf5::read_scalar ( hid_t  a_loc,
const std::string &  a_name,
TYPE &  aValue 
)
inline

Definition at line 922 of file T_tools.

922  {
923  return read_scalar<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),aValue);
924 }

◆ read_std_map_ss()

bool tools::hdf5::read_std_map_ss ( hid_t  a_loc,
const std::string &  a_name,
std::map< std::string, std::string > &  a_map,
unsigned int  = 0,
unsigned int  = 0 
)
inline

Definition at line 38 of file h2file.

39  {
40  a_map.clear();
41  tools::uint64 sz;
42  if(!read_scalar<tools::uint64>(a_loc,a_name+"_size",sz)) return false;
43  std::string scount,key,value;
44  for(tools::uint64 count=0;count<sz;count++) {
45  tools::num2s(count,scount);
46  if(!read_string(a_loc,a_name+"_elem_"+scount+"_first",key)) return false;
47  if(!read_string(a_loc,a_name+"_elem_"+scount+"_secon",value)) return false;
48  a_map[key] = value;
49  }
50  return true;
51 }

◆ read_std_vec() [1/2]

template<class T >
bool tools::hdf5::read_std_vec ( hid_t  a_loc,
const std::string &  a_name,
hid_t  a_mem_type,
std::vector< T > &  a_vec 
)
inline

Definition at line 927 of file T_tools.

927  {
928  tools::uint64 sz;
929  if(!read_scalar<tools::uint64>(a_loc,a_name+"_size",sz)) return false;
930  if(!sz) {a_vec.clear();return true;} //it is ok.
931  a_vec.resize((size_t)sz);
932  T* data = tools::vec_data(a_vec);
933  unsigned int _sz;
934  if(!read_array(a_loc,a_name,a_mem_type,_sz,data,false)) return false; //false = do not alloc.
935  if(tools::uint64(_sz)!=sz) {a_vec.clear();return false;}
936  return true;
937 }

◆ read_std_vec() [2/2]

template<class TYPE >
bool tools::hdf5::read_std_vec ( hid_t  a_loc,
const std::string &  a_name,
std::vector< TYPE > &  a_vec 
)
inline

Definition at line 1243 of file T_tools.

1243  {
1244  return read_std_vec<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_vec);
1245 }

◆ read_std_vec_vec() [1/2]

template<class TYPE >
bool tools::hdf5::read_std_vec_vec ( hid_t  a_loc,
const std::string &  a_name,
hid_t  a_mem_type,
std::vector< std::vector< TYPE > > &  a_vec_vec 
)
inline

Definition at line 940 of file T_tools.

940  {
941  tools::uint64 sz;
942  if(!read_scalar<tools::uint64>(a_loc,a_name+"_size",sz)) {a_vec_vec.clear();return false;}
943  a_vec_vec.resize((size_t)sz);
944  std::string scount;
945  for(size_t count=0;count<(size_t)sz;count++) {
946  tools::num2s(tools::uint64(count),scount);
947  if(!read_std_vec<TYPE>(a_loc,a_name+"_elem_"+scount,a_mem_type,a_vec_vec[count])) {a_vec_vec.clear();return false;}
948  }
949  return true;
950 }

◆ read_std_vec_vec() [2/2]

template<class TYPE >
bool tools::hdf5::read_std_vec_vec ( hid_t  a_loc,
const std::string &  a_name,
std::vector< std::vector< TYPE > > &  a_vec_vec 
)
inline

Definition at line 1248 of file T_tools.

1248  {
1249  return read_std_vec_vec<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_vec_vec);
1250 }

◆ read_string()

bool tools::hdf5::read_string ( hid_t  a_loc,
const std::string &  a_name,
std::string &  a_string 
)
inline

Definition at line 712 of file tools.

712  {
713  // From H5LTread_dataset_string.
714  hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
715  if(dataset<0) {
716  a_string.clear();
717  return false; // data set not found.
718  }
719 
720  hid_t file_type = H5Dget_type(dataset);
721  if(file_type<0) {
722  ::H5Dclose(dataset);
723  a_string.clear();
724  return false;
725  }
726 
727  H5T_class_t t_class = H5Tget_class(file_type);
728  if(t_class!=H5T_STRING) {
729  ::H5Tclose(file_type);
730  ::H5Dclose(dataset);
731  a_string.clear();
732  return false;
733  }
734 
735  size_t sz = H5Tget_size(file_type);
736  ::H5Tclose(file_type);
737  if(!sz) {
738  ::H5Dclose(dataset);
739  a_string.clear();
740  return false;
741  }
742 
743  // We could have use file_type since, for string,
744  // file type is the same than memory type.
745  hid_t mem_type = string_datatype(sz);
746  if(mem_type<0) {
747  ::H5Dclose(dataset);
748  a_string.clear();
749  return false;
750  }
751 
752  char* buff = new char[sz];
753  herr_t stat = H5Dread(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,buff);
754  ::H5Tclose(mem_type);
755  ::H5Dclose(dataset);
756  if(stat<0) {
757  delete [] buff;
758  a_string.clear();
759  return false;
760  }
761 
762  size_t len = sz-1;
763  a_string.resize(len,0);
764  for(size_t index=0;index<len;index++) a_string[index] = buff[index];
765 
766  delete [] buff;
767 
768  return true;
769 }

◆ read_struct()

template<class T >
bool tools::hdf5::read_struct ( hid_t  a_loc,
const std::string &  a_name,
hid_t  aReadType,
T &  a_data 
)
inline

Definition at line 1038 of file T_tools.

1038  {
1039  hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
1040  if(dataset<0) return false;
1041 
1042  hid_t file_space = H5Dget_space(dataset);
1043  if(file_space<0) {
1044  ::H5Dclose(dataset);
1045  return false;
1046  }
1047 
1048  hid_t mem_space = ::H5Screate(H5S_SCALAR);
1049  if(mem_space<0) {
1050  ::H5Sclose(file_space);
1051  ::H5Dclose(dataset);
1052  return false;
1053  }
1054 
1055  if(H5Dread(dataset,aReadType,mem_space,file_space,H5P_DEFAULT,&a_data)<0) {
1056  ::H5Sclose(mem_space);
1057  ::H5Sclose(file_space);
1058  ::H5Dclose(dataset);
1059  return false;
1060  }
1061 
1062  ::H5Sclose(mem_space);
1063  ::H5Sclose(file_space);
1064  ::H5Dclose(dataset);
1065  return true;
1066 }

◆ read_sub_array() [1/2]

template<class T >
bool tools::hdf5::read_sub_array ( hid_t  a_loc,
const std::string &  a_name,
hid_t  a_mem_type,
unsigned int  a_offset,
unsigned int  a_number,
unsigned int &  a_size,
T *&  a_array 
)
inline

Definition at line 682 of file T_tools.

684  {
685  hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
686  if(dataset<0) {
687  a_size = 0;
688  a_array = 0;
689  return false; // data set not found.
690  }
691 
692  hid_t file_space = H5Dget_space(dataset);
693  if(file_space<0) {
694  ::H5Dclose(dataset);
695  a_size = 0;
696  a_array = 0;
697  return false;
698  }
699 
700  {int dimn = H5Sget_simple_extent_ndims(file_space);
701  if(dimn<0) {
702  ::H5Sclose(file_space);
703  ::H5Dclose(dataset);
704  a_size = 0;
705  a_array = 0;
706  return false;
707  }
708  if(dimn!=1) {
709  ::H5Sclose(file_space);
710  ::H5Dclose(dataset);
711  a_size = 0;
712  a_array = 0;
713  return false;
714  }
715  //printf("debug : read dimn %d\n",dimn);
716  }
717 
718  hsize_t dims[1];
719  {if(H5Sget_simple_extent_dims(file_space,dims,NULL)<0) {
720  ::H5Sclose(file_space);
721  ::H5Dclose(dataset);
722  a_size = 0;
723  a_array = 0;
724  return false;
725  }}
726 
727  unsigned int sz = (unsigned int)dims[0];
728  if(!sz) {
729  ::H5Sclose(file_space);
730  ::H5Dclose(dataset);
731  a_size = 0;
732  a_array = 0;
733  return true; //It is ok.
734  }
735 
736  // abcdef
737  // 012345
738  int remain = sz-a_offset;
739  if(remain<=0) {
740  ::H5Sclose(file_space);
741  ::H5Dclose(dataset);
742  a_size = 0;
743  a_array = 0;
744  return a_number?false:true;
745  }
746 
747  int number = (int(a_number)<=remain) ? int(a_number) : remain;
748  if(number<=0) {
749  ::H5Sclose(file_space);
750  ::H5Dclose(dataset);
751  a_size = 0;
752  a_array = 0;
753  return true; //It is ok.
754  }
755 
756  {hsize_t offset[1];
757  offset[0] = a_offset;
758  hsize_t count[1];
759  count[0] = number;
760  if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
761  ::H5Sclose(file_space);
762  ::H5Dclose(dataset);
763  a_size = 0;
764  a_array = 0;
765  return false;
766  }}
767 
768  dims[0] = number;
769  hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
770  if(mem_space<0) {
771  ::H5Sclose(file_space);
772  ::H5Dclose(dataset);
773  a_size = 0;
774  a_array = 0;
775  return false;
776  }
777 
778  a_array = new T[number];
779  if(H5Dread(dataset,a_mem_type,mem_space,file_space,H5P_DEFAULT,a_array)<0) {
780  delete [] a_array;
781  ::H5Sclose(mem_space);
782  ::H5Sclose(file_space);
783  ::H5Dclose(dataset);
784  a_array = 0;
785  return false;
786  }
787 
788  ::H5Sclose(mem_space);
789  ::H5Sclose(file_space);
790  ::H5Dclose(dataset);
791 
792  a_size = number;
793 
794  return true;
795 }

◆ read_sub_array() [2/2]

template<class TYPE >
bool tools::hdf5::read_sub_array ( hid_t  a_loc,
const std::string &  a_name,
unsigned int  a_offset,
unsigned int  a_number,
unsigned int &  a_size,
TYPE *&  a_array 
)
inline

Definition at line 1253 of file T_tools.

1254  {
1255  return read_sub_array<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_offset,a_number,a_size,a_array);
1256 }

◆ read_sub_string()

bool tools::hdf5::read_sub_string ( hid_t  a_loc,
const std::string &  a_name,
unsigned int  a_offset,
std::string &  a_string 
)
inline

Definition at line 771 of file tools.

771  {
772  hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
773  if(dataset<0) {
774  a_string.clear();
775  return false; // data set not found.
776  }
777 
778  hid_t file_space = H5Dget_space(dataset);
779  if(file_space<0) {
780  ::H5Dclose(dataset);
781  a_string.clear();
782  return false;
783  }
784 
785  {int dimn = H5Sget_simple_extent_ndims(file_space);
786  if(dimn<0) {
787  ::H5Sclose(file_space);
788  ::H5Dclose(dataset);
789  a_string.clear();
790  return false;
791  }
792  if(dimn!=1) {
793  ::H5Sclose(file_space);
794  ::H5Dclose(dataset);
795  a_string.clear();
796  return false;
797  }}
798 
799  hsize_t dims[1];
800  {if(H5Sget_simple_extent_dims(file_space,dims,NULL)<0) {
801  ::H5Sclose(file_space);
802  ::H5Dclose(dataset);
803  a_string.clear();
804  return false;
805  }}
806 
807  {unsigned int sz = (unsigned int)dims[0];
808  if(!sz) {
809  ::H5Sclose(file_space);
810  ::H5Dclose(dataset);
811  a_string.clear();
812  return false; //Is it ok ?
813  }
814 
815  // abcdef
816  // 012345
817  int remain = sz-a_offset;
818  if(remain<=0) {
819  ::H5Sclose(file_space);
820  ::H5Dclose(dataset);
821  a_string.clear();
822  return false;
823  }}
824 
825  {hsize_t offset[1];
826  offset[0] = a_offset;
827  hsize_t count[1];
828  count[0] = 1;
829  if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
830  ::H5Sclose(file_space);
831  ::H5Dclose(dataset);
832  a_string.clear();
833  return false;
834  }}
835 
836  dims[0] = 1;
837  hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
838  if(mem_space<0) {
839  ::H5Sclose(file_space);
840  ::H5Dclose(dataset);
841  a_string.clear();
842  return false;
843  }
844 
845  hid_t file_type = H5Dget_type(dataset);
846  if(file_type<0) {
847  ::H5Sclose(file_space);
848  ::H5Dclose(dataset);
849  a_string.clear();
850  return false;
851  }
852 
853  H5T_class_t t_class = H5Tget_class(file_type);
854  if(t_class!=H5T_STRING) {
855  ::H5Tclose(file_type);
856  ::H5Sclose(file_space);
857  ::H5Dclose(dataset);
858  a_string.clear();
859  return false;
860  }
861 
862 //size_t sz = H5Tget_size(file_type); //it gives the largest string size in the dataset.
863 //if(!sz) {
864 // ::H5Tclose(file_type);
865 // ::H5Sclose(file_space);
866 // ::H5Dclose(dataset);
867 // a_string.clear();
868 // return false;
869 //}
870 
871  ::H5Tclose(file_type);
872 
873  hid_t mem_type = str_datatype();
874  if(mem_type<0) {
875  ::H5Sclose(file_space);
876  ::H5Dclose(dataset);
877  a_string.clear();
878  return false;
879  }
880 
881  char* rdata[1];
882  herr_t stat = H5Dread(dataset,mem_type,mem_space,file_space,H5P_DEFAULT,rdata);
883  if(stat<0) {
884  ::H5Dvlen_reclaim(mem_type,mem_space, H5P_DEFAULT,rdata);
885  ::H5Tclose(mem_type);
886  ::H5Sclose(mem_space);
887  ::H5Sclose(file_space);
888  ::H5Dclose(dataset);
889  a_string.clear();
890  return false;
891  }
892 
893  char* buff = rdata[0];
894 
895  size_t len = ::strlen(buff);
896  a_string.resize(len,0);
897  for(size_t index=0;index<len;index++) a_string[index] = buff[index];
898 
899  ::H5Dvlen_reclaim(mem_type,mem_space, H5P_DEFAULT,rdata);
900 
901  ::H5Tclose(mem_type);
902  ::H5Sclose(mem_space);
903  ::H5Sclose(file_space);
904  ::H5Dclose(dataset);
905 
906  return true;
907 }

◆ read_sub_vlen() [1/2]

template<class T >
bool tools::hdf5::read_sub_vlen ( hid_t  a_loc,
const std::string &  a_name,
hid_t  a_mem_type,
unsigned int  a_offset,
unsigned int &  a_size,
T *&  a_array 
)
inline

Definition at line 798 of file T_tools.

800  {
801  hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
802  if(dataset<0) {
803  a_size = 0;
804  a_array = 0;
805  return false; // data set not found.
806  }
807 
808  hid_t file_space = H5Dget_space(dataset);
809  if(file_space<0) {
810  ::H5Dclose(dataset);
811  a_size = 0;
812  a_array = 0;
813  return false;
814  }
815 
816  {int dimn = H5Sget_simple_extent_ndims(file_space);
817  if(dimn<0) {
818  ::H5Sclose(file_space);
819  ::H5Dclose(dataset);
820  a_size = 0;
821  a_array = 0;
822  return false;
823  }
824  if(dimn!=1) {
825  ::H5Sclose(file_space);
826  ::H5Dclose(dataset);
827  a_size = 0;
828  a_array = 0;
829  return false;
830  }
831  //printf("debug : read dimn %d\n",dimn);
832  }
833 
834  hsize_t dims[1];
835  {if(H5Sget_simple_extent_dims(file_space,dims,NULL)<0) {
836  ::H5Sclose(file_space);
837  ::H5Dclose(dataset);
838  a_size = 0;
839  a_array = 0;
840  return false;
841  }}
842 
843  unsigned int sz = (unsigned int)dims[0];
844  if(!sz) {
845  ::H5Sclose(file_space);
846  ::H5Dclose(dataset);
847  a_size = 0;
848  a_array = 0;
849  return true; //It is ok.
850  }
851 
852  // abcdef
853  // 012345
854  int remain = sz-a_offset;
855  if(remain<=0) {
856  ::H5Sclose(file_space);
857  ::H5Dclose(dataset);
858  a_size = 0;
859  a_array = 0;
860  return false;
861  }
862 
863  {hsize_t offset[1];
864  offset[0] = a_offset;
865  hsize_t count[1];
866  count[0] = 1;
867  if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
868  ::H5Sclose(file_space);
869  ::H5Dclose(dataset);
870  a_size = 0;
871  a_array = 0;
872  return false;
873  }}
874 
875  dims[0] = 1;
876  hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
877  if(mem_space<0) {
878  ::H5Sclose(file_space);
879  ::H5Dclose(dataset);
880  a_size = 0;
881  a_array = 0;
882  return false;
883  }
884 
885  hid_t mem_type = ::H5Tvlen_create(a_mem_type);
886 
887  hvl_t rdata[1];
888  if(H5Dread(dataset,mem_type,mem_space,file_space,H5P_DEFAULT,rdata)<0) {
889  //::H5Dvlen_reclaim(mem_type,mem_space,H5P_DEFAULT,rdata); ???
890  ::H5Tclose(mem_type);
891  ::H5Sclose(mem_space);
892  ::H5Sclose(file_space);
893  ::H5Dclose(dataset);
894  a_size = 0;
895  a_array = 0;
896  return false;
897  }
898 
899  hsize_t len = rdata[0].len;
900  if(!len) {
901  //a_array = new T[1];
902  a_array = 0; //it is ok.
903  } else {
904  a_array = new T[len];
905  T* _data = (T*)rdata[0].p;
906  T* pos = a_array;
907  for(hsize_t index=0;index<len;index++,pos++,_data++) *pos = *_data;
908  }
909  a_size = len;
910 
911  ::H5Dvlen_reclaim(mem_type,mem_space,H5P_DEFAULT,rdata);
912 
913  ::H5Tclose(mem_type);
914  ::H5Sclose(mem_space);
915  ::H5Sclose(file_space);
916  ::H5Dclose(dataset);
917 
918  return true;
919 }

◆ read_sub_vlen() [2/2]

template<class TYPE >
bool tools::hdf5::read_sub_vlen ( hid_t  a_loc,
const std::string &  a_name,
unsigned int  a_offset,
unsigned int &  a_size,
TYPE *&  a_array 
)
inline

Definition at line 1259 of file T_tools.

1260  {
1261  return read_sub_vlen<TYPE>(a_loc,a_name,to_T_mem_type(TYPE()),a_offset,a_size,a_array);
1262 }

◆ str_datatype()

hid_t tools::hdf5::str_datatype ( )
inline

Definition at line 44 of file tools.

44  {
45  hid_t datatype = ::H5Tcopy(H5T_C_S1);
46  if(datatype<0) return failure();
47  if(::H5Tset_size(datatype,H5T_VARIABLE)<0) {
48  ::H5Tclose(datatype);
49  return failure();
50  }
51  if(::H5Tset_strpad(datatype,H5T_STR_NULLTERM)<0) {
52  ::H5Tclose(datatype);
53  return failure();
54  }
55  return datatype;
56 }

◆ string_datatype()

hid_t tools::hdf5::string_datatype ( size_t  aSize)
inline

Definition at line 26 of file tools.

26  {
27  // aSize should include the trailing null char.
28  hid_t datatype = ::H5Tcopy(H5T_C_S1);
29  if(datatype<0) return failure();
30 
31  if(::H5Tset_size(datatype,aSize)<0) {
32  ::H5Tclose(datatype);
33  return failure();
34  }
35 
36  if(::H5Tset_strpad(datatype,H5T_STR_NULLTERM)<0) {
37  ::H5Tclose(datatype);
38  return failure();
39  }
40 
41  return datatype;
42 }

◆ to_T_file_type() [1/10]

hid_t tools::hdf5::to_T_file_type ( char  )
inline

Definition at line 18 of file T_tools.

18 {return H5T_STD_I8LE;} //H5T_STD_I8XX()

◆ to_T_file_type() [2/10]

hid_t tools::hdf5::to_T_file_type ( double  )
inline

Definition at line 24 of file T_tools.

24 {return H5T_IEEE_F64LE;} //H5T_IEEE_F64XX()

◆ to_T_file_type() [3/10]

hid_t tools::hdf5::to_T_file_type ( float  )
inline

Definition at line 23 of file T_tools.

23 {return H5T_IEEE_F32LE;} //H5T_IEEE_F32XX()

◆ to_T_file_type() [4/10]

hid_t tools::hdf5::to_T_file_type ( int  )
inline

Definition at line 20 of file T_tools.

20 {return H5T_STD_I32LE;} //H5T_STD_I32XX()

◆ to_T_file_type() [5/10]

hid_t tools::hdf5::to_T_file_type ( short  )
inline

Definition at line 19 of file T_tools.

19 {return H5T_STD_I16LE;} //HST_STD_I16XX()

◆ to_T_file_type() [6/10]

hid_t tools::hdf5::to_T_file_type ( tools::int64  )
inline

Definition at line 21 of file T_tools.

21 {return H5T_STD_I64LE;} //H5T_STD_I64XX()

◆ to_T_file_type() [7/10]

hid_t tools::hdf5::to_T_file_type ( tools::uint64  )
inline

Definition at line 29 of file T_tools.

29 {return H5T_STD_U64LE;}

◆ to_T_file_type() [8/10]

hid_t tools::hdf5::to_T_file_type ( unsigned char  )
inline

Definition at line 26 of file T_tools.

26 {return H5T_STD_U8LE;}

◆ to_T_file_type() [9/10]

hid_t tools::hdf5::to_T_file_type ( unsigned int  )
inline

Definition at line 28 of file T_tools.

28 {return H5T_STD_U32LE;}

◆ to_T_file_type() [10/10]

hid_t tools::hdf5::to_T_file_type ( unsigned short  )
inline

Definition at line 27 of file T_tools.

27 {return H5T_STD_U16LE;}

◆ to_T_mem_type() [1/10]

hid_t tools::hdf5::to_T_mem_type ( char  )
inline

Definition at line 31 of file T_tools.

31 {return H5T_NATIVE_CHAR;}

◆ to_T_mem_type() [2/10]

hid_t tools::hdf5::to_T_mem_type ( double  )
inline

Definition at line 37 of file T_tools.

37 {return H5T_NATIVE_DOUBLE;}

◆ to_T_mem_type() [3/10]

hid_t tools::hdf5::to_T_mem_type ( float  )
inline

Definition at line 36 of file T_tools.

36 {return H5T_NATIVE_FLOAT;}

◆ to_T_mem_type() [4/10]

hid_t tools::hdf5::to_T_mem_type ( int  )
inline

Definition at line 33 of file T_tools.

33 {return H5T_NATIVE_INT;}

◆ to_T_mem_type() [5/10]

hid_t tools::hdf5::to_T_mem_type ( short  )
inline

Definition at line 32 of file T_tools.

32 {return H5T_NATIVE_SHORT;}

◆ to_T_mem_type() [6/10]

hid_t tools::hdf5::to_T_mem_type ( tools::int64  )
inline

Definition at line 34 of file T_tools.

34 {return H5T_NATIVE_INT64;}

◆ to_T_mem_type() [7/10]

hid_t tools::hdf5::to_T_mem_type ( tools::uint64  )
inline

Definition at line 42 of file T_tools.

42 {return H5T_NATIVE_UINT64;}

◆ to_T_mem_type() [8/10]

hid_t tools::hdf5::to_T_mem_type ( unsigned char  )
inline

Definition at line 39 of file T_tools.

39 {return H5T_NATIVE_UCHAR;}

◆ to_T_mem_type() [9/10]

hid_t tools::hdf5::to_T_mem_type ( unsigned int  )
inline

Definition at line 41 of file T_tools.

41 {return H5T_NATIVE_UINT;}

◆ to_T_mem_type() [10/10]

hid_t tools::hdf5::to_T_mem_type ( unsigned short  )
inline

Definition at line 40 of file T_tools.

40 {return H5T_NATIVE_USHORT;}

◆ write_append_array() [1/2]

template<class T >
bool tools::hdf5::write_append_array ( hid_t  a_loc,
const std::string &  a_name,
hid_t  a_file_type,
hid_t  a_mem_type,
unsigned int  a_number,
const T  a_array[] 
)
inline

Definition at line 425 of file T_tools.

426  {
427  hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
428  if(dataset<0) return false;
429  bool status = write_append_array_dataset(dataset,a_file_type,a_mem_type,a_number,a_array);
430  ::H5Dclose(dataset);
431  return status;
432 }

◆ write_append_array() [2/2]

template<class TYPE >
bool tools::hdf5::write_append_array ( hid_t  a_loc,
const std::string &  a_name,
unsigned int  a_number,
const TYPE  a_array[] 
)
inline

Definition at line 1228 of file T_tools.

1228  {
1229  return hdf5::write_append_array<TYPE>(a_loc,a_name,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),a_number,a_array);
1230 }

◆ write_append_array_dataset() [1/2]

template<class T >
bool tools::hdf5::write_append_array_dataset ( hid_t  a_dataset,
hid_t  ,
hid_t  a_mem_type,
unsigned int  a_number,
const T  a_array[] 
)
inline

Definition at line 313 of file T_tools.

314  {
315  hsize_t old_size = 0;
316 
317  {hid_t dataspace = H5Dget_space(a_dataset);
318  if(dataspace<0) return false;
319  hsize_t dims[1];
320  if(H5Sget_simple_extent_dims(dataspace,dims,NULL)<0) {
321  ::H5Sclose(dataspace);
322  return false;
323  }
324  old_size = dims[0];
325  ::H5Sclose(dataspace);}
326 
327  {hsize_t exts[1];
328  exts[0] = old_size+a_number;
329 // if(H5Dextend(dataset,exts)<0) {
330  if(H5Dset_extent(a_dataset,exts)<0) return false;}
331 
332  hid_t file_space = H5Dget_space(a_dataset);
333  if(file_space<0) return false;
334 
335  {hsize_t offset[1];
336  offset[0] = old_size;
337  hsize_t count[1];
338  count[0] = a_number;
339  if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
340  ::H5Sclose(file_space);
341  return false;
342  }}
343 
344  hsize_t dims[1];
345  dims[0] = a_number;
346  hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
347  if(mem_space<0) {
348  ::H5Sclose(file_space);
349  return false;
350  }
351 
352  if(H5Dwrite(a_dataset,a_mem_type,mem_space,file_space,H5P_DEFAULT,a_array)<0) {
353  ::H5Sclose(mem_space);
354  ::H5Sclose(file_space);
355  return false;
356  }
357 
358  ::H5Sclose(mem_space);
359  ::H5Sclose(file_space);
360 
361  return true;
362 }

◆ write_append_array_dataset() [2/2]

template<class TYPE >
bool tools::hdf5::write_append_array_dataset ( hid_t  a_dataset,
unsigned int  a_number,
const TYPE  a_array[] 
)
inline

Definition at line 1218 of file T_tools.

1218  {
1219  return hdf5::write_append_array_dataset<TYPE>(a_dataset,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),a_number,a_array);
1220 }

◆ write_append_string_dataset()

bool tools::hdf5::write_append_string_dataset ( hid_t  a_dataset,
const std::string &  a_string 
)
inline

Definition at line 525 of file tools.

525  {
526  hsize_t old_size = 0;
527 
528  {hid_t dataspace = H5Dget_space(a_dataset);
529  if(dataspace<0) return false;
530  hsize_t dims[1];
531  if(H5Sget_simple_extent_dims(dataspace,dims,NULL)<0) {
532  ::H5Sclose(dataspace);
533  return false;
534  }
535  old_size = dims[0];
536  ::H5Sclose(dataspace);}
537 
538  {hsize_t exts[1];
539  exts[0] = old_size+1;
540 // if(H5Dextend(dataset,exts)<0) {
541  if(H5Dset_extent(a_dataset,exts)<0) return false;}
542 
543  hid_t file_space = H5Dget_space(a_dataset);
544  if(file_space<0) return false;
545 
546  {hsize_t offset[1];
547  offset[0] = old_size;
548  hsize_t count[1];
549  count[0] = 1;
550  if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
551  ::H5Sclose(file_space);
552  return false;
553  }}
554 
555  hsize_t dims[1];
556  dims[0] = 1;
557  hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
558  if(mem_space<0) {
559  ::H5Sclose(file_space);
560  return false;
561  }
562 
563  hid_t mem_type = str_datatype();
564  if(mem_type<0) {
565  ::H5Sclose(mem_space);
566  ::H5Sclose(file_space);
567  return false;
568  }
569 
570  const char* wdata[1];
571  wdata[0] = a_string.c_str();
572 
573  if(H5Dwrite(a_dataset,mem_type,mem_space,file_space,H5P_DEFAULT,wdata)<0) {
574  ::H5Tclose(mem_type);
575  ::H5Sclose(mem_space);
576  ::H5Sclose(file_space);
577  return false;
578  }
579 
580  ::H5Tclose(mem_type);
581  ::H5Sclose(mem_space);
582  ::H5Sclose(file_space);
583 
584  return true;
585 }

◆ write_append_vlen_dataset() [1/2]

template<class T >
bool tools::hdf5::write_append_vlen_dataset ( hid_t  a_dataset,
hid_t  ,
hid_t  a_mem_type,
unsigned int  a_number,
const T  a_array[] 
)
inline

Definition at line 365 of file T_tools.

366  {
367  hsize_t old_size = 0;
368 
369  {hid_t dataspace = H5Dget_space(a_dataset);
370  if(dataspace<0) return false;
371  hsize_t dims[1];
372  if(H5Sget_simple_extent_dims(dataspace,dims,NULL)<0) {
373  ::H5Sclose(dataspace);
374  return false;
375  }
376  old_size = dims[0];
377  ::H5Sclose(dataspace);}
378 
379  {hsize_t exts[1];
380  exts[0] = old_size+1;
381 // if(H5Dextend(dataset,exts)<0) {
382  if(H5Dset_extent(a_dataset,exts)<0) return false;}
383 
384  hid_t file_space = H5Dget_space(a_dataset);
385  if(file_space<0) return false;
386 
387  {hsize_t offset[1];
388  offset[0] = old_size;
389  hsize_t count[1];
390  count[0] = 1;
391  if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
392  ::H5Sclose(file_space);
393  return false;
394  }}
395 
396  hsize_t dims[1];
397  dims[0] = 1;
398  hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
399  if(mem_space<0) {
400  ::H5Sclose(file_space);
401  return false;
402  }
403 
404  hid_t mem_type = ::H5Tvlen_create(a_mem_type);
405 
406  hvl_t wdata[1];
407  wdata[0].len = a_number;
408  wdata[0].p = (void*)a_array;
409 
410  if(H5Dwrite(a_dataset,mem_type,mem_space,file_space,H5P_DEFAULT,wdata)<0) {
411  ::H5Tclose(mem_type);
412  ::H5Sclose(mem_space);
413  ::H5Sclose(file_space);
414  return false;
415  }
416 
417  ::H5Tclose(mem_type);
418  ::H5Sclose(mem_space);
419  ::H5Sclose(file_space);
420 
421  return true;
422 }

◆ write_append_vlen_dataset() [2/2]

template<class TYPE >
bool tools::hdf5::write_append_vlen_dataset ( hid_t  a_dataset,
unsigned int  a_number,
const TYPE  a_array[] 
)
inline

Definition at line 1223 of file T_tools.

1223  {
1224  return hdf5::write_append_vlen_dataset<TYPE>(a_dataset,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),a_number,a_array);
1225 }

◆ write_array() [1/2]

template<class T >
bool tools::hdf5::write_array ( hid_t  a_loc,
const std::string &  a_name,
hid_t  a_file_type,
hid_t  a_mem_type,
unsigned int  a_chunked,
unsigned int  a_compress,
unsigned int  a_size,
const T  a_array[] 
)
inline

Definition at line 45 of file T_tools.

48  {
49  if(!a_size) return false;
50 
51  hid_t cpt = -1;
52  if(a_compress || a_chunked) {
53  cpt = ::H5Pcreate(H5P_DATASET_CREATE);
54  if(cpt<0) return false;
55  if(a_chunked) {
56  if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
57  ::H5Pclose(cpt);
58  return false;
59  }
60  hsize_t cdims[1];
61  cdims[0] = a_chunked;
62  if(H5Pset_chunk(cpt,1,cdims)<0) {
63  ::H5Pclose(cpt);
64  return false;
65  }
66  } else {
67  if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
68  ::H5Pclose(cpt);
69  return false;
70  }
71  }
72  if(a_compress) {
73  if(H5Pset_deflate(cpt,a_compress>9?9:a_compress)<0) {
74  ::H5Pclose(cpt);
75  return false;
76  }
77  }
78  } else {
79  cpt = H5P_DEFAULT;
80  }
81 
82  hid_t dataset = -1;
83 
84  {hsize_t dims[1];
85  dims[0] = a_size;
86  hid_t file_space = -1;
87  if(a_chunked) {
88  hsize_t mx_dims[1];
89  mx_dims[0] = H5S_UNLIMITED; //extendable.
90  file_space = ::H5Screate_simple(1,dims,mx_dims);
91  } else {
92  file_space = ::H5Screate_simple(1,dims,NULL);
93  }
94  if(file_space<0) {if(cpt>=0) ::H5Pclose(cpt);return false;}
95  dataset = tools_H5Dcreate(a_loc,a_name.c_str(),a_file_type,file_space,cpt);
96  if(cpt>=0) ::H5Pclose(cpt);
97  ::H5Sclose(file_space);
98  if(dataset<0) return false;}
99 
100  if(H5Dwrite(dataset,a_mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,a_array)<0) {
101  ::H5Dclose(dataset);
102  return false;
103  }
104  ::H5Dclose(dataset);
105 
106  return true;
107 }

◆ write_array() [2/2]

template<class TYPE >
bool tools::hdf5::write_array ( hid_t  a_loc,
const std::string &  a_name,
unsigned int  a_size,
const TYPE  a_array[],
unsigned int  a_chunked = 0,
unsigned int  a_compress = 0 
)
inline

Definition at line 1147 of file T_tools.

1149  {
1150  return hdf5::write_array<TYPE>(a_loc,a_name,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),
1151  a_chunked,a_compress,a_size,a_array);
1152 }

◆ write_array_string()

bool tools::hdf5::write_array_string ( hid_t  a_loc,
const std::string &  a_name,
const std::vector< std::string > &  a_array 
)
inline

Definition at line 594 of file tools.

594  {
595  hid_t scalar = ::H5Screate(H5S_SCALAR);
596  if(scalar<0) return false;
597 
598  // From H5LTmake_dataset_string.
599  size_t sz;
600  char* buffer;
601  if(!tools::strings2buf(a_array,sz,buffer)) {
602  ::H5Sclose(scalar);
603  return false;
604  }
605 
606  hid_t file_type = string_datatype(sz);
607  if(file_type<0) {
608  delete [] buffer;
609  ::H5Sclose(scalar);
610  return false;
611  }
612 
613  hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),file_type,scalar,H5P_DEFAULT);
614  if(dataset<0) {
615  delete [] buffer;
616  ::H5Tclose(file_type);
617  ::H5Sclose(scalar);
618  return false;
619  }
620 
621  hid_t mem_type = file_type;
622  if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,buffer)<0) {
623  delete [] buffer;
624  ::H5Dclose(dataset);
625  ::H5Tclose(file_type);
626  ::H5Sclose(scalar);
627  return false;
628  }
629 
630  delete [] buffer;
631 
632  ::H5Dclose(dataset);
633  ::H5Tclose(file_type);
634  ::H5Sclose(scalar);
635  return true;
636 }

◆ write_atb()

bool tools::hdf5::write_atb ( hid_t  a_id,
const std::string &  a_name,
const std::string &  a_data 
)
inline

Definition at line 320 of file tools.

320  {
321  // From H5LT.c/H5LTset_attribute_string.
322  int has_attr = H5LT_find_attribute(a_id,a_name.c_str());
323  if(has_attr==1) {
324  if(H5Adelete(a_id,a_name.c_str())<0) return false;
325  }
326 
327  hid_t datatype = string_datatype(a_data.size()+1);
328  if(datatype<0) return false;
329 
330  hid_t scalar = ::H5Screate(H5S_SCALAR);
331  if(scalar<0) {
332  ::H5Tclose(datatype);
333  return false;
334  }
335 
336  hid_t aid = tools_H5Acreate(a_id,a_name.c_str(),datatype,scalar,H5P_DEFAULT);
337  if(aid<0) {
338  ::H5Sclose(scalar);
339  ::H5Tclose(datatype);
340  return false;
341  }
342 
343  if(H5Awrite(aid,datatype,a_data.c_str())<0) {
344  ::H5Aclose(aid);
345  ::H5Sclose(scalar);
346  ::H5Tclose(datatype);
347  return false;
348  }
349 
350  ::H5Aclose(aid);
351  ::H5Sclose(scalar);
352  ::H5Tclose(datatype);
353 
354  return true;
355 }

◆ write_bool()

bool tools::hdf5::write_bool ( hid_t  a_loc,
const std::string &  a_name,
bool  a_data 
)
inline

Definition at line 357 of file tools.

357  {
358  hid_t scalar = ::H5Screate(H5S_SCALAR);
359  if(scalar<0) return false;
360 
361  hid_t compact = ::H5Pcreate(H5P_DATASET_CREATE);
362  if(compact<0) {
363  ::H5Sclose(scalar);
364  return false;
365  }
366  if(H5Pset_layout(compact,H5D_COMPACT)<0) {
367  ::H5Pclose(compact);
368  ::H5Sclose(scalar);
369  return false;
370  }
371 
372  hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),H5T_STD_U8XX(),scalar,compact);
373  if(dataset<0) {
374  ::H5Pclose(compact);
375  ::H5Sclose(scalar);
376  return false;
377  }
378 
379  unsigned char data = a_data?1:0;
380  if(::H5Dwrite(dataset,H5T_NATIVE_UCHAR,H5S_ALL,H5S_ALL,H5P_DEFAULT,&data)<0) {
381  ::H5Pclose(compact);
382  ::H5Sclose(scalar);
383  ::H5Dclose(dataset);
384  return false;
385  }
386 
387  ::H5Pclose(compact);
388  ::H5Sclose(scalar);
389  ::H5Dclose(dataset);
390  return true;
391 }

◆ write_hdata()

bool tools::hdf5::write_hdata ( hid_t  a_loc,
const histo_data_t a_hdata 
)
inline

Definition at line 55 of file h2file.

55  {
56 
57  if(!write_string(a_loc,"title",a_hdata.m_title)) return false;
58  if(!write_scalar<unsigned int>(a_loc,"dimension",a_hdata.m_dimension)) return false;
59  if(!write_scalar<unsigned int>(a_loc,"bin_number",a_hdata.m_bin_number)) return false;
60 
61  if(!write_std_vec<unsigned int>(a_loc,"bin_entries",a_hdata.m_bin_entries)) return false;
62  if(!write_std_vec<double>(a_loc,"bin_Sw",a_hdata.m_bin_Sw)) return false;
63  if(!write_std_vec<double>(a_loc,"bin_Sw2",a_hdata.m_bin_Sw2)) return false;
64  if(!write_std_vec_vec<double>(a_loc,"bin_Sxw",a_hdata.m_bin_Sxw)) return false;
65  if(!write_std_vec_vec<double>(a_loc,"bin_Sx2w",a_hdata.m_bin_Sx2w)) return false;
66 
67  // axes :
68  {std::string name,saxis;
69  for(unsigned int iaxis=0;iaxis<a_hdata.m_dimension;iaxis++) {
70  tools::num2s(iaxis,saxis);
71  name = "axis_"+saxis+"_";
72  const histo_data_t::axis_t& _axis = a_hdata.m_axes[iaxis];
73  if(!write_scalar<unsigned int>(a_loc,name+"offset",_axis.m_offset)) return false;
74  if(!write_scalar<unsigned int>(a_loc,name+"number_of_bins",_axis.m_number_of_bins)) return false;
75  if(!write_scalar<double>(a_loc,name+"minimum_value",_axis.m_minimum_value)) return false;
76  if(!write_scalar<double>(a_loc,name+"maximum_value",_axis.m_maximum_value)) return false;
77  if(!write_scalar<bool>(a_loc,name+"fixed",_axis.m_fixed)) return false;
78  if(!write_scalar<double>(a_loc,name+"bin_width",_axis.m_bin_width)) return false;
79  if(!write_std_vec<double>(a_loc,name+"edges",_axis.m_edges)) return false;
80  }}
81 
82  // etc :
83  if(!write_std_vec<double>(a_loc,"in_range_plane_Sxyw",a_hdata.m_in_range_plane_Sxyw)) return false;
84 
85  // m_annotations :
86  if(!write_std_map_ss(a_loc,"annotations",a_hdata.m_annotations)) return false;
87 
88  return true;
89 }

◆ write_header()

bool tools::hdf5::write_header ( hid_t  a_file,
int  a_version = 1 
)
inline

Definition at line 13 of file header.

13  {
14  hid_t header = tools_H5Gcreate(a_file,"header",0);
15  if(header<0) return false;
16  if(!write_atb(header,"writer","exlib")) {::H5Gclose(header);return false;}
17  if(!write_scalar_atb<int>(header,"data_schema_version",a_version)) {::H5Gclose(header);return false;}
18  ::H5Gclose(header);
19  return true;
20 }

◆ write_histo()

template<class HISTO >
bool tools::hdf5::write_histo ( std::ostream &  a_out,
hid_t  a_loc,
const std::string &  a_name,
const HISTO &  a_histo 
)
inline

Definition at line 92 of file h2file.

92  {
93 
94  hid_t histo = tools_H5Gcreate(a_loc,a_name.c_str(),0);
95  if(histo<0) {
96  a_out << "tools::hdf5::write_histo : can't create group for histo " << tools::sout(a_name) << "." << std::endl;
97  ::H5Gclose(histo);
98  return false;
99  }
100 
101  if(!write_atb(histo,"type","object")) {
102  a_out << "tools::hdf5::write_histo : write_atb() class failed." << std::endl;
103  ::H5Gclose(histo);
104  return false;
105  }
106  if(!write_atb(histo,"class",a_histo.s_cls())) {
107  a_out << "tools::hdf5::write_histo : write_atb() class failed." << std::endl;
108  ::H5Gclose(histo);
109  return false;
110  }
111  int v = 1;
112  if(!write_scalar_atb<int>(histo,"version",v)) {
113  a_out << "tools::hdf5::write_histo : write_scalar_atb() version failed." << std::endl;
114  ::H5Gclose(histo);
115  return false;
116  }
117 
118  if(!write_hdata(histo,a_histo.dac())) {::H5Gclose(histo);return false;}
119 
120  ::H5Gclose(histo);
121 
122  a_histo.not_a_profile(); //trick to be sure to use this function on an histo and not a profile.
123 
124  return true;
125 }

◆ write_object()

bool tools::hdf5::write_object ( hid_t  a_loc,
const std::string &  a_name,
hid_t  a_file_type,
char *  a_data 
)
inline

Definition at line 638 of file tools.

638  {
639  unsigned int chunked = 0;
640  unsigned int compress = 0;
641 
642  hid_t cpt = -1;
643  if(compress || chunked) {
644  cpt = ::H5Pcreate(H5P_DATASET_CREATE);
645  if(cpt<0) return false;
646  if(chunked) {
647  if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
648  ::H5Pclose(cpt);
649  return false;
650  }
651  hsize_t cdims[1];
652  cdims[0] = chunked;
653  if(H5Pset_chunk(cpt,1,cdims)<0) {
654  ::H5Pclose(cpt);
655  return false;
656  }
657  } else {
658  if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
659  ::H5Pclose(cpt);
660  return false;
661  }
662  }
663  if(compress) {
664  if(H5Pset_deflate(cpt,compress>9?9:compress)<0) {
665  ::H5Pclose(cpt);
666  return false;
667  }
668  }
669  } else {
670  cpt = H5P_DEFAULT;
671  }
672 
673  hsize_t dims[1];
674  dims[0] = 1;
675  hid_t simple = ::H5Screate_simple(1,dims,NULL);
676  if(simple<0) {
677  if(cpt>=0) ::H5Pclose(cpt);
678  return false;
679  }
680 
681  hid_t mem_type = compound_mem_type(a_file_type);
682  if(mem_type<0) {
683  ::H5Sclose(simple);
684  if(cpt>=0) ::H5Pclose(cpt);
685  return false;
686  }
687 
688  hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),a_file_type,simple,cpt);
689  if(dataset<0) {
690  ::H5Tclose(mem_type);
691  ::H5Sclose(simple);
692  if(cpt>=0) ::H5Pclose(cpt);
693  return false;
694  }
695 
696  if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,a_data)<0) {
697  ::H5Dclose(dataset);
698  ::H5Tclose(mem_type);
699  ::H5Sclose(simple);
700  if(cpt>=0) ::H5Pclose(cpt);
701  return false;
702  }
703 
704  ::H5Dclose(dataset);
705  ::H5Tclose(mem_type);
706  ::H5Sclose(simple);
707  if(cpt>=0) ::H5Pclose(cpt);
708 
709  return true;
710 }

◆ write_profile()

template<class PROFILE >
bool tools::hdf5::write_profile ( std::ostream &  a_out,
hid_t  a_loc,
const std::string &  a_name,
const PROFILE &  a_histo 
)
inline

Definition at line 128 of file h2file.

128  {
129 
130  hid_t histo = tools_H5Gcreate(a_loc,a_name.c_str(),0);
131  if(histo<0) {
132  a_out << "tools::hdf5::write_profile : can't create group for histo " << tools::sout(a_name) << "." << std::endl;
133  ::H5Gclose(histo);
134  return false;
135  }
136 
137  if(!write_atb(histo,"type","object")) {
138  a_out << "tools::hdf5::write_profile : write_atb() class failed." << std::endl;
139  ::H5Gclose(histo);
140  return false;
141  }
142  if(!write_atb(histo,"class",a_histo.s_cls())) {
143  a_out << "tools::hdf5::write_profile : write_atb() class failed." << std::endl;
144  ::H5Gclose(histo);
145  return false;
146  }
147  int v = 1;
148  if(!write_scalar_atb<int>(histo,"version",v)) {
149  a_out << "tools::hdf5::write_profile : write_scalar_atb() version failed." << std::endl;
150  ::H5Gclose(histo);
151  return false;
152  }
153 
154  typename PROFILE::pd_t pdata = a_histo.get_histo_data();
155 
156  if(!write_hdata(histo,pdata)) {::H5Gclose(histo);return false;}
157 
158  if(!write_bool(histo,"is_profile",pdata.m_is_profile)) {::H5Gclose(histo);return false;}
159  if(!write_std_vec<double>(histo,"bin_Svw",pdata.m_bin_Svw)) {::H5Gclose(histo);return false;}
160  if(!write_std_vec<double>(histo,"bin_Sv2w",pdata.m_bin_Sv2w)) {::H5Gclose(histo);return false;}
161  if(!write_bool(histo,"cut_v",pdata.m_cut_v)) {::H5Gclose(histo);return false;}
162  if(!write_scalar<double>(histo,"min_v",pdata.m_min_v)) {::H5Gclose(histo);return false;}
163  if(!write_scalar<double>(histo,"max_v",pdata.m_max_v)) {::H5Gclose(histo);return false;}
164 
165  ::H5Gclose(histo);
166 
167  return true;
168 }

◆ write_scalar()

template<class TYPE >
bool tools::hdf5::write_scalar ( hid_t  a_loc,
const std::string &  a_name,
const TYPE &  aData 
)
inline

Definition at line 1069 of file T_tools.

1069  {
1070  hid_t scalar = ::H5Screate(H5S_SCALAR);
1071  if(scalar<0) return false;
1072 
1073  hid_t compact = ::H5Pcreate(H5P_DATASET_CREATE);
1074  if(compact<0) {
1075  ::H5Sclose(scalar);
1076  return false;
1077  }
1078 
1079  if(H5Pset_layout(compact,H5D_COMPACT)<0) {
1080  ::H5Pclose(compact);
1081  ::H5Sclose(scalar);
1082  return false;
1083  }
1084 
1085  hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),to_T_file_type(TYPE()),scalar,compact);
1086  if(dataset<0) {
1087  ::H5Pclose(compact);
1088  ::H5Sclose(scalar);
1089  return false;
1090  }
1091 
1092  if(::H5Dwrite(dataset,to_T_mem_type(TYPE()),H5S_ALL,H5S_ALL,H5P_DEFAULT,&aData)<0) {
1093  ::H5Pclose(compact);
1094  ::H5Sclose(scalar);
1095  ::H5Dclose(dataset);
1096  return false;
1097  }
1098 
1099  ::H5Pclose(compact);
1100  ::H5Sclose(scalar);
1101  ::H5Dclose(dataset);
1102  return true;
1103 }

◆ write_scalar_atb()

template<class TYPE >
bool tools::hdf5::write_scalar_atb ( hid_t  aDS,
const std::string &  a_name,
const TYPE &  aData 
)
inline

Definition at line 1286 of file T_tools.

1286  {
1287  int has_attr = H5LT_find_attribute(aDS,a_name.c_str());
1288  if(has_attr==1) {
1289  if(H5Adelete(aDS,a_name.c_str())<0) return false;
1290  }
1291 
1292  hid_t scalar = ::H5Screate(H5S_SCALAR);
1293  if(scalar<0) return false;
1294 
1295  hid_t aid = tools_H5Acreate(aDS,a_name.c_str(),to_T_file_type(TYPE()),scalar,H5P_DEFAULT);
1296  if(aid<0) {
1297  ::H5Sclose(scalar);
1298  return false;
1299  }
1300 
1301  if(H5Awrite(aid,to_T_mem_type(TYPE()),&aData)<0) {
1302  ::H5Sclose(scalar);
1303  ::H5Aclose(aid);
1304  return false;
1305  }
1306 
1307  ::H5Sclose(scalar);
1308  ::H5Aclose(aid);
1309 
1310  return true;
1311 }

◆ write_std_map_ss()

bool tools::hdf5::write_std_map_ss ( hid_t  a_loc,
const std::string &  a_name,
const std::map< std::string, std::string > &  a_map,
unsigned int  = 0,
unsigned int  = 0 
)
inline

Definition at line 24 of file h2file.

25  {
26  if(!write_scalar<tools::uint64>(a_loc,a_name+"_size",a_map.size())) return false;
27  unsigned int count = 0; //uint for num2s.
28  std::string scount;
29  tools_mforcit(std::string,std::string,a_map,it) {
30  tools::num2s(count,scount);
31  if(!write_string(a_loc,a_name+"_elem_"+scount+"_first",(*it).first)) return false;
32  if(!write_string(a_loc,a_name+"_elem_"+scount+"_secon",(*it).second)) return false;
33  count++;
34  }
35  return true;
36 }

◆ write_std_vec() [1/2]

template<class TYPE >
bool tools::hdf5::write_std_vec ( hid_t  a_loc,
const std::string &  a_name,
const std::vector< TYPE > &  a_array,
unsigned int  a_chunked = 0,
unsigned int  a_compress = 0 
)
inline

Definition at line 1174 of file T_tools.

1175  {
1176  return hdf5::write_std_vec<TYPE>(a_loc,a_name,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),a_chunked,a_compress,a_array);
1177 }

◆ write_std_vec() [2/2]

template<class T >
bool tools::hdf5::write_std_vec ( hid_t  a_loc,
const std::string &  a_name,
hid_t  a_file_type,
hid_t  a_mem_type,
unsigned int  a_chunked,
unsigned int  a_compress,
const std::vector< T > &  a_vec 
)
inline

Definition at line 1163 of file T_tools.

1166  {
1167  if(!write_scalar<tools::uint64>(a_loc,a_name+"_size",a_vec.size())) return false;
1168  if(a_vec.empty()) return true; //it is ok.
1169  const T* data = tools::vec_data(a_vec);
1170  return write_array(a_loc,a_name,a_file_type,a_mem_type,a_chunked,a_compress,a_vec.size(),data);
1171 }

◆ write_std_vec_vec()

template<class TYPE >
bool tools::hdf5::write_std_vec_vec ( hid_t  a_loc,
const std::string &  a_name,
const std::vector< std::vector< TYPE > > &  a_vec_vec,
unsigned int  = 0,
unsigned int  = 0 
)
inline

Definition at line 1180 of file T_tools.

1181  {
1182  if(!write_scalar<tools::uint64>(a_loc,a_name+"_size",a_vec_vec.size())) return false;
1183  unsigned int count = 0; //uint for num2s.
1184  std::string scount;
1185  tools_typename_vforcit(std::vector<TYPE>,a_vec_vec,it) {
1186  tools::num2s(count,scount);
1187  if(!write_std_vec<TYPE>(a_loc,a_name+"_elem_"+scount,*it)) return false;
1188  count++;
1189  }
1190  return true;
1191 }

◆ write_string()

bool tools::hdf5::write_string ( hid_t  a_loc,
const std::string &  a_name,
const std::string &  a_string 
)
inline

Definition at line 393 of file tools.

393  {
394  hid_t scalar = ::H5Screate(H5S_SCALAR);
395  if(scalar<0) return false;
396 
397  hid_t compact = ::H5Pcreate(H5P_DATASET_CREATE);
398  if(compact<0) {
399  ::H5Sclose(scalar);
400  return false;
401  }
402 
403  if(H5Pset_layout(compact,H5D_COMPACT)<0) {
404  ::H5Pclose(compact);
405  ::H5Sclose(scalar);
406  return false;
407  }
408 
409  // From H5LTmakge_dataset_string.
410  hid_t file_type = string_datatype(a_string.size()+1);
411  if(file_type<0) {
412  ::H5Pclose(compact);
413  ::H5Sclose(scalar);
414  return false;
415  }
416 
417  hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),file_type,scalar,compact);
418  if(dataset<0) {
419  ::H5Pclose(compact);
420  ::H5Sclose(scalar);
421  ::H5Tclose(file_type);
422  return false;
423  }
424 
425  hid_t mem_type = file_type;
426  if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,a_string.c_str())<0) {
427  ::H5Pclose(compact);
428  ::H5Sclose(scalar);
429  ::H5Dclose(dataset);
430  ::H5Tclose(file_type);
431  return false;
432  }
433 
434  ::H5Pclose(compact);
435  ::H5Sclose(scalar);
436  ::H5Dclose(dataset);
437  ::H5Tclose(file_type);
438 
439  return true;
440 }

◆ write_string_dataset() [1/2]

bool tools::hdf5::write_string_dataset ( hid_t  a_loc,
const std::string &  a_name,
const std::string &  a_string,
unsigned int  a_chunked = 0,
unsigned int  a_compress = 0 
)
inline

Definition at line 519 of file tools.

521  {
522  return hdf5::write_string_dataset(a_loc,a_name,a_chunked,a_compress,a_string);
523 }

◆ write_string_dataset() [2/2]

bool tools::hdf5::write_string_dataset ( hid_t  a_loc,
const std::string &  a_name,
unsigned int  a_chunked,
unsigned int  a_compress,
const std::string &  a_string 
)
inline

Definition at line 442 of file tools.

444  {
445  hid_t cpt = -1;
446  if(a_compress || a_chunked) {
447  cpt = ::H5Pcreate(H5P_DATASET_CREATE);
448  if(cpt<0) return false;
449  if(a_chunked) {
450  if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
451  ::H5Pclose(cpt);
452  return false;
453  }
454  hsize_t cdims[1];
455  cdims[0] = a_chunked;
456  if(H5Pset_chunk(cpt,1,cdims)<0) {
457  ::H5Pclose(cpt);
458  return false;
459  }
460  } else {
461  if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
462  ::H5Pclose(cpt);
463  return false;
464  }
465  }
466  if(a_compress) {
467  if(H5Pset_deflate(cpt,a_compress>9?9:a_compress)<0) {
468  ::H5Pclose(cpt);
469  return false;
470  }
471  }
472  } else {
473  cpt = H5P_DEFAULT;
474  }
475 
476  hid_t file_type = str_datatype(); //first input => H5T_VARIABLE.
477  if(file_type<0) {
478  if(cpt>=0) ::H5Pclose(cpt);
479  return false;
480  }
481 
482  hid_t file_space = -1;
483  {hsize_t dims[1];
484  dims[0] = 1;
485  if(a_chunked) {
486  hsize_t mx_dims[1];
487  mx_dims[0] = H5S_UNLIMITED; //extendable.
488  file_space = ::H5Screate_simple(1,dims,mx_dims);
489  } else {
490  file_space = ::H5Screate_simple(1,dims,NULL);
491  }
492  if(file_space<0) {if(cpt>=0) ::H5Pclose(cpt);::H5Tclose(file_type);return false;}}
493 
494  hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),file_type,file_space,cpt);
495  if(cpt>=0) ::H5Pclose(cpt);
496  ::H5Sclose(file_space);
497  if(dataset<0) {
498  ::H5Tclose(file_type);
499  return false;
500  }
501 
502  hid_t mem_type = file_type;
503 
504  const char* wdata[1];
505  wdata[0] = a_string.c_str();
506 
507  if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata)<0) {
508  ::H5Dclose(dataset);
509  ::H5Tclose(file_type);
510  return false;
511  }
512 
513  ::H5Tclose(file_type);
514  ::H5Dclose(dataset);
515 
516  return true;
517 }

◆ write_struct()

template<class T >
bool tools::hdf5::write_struct ( hid_t  a_loc,
const std::string &  a_name,
hid_t  a_create_type,
hid_t  aWriteType,
const T &  aData 
)
inline

Definition at line 1106 of file T_tools.

1107  {
1108  hid_t scalar = ::H5Screate(H5S_SCALAR);
1109  if(scalar<0) return false;
1110 
1111  hid_t compact = ::H5Pcreate(H5P_DATASET_CREATE);
1112  if(compact<0) {
1113  ::H5Sclose(scalar);
1114  return false;
1115  }
1116 
1117  if(H5Pset_layout(compact,H5D_COMPACT)<0) {
1118  ::H5Pclose(compact);
1119  ::H5Sclose(scalar);
1120  return false;
1121  }
1122 
1123  hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),a_create_type,scalar,compact);
1124  if(dataset<0) {
1125  ::H5Pclose(compact);
1126  ::H5Sclose(scalar);
1127  return false;
1128  }
1129 
1130  if(H5Dwrite(dataset,aWriteType,H5S_ALL,H5S_ALL,H5P_DEFAULT,&aData)<0) {
1131  ::H5Pclose(compact);
1132  ::H5Sclose(scalar);
1133  ::H5Dclose(dataset);
1134  return false;
1135  }
1136 
1137  ::H5Pclose(compact);
1138  ::H5Sclose(scalar);
1139  ::H5Dclose(dataset);
1140  return true;
1141 }

◆ write_sub_array() [1/2]

template<class T >
bool tools::hdf5::write_sub_array ( hid_t  a_loc,
const std::string &  a_name,
hid_t  a_file_type,
hid_t  a_mem_type,
bool  a_create,
unsigned int  a_chunked,
unsigned int  a_compress,
unsigned int  a_size,
unsigned int  a_offset,
unsigned int  a_number,
const T  a_array[] 
)
inline

Definition at line 185 of file T_tools.

190  {
191 
192  int remain = a_size-a_offset;
193  int number = (int(a_number)<=remain) ? int(a_number) : remain;
194  if(number<=0) return false;
195 
196  hid_t cpt = -1;
197 
198  if(a_create) {
199  if(a_compress || a_chunked) {
200  cpt = ::H5Pcreate(H5P_DATASET_CREATE);
201  if(cpt<0) return false;
202  if(a_chunked) {
203  if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
204  ::H5Pclose(cpt);
205  return false;
206  }
207  hsize_t cdims[1];
208  //cdims[0] = (a_size<=32?a_size:32);
209  cdims[0] = a_chunked;
210  if(H5Pset_chunk(cpt,1,cdims)<0) {
211  ::H5Pclose(cpt);
212  return false;
213  }
214  } else {
215  if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
216  ::H5Pclose(cpt);
217  return false;
218  }
219  }
220  if(a_compress) {
221  if(H5Pset_deflate(cpt,a_compress>9?9:a_compress)<0) {
222  ::H5Pclose(cpt);
223  return false;
224  }
225  }
226  } else {
227  cpt = H5P_DEFAULT;
228  }
229  }
230 
231  hid_t dataset = -1;
232 
233  hid_t file_space = -1;
234 
235  if(a_create) {
236  hsize_t dims[1];
237  dims[0] = a_size;
238  file_space = ::H5Screate_simple(1,dims,NULL);
239  if(file_space<0) {
240  if(cpt>=0) ::H5Pclose(cpt);
241  return false;
242  }
243 
244  {hsize_t offset[1];
245  offset[0] = a_offset;
246  hsize_t count[1];
247  count[0] = number;
248  if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
249  ::H5Sclose(file_space);
250  if(cpt>=0) ::H5Pclose(cpt);
251  return false;
252  }}
253 
254  dataset = tools_H5Dcreate(a_loc,a_name.c_str(),a_file_type,file_space,cpt);
255  if(dataset<0) {
256  ::H5Sclose(file_space);
257  if(cpt>=0) ::H5Pclose(cpt);
258  return false;
259  }
260 
261  } else { //open an existing dataset :
262  dataset = tools_H5Dopen(a_loc,a_name.c_str());
263  if(dataset<0) {
264  if(cpt>=0) ::H5Pclose(cpt);
265  return false;
266  }
267 
268  file_space = H5Dget_space(dataset);
269  if(file_space<0) {
270  ::H5Dclose(dataset);
271  if(cpt>=0) ::H5Pclose(cpt);
272  return false;
273  }
274 
275  {hsize_t offset[1];
276  offset[0] = a_offset;
277  hsize_t count[1];
278  count[0] = number;
279  if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
280  ::H5Sclose(file_space);
281  ::H5Dclose(dataset);
282  if(cpt>=0) ::H5Pclose(cpt);
283  return false;
284  }}
285 
286  }
287 
288  hsize_t dims[1];
289  dims[0] = number;
290  hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
291  if(mem_space<0) {
292  ::H5Sclose(file_space);
293  ::H5Dclose(dataset);
294  if(cpt>=0) ::H5Pclose(cpt);
295  return false;
296  }
297 
298  if(H5Dwrite(dataset,a_mem_type,mem_space,file_space,H5P_DEFAULT,a_array)<0) {
299  ::H5Sclose(file_space);
300  ::H5Dclose(dataset);
301  if(cpt>=0) ::H5Pclose(cpt);
302  return false;
303  }
304 
305  ::H5Sclose(file_space);
306  ::H5Dclose(dataset);
307  if(cpt>=0) ::H5Pclose(cpt);
308 
309  return true;
310 }

◆ write_sub_array() [2/2]

template<class TYPE >
bool tools::hdf5::write_sub_array ( hid_t  a_loc,
const std::string &  a_name,
unsigned int  a_size,
unsigned int  a_offset,
unsigned int  a_number,
const TYPE  a_array[],
bool  a_create = true,
unsigned int  a_chunked = 0,
unsigned int  a_compress = 0 
)
inline

Definition at line 1209 of file T_tools.

1211  {
1212  return hdf5::write_sub_array<TYPE>(a_loc,a_name,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),
1213  a_create,a_chunked,a_compress,
1214  a_size,a_offset,a_number,a_array);
1215 }

◆ write_vlen() [1/2]

template<class T >
bool tools::hdf5::write_vlen ( hid_t  a_loc,
const std::string &  a_name,
hid_t  a_file_type,
hid_t  a_mem_type,
unsigned int  a_chunked,
unsigned int  a_compress,
unsigned int  a_size,
const T  a_array[] 
)
inline

Definition at line 110 of file T_tools.

113  {
114  hid_t cpt = -1;
115  if(a_compress || a_chunked) {
116  cpt = ::H5Pcreate(H5P_DATASET_CREATE);
117  if(cpt<0) return false;
118  if(a_chunked) {
119  if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
120  ::H5Pclose(cpt);
121  return false;
122  }
123  hsize_t cdims[1];
124  cdims[0] = a_chunked;
125  if(H5Pset_chunk(cpt,1,cdims)<0) {
126  ::H5Pclose(cpt);
127  return false;
128  }
129  } else {
130  if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
131  ::H5Pclose(cpt);
132  return false;
133  }
134  }
135  if(a_compress) {
136  if(H5Pset_deflate(cpt,a_compress>9?9:a_compress)<0) {
137  ::H5Pclose(cpt);
138  return false;
139  }
140  }
141  } else {
142  cpt = H5P_DEFAULT;
143  }
144 
145  hid_t dataset = -1;
146 
147  {hsize_t dims[1];
148  dims[0] = 1;
149  hid_t file_space = -1;
150  if(a_chunked) {
151  hsize_t mx_dims[1];
152  mx_dims[0] = H5S_UNLIMITED; //extendable.
153  file_space = ::H5Screate_simple(1,dims,mx_dims);
154  } else {
155  file_space = ::H5Screate_simple(1,dims,NULL);
156  }
157  if(file_space<0) {if(cpt>=0) ::H5Pclose(cpt);return false;}
158 
159  hid_t file_type = ::H5Tvlen_create(a_file_type);
160 
161  dataset = tools_H5Dcreate(a_loc,a_name.c_str(),file_type,file_space,cpt);
162  if(cpt>=0) ::H5Pclose(cpt);
163  ::H5Sclose(file_space);
164  ::H5Tclose(file_type);
165  if(dataset<0) return false;}
166 
167  hid_t mem_type = ::H5Tvlen_create(a_mem_type);
168 
169  hvl_t wdata[1];
170  wdata[0].len = a_size;
171  wdata[0].p = (void*)a_array;
172 
173  if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata)<0) {
174  ::H5Tclose(mem_type);
175  ::H5Dclose(dataset);
176  return false;
177  }
178  ::H5Tclose(mem_type);
179  ::H5Dclose(dataset);
180 
181  return true;
182 }

◆ write_vlen() [2/2]

template<class TYPE >
bool tools::hdf5::write_vlen ( hid_t  a_loc,
const std::string &  a_name,
unsigned int  a_size,
const TYPE  a_array[],
unsigned int  a_chunked = 0,
unsigned int  a_compress = 0 
)
inline

Definition at line 1155 of file T_tools.

1157  {
1158  return hdf5::write_vlen<TYPE>(a_loc,a_name,to_T_file_type(TYPE()),to_T_mem_type(TYPE()),
1159  a_chunked,a_compress,a_size,a_array);
1160 }
tools::hdf5::string_datatype
hid_t string_datatype(size_t aSize)
Definition: tools:26
tools::hdf5::histo_data_t
tools::histo::histo_data< double, unsigned int, unsigned int, double > histo_data_t
Definition: h2file:53
tools::uint64
unsigned long long uint64
Definition: typedefs:72
tools::hdf5::write_bool
bool write_bool(hid_t a_loc, const std::string &a_name, bool a_data)
Definition: tools:357
tools_H5Tget_array_dims
#define tools_H5Tget_array_dims
Definition: hdf5_h:29
tools_H5Gcreate
#define tools_H5Gcreate
Definition: hdf5_h:30
tools::hdf5::write_hdata
bool write_hdata(hid_t a_loc, const histo_data_t &a_hdata)
Definition: h2file:55
tools::buf2strings
bool buf2strings(size_t a_size, char *a_buffer, std::vector< std::string > &a_strings)
Definition: buf2lines:116
tools::hdf5::read_bool
bool read_bool(hid_t a_loc, const std::string &a_name, bool &aValue)
Definition: T_tools:1264
tools::vec_data
const T * vec_data(const std::vector< T > &a_vec)
Definition: vdata:18
tools::hdf5::H5LT_find_attribute
herr_t H5LT_find_attribute(hid_t loc_id, const char *attr_name)
Definition: atb:35
tools_H5free_memory
#define tools_H5free_memory
Definition: hdf5_h:33
tools::hdf5::group_exists_visit
herr_t group_exists_visit(hid_t a_id, const char *a_name, void *a_tag)
Definition: group_exists:26
tools_H5Dopen
#define tools_H5Dopen
Definition: hdf5_h:25
tools::mn
T mn(const T &a, const T &b)
Definition: mnmx:10
tools::hdf5::compound_mem_type
hid_t compound_mem_type(hid_t a_file_type)
Definition: tools:106
tools::hdf5::basic_mem_type
hid_t basic_mem_type(hid_t a_file_type)
Definition: tools:58
tools::hdf5::to_T_mem_type
hid_t to_T_mem_type(tools::uint64)
Definition: T_tools:42
tools::hdf5::write_atb
bool write_atb(hid_t a_id, const std::string &a_name, const std::string &a_data)
Definition: tools:320
tools::hdf5::write_string
bool write_string(hid_t a_loc, const std::string &a_name, const std::string &a_string)
Definition: tools:393
tools_typename_vforcit
#define tools_typename_vforcit(a__T, a__v, a__it)
Definition: forit:28
tools::hdf5::read_atb
bool read_atb(hid_t a_id, const std::string &a_name, std::string &a_data, unsigned int aSize=100)
Definition: tools:240
tools::hdf5::write_std_map_ss
bool write_std_map_ss(hid_t a_loc, const std::string &a_name, const std::map< std::string, std::string > &a_map, unsigned int=0, unsigned int=0)
Definition: h2file:24
tools_H5Aiterate
#define tools_H5Aiterate
Definition: hdf5_h:32
tools::sout
Definition: sout:17
tools::hdf5::read_std_map_ss
bool read_std_map_ss(hid_t a_loc, const std::string &a_name, std::map< std::string, std::string > &a_map, unsigned int=0, unsigned int=0)
Definition: h2file:38
tools_H5Tarray_create
#define tools_H5Tarray_create
Definition: hdf5_h:28
tools::hdf5::to_T_file_type
hid_t to_T_file_type(tools::uint64)
Definition: T_tools:29
tools_H5Dcreate
#define tools_H5Dcreate
Definition: hdf5_h:26
tools_mforcit
#define tools_mforcit(a__K, a__V, a__m, a__it)
Definition: forit:49
tools::hdf5::write_string_dataset
bool write_string_dataset(hid_t a_loc, const std::string &a_name, const std::string &a_string, unsigned int a_chunked=0, unsigned int a_compress=0)
Definition: tools:519
tools::hdf5::H5T_STD_U8XX
hid_t H5T_STD_U8XX()
Definition: tools:266
tools::rroot::axis_t
histo::axis< double, unsigned int > axis_t
Definition: THistogram:19
tools::hdf5::write_append_array_dataset
bool write_append_array_dataset(hid_t a_dataset, unsigned int a_number, const TYPE a_array[])
Definition: T_tools:1218
tools::hdf5::failure
int failure()
Definition: tools:24
tools::hdf5::read_hdata
bool read_hdata(hid_t a_loc, histo_data_t &a_hdata)
Definition: h2file:170
tools_H5Acreate
#define tools_H5Acreate
Definition: hdf5_h:27
tools_H5Gopen
#define tools_H5Gopen
Definition: hdf5_h:31
tools::strings2buf
bool strings2buf(const std::vector< std::string > &a_strings, size_t &a_size, char *&a_buffer)
Definition: buf2lines:94
tools::hdf5::find_attr
herr_t find_attr(hid_t loc_id, const char *name, void *op_data)
Definition: atb:27
tools::hdf5::H5LT_get_attribute_disk
herr_t H5LT_get_attribute_disk(hid_t loc_id, const char *attr_name, void *attr_out)
Definition: atb:41
tools::hdf5::read_array
bool read_array(hid_t a_loc, const std::string &a_name, unsigned int &a_size, TYPE *&a_array)
Definition: T_tools:1233
tools::hdf5::read_string
bool read_string(hid_t a_loc, const std::string &a_name, std::string &a_string)
Definition: tools:712
tools::num2s
bool num2s(unsigned short a_value, std::string &a_s)
Definition: num2s:26
tools::hdf5::H5LT_get_attribute_mem
herr_t H5LT_get_attribute_mem(hid_t obj_id, const char *attr_name, hid_t mem_type_id, void *data)
Definition: atb:16
tools::hdf5::write_array
bool write_array(hid_t a_loc, const std::string &a_name, unsigned int a_size, const TYPE a_array[], unsigned int a_chunked=0, unsigned int a_compress=0)
Definition: T_tools:1147
tools::hdf5::str_datatype
hid_t str_datatype()
Definition: tools:44