Import Geant4 10.7.0 source tree

This commit is contained in:
Gabriele Cosmo
2020-12-04 12:30:43 +01:00
parent 67ba86d073
commit dab42d2018
3770 changed files with 226369 additions and 286486 deletions
@@ -53,7 +53,7 @@ inline bool write_array(hid_t a_loc,const std::string& a_name,
cpt = ::H5Pcreate(H5P_DATASET_CREATE);
if(cpt<0) return false;
if(a_chunked) {
if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
::H5Pclose(cpt);
return false;
}
@@ -64,7 +64,7 @@ inline bool write_array(hid_t a_loc,const std::string& a_name,
return false;
}
} else {
if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
::H5Pclose(cpt);
return false;
}
@@ -87,9 +87,9 @@ inline bool write_array(hid_t a_loc,const std::string& a_name,
if(a_chunked) {
hsize_t mx_dims[1];
mx_dims[0] = H5S_UNLIMITED; //extendable.
file_space = ::H5Screate_simple(1,dims,mx_dims);
file_space = ::H5Screate_simple(1,dims,mx_dims);
} else {
file_space = ::H5Screate_simple(1,dims,NULL);
file_space = ::H5Screate_simple(1,dims,NULL);
}
if(file_space<0) {if(cpt>=0) ::H5Pclose(cpt);return false;}
dataset = tools_H5Dcreate(a_loc,a_name.c_str(),a_file_type,file_space,cpt);
@@ -98,7 +98,7 @@ inline bool write_array(hid_t a_loc,const std::string& a_name,
if(dataset<0) return false;}
if(H5Dwrite(dataset,a_mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,a_array)<0) {
::H5Dclose(dataset);
::H5Dclose(dataset);
return false;
}
::H5Dclose(dataset);
@@ -116,7 +116,7 @@ inline bool write_vlen(hid_t a_loc,const std::string& a_name,
cpt = ::H5Pcreate(H5P_DATASET_CREATE);
if(cpt<0) return false;
if(a_chunked) {
if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
::H5Pclose(cpt);
return false;
}
@@ -127,7 +127,7 @@ inline bool write_vlen(hid_t a_loc,const std::string& a_name,
return false;
}
} else {
if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
::H5Pclose(cpt);
return false;
}
@@ -150,9 +150,9 @@ inline bool write_vlen(hid_t a_loc,const std::string& a_name,
if(a_chunked) {
hsize_t mx_dims[1];
mx_dims[0] = H5S_UNLIMITED; //extendable.
file_space = ::H5Screate_simple(1,dims,mx_dims);
file_space = ::H5Screate_simple(1,dims,mx_dims);
} else {
file_space = ::H5Screate_simple(1,dims,NULL);
file_space = ::H5Screate_simple(1,dims,NULL);
}
if(file_space<0) {if(cpt>=0) ::H5Pclose(cpt);return false;}
@@ -165,14 +165,14 @@ inline bool write_vlen(hid_t a_loc,const std::string& a_name,
if(dataset<0) return false;}
hid_t mem_type = ::H5Tvlen_create(a_mem_type);
hvl_t wdata[1];
wdata[0].len = a_size;
wdata[0].p = (void*)a_array;
if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata)<0) {
::H5Tclose(mem_type);
::H5Dclose(dataset);
::H5Dclose(dataset);
return false;
}
::H5Tclose(mem_type);
@@ -200,7 +200,7 @@ inline bool write_sub_array(hid_t a_loc,const std::string& a_name,
cpt = ::H5Pcreate(H5P_DATASET_CREATE);
if(cpt<0) return false;
if(a_chunked) {
if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
::H5Pclose(cpt);
return false;
}
@@ -212,7 +212,7 @@ inline bool write_sub_array(hid_t a_loc,const std::string& a_name,
return false;
}
} else {
if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
::H5Pclose(cpt);
return false;
}
@@ -235,7 +235,7 @@ inline bool write_sub_array(hid_t a_loc,const std::string& a_name,
if(a_create) {
hsize_t dims[1];
dims[0] = a_size;
file_space = ::H5Screate_simple(1,dims,NULL);
file_space = ::H5Screate_simple(1,dims,NULL);
if(file_space<0) {
if(cpt>=0) ::H5Pclose(cpt);
return false;
@@ -265,9 +265,9 @@ inline bool write_sub_array(hid_t a_loc,const std::string& a_name,
return false;
}
file_space = H5Dget_space(dataset);
file_space = H5Dget_space(dataset);
if(file_space<0) {
::H5Dclose(dataset);
::H5Dclose(dataset);
if(cpt>=0) ::H5Pclose(cpt);
return false;
}
@@ -278,7 +278,7 @@ inline bool write_sub_array(hid_t a_loc,const std::string& a_name,
count[0] = number;
if(H5Sselect_hyperslab(file_space,H5S_SELECT_SET,offset,NULL,count,NULL)<0) {
::H5Sclose(file_space);
::H5Dclose(dataset);
::H5Dclose(dataset);
if(cpt>=0) ::H5Pclose(cpt);
return false;
}}
@@ -287,7 +287,7 @@ inline bool write_sub_array(hid_t a_loc,const std::string& a_name,
hsize_t dims[1];
dims[0] = number;
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
if(mem_space<0) {
::H5Sclose(file_space);
::H5Dclose(dataset);
@@ -297,7 +297,7 @@ inline bool write_sub_array(hid_t a_loc,const std::string& a_name,
if(H5Dwrite(dataset,a_mem_type,mem_space,file_space,H5P_DEFAULT,a_array)<0) {
::H5Sclose(file_space);
::H5Dclose(dataset);
::H5Dclose(dataset);
if(cpt>=0) ::H5Pclose(cpt);
return false;
}
@@ -314,8 +314,8 @@ inline bool write_append_array_dataset(hid_t a_dataset,hid_t /*a_file_type*/,hid
unsigned int a_number,const T a_array[]) {
hsize_t old_size = 0;
{hid_t dataspace = H5Dget_space(a_dataset);
if(dataspace<0) return false;
{hid_t dataspace = H5Dget_space(a_dataset);
if(dataspace<0) return false;
hsize_t dims[1];
if(H5Sget_simple_extent_dims(dataspace,dims,NULL)<0) {
::H5Sclose(dataspace);
@@ -329,7 +329,7 @@ inline bool write_append_array_dataset(hid_t a_dataset,hid_t /*a_file_type*/,hid
// if(H5Dextend(dataset,exts)<0) {
if(H5Dset_extent(a_dataset,exts)<0) return false;}
hid_t file_space = H5Dget_space(a_dataset);
hid_t file_space = H5Dget_space(a_dataset);
if(file_space<0) return false;
{hsize_t offset[1];
@@ -343,7 +343,7 @@ inline bool write_append_array_dataset(hid_t a_dataset,hid_t /*a_file_type*/,hid
hsize_t dims[1];
dims[0] = a_number;
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
if(mem_space<0) {
::H5Sclose(file_space);
return false;
@@ -366,8 +366,8 @@ inline bool write_append_vlen_dataset(hid_t a_dataset,hid_t /*a_file_type*/,hid_
unsigned int a_number,const T a_array[]) {
hsize_t old_size = 0;
{hid_t dataspace = H5Dget_space(a_dataset);
if(dataspace<0) return false;
{hid_t dataspace = H5Dget_space(a_dataset);
if(dataspace<0) return false;
hsize_t dims[1];
if(H5Sget_simple_extent_dims(dataspace,dims,NULL)<0) {
::H5Sclose(dataspace);
@@ -381,7 +381,7 @@ inline bool write_append_vlen_dataset(hid_t a_dataset,hid_t /*a_file_type*/,hid_
// if(H5Dextend(dataset,exts)<0) {
if(H5Dset_extent(a_dataset,exts)<0) return false;}
hid_t file_space = H5Dget_space(a_dataset);
hid_t file_space = H5Dget_space(a_dataset);
if(file_space<0) return false;
{hsize_t offset[1];
@@ -395,18 +395,18 @@ inline bool write_append_vlen_dataset(hid_t a_dataset,hid_t /*a_file_type*/,hid_
hsize_t dims[1];
dims[0] = 1;
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
if(mem_space<0) {
::H5Sclose(file_space);
return false;
}
hid_t mem_type = ::H5Tvlen_create(a_mem_type);
hvl_t wdata[1];
wdata[0].len = a_number;
wdata[0].p = (void*)a_array;
if(H5Dwrite(a_dataset,mem_type,mem_space,file_space,H5P_DEFAULT,wdata)<0) {
::H5Tclose(mem_type);
::H5Sclose(mem_space);
@@ -427,7 +427,7 @@ inline bool write_append_array(hid_t a_loc,const std::string& a_name,hid_t a_fil
hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
if(dataset<0) return false;
bool status = write_append_array_dataset(dataset,a_file_type,a_mem_type,a_number,a_array);
::H5Dclose(dataset);
::H5Dclose(dataset);
return status;
}
@@ -443,7 +443,7 @@ inline bool write_array_struct(
){
hsize_t dims[1];
dims[0] = a_size;
hid_t dataspace = ::H5Screate_simple(1,dims,NULL);
hid_t dataspace = ::H5Screate_simple(1,dims,NULL);
if(dataspace<0) return false;
hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),a_create_type,dataspace,H5P_DEFAULT);
@@ -453,12 +453,12 @@ inline bool write_array_struct(
}
if(H5Dwrite(dataset,aWriteType,H5S_ALL,H5S_ALL,H5P_DEFAULT,a_array)<0) {
::H5Dclose(dataset);
::H5Dclose(dataset);
::H5Sclose(dataspace);
return false;
}
::H5Dclose(dataset);
::H5Dclose(dataset);
::H5Sclose(dataspace);
return true;
@@ -476,7 +476,7 @@ inline bool read_scalar(hid_t a_loc,const std::string& a_name,hid_t a_mem_type,T
return false;
}
hid_t mem_space = ::H5Screate(H5S_SCALAR);
hid_t mem_space = ::H5Screate(H5S_SCALAR);
if(mem_space<0) {
::H5Sclose(file_space);
::H5Dclose(dataset);
@@ -550,7 +550,7 @@ inline bool read_array(hid_t a_loc,const std::string& a_name,hid_t a_mem_type,un
return true; //It is ok.
}
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
if(mem_space<0) {
::H5Sclose(file_space);
::H5Dclose(dataset);
@@ -631,8 +631,8 @@ inline bool read_vlen(hid_t a_loc,const std::string& a_name,hid_t a_mem_type,uns
a_array = 0;
return false;
}
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
if(mem_space<0) {
::H5Sclose(file_space);
::H5Dclose(dataset);
@@ -666,9 +666,9 @@ inline bool read_vlen(hid_t a_loc,const std::string& a_name,hid_t a_mem_type,uns
for(hsize_t index=0;index<len;index++,pos++,_data++) *pos = *_data;
}
a_size = len;
::H5Dvlen_reclaim(mem_type,mem_space,H5P_DEFAULT,rdata);
::H5Tclose(mem_type);
::H5Sclose(mem_space);
::H5Sclose(file_space);
@@ -734,7 +734,7 @@ inline bool read_sub_array(hid_t a_loc,const std::string& a_name,hid_t a_mem_typ
}
// abcdef
// 012345
// 012345
int remain = sz-a_offset;
if(remain<=0) {
::H5Sclose(file_space);
@@ -743,7 +743,7 @@ inline bool read_sub_array(hid_t a_loc,const std::string& a_name,hid_t a_mem_typ
a_array = 0;
return a_number?false:true;
}
int number = (int(a_number)<=remain) ? int(a_number) : remain;
if(number<=0) {
::H5Sclose(file_space);
@@ -766,7 +766,7 @@ inline bool read_sub_array(hid_t a_loc,const std::string& a_name,hid_t a_mem_typ
}}
dims[0] = number;
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
if(mem_space<0) {
::H5Sclose(file_space);
::H5Dclose(dataset);
@@ -850,7 +850,7 @@ inline bool read_sub_vlen(hid_t a_loc,const std::string& a_name,hid_t a_mem_type
}
// abcdef
// 012345
// 012345
int remain = sz-a_offset;
if(remain<=0) {
::H5Sclose(file_space);
@@ -859,7 +859,7 @@ inline bool read_sub_vlen(hid_t a_loc,const std::string& a_name,hid_t a_mem_type
a_array = 0;
return false;
}
{hsize_t offset[1];
offset[0] = a_offset;
hsize_t count[1];
@@ -873,7 +873,7 @@ inline bool read_sub_vlen(hid_t a_loc,const std::string& a_name,hid_t a_mem_type
}}
dims[0] = 1;
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
if(mem_space<0) {
::H5Sclose(file_space);
::H5Dclose(dataset);
@@ -907,9 +907,9 @@ inline bool read_sub_vlen(hid_t a_loc,const std::string& a_name,hid_t a_mem_type
for(hsize_t index=0;index<len;index++,pos++,_data++) *pos = *_data;
}
a_size = len;
::H5Dvlen_reclaim(mem_type,mem_space,H5P_DEFAULT,rdata);
::H5Tclose(mem_type);
::H5Sclose(mem_space);
::H5Sclose(file_space);
@@ -994,7 +994,7 @@ inline bool read_array_struct(
return false;
}}
hid_t memspace = ::H5Screate_simple(dimn,dims,NULL);
hid_t memspace = ::H5Screate_simple(dimn,dims,NULL);
if(memspace<0) {
delete [] dims;
::H5Sclose(dataspace);
@@ -1064,7 +1064,7 @@ inline bool read_struct(hid_t a_loc,const std::string& a_name,hid_t aReadType,T&
::H5Dclose(dataset);
return true;
}
template <class TYPE>
inline bool write_scalar(hid_t a_loc,const std::string& a_name,const TYPE& aData) {
hid_t scalar = ::H5Screate(H5S_SCALAR);
@@ -1076,7 +1076,7 @@ inline bool write_scalar(hid_t a_loc,const std::string& a_name,const TYPE& aData
return false;
}
if(H5Pset_layout(compact,H5D_COMPACT)<0) {
if(H5Pset_layout(compact,H5D_COMPACT)<0) {
::H5Pclose(compact);
::H5Sclose(scalar);
return false;
@@ -1088,22 +1088,22 @@ inline bool write_scalar(hid_t a_loc,const std::string& a_name,const TYPE& aData
::H5Sclose(scalar);
return false;
}
if(::H5Dwrite(dataset,to_T_mem_type(TYPE()),H5S_ALL,H5S_ALL,H5P_DEFAULT,&aData)<0) {
::H5Pclose(compact);
::H5Sclose(scalar);
::H5Dclose(dataset);
::H5Dclose(dataset);
return false;
}
::H5Pclose(compact);
::H5Sclose(scalar);
::H5Dclose(dataset);
::H5Dclose(dataset);
return true;
}
template <class T>
inline bool write_struct(hid_t a_loc,const std::string& a_name,
inline bool write_struct(hid_t a_loc,const std::string& a_name,
hid_t a_create_type,hid_t aWriteType,const T& aData) {
hid_t scalar = ::H5Screate(H5S_SCALAR);
if(scalar<0) return false;
@@ -1114,7 +1114,7 @@ inline bool write_struct(hid_t a_loc,const std::string& a_name,
return false;
}
if(H5Pset_layout(compact,H5D_COMPACT)<0) {
if(H5Pset_layout(compact,H5D_COMPACT)<0) {
::H5Pclose(compact);
::H5Sclose(scalar);
return false;
@@ -1130,13 +1130,13 @@ inline bool write_struct(hid_t a_loc,const std::string& a_name,
if(H5Dwrite(dataset,aWriteType,H5S_ALL,H5S_ALL,H5P_DEFAULT,&aData)<0) {
::H5Pclose(compact);
::H5Sclose(scalar);
::H5Dclose(dataset);
::H5Dclose(dataset);
return false;
}
::H5Pclose(compact);
::H5Sclose(scalar);
::H5Dclose(dataset);
::H5Dclose(dataset);
return true;
}
@@ -1288,7 +1288,7 @@ inline bool write_scalar_atb(hid_t aDS,const std::string& a_name,const TYPE& aDa
if(has_attr==1) {
if(H5Adelete(aDS,a_name.c_str())<0) return false;
}
hid_t scalar = ::H5Screate(H5S_SCALAR);
if(scalar<0) return false;
@@ -1297,16 +1297,16 @@ inline bool write_scalar_atb(hid_t aDS,const std::string& a_name,const TYPE& aDa
::H5Sclose(scalar);
return false;
}
if(H5Awrite(aid,to_T_mem_type(TYPE()),&aData)<0) {
::H5Sclose(scalar);
::H5Aclose(aid);
return false;
}
::H5Sclose(scalar);
::H5Aclose(aid);
return true;
}
@@ -1321,7 +1321,7 @@ namespace hdf5 {
inline bool write_strings(hid_t a_loc,const std::string& a_name,
size_t a_number,const char** a_strings,
unsigned int a_chunked = 0,unsigned int a_compress = 0) {
size_t sz;char* buffer;
size_t sz;char* buffer;
if(!tools::strings2buf(a_number,a_strings,sz,buffer)) return false;
sz--;
bool status = hdf5::write_array<char>(a_loc,a_name,to_T_file_type(char()),to_T_mem_type(char()),
@@ -1333,7 +1333,7 @@ inline bool write_strings(hid_t a_loc,const std::string& a_name,
inline bool write_strings(hid_t a_loc,const std::string& a_name,
const std::vector<std::string>& a_strings,
unsigned int a_chunked = 0,unsigned int a_compress = 0) {
size_t sz;char* buffer;
size_t sz;char* buffer;
if(!tools::strings2buf(a_strings,sz,buffer)) return false;
sz--;
bool status = hdf5::write_array<char>(a_loc,a_name,to_T_file_type(char()),to_T_mem_type(char()),
@@ -1343,7 +1343,7 @@ inline bool write_strings(hid_t a_loc,const std::string& a_name,
}
inline bool write_append_strings(hid_t a_loc,const std::string& a_name,size_t a_number,const char** a_strings) {
size_t sz;char* buffer;
size_t sz;char* buffer;
if(!tools::strings2buf(a_number,a_strings,sz,buffer)) return false;
sz--;
bool status = hdf5::write_append_array<char>(a_loc,a_name,to_T_file_type(char()),to_T_mem_type(char()),(unsigned int)sz,buffer);
@@ -1352,7 +1352,7 @@ inline bool write_append_strings(hid_t a_loc,const std::string& a_name,size_t a_
}
inline bool write_append_strings(hid_t a_loc,const std::string& a_name,const std::vector<std::string>& a_strings) {
size_t sz;char* buffer;
size_t sz;char* buffer;
if(!tools::strings2buf(a_strings,sz,buffer)) return false;
sz--;
bool status = hdf5::write_append_array<char>(a_loc,a_name,to_T_file_type(char()),to_T_mem_type(char()),(unsigned int)sz,buffer);
@@ -41,7 +41,7 @@ inline herr_t group_exists_visit(hid_t a_id,const char* a_name,void* a_tag){ //a
inline bool group_exists(hid_t a_file_id,const std::string& a_name) {
group_exists_struct visitor(a_name);
::H5Giterate(a_file_id,".",NULL,group_exists_visit,&visitor);
return visitor.m_found;
return visitor.m_found;
}
}}
@@ -63,7 +63,7 @@ inline bool write_hdata(hid_t a_loc,const histo_data_t& a_hdata) {
if(!write_std_vec<double>(a_loc,"bin_Sw2",a_hdata.m_bin_Sw2)) return false;
if(!write_std_vec_vec<double>(a_loc,"bin_Sxw",a_hdata.m_bin_Sxw)) return false;
if(!write_std_vec_vec<double>(a_loc,"bin_Sx2w",a_hdata.m_bin_Sx2w)) return false;
// axes :
{std::string name,saxis;
for(unsigned int iaxis=0;iaxis<a_hdata.m_dimension;iaxis++) {
@@ -76,15 +76,15 @@ inline bool write_hdata(hid_t a_loc,const histo_data_t& a_hdata) {
if(!write_scalar<double>(a_loc,name+"maximum_value",_axis.m_maximum_value)) return false;
if(!write_scalar<bool>(a_loc,name+"fixed",_axis.m_fixed)) return false;
if(!write_scalar<double>(a_loc,name+"bin_width",_axis.m_bin_width)) return false;
if(!write_std_vec<double>(a_loc,name+"edges",_axis.m_edges)) return false;
if(!write_std_vec<double>(a_loc,name+"edges",_axis.m_edges)) return false;
}}
// etc :
if(!write_std_vec<double>(a_loc,"in_range_plane_Sxyw",a_hdata.m_in_range_plane_Sxyw)) return false;
// m_annotations :
if(!write_std_map_ss(a_loc,"annotations",a_hdata.m_annotations)) return false;
return true;
}
@@ -116,7 +116,7 @@ inline bool write_histo(std::ostream& a_out,hid_t a_loc,const std::string& a_nam
}
if(!write_hdata(histo,a_histo.dac())) {::H5Gclose(histo);return false;}
::H5Gclose(histo);
a_histo.not_a_profile(); //trick to be sure to use this function on an histo and not a profile.
@@ -151,7 +151,7 @@ inline bool write_profile(std::ostream& a_out,hid_t a_loc,const std::string& a_n
return false;
}
typename PROFILE::pd_t pdata = a_histo.get_histo_data();
typename PROFILE::pd_t pdata = a_histo.get_histo_data();
if(!write_hdata(histo,pdata)) {::H5Gclose(histo);return false;}
@@ -175,10 +175,10 @@ inline bool read_hdata(hid_t a_loc,histo_data_t& a_hdata) {
if(!read_std_vec<unsigned int>(a_loc,"bin_entries",a_hdata.m_bin_entries)) return false;
if(!read_std_vec<double>(a_loc,"bin_Sw",a_hdata.m_bin_Sw)) return false;
if(!read_std_vec<double>(a_loc,"bin_Sw2",a_hdata.m_bin_Sw2)) return false;
if(!read_std_vec_vec<double>(a_loc,"bin_Sxw",a_hdata.m_bin_Sxw)) return false;
if(!read_std_vec_vec<double>(a_loc,"bin_Sx2w",a_hdata.m_bin_Sx2w)) return false;
// axes :
{a_hdata.m_axes.resize(a_hdata.m_dimension);
std::string name,saxis;
@@ -192,15 +192,15 @@ inline bool read_hdata(hid_t a_loc,histo_data_t& a_hdata) {
if(!read_scalar<double>(a_loc,name+"maximum_value",_axis.m_maximum_value)) return false;
if(!read_scalar<bool>(a_loc,name+"fixed",_axis.m_fixed)) return false;
if(!read_scalar<double>(a_loc,name+"bin_width",_axis.m_bin_width)) return false;
if(!read_std_vec<double>(a_loc,name+"edges",_axis.m_edges)) return false;
if(!read_std_vec<double>(a_loc,name+"edges",_axis.m_edges)) return false;
}}
// etc :
if(!read_std_vec<double>(a_loc,"in_range_plane_Sxyw",a_hdata.m_in_range_plane_Sxyw)) return false;
// m_annotations :
if(!read_std_map_ss(a_loc,"annotations",a_hdata.m_annotations)) return false;
return true;
}
@@ -227,11 +227,11 @@ inline bool read_histo(std::ostream& a_out,hid_t a_loc,const std::string& a_name
if(a_verb_class) {
a_out << "tools::hdf5::read_histo :"
<< " read class " << tools::sout(sclass) << " not " << tools::sout(HISTO::s_class()) << std::endl;
}
}
::H5Gclose(histo);
return false;
}
int v;
if(!read_atb(histo,"version",v)) {
a_out << "tools::hdf5::read_histo : read_atb version failed." << std::endl;
@@ -244,9 +244,9 @@ inline bool read_histo(std::ostream& a_out,hid_t a_loc,const std::string& a_name
if(!read_hdata(histo,hdata)) {::H5Gclose(histo);return false;}
::H5Gclose(histo);
hdata.update_fast_getters();
a_histo = new HISTO;
a_histo->copy_from_data(hdata);
a_histo->not_a_profile(); //trick to be sure to use this function on an histo and not a profile.
@@ -278,7 +278,7 @@ inline bool read_profile(std::ostream& a_out,hid_t a_loc,const std::string& a_na
::H5Gclose(histo);
return false;
}
int v;
if(!read_atb(histo,"version",v)) {
a_out << "tools::hdf5::read_profile : read_atb version failed." << std::endl;
@@ -298,9 +298,9 @@ inline bool read_profile(std::ostream& a_out,hid_t a_loc,const std::string& a_na
if(!read_scalar<double>(histo,"max_v",pdata.m_max_v)) {::H5Gclose(histo);return false;}
::H5Gclose(histo);
pdata.update_fast_getters();
a_histo = new PROFILE;
a_histo->copy_from_data(pdata);
return true;
@@ -20,6 +20,7 @@
#define tools_H5Gcreate H5Gcreate
#define tools_H5Gopen H5Gopen
#define tools_H5Aiterate H5Aiterate
#define tools_H5free_memory free
#else
#define tools_H5Dopen H5Dopen1
#define tools_H5Dcreate H5Dcreate1
@@ -29,6 +30,7 @@
#define tools_H5Gcreate H5Gcreate1
#define tools_H5Gopen H5Gopen1
#define tools_H5Aiterate H5Aiterate1
#define tools_H5free_memory H5free_memory
#endif
#endif
@@ -30,8 +30,8 @@ inline bool read_header(hid_t a_file,std::string& a_writer,int& a_data_schema_ve
}
::H5Gclose(header);
return true;
}
}
}}
#endif
@@ -90,14 +90,14 @@ public:
m_basket_pos = 0;
m_basket_end = 0;
return false;
}
}
if(m_want_new_basket_size) {
delete [] m_basket;
m_basket = new T[m_want_new_basket_size];
m_basket_pos = 0;
m_basket_size = m_want_new_basket_size;
m_want_new_basket_size = 0;
}
}
tools::uint64 remain = m_branch.entries()-m_branch.pos();
size_t n = tools::mn<size_t>((size_t)remain,m_basket_size);
if(!m_branch.read_page<T>(n,m_basket)) {
@@ -107,7 +107,7 @@ public:
return false;
}
m_basket_pos = 0;
m_basket_end = n;
m_basket_end = n;
}
m_ref = m_basket[m_basket_pos];
m_basket_pos++;
@@ -182,7 +182,7 @@ public:
if(&a_from==this) return *this;
m_name = a_from.m_name;
m_basket_size = a_from.m_basket_size;
m_basket_pos = 0;
m_basket_pos = 0;
m_basket_end = 0;
m_want_new_basket_size = 0;
return *this;
@@ -257,9 +257,9 @@ public:
TOOLS_CLASS_STRING_VALUE(vector_int,vector<int>)
TOOLS_CLASS_STRING_VALUE(vector_float,vector<float>)
TOOLS_CLASS_STRING_VALUE(vector_double,vector<double>)
TOOLS_CLASS_STRING_VALUE(string,string)
TOOLS_CLASS_STRING_VALUE(vector_int64,vector<tools::int64>)
TOOLS_CLASS_STRING_VALUE(vector_uchar,vector<tools::uchar>)
TOOLS_CLASS_STRING_VALUE(vector_ushort,vector<tools::ushort>)
@@ -434,7 +434,7 @@ public:
m_name = a_from.m_name;
return *this;
}
public:
public:
//const std::vector<T>& ref() const {return m_ref;}
protected:
std::vector<T>& m_ref;
@@ -472,7 +472,7 @@ public:
parent::operator=(a_from);
return *this;
}
public:
public:
//bool get_entry(std::vector<T>& a_v) const {
// a_v = m_tmp;
// return true;
@@ -635,7 +635,7 @@ public:
m_name = a_from.m_name;
return *this;
}
public:
public:
//const std::string& ref() const {return m_ref;}
protected:
std::string& m_ref;
@@ -687,7 +687,7 @@ public:
protected:
std::string m_tmp;
};
public:
ntuple(std::ostream& a_out,hid_t a_group,const std::string& a_name,
unsigned int a_compress,size_t /*a_basket_size*//* = 32000*/)
@@ -712,22 +712,22 @@ public:
if(!col) {tools::safe_clear<icol>(m_cols);return;}\
m_cols.push_back(col);\
}
TOOLS_HDF5_NTUPLE_READ_CREATE_COL(char)
else TOOLS_HDF5_NTUPLE_READ_CREATE_COL(short)
else TOOLS_HDF5_NTUPLE_READ_CREATE_COL(int)
else TOOLS_HDF5_NTUPLE_READ_CREATE_COL(tools::int64)
else TOOLS_HDF5_NTUPLE_READ_CREATE_COL(float)
else TOOLS_HDF5_NTUPLE_READ_CREATE_COL(double)
else TOOLS_HDF5_NTUPLE_READ_CREATE_COL(tools::byte)
else TOOLS_HDF5_NTUPLE_READ_CREATE_COL(tools::byte)
else TOOLS_HDF5_NTUPLE_READ_CREATE_COL(tools::ushort)
else TOOLS_HDF5_NTUPLE_READ_CREATE_COL(tools::uint32)
else TOOLS_HDF5_NTUPLE_READ_CREATE_COL(tools::uint64)
//else TOOLS_HDF5_NTUPLE_READ_CREATE_COL(bool) //use byte=uchar.
else
if((*it)->form()==s_string()) {
column_string* col = new column_string(*this,*(*it),false,(*it)->name(),0);
@@ -739,10 +739,10 @@ public:
else TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL(short,short)
else TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL(int,int)
else TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL(int64,tools::int64)
else TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL(float,float)
else TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL(double,double)
else TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL(uchar,tools::uchar)
else TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL(ushort,tools::ushort)
else TOOLS_HDF5_NTUPLE_READ_CREATE_VEC_COL(uint32,tools::uint32)
@@ -771,11 +771,11 @@ public:
if(!initialize(a_out,a_bd)) {}
}
ntuple(std::ostream& a_out,hid_t a_group,const tools::ntuple_booking& a_bkg,
ntuple(std::ostream& a_out,hid_t a_group,const tools::ntuple_booking& a_bkg,
unsigned int a_compress,size_t a_basket_size/* = 32000*/)
:store(a_out,a_group,a_bkg.name(),true,a_compress) //true=write
,m_title(a_bkg.title())
{
{
const std::vector<tools::column_booking>& cols = a_bkg.columns();
tools_vforcit(tools::column_booking,cols,it){
@@ -820,22 +820,22 @@ public:
return;\
}\
}
TOOLS_HDF5_NTUPLE_CREATE_COL(char)
else TOOLS_HDF5_NTUPLE_CREATE_COL(short)
else TOOLS_HDF5_NTUPLE_CREATE_COL(int)
else TOOLS_HDF5_NTUPLE_CREATE_COL(tools::int64)
else TOOLS_HDF5_NTUPLE_CREATE_COL(float)
else TOOLS_HDF5_NTUPLE_CREATE_COL(double)
else TOOLS_HDF5_NTUPLE_CREATE_COL(tools::byte)
else TOOLS_HDF5_NTUPLE_CREATE_COL(tools::byte)
else TOOLS_HDF5_NTUPLE_CREATE_COL(tools::ushort)
else TOOLS_HDF5_NTUPLE_CREATE_COL(tools::uint32)
else TOOLS_HDF5_NTUPLE_CREATE_COL(tools::uint64)
//else TOOLS_HDF5_NTUPLE_CREATE_COL(bool) //use byte=uchar.
else if((*it).cls_id()==tools::_cid(std::string())) {
if(!create_column_string((*it).name(),a_basket_size)) {
m_out << "tools::hdf5::ntuple :"
@@ -849,10 +849,10 @@ public:
else TOOLS_HDF5_NTUPLE_CREATE_VEC_COL(short)
else TOOLS_HDF5_NTUPLE_CREATE_VEC_COL(int)
else TOOLS_HDF5_NTUPLE_CREATE_VEC_COL(tools::int64)
else TOOLS_HDF5_NTUPLE_CREATE_VEC_COL(float)
else TOOLS_HDF5_NTUPLE_CREATE_VEC_COL(double)
else TOOLS_HDF5_NTUPLE_CREATE_VEC_COL(tools::uchar)
else TOOLS_HDF5_NTUPLE_CREATE_VEC_COL(tools::ushort)
else TOOLS_HDF5_NTUPLE_CREATE_VEC_COL(tools::uint32)
@@ -868,7 +868,7 @@ public:
<< std::endl;
tools::safe_clear<icol>(m_cols);
return;
}
}
}
#undef TOOLS_HDF5_NTUPLE_CREATE_COL
#undef TOOLS_HDF5_NTUPLE_CREATE_VEC_COL
@@ -885,9 +885,9 @@ public:
bool initialize(std::ostream& a_out,const tools::ntuple_binding& a_bd = tools::ntuple_binding()) {
tools::safe_clear<icol>(m_cols);
{tools_vforcit(pages*,m_pagess,it) (*it)->reset_pos();}
tools_vforcit(pages*,m_pagess,it) {
#define TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL(a__type) \
if((*it)->form()==tools::stype(a__type())) {\
a__type* user_var = a_bd.find_variable<a__type>((*it)->name());\
@@ -901,7 +901,7 @@ public:
m_cols.push_back(col);\
}\
}
#define TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL(a__vec_type,a__type) \
if((*it)->form()==s_vector_##a__vec_type()) {\
std::vector<a__type>* user_var = a_bd.find_variable< std::vector<a__type> >((*it)->name());\
@@ -921,17 +921,17 @@ public:
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL(short)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL(int)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL(tools::int64)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL(float)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL(double)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL(tools::byte)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL(tools::byte)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL(tools::ushort)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL(tools::uint32)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL(tools::uint64)
//else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_COL(bool) //use byte=uchar.
else
if((*it)->form()==s_string()) {
std::string* user_var = a_bd.find_variable<std::string>((*it)->name());
@@ -945,15 +945,15 @@ public:
m_cols.push_back(col);
}
}
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL(char,char)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL(short,short)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL(int,int)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL(int64,tools::int64)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL(float,float)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL(double,double)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL(uchar,tools::uchar)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL(ushort,tools::ushort)
else TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL(uint32,tools::uint32)
@@ -975,9 +975,9 @@ public:
#undef TOOLS_HDF5_NTUPLE_READ_BINDING_CREATE_VEC_COL
return true;
}
const std::string& title() const {return m_title;}
const std::vector<icol*>& columns() const {return m_cols;}
std::vector<icol*>& columns() {return m_cols;}
@@ -1024,7 +1024,7 @@ public:
m_cols.push_back(col);
return col;
}
template <class T>
column_ref<T>* find_column_ref(const std::string& a_name) {
icol* col = tools::find_named<icol>(m_cols,a_name);
@@ -1037,7 +1037,7 @@ public:
if(!col) return 0;
return tools::id_cast<icol, column<T> >(*col);
}
template <class T>
std_vector_column_ref<T>* find_std_vector_column_ref(const std::string& a_name) {
icol* col = tools::find_named<icol>(m_cols,a_name);
@@ -1050,13 +1050,13 @@ public:
if(!col) return 0;
return tools::id_cast<icol, std_vector_column<T> >(*col);
}
column_string* find_column_string(const std::string& a_name) {
icol* col = tools::find_named<icol>(m_cols,a_name);
if(!col) return 0;
return tools::id_cast<icol, column_string >(*col);
}
bool add_row() { //write.
if(m_cols.empty()) return false;
bool status = true;
@@ -1074,7 +1074,7 @@ public:
}
return status;
}
bool set_basket_size(size_t a_size) {
tools_vforit(icol*,m_cols,it) {if(!(*it)->set_basket_size(a_size)) return false;}
return true;
@@ -64,7 +64,7 @@ public:
return;
}
if(!read_scalar<tools::uint64>(m_group,s_entries(),m_entries)) {
m_out << "pages::pages : read_scalar(entries) failed." << std::endl;
m_out << "pages::pages : read_scalar(entries) failed." << std::endl;
::H5Gclose(m_group);
m_group = -1;
return;
@@ -76,7 +76,7 @@ public:
if(!write_scalar<tools::uint64>(m_group,s_entries(),m_entries)) {
m_out << "pages::~pages : write_scalar(entries) failed." << std::endl;
}
if(m_dataset>=0) ::H5Dclose(m_dataset);
if(m_dataset>=0) ::H5Dclose(m_dataset);
}
::H5Gclose(m_group);
#ifdef TOOLS_MEM
@@ -92,7 +92,7 @@ protected:
pages& operator=(const pages&){return *this;}
public:
bool is_valid() const {return m_group<0?false:true;}
const std::string& name() const {return m_name;}
const std::string& form() const {return m_form;}
//int type() const {return m_type;}
@@ -100,7 +100,7 @@ public:
tools::uint64 entries() const {return m_entries;}
tools::uint64 pos() const {return m_pos;}
void reset_pos() {m_pos = 0;}
template <class TYPE>
bool write_page(size_t a_size,const TYPE* a_array) {
if(!m_pos) {
@@ -123,7 +123,7 @@ public:
m_entries = m_pos;
return true;
}
template <class TYPE>
bool read_page(size_t a_size,TYPE* a_array) {
//it is assumed that a_array can contain a_size*sizeof(TYPE) bytes.
@@ -144,7 +144,7 @@ public:
TYPE* wpos = (TYPE*)a_array;
for(size_t i=0;i<n;i++,rpos++,wpos++) *wpos = *rpos;
for(size_t i=n;i<_size;i++,rpos++,wpos++) *wpos = TYPE();}
delete [] array;
m_pos += n;
@@ -222,7 +222,7 @@ public:
m_entries++;
return true;
}
/*
bool write_string(const std::string& a_string) {return write_vlen<char>(a_string.size(),a_string.c_str());}
@@ -234,15 +234,15 @@ public:
delete [] _data;
return true;
}
*/
*/
/*
bool write_strings(size_t a_number,void* a_array) {
size_t sz = m_size*a_number;
char* buffer = new char[sz];
{char* pos = buffer;
for(size_t index=0;index<sz;index++,pos++) *pos = ' ';}
for(size_t index=0;index<sz;index++,pos++) *pos = ' ';}
{char** strings = (char**)a_array;
char* pos = buffer;
size_t ls;
@@ -253,8 +253,8 @@ public:
*(pos+m_size-1) = 0;
pos += m_size;
}}
if(!m_pos) {
if(!m_pos) {
unsigned int chunked = 32*m_size; //<size>A strings.
if(!write_array<char>(m_group,s_pages(),sz,buffer,chunked,m_compress)) {
m_out << "pages::write_strings : write_strings() failed. Pos " << m_pos << std::endl;
@@ -295,11 +295,11 @@ public:
::memcpy(strings[index],pos,m_size*sizeof(char));
pos += m_size;
}}
delete [] array;
delete [] array;
m_pos += n;
return true;
}
*/
*/
protected:
std::ostream& m_out;
std::string m_name;
@@ -153,7 +153,7 @@ protected:
public:
std::ostream& out() const {return m_out;}
//bool fill(tools::uint32 &a_n){a_n = 0;return true;}
bool entries(tools::uint64& a_entries) const {
if(m_pagess.empty()) {a_entries = 0;return true;}
a_entries = m_pagess.front()->entries();
@@ -165,9 +165,9 @@ public:
return false;
}
}
return true;
return true;
}
pages* create_pages(const std::string& a_name,const std::string& a_form) {
//::printf("debug : create_pages %s %s\n",a_name.c_str(),a_form.c_str());
pages* _pages = new pages(m_out,m_group,a_name,a_form,m_write,m_compress);
@@ -127,20 +127,20 @@ inline hid_t compound_mem_type(hid_t a_file_type){
//printf("debug : members : %d (%d) : %s : begin\n",index,mn,mname);
{H5T_class_t mclass = H5Tget_class(mtype);
if( (mclass==H5T_INTEGER) ||
if( (mclass==H5T_INTEGER) ||
(mclass==H5T_STRING) ||
(mclass==H5T_FLOAT) ) {
hid_t mmem_type = basic_mem_type(mtype);
if(mmem_type<0) {
::H5Tclose(mtype);
if(mname) ::free(mname);
if(mname) tools_H5free_memory(mname);
::H5Tclose(mem_type);
return failure();
}
if(H5Tinsert(mem_type,mname,moffset,mmem_type)<0) {
::H5Tclose(mmem_type);
::H5Tclose(mtype);
if(mname) ::free(mname);
if(mname) tools_H5free_memory(mname);
::H5Tclose(mem_type);
return failure();
}
@@ -154,7 +154,7 @@ inline hid_t compound_mem_type(hid_t a_file_type){
delete [] dims;
delete [] perms;
::H5Tclose(mtype);
if(mname) ::free(mname);
if(mname) tools_H5free_memory(mname);
::H5Tclose(mem_type);
return failure();
}
@@ -163,7 +163,7 @@ inline hid_t compound_mem_type(hid_t a_file_type){
delete [] dims;
delete [] perms;
::H5Tclose(mtype);
if(mname) ::free(mname);
if(mname) tools_H5free_memory(mname);
::H5Tclose(mem_type);
return failure();
}
@@ -173,7 +173,7 @@ inline hid_t compound_mem_type(hid_t a_file_type){
delete [] perms;
::H5Tclose(base_type);
::H5Tclose(mtype);
if(mname) ::free(mname);
if(mname) tools_H5free_memory(mname);
::H5Tclose(mem_type);
return failure();
}
@@ -184,7 +184,7 @@ inline hid_t compound_mem_type(hid_t a_file_type){
if(array_type<0) {
::H5Tclose(mmem_type);
::H5Tclose(mtype);
if(mname) ::free(mname);
if(mname) tools_H5free_memory(mname);
::H5Tclose(mem_type);
return failure();
}
@@ -193,7 +193,7 @@ inline hid_t compound_mem_type(hid_t a_file_type){
if(H5Tinsert(mem_type,mname,moffset,array_type)<0) {
::H5Tclose(array_type);
::H5Tclose(mtype);
if(mname) ::free(mname);
if(mname) tools_H5free_memory(mname);
::H5Tclose(mem_type);
return failure();
}
@@ -203,27 +203,27 @@ inline hid_t compound_mem_type(hid_t a_file_type){
hid_t mmem_type = compound_mem_type(mtype);
if(mem_type<0) {
::H5Tclose(mtype);
if(mname) ::free(mname);
if(mname) tools_H5free_memory(mname);
::H5Tclose(mem_type);
return failure();
}
if(H5Tinsert(mem_type,mname,moffset,mmem_type)<0) {
::H5Tclose(mmem_type);
::H5Tclose(mtype);
if(mname) ::free(mname);
if(mname) tools_H5free_memory(mname);
::H5Tclose(mem_type);
return failure();
}
::H5Tclose(mmem_type);
} else {
::H5Tclose(mtype);
if(mname) ::free(mname);
if(mname) tools_H5free_memory(mname);
::H5Tclose(mem_type);
return failure();
}}
::H5Tclose(mtype);
//printf("debug : compound_mem_type : %d (%d) : %s : end\n",index,mn,mname);
if(mname) ::free(mname);
if(mname) tools_H5free_memory(mname);
}
return mem_type;
@@ -323,7 +323,7 @@ inline bool write_atb(hid_t a_id,const std::string& a_name,const std::string& a_
if(has_attr==1) {
if(H5Adelete(a_id,a_name.c_str())<0) return false;
}
hid_t datatype = string_datatype(a_data.size()+1);
if(datatype<0) return false;
@@ -332,28 +332,28 @@ inline bool write_atb(hid_t a_id,const std::string& a_name,const std::string& a_
::H5Tclose(datatype);
return false;
}
hid_t aid = tools_H5Acreate(a_id,a_name.c_str(),datatype,scalar,H5P_DEFAULT);
if(aid<0) {
::H5Sclose(scalar);
::H5Tclose(datatype);
return false;
}
if(H5Awrite(aid,datatype,a_data.c_str())<0) {
::H5Aclose(aid);
::H5Sclose(scalar);
::H5Tclose(datatype);
return false;
}
::H5Aclose(aid);
::H5Sclose(scalar);
::H5Tclose(datatype);
return true;
}
inline bool write_bool(hid_t a_loc,const std::string& a_name,bool a_data) {
hid_t scalar = ::H5Screate(H5S_SCALAR);
if(scalar<0) return false;
@@ -363,7 +363,7 @@ inline bool write_bool(hid_t a_loc,const std::string& a_name,bool a_data) {
::H5Sclose(scalar);
return false;
}
if(H5Pset_layout(compact,H5D_COMPACT)<0) {
if(H5Pset_layout(compact,H5D_COMPACT)<0) {
::H5Pclose(compact);
::H5Sclose(scalar);
return false;
@@ -375,21 +375,21 @@ inline bool write_bool(hid_t a_loc,const std::string& a_name,bool a_data) {
::H5Sclose(scalar);
return false;
}
unsigned char data = a_data?1:0;
if(::H5Dwrite(dataset,H5T_NATIVE_UCHAR,H5S_ALL,H5S_ALL,H5P_DEFAULT,&data)<0) {
::H5Pclose(compact);
::H5Sclose(scalar);
::H5Dclose(dataset);
::H5Dclose(dataset);
return false;
}
::H5Pclose(compact);
::H5Sclose(scalar);
::H5Dclose(dataset);
::H5Dclose(dataset);
return true;
}
inline bool write_string(hid_t a_loc,const std::string& a_name,const std::string& a_string) {
hid_t scalar = ::H5Screate(H5S_SCALAR);
if(scalar<0) return false;
@@ -400,7 +400,7 @@ inline bool write_string(hid_t a_loc,const std::string& a_name,const std::string
return false;
}
if(H5Pset_layout(compact,H5D_COMPACT)<0) {
if(H5Pset_layout(compact,H5D_COMPACT)<0) {
::H5Pclose(compact);
::H5Sclose(scalar);
return false;
@@ -413,7 +413,7 @@ inline bool write_string(hid_t a_loc,const std::string& a_name,const std::string
::H5Sclose(scalar);
return false;
}
hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),file_type,scalar,compact);
if(dataset<0) {
::H5Pclose(compact);
@@ -421,21 +421,21 @@ inline bool write_string(hid_t a_loc,const std::string& a_name,const std::string
::H5Tclose(file_type);
return false;
}
hid_t mem_type = file_type;
if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,a_string.c_str())<0) {
::H5Pclose(compact);
::H5Sclose(scalar);
::H5Dclose(dataset);
::H5Dclose(dataset);
::H5Tclose(file_type);
return false;
}
::H5Pclose(compact);
::H5Sclose(scalar);
::H5Dclose(dataset);
::H5Dclose(dataset);
::H5Tclose(file_type);
return true;
}
@@ -447,7 +447,7 @@ inline bool write_string_dataset(hid_t a_loc,const std::string& a_name,
cpt = ::H5Pcreate(H5P_DATASET_CREATE);
if(cpt<0) return false;
if(a_chunked) {
if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
::H5Pclose(cpt);
return false;
}
@@ -458,7 +458,7 @@ inline bool write_string_dataset(hid_t a_loc,const std::string& a_name,
return false;
}
} else {
if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
::H5Pclose(cpt);
return false;
}
@@ -485,9 +485,9 @@ inline bool write_string_dataset(hid_t a_loc,const std::string& a_name,
if(a_chunked) {
hsize_t mx_dims[1];
mx_dims[0] = H5S_UNLIMITED; //extendable.
file_space = ::H5Screate_simple(1,dims,mx_dims);
file_space = ::H5Screate_simple(1,dims,mx_dims);
} else {
file_space = ::H5Screate_simple(1,dims,NULL);
file_space = ::H5Screate_simple(1,dims,NULL);
}
if(file_space<0) {if(cpt>=0) ::H5Pclose(cpt);::H5Tclose(file_type);return false;}}
@@ -500,16 +500,16 @@ inline bool write_string_dataset(hid_t a_loc,const std::string& a_name,
}
hid_t mem_type = file_type;
const char* wdata[1];
wdata[0] = a_string.c_str();
if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata)<0) {
::H5Dclose(dataset);
::H5Dclose(dataset);
::H5Tclose(file_type);
return false;
}
::H5Tclose(file_type);
::H5Dclose(dataset);
@@ -525,8 +525,8 @@ inline bool write_string_dataset(hid_t a_loc,const std::string& a_name,
inline bool write_append_string_dataset(hid_t a_dataset,const std::string& a_string) {
hsize_t old_size = 0;
{hid_t dataspace = H5Dget_space(a_dataset);
if(dataspace<0) return false;
{hid_t dataspace = H5Dget_space(a_dataset);
if(dataspace<0) return false;
hsize_t dims[1];
if(H5Sget_simple_extent_dims(dataspace,dims,NULL)<0) {
::H5Sclose(dataspace);
@@ -534,13 +534,13 @@ inline bool write_append_string_dataset(hid_t a_dataset,const std::string& a_str
}
old_size = dims[0];
::H5Sclose(dataspace);}
{hsize_t exts[1];
exts[0] = old_size+1;
// if(H5Dextend(dataset,exts)<0) {
if(H5Dset_extent(a_dataset,exts)<0) return false;}
hid_t file_space = H5Dget_space(a_dataset);
hid_t file_space = H5Dget_space(a_dataset);
if(file_space<0) return false;
{hsize_t offset[1];
@@ -554,7 +554,7 @@ inline bool write_append_string_dataset(hid_t a_dataset,const std::string& a_str
hsize_t dims[1];
dims[0] = 1;
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
if(mem_space<0) {
::H5Sclose(file_space);
return false;
@@ -566,10 +566,10 @@ inline bool write_append_string_dataset(hid_t a_dataset,const std::string& a_str
::H5Sclose(file_space);
return false;
}
const char* wdata[1];
wdata[0] = a_string.c_str();
if(H5Dwrite(a_dataset,mem_type,mem_space,file_space,H5P_DEFAULT,wdata)<0) {
::H5Tclose(mem_type);
::H5Sclose(mem_space);
@@ -602,14 +602,14 @@ inline bool write_array_string(hid_t a_loc,const std::string& a_name,const std::
::H5Sclose(scalar);
return false;
}
hid_t file_type = string_datatype(sz);
if(file_type<0) {
delete [] buffer;
::H5Sclose(scalar);
return false;
}
hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),file_type,scalar,H5P_DEFAULT);
if(dataset<0) {
delete [] buffer;
@@ -617,19 +617,19 @@ inline bool write_array_string(hid_t a_loc,const std::string& a_name,const std::
::H5Sclose(scalar);
return false;
}
hid_t mem_type = file_type;
if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,buffer)<0) {
delete [] buffer;
::H5Dclose(dataset);
::H5Dclose(dataset);
::H5Tclose(file_type);
::H5Sclose(scalar);
return false;
}
delete [] buffer;
::H5Dclose(dataset);
::H5Dclose(dataset);
::H5Tclose(file_type);
::H5Sclose(scalar);
return true;
@@ -644,7 +644,7 @@ inline bool write_object(hid_t a_loc,const std::string& a_name,hid_t a_file_type
cpt = ::H5Pcreate(H5P_DATASET_CREATE);
if(cpt<0) return false;
if(chunked) {
if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
if(H5Pset_layout(cpt,H5D_CHUNKED)<0) {
::H5Pclose(cpt);
return false;
}
@@ -655,7 +655,7 @@ inline bool write_object(hid_t a_loc,const std::string& a_name,hid_t a_file_type
return false;
}
} else {
if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
if(H5Pset_layout(cpt,H5D_COMPACT)<0) {
::H5Pclose(cpt);
return false;
}
@@ -669,7 +669,7 @@ inline bool write_object(hid_t a_loc,const std::string& a_name,hid_t a_file_type
} else {
cpt = H5P_DEFAULT;
}
hsize_t dims[1];
dims[0] = 1;
hid_t simple = ::H5Screate_simple(1,dims,NULL);
@@ -684,31 +684,31 @@ inline bool write_object(hid_t a_loc,const std::string& a_name,hid_t a_file_type
if(cpt>=0) ::H5Pclose(cpt);
return false;
}
hid_t dataset = tools_H5Dcreate(a_loc,a_name.c_str(),a_file_type,simple,cpt);
if(dataset<0) {
::H5Tclose(mem_type);
::H5Tclose(mem_type);
::H5Sclose(simple);
if(cpt>=0) ::H5Pclose(cpt);
return false;
}
if(H5Dwrite(dataset,mem_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,a_data)<0) {
::H5Dclose(dataset);
::H5Tclose(mem_type);
::H5Dclose(dataset);
::H5Tclose(mem_type);
::H5Sclose(simple);
if(cpt>=0) ::H5Pclose(cpt);
return false;
}
::H5Dclose(dataset);
::H5Tclose(mem_type);
::H5Dclose(dataset);
::H5Tclose(mem_type);
::H5Sclose(simple);
if(cpt>=0) ::H5Pclose(cpt);
return true;
}
inline bool read_string(hid_t a_loc,const std::string& a_name,std::string& a_string) {
// From H5LTread_dataset_string.
hid_t dataset = tools_H5Dopen(a_loc,a_name.c_str());
@@ -731,7 +731,7 @@ inline bool read_string(hid_t a_loc,const std::string& a_name,std::string& a_str
a_string.clear();
return false;
}
size_t sz = H5Tget_size(file_type);
::H5Tclose(file_type);
if(!sz) {
@@ -740,7 +740,7 @@ inline bool read_string(hid_t a_loc,const std::string& a_name,std::string& a_str
return false;
}
// We could have use file_type since, for string,
// We could have use file_type since, for string,
// file type is the same than memory type.
hid_t mem_type = string_datatype(sz);
if(mem_type<0) {
@@ -813,7 +813,7 @@ inline bool read_sub_string(hid_t a_loc,const std::string& a_name,unsigned int a
}
// abcdef
// 012345
// 012345
int remain = sz-a_offset;
if(remain<=0) {
::H5Sclose(file_space);
@@ -821,7 +821,7 @@ inline bool read_sub_string(hid_t a_loc,const std::string& a_name,unsigned int a
a_string.clear();
return false;
}}
{hsize_t offset[1];
offset[0] = a_offset;
hsize_t count[1];
@@ -834,7 +834,7 @@ inline bool read_sub_string(hid_t a_loc,const std::string& a_name,unsigned int a
}}
dims[0] = 1;
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
hid_t mem_space = ::H5Screate_simple(1,dims,NULL);
if(mem_space<0) {
::H5Sclose(file_space);
::H5Dclose(dataset);
@@ -891,13 +891,13 @@ inline bool read_sub_string(hid_t a_loc,const std::string& a_name,unsigned int a
}
char* buff = rdata[0];
size_t len = ::strlen(buff);
a_string.resize(len,0);
for(size_t index=0;index<len;index++) a_string[index] = buff[index];
::H5Dvlen_reclaim(mem_type,mem_space, H5P_DEFAULT,rdata);
::H5Tclose(mem_type);
::H5Sclose(mem_space);
::H5Sclose(file_space);
@@ -913,7 +913,7 @@ inline bool read_object(hid_t a_loc,const std::string& a_name,size_t& a_size,cha
a_data = 0;
return false;
}
hid_t file_type = H5Dget_type(dataset);
if(file_type<0) {
::H5Dclose(dataset);
@@ -921,7 +921,7 @@ inline bool read_object(hid_t a_loc,const std::string& a_name,size_t& a_size,cha
a_data = 0;
return false;
}
H5T_class_t t_class = H5Tget_class(file_type);
if(t_class!=H5T_COMPOUND) {
::H5Tclose(file_type);
@@ -930,7 +930,7 @@ inline bool read_object(hid_t a_loc,const std::string& a_name,size_t& a_size,cha
a_data = 0;
return false;
}
size_t sz = H5Tget_size(file_type);
if(!sz) {
::H5Tclose(file_type);
@@ -939,7 +939,7 @@ inline bool read_object(hid_t a_loc,const std::string& a_name,size_t& a_size,cha
a_data = 0;
return false;
}
hid_t mem_type = compound_mem_type(file_type);
if(mem_type<0) {
::H5Tclose(file_type);
@@ -948,9 +948,9 @@ inline bool read_object(hid_t a_loc,const std::string& a_name,size_t& a_size,cha
a_data = 0;
return false;
}
::H5Tclose(file_type);
hid_t dataspace = H5Dget_space(dataset);
if(dataspace<0) {
::H5Tclose(mem_type);
@@ -959,7 +959,7 @@ inline bool read_object(hid_t a_loc,const std::string& a_name,size_t& a_size,cha
a_data = 0;
return false;
}
hid_t scalar = ::H5Screate(H5S_SCALAR);
if(scalar<0) {
::H5Sclose(dataspace);
@@ -981,14 +981,14 @@ inline bool read_object(hid_t a_loc,const std::string& a_name,size_t& a_size,cha
a_data = 0;
return false;
}
::H5Sclose(scalar);
::H5Sclose(dataspace);
::H5Tclose(mem_type);
::H5Dclose(dataset);
a_size = sz;
a_data = buffer;
a_data = buffer;
return true;
}
@@ -1009,7 +1009,7 @@ inline bool read_array_string(hid_t a_loc,const std::string& a_name,std::vector<
::H5Dclose(dataset);
return false;
}
size_t sz = H5Tget_size(file_type);
::H5Tclose(file_type);
if(!sz) {
@@ -1017,7 +1017,7 @@ inline bool read_array_string(hid_t a_loc,const std::string& a_name,std::vector<
return false;
}
// We could have use file_type since, for string,
// We could have use file_type since, for string,
// file type is the same than memory type.
hid_t mem_type = string_datatype(sz);
if(mem_type<0) {
@@ -1042,7 +1042,7 @@ inline bool read_array_string(hid_t a_loc,const std::string& a_name,std::vector<
delete [] buffer;
return true;
}
}}
#endif