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[ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/wcsv_histo (Version 11.3.0) and /externals/g4tools/include/tools/wcsv_histo (Version 11.0.p4)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef tools_wcsv_histo                            4 #ifndef tools_wcsv_histo
  5 #define tools_wcsv_histo                            5 #define tools_wcsv_histo
  6                                                     6 
  7 #include <ostream>                                  7 #include <ostream>
  8 #include <vector>                                   8 #include <vector>
  9 #include <string>                                   9 #include <string>
 10                                                    10 
 11 namespace tools {                                  11 namespace tools {
 12 namespace wcsv {                                   12 namespace wcsv {
 13                                                    13 
 14 template <class AXIS>                              14 template <class AXIS>
 15 inline void axis_to(std::ostream& a_writer,con     15 inline void axis_to(std::ostream& a_writer,const AXIS& a_axis,char a_hc) {
 16   if(a_axis.m_fixed) {                             16   if(a_axis.m_fixed) {
 17     a_writer << a_hc                               17     a_writer << a_hc
 18              << "axis fixed " << a_axis.m_numb     18              << "axis fixed " << a_axis.m_number_of_bins
 19              << " " << a_axis.m_minimum_value      19              << " " << a_axis.m_minimum_value
 20              << " " << a_axis.m_maximum_value      20              << " " << a_axis.m_maximum_value
 21 //           << " " << a_axis.m_bin_width          21 //           << " " << a_axis.m_bin_width
 22              << std::endl;                         22              << std::endl;
 23   } else {                                         23   } else {
 24     a_writer << a_hc << "axis edges";              24     a_writer << a_hc << "axis edges";
 25     for(unsigned int iedge=0;iedge<a_axis.m_ed     25     for(unsigned int iedge=0;iedge<a_axis.m_edges.size();iedge++) {
 26       a_writer << " " << a_axis.m_edges[iedge]     26       a_writer << " " << a_axis.m_edges[iedge];
 27     }                                              27     }
 28     a_writer << std::endl;                         28     a_writer << std::endl;
 29   }                                                29   }
 30 }                                                  30 }
 31                                                    31 
 32 template <class ANNOTATION>                        32 template <class ANNOTATION>
 33 inline void annotations_to(std::ostream& a_wri     33 inline void annotations_to(std::ostream& a_writer,const ANNOTATION& a_ans,char a_hc) {
 34   typename ANNOTATION::const_iterator it;          34   typename ANNOTATION::const_iterator it;
 35   for(it=a_ans.begin();it!=a_ans.end();++it) {     35   for(it=a_ans.begin();it!=a_ans.end();++it) {
 36     a_writer << a_hc << "annotation " << (*it)     36     a_writer << a_hc << "annotation " << (*it).first << " " << (*it).second << std::endl;
 37   }                                                37   }
 38 }                                                  38 }
 39                                                    39 
 40 template <class HIST>                              40 template <class HIST>
 41 inline void h_header(std::ostream& a_writer,co     41 inline void h_header(std::ostream& a_writer,const std::string& a_class,const HIST& a_h,char a_hc = '#') {
 42   a_writer << a_hc << "class " << a_class << s     42   a_writer << a_hc << "class " << a_class << std::endl;
 43   a_writer << a_hc << "title " << a_h.title()      43   a_writer << a_hc << "title " << a_h.title() << std::endl;
 44   a_writer << a_hc << "dimension " << a_h.dime     44   a_writer << a_hc << "dimension " << a_h.dimension() << std::endl;
 45   for(unsigned int iaxis=0;iaxis<a_h.dimension     45   for(unsigned int iaxis=0;iaxis<a_h.dimension();iaxis++) axis_to(a_writer,a_h.get_axis(iaxis),a_hc);
 46  {const std::vector<typename HIST::coordinate_     46  {const std::vector<typename HIST::coordinate_t>& planes = a_h.in_range_planes_xyw();
 47   if(planes.size()) {                              47   if(planes.size()) {
 48     a_writer << a_hc << "planes_Sxyw";             48     a_writer << a_hc << "planes_Sxyw";
 49     for(unsigned int iplane=0;iplane<planes.si     49     for(unsigned int iplane=0;iplane<planes.size();iplane++) a_writer << " " << planes[iplane];
 50     a_writer << std::endl;                         50     a_writer << std::endl;
 51   }}                                               51   }}
 52   annotations_to(a_writer,a_h.annotations(),a_     52   annotations_to(a_writer,a_h.annotations(),a_hc);
 53   a_writer << a_hc << "bin_number " << a_h.get     53   a_writer << a_hc << "bin_number " << a_h.get_bins() << std::endl;
 54 }                                                  54 }
 55                                                    55 
 56 template <class HIST>                              56 template <class HIST>
 57 inline bool hto(std::ostream& a_writer,const s     57 inline bool hto(std::ostream& a_writer,const std::string& a_class,const HIST& a_h,
 58                 char a_sep = ',',char a_hc = '     58                 char a_sep = ',',char a_hc = '#',bool a_header = true) {
 59   if(a_header) h_header(a_writer,a_class,a_h,a     59   if(a_header) h_header(a_writer,a_class,a_h,a_hc);
 60                                                    60 
 61  {a_writer << "entries" << a_sep << "Sw" << a_     61  {a_writer << "entries" << a_sep << "Sw" << a_sep << "Sw2";
 62   for(unsigned int iaxis=0;iaxis<a_h.dimension     62   for(unsigned int iaxis=0;iaxis<a_h.dimension();iaxis++) {
 63     a_writer << a_sep << "Sxw" << iaxis << a_s     63     a_writer << a_sep << "Sxw" << iaxis << a_sep << "Sx2w" << iaxis;
 64   }                                                64   }
 65   a_writer << std::endl;}                          65   a_writer << std::endl;}
 66                                                    66 
 67   typedef typename HIST::coordinate_t coordina     67   typedef typename HIST::coordinate_t coordinate_t;
 68   typedef typename HIST::dim_t dim_t;              68   typedef typename HIST::dim_t dim_t;
 69   typedef typename HIST::offset_t offset_t;        69   typedef typename HIST::offset_t offset_t;
 70   typedef typename HIST::num_entries_t num_ent     70   typedef typename HIST::num_entries_t num_entries_t;
 71   typedef typename HIST::weight_t weight_t;        71   typedef typename HIST::weight_t weight_t;
 72                                                    72 
 73   dim_t _dim = a_h.dimension();                    73   dim_t _dim = a_h.dimension();
 74   offset_t _bins = a_h.get_bins();                 74   offset_t _bins = a_h.get_bins();
 75                                                    75 
 76   const std::vector<num_entries_t>& _bin_entri     76   const std::vector<num_entries_t>& _bin_entries = a_h.bins_entries();
 77   const std::vector<weight_t>& _bin_Sw = a_h.b     77   const std::vector<weight_t>& _bin_Sw = a_h.bins_sum_w();
 78   const std::vector<weight_t>& _bin_Sw2 = a_h.     78   const std::vector<weight_t>& _bin_Sw2 = a_h.bins_sum_w2();
 79   const std::vector< std::vector<coordinate_t>     79   const std::vector< std::vector<coordinate_t> >& _bin_Sxw = a_h.bins_sum_xw();
 80   const std::vector< std::vector<coordinate_t>     80   const std::vector< std::vector<coordinate_t> >& _bin_Sx2w = a_h.bins_sum_x2w();
 81                                                    81 
 82   for(unsigned int i=0;i<_bins;i++) {              82   for(unsigned int i=0;i<_bins;i++) {
 83     a_writer << _bin_entries[i] << a_sep << _b     83     a_writer << _bin_entries[i] << a_sep << _bin_Sw[i] << a_sep << _bin_Sw2[i];
 84     for(unsigned int iaxis=0;iaxis<_dim;iaxis+     84     for(unsigned int iaxis=0;iaxis<_dim;iaxis++) {
 85       a_writer << a_sep << _bin_Sxw[i][iaxis]      85       a_writer << a_sep << _bin_Sxw[i][iaxis] << a_sep << _bin_Sx2w[i][iaxis];
 86     }                                              86     }
 87     a_writer << std::endl;                         87     a_writer << std::endl;
 88   }                                                88   }
 89                                                    89 
 90   a_h.not_a_profile(); //trick to be sure to u     90   a_h.not_a_profile(); //trick to be sure to use this function on an histo and not a profile.
 91                                                    91 
 92   return true;                                     92   return true;
 93 }                                                  93 }
 94                                                    94 
 95 template <class PROF>                              95 template <class PROF>
 96 inline void p_header(std::ostream& a_writer,co     96 inline void p_header(std::ostream& a_writer,const std::string& a_class,const PROF& a_prof,char a_hc = '#') {
 97   a_writer << a_hc << "class " << a_class << s     97   a_writer << a_hc << "class " << a_class << std::endl;
 98   a_writer << a_hc << "title " << a_prof.title     98   a_writer << a_hc << "title " << a_prof.title() << std::endl;
 99   a_writer << a_hc << "dimension " << a_prof.d     99   a_writer << a_hc << "dimension " << a_prof.dimension() << std::endl;
100   for(unsigned int iaxis=0;iaxis<a_prof.dimens    100   for(unsigned int iaxis=0;iaxis<a_prof.dimension();iaxis++) axis_to(a_writer,a_prof.get_axis(iaxis),a_hc);
101  {const std::vector<typename PROF::coordinate_    101  {const std::vector<typename PROF::coordinate_t>& planes = a_prof.in_range_planes_xyw();
102   if(planes.size()) {                             102   if(planes.size()) {
103     a_writer << a_hc << "planes_Sxyw";            103     a_writer << a_hc << "planes_Sxyw";
104     for(unsigned int iplane=0;iplane<planes.si    104     for(unsigned int iplane=0;iplane<planes.size();iplane++) a_writer << " " << planes[iplane];
105     a_writer << std::endl;                        105     a_writer << std::endl;
106   }}                                              106   }}
107   annotations_to(a_writer,a_prof.annotations()    107   annotations_to(a_writer,a_prof.annotations(),a_hc);
108   a_writer << a_hc << "cut_v " << (a_prof.cut_    108   a_writer << a_hc << "cut_v " << (a_prof.cut_v()?"true":"false") << std::endl;
109   a_writer << a_hc << "min_v " << a_prof.min_v    109   a_writer << a_hc << "min_v " << a_prof.min_v() << std::endl;
110   a_writer << a_hc << "max_v " << a_prof.max_v    110   a_writer << a_hc << "max_v " << a_prof.max_v() << std::endl;
111   a_writer << a_hc << "bin_number " << a_prof.    111   a_writer << a_hc << "bin_number " << a_prof.get_bins() << std::endl;
112 }                                                 112 }
113                                                   113 
114 template <class PROF>                             114 template <class PROF>
115 inline bool pto(std::ostream& a_writer,const s    115 inline bool pto(std::ostream& a_writer,const std::string& a_class,const PROF& a_prof,
116                 char a_sep = ',',char a_hc = '    116                 char a_sep = ',',char a_hc = '#',bool a_header = true) {
117   if(a_header) p_header(a_writer,a_class,a_pro    117   if(a_header) p_header(a_writer,a_class,a_prof,a_hc);
118                                                   118 
119  {a_writer << "entries" << a_sep << "Sw" << a_    119  {a_writer << "entries" << a_sep << "Sw" << a_sep << "Sw2" << a_sep << "Svw" << a_sep << "Sv2w";
120   for(unsigned int iaxis=0;iaxis<a_prof.dimens    120   for(unsigned int iaxis=0;iaxis<a_prof.dimension();iaxis++) {
121     a_writer << a_sep << "Sxw" << iaxis << a_s    121     a_writer << a_sep << "Sxw" << iaxis << a_sep << "Sx2w" << iaxis;
122   }                                               122   }
123   a_writer << std::endl;}                         123   a_writer << std::endl;}
124                                                   124 
125   typedef typename PROF::coordinate_t coordina    125   typedef typename PROF::coordinate_t coordinate_t;
126   typedef typename PROF::dim_t dim_t;             126   typedef typename PROF::dim_t dim_t;
127   typedef typename PROF::offset_t offset_t;       127   typedef typename PROF::offset_t offset_t;
128   typedef typename PROF::num_entries_t num_ent    128   typedef typename PROF::num_entries_t num_entries_t;
129   typedef typename PROF::weight_t weight_t;       129   typedef typename PROF::weight_t weight_t;
130                                                   130 
131   dim_t _dim = a_prof.dimension();                131   dim_t _dim = a_prof.dimension();
132   offset_t _bins = a_prof.get_bins();             132   offset_t _bins = a_prof.get_bins();
133                                                   133 
134   const std::vector<num_entries_t>& _bin_entri    134   const std::vector<num_entries_t>& _bin_entries = a_prof.bins_entries();
135   const std::vector<weight_t>& _bin_Sw = a_pro    135   const std::vector<weight_t>& _bin_Sw = a_prof.bins_sum_w();
136   const std::vector<weight_t>& _bin_Sw2 = a_pr    136   const std::vector<weight_t>& _bin_Sw2 = a_prof.bins_sum_w2();
137   const std::vector< std::vector<coordinate_t>    137   const std::vector< std::vector<coordinate_t> >& _bin_Sxw = a_prof.bins_sum_xw();
138   const std::vector< std::vector<coordinate_t>    138   const std::vector< std::vector<coordinate_t> >& _bin_Sx2w = a_prof.bins_sum_x2w();
139                                                   139 
140   typedef typename PROF::vs_t vs_t;               140   typedef typename PROF::vs_t vs_t;
141   const vs_t& _bin_Svw = a_prof.bins_sum_vw();    141   const vs_t& _bin_Svw = a_prof.bins_sum_vw();
142   const vs_t& _bin_Sv2w = a_prof.bins_sum_v2w(    142   const vs_t& _bin_Sv2w = a_prof.bins_sum_v2w();
143                                                   143 
144   for(unsigned int i=0;i<_bins;i++) {             144   for(unsigned int i=0;i<_bins;i++) {
145     a_writer << _bin_entries[i] << a_sep << _b    145     a_writer << _bin_entries[i] << a_sep << _bin_Sw[i] << a_sep << _bin_Sw2[i]
146              << a_sep << _bin_Svw[i] << a_sep     146              << a_sep << _bin_Svw[i] << a_sep << _bin_Sv2w[i];
147     for(unsigned int iaxis=0;iaxis<_dim;iaxis+    147     for(unsigned int iaxis=0;iaxis<_dim;iaxis++) {
148       a_writer << a_sep << _bin_Sxw[i][iaxis]     148       a_writer << a_sep << _bin_Sxw[i][iaxis] << a_sep << _bin_Sx2w[i][iaxis];
149     }                                             149     }
150     a_writer << std::endl;                        150     a_writer << std::endl;
151   }                                               151   }
152                                                   152 
153   return true;                                    153   return true;
154 }                                                 154 }
155                                                   155 
156 }}                                                156 }}
157                                                   157 
158 #endif                                            158 #endif