4 #ifndef tools_hdf5_h2file
5 #define tools_hdf5_h2file
24 inline bool write_std_map_ss(hid_t a_loc,
const std::string& a_name,
const std::map<std::string,std::string>& a_map,
25 unsigned int = 0,
unsigned int = 0) {
26 if(!write_scalar<tools::uint64>(a_loc,a_name+
"_size",a_map.size()))
return false;
27 unsigned int count = 0;
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;
38 inline bool read_std_map_ss(hid_t a_loc,
const std::string& a_name,std::map<std::string,std::string>& a_map,
39 unsigned int = 0,
unsigned int = 0) {
42 if(!read_scalar<tools::uint64>(a_loc,a_name+
"_size",sz))
return false;
43 std::string scount,key,
value;
46 if(!
read_string(a_loc,a_name+
"_elem_"+scount+
"_first",key))
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;
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;
68 {std::string name,saxis;
69 for(
unsigned int iaxis=0;iaxis<a_hdata.
m_dimension;iaxis++) {
71 name =
"axis_"+saxis+
"_";
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;
91 template <
class HISTO>
92 inline bool write_histo(std::ostream& a_out,hid_t a_loc,
const std::string& a_name,
const HISTO& a_histo) {
96 a_out <<
"tools::hdf5::write_histo : can't create group for histo " <<
tools::sout(a_name) <<
"." << std::endl;
102 a_out <<
"tools::hdf5::write_histo : write_atb() class failed." << std::endl;
106 if(!
write_atb(histo,
"class",a_histo.s_cls())) {
107 a_out <<
"tools::hdf5::write_histo : write_atb() class failed." << std::endl;
112 if(!write_scalar_atb<int>(histo,
"version",v)) {
113 a_out <<
"tools::hdf5::write_histo : write_scalar_atb() version failed." << std::endl;
118 if(!
write_hdata(histo,a_histo.dac())) {::H5Gclose(histo);
return false;}
122 a_histo.not_a_profile();
127 template <
class PROFILE>
128 inline bool write_profile(std::ostream& a_out,hid_t a_loc,
const std::string& a_name,
const PROFILE& a_histo) {
132 a_out <<
"tools::hdf5::write_profile : can't create group for histo " <<
tools::sout(a_name) <<
"." << std::endl;
138 a_out <<
"tools::hdf5::write_profile : write_atb() class failed." << std::endl;
142 if(!
write_atb(histo,
"class",a_histo.s_cls())) {
143 a_out <<
"tools::hdf5::write_profile : write_atb() class failed." << std::endl;
148 if(!write_scalar_atb<int>(histo,
"version",v)) {
149 a_out <<
"tools::hdf5::write_profile : write_scalar_atb() version failed." << std::endl;
154 typename PROFILE::pd_t pdata = a_histo.get_histo_data();
156 if(!
write_hdata(histo,pdata)) {::H5Gclose(histo);
return false;}
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;}
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;
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;
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;
184 std::string name,saxis;
185 for(
unsigned int iaxis=0;iaxis<a_hdata.
m_dimension;iaxis++) {
187 name =
"axis_"+saxis+
"_";
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;
207 template <
class HISTO>
208 inline bool read_histo(std::ostream& a_out,hid_t a_loc,
const std::string& a_name,HISTO*& a_histo,
bool a_verb_class =
true) {
215 a_out <<
"tools::hdf5::read_histo : can't open group." << std::endl;
220 if(!
read_atb(histo,
"class",sclass)) {
221 a_out <<
"tools::hdf5::read_histo : can't read_atb() class." << std::endl;
226 if(sclass!=HISTO::s_class()) {
228 a_out <<
"tools::hdf5::read_histo :"
237 a_out <<
"tools::hdf5::read_histo : read_atb version failed." << std::endl;
244 if(!
read_hdata(histo,hdata)) {::H5Gclose(histo);
return false;}
251 a_histo->copy_from_data(hdata);
252 a_histo->not_a_profile();
256 template <
class PROFILE>
257 inline bool read_profile(std::ostream& a_out,hid_t a_loc,
const std::string& a_name,PROFILE*& a_histo,
bool a_verb_class =
true) {
262 a_out <<
"tools::hdf5::read_profile : can't open group." << std::endl;
267 if(!
read_atb(histo,
"class",sclass)) {
268 a_out <<
"tools::hdf5::read_profile : can't read_atb() class." << std::endl;
273 if(sclass!=PROFILE::s_class()) {
275 a_out <<
"tools::hdf5::read_profile :"
284 a_out <<
"tools::hdf5::read_profile : read_atb version failed." << std::endl;
289 typename PROFILE::pd_t pdata;
291 if(!
read_hdata(histo,pdata)) {::H5Gclose(histo);
return false;}
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;}
302 pdata.update_fast_getters();
304 a_histo =
new PROFILE;
305 a_histo->copy_from_data(pdata);
310 std::string& a_class,
int& a_version,
bool a_verbose =
true) {
313 if(a_verbose) a_out <<
"tools::hdf5::read_class_version : can't open group." << std::endl;
320 if(a_verbose) a_out <<
"tools::hdf5::read_class_version : can't read_atb() class." << std::endl;
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;