// Copyright (C) 2010, Guy Barrand. All rights reserved. // See the file tools.license for terms. #ifndef tools_wcsv_histo #define tools_wcsv_histo #include #include #include namespace tools { namespace wcsv { template inline void axis_to(std::ostream& a_writer,const AXIS& a_axis,char a_hc) { if(a_axis.m_fixed) { a_writer << a_hc << "axis fixed " << a_axis.m_number_of_bins << " " << a_axis.m_minimum_value << " " << a_axis.m_maximum_value // << " " << a_axis.m_bin_width << std::endl; } else { a_writer << a_hc << "axis edges"; for(unsigned int iedge=0;iedge inline void annotations_to(std::ostream& a_writer,const ANNOTATION& a_ans,char a_hc) { typename ANNOTATION::const_iterator it; for(it=a_ans.begin();it!=a_ans.end();++it) { a_writer << a_hc << "annotation " << (*it).first << " " << (*it).second << std::endl; } } template inline bool hto(std::ostream& a_writer,const std::string& a_class,const HIST& a_h, char a_sep = ',',char a_hc = '#',bool a_header = true) { if(a_header) { a_writer << a_hc << "class " << a_class << std::endl; a_writer << a_hc << "title " << a_h.title() << std::endl; a_writer << a_hc << "dimension " << a_h.dimension() << std::endl; for(unsigned int iaxis=0;iaxis& planes = a_h.in_range_planes_xyw(); if(planes.size()) { a_writer << a_hc << "planes_Sxyw"; for(unsigned int iplane=0;iplane& _bin_entries = a_h.bins_entries(); const std::vector& _bin_Sw = a_h.bins_sum_w(); const std::vector& _bin_Sw2 = a_h.bins_sum_w2(); const std::vector< std::vector >& _bin_Sxw = a_h.bins_sum_xw(); const std::vector< std::vector >& _bin_Sx2w = a_h.bins_sum_x2w(); for(unsigned int i=0;i<_bins;i++) { a_writer << _bin_entries[i] << a_sep << _bin_Sw[i] << a_sep << _bin_Sw2[i]; for(unsigned int iaxis=0;iaxis<_dim;iaxis++) { a_writer << a_sep << _bin_Sxw[i][iaxis] << a_sep << _bin_Sx2w[i][iaxis]; } a_writer << std::endl; } a_h.not_a_profile(); //trick to be sure to use this function on an histo and not a profile. return true; } template inline bool pto(std::ostream& a_writer,const std::string& a_class,const PROF& a_prof, char a_sep = ',',char a_hc = '#',bool a_header = true) { if(a_header) { a_writer << a_hc << "class " << a_class << std::endl; a_writer << a_hc << "title " << a_prof.title() << std::endl; a_writer << a_hc << "dimension " << a_prof.dimension() << std::endl; for(unsigned int iaxis=0;iaxis& planes = a_prof.in_range_planes_xyw(); if(planes.size()) { a_writer << a_hc << "planes_Sxyw"; for(unsigned int iplane=0;iplane& _bin_entries = a_prof.bins_entries(); const std::vector& _bin_Sw = a_prof.bins_sum_w(); const std::vector& _bin_Sw2 = a_prof.bins_sum_w2(); const std::vector< std::vector >& _bin_Sxw = a_prof.bins_sum_xw(); const std::vector< std::vector >& _bin_Sx2w = a_prof.bins_sum_x2w(); typedef typename PROF::vs_t vs_t; const vs_t& _bin_Svw = a_prof.bins_sum_vw(); const vs_t& _bin_Sv2w = a_prof.bins_sum_v2w(); for(unsigned int i=0;i<_bins;i++) { a_writer << _bin_entries[i] << a_sep << _bin_Sw[i] << a_sep << _bin_Sw2[i] << a_sep << _bin_Svw[i] << a_sep << _bin_Sv2w[i]; for(unsigned int iaxis=0;iaxis<_dim;iaxis++) { a_writer << a_sep << _bin_Sxw[i][iaxis] << a_sep << _bin_Sx2w[i][iaxis]; } a_writer << std::endl; } return true; } }} #endif