Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/g4tools/include/tools/rcsv_histo

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 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/rcsv_histo (Version 11.3.0) and /externals/g4tools/include/tools/rcsv_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_rcsv_histo                            4 #ifndef tools_rcsv_histo
  5 #define tools_rcsv_histo                            5 #define tools_rcsv_histo
  6                                                     6 
  7 #include "sto"                                      7 #include "sto"
  8 #include "chars"                                    8 #include "chars"
  9 #include "words"                                    9 #include "words"
 10 #include "forit"                                   10 #include "forit"
 11 #include "sout"                                    11 #include "sout"
 12                                                    12 
 13 #include "histo/h1d"                               13 #include "histo/h1d"
 14 #include "histo/h2d"                               14 #include "histo/h2d"
 15 #include "histo/h3d"                               15 #include "histo/h3d"
 16 #include "histo/p1d"                               16 #include "histo/p1d"
 17 #include "histo/p2d"                               17 #include "histo/p2d"
 18 //#include "histo/h1df"                            18 //#include "histo/h1df"
 19                                                    19 
 20 #ifdef TOOLS_MEM                                   20 #ifdef TOOLS_MEM
 21 #include "mem"                                     21 #include "mem"
 22 #endif                                             22 #endif
 23                                                    23 
 24 #include <istream>                                 24 #include <istream>
 25 #include <utility>                             << 
 26                                                    25 
 27 namespace tools {                                  26 namespace tools {
 28 namespace rcsv {                                   27 namespace rcsv {
 29                                                    28 
 30 class histo {                                      29 class histo {
 31 #ifdef TOOLS_MEM                                   30 #ifdef TOOLS_MEM
 32 public:                                            31 public:
 33   static const std::string& s_class() {            32   static const std::string& s_class() {
 34     static const std::string s_v("tools::rcsv:     33     static const std::string s_v("tools::rcsv::histo");
 35     return s_v;                                    34     return s_v;
 36   }                                                35   }
 37 #endif                                             36 #endif
 38 public:                                            37 public:
 39   histo(std::istream& a_reader)                    38   histo(std::istream& a_reader)
 40   :m_reader(a_reader)                              39   :m_reader(a_reader)
 41   {                                                40   {
 42 #ifdef TOOLS_MEM                                   41 #ifdef TOOLS_MEM
 43     mem::increment(s_class().c_str());             42     mem::increment(s_class().c_str());
 44 #endif                                             43 #endif
 45   }                                                44   }
 46   virtual ~histo() {                               45   virtual ~histo() {
 47 #ifdef TOOLS_MEM                                   46 #ifdef TOOLS_MEM
 48     mem::decrement(s_class().c_str());             47     mem::decrement(s_class().c_str());
 49 #endif                                             48 #endif
 50   }                                                49   }
 51 protected:                                         50 protected:
 52   histo(const histo& a_from)                       51   histo(const histo& a_from)
 53   :m_reader(a_from.m_reader)                       52   :m_reader(a_from.m_reader)
 54   {                                                53   {
 55 #ifdef TOOLS_MEM                                   54 #ifdef TOOLS_MEM
 56     mem::increment(s_class().c_str());             55     mem::increment(s_class().c_str());
 57 #endif                                             56 #endif
 58   }                                                57   }
 59   histo& operator=(const histo&){return *this;     58   histo& operator=(const histo&){return *this;}
 60 public:                                            59 public:
 61   std::istream& istrm() {return m_reader;}         60   std::istream& istrm() {return m_reader;}
 62 public:                                            61 public:
 63   bool read(std::ostream& a_out,std::string& a     62   bool read(std::ostream& a_out,std::string& a_class,void*& a_obj,bool a_verbose = false) {
 64     a_class.clear();                               63     a_class.clear();
 65     a_obj = 0;                                     64     a_obj = 0;
 66                                                    65 
 67     std::streampos file_sz = 0;                    66     std::streampos file_sz = 0;
 68     m_reader.clear();                              67     m_reader.clear();
 69     m_reader.seekg(0,std::ios::end);               68     m_reader.seekg(0,std::ios::end);
 70     file_sz = m_reader.tellg();                    69     file_sz = m_reader.tellg();
 71     m_reader.seekg(0,std::ios::beg);               70     m_reader.seekg(0,std::ios::beg);
 72     if(!file_sz) {                                 71     if(!file_sz) {
 73       a_out << "tools::rcsv::histo::read : str     72       a_out << "tools::rcsv::histo::read : stream is empty." << std::endl;
 74       return false;                                73       return false;
 75     }                                              74     }
 76     if(a_verbose) a_out << "file size is " <<      75     if(a_verbose) a_out << "file size is " << file_sz << std::endl;
 77                                                    76 
 78     tools::histo::histo_data<double,unsigned i     77     tools::histo::histo_data<double,unsigned int,unsigned int,double> hdata; //to be filled correctly.
 79     hdata.m_dimension = 0;                         78     hdata.m_dimension = 0;
 80     hdata.m_bin_number = 0;                        79     hdata.m_bin_number = 0;
 81                                                    80 
 82     bool is_profile = false;                       81     bool is_profile = false;
 83     bool _cut_v = false;                           82     bool _cut_v = false;
 84     double _min_v = 0;                             83     double _min_v = 0;
 85     double _max_v = 0;                             84     double _max_v = 0;
 86                                                    85 
 87     // read commented header :                     86     // read commented header :
 88     std::string _class;                            87     std::string _class;
 89     typedef tools::histo::axis<double,unsigned     88     typedef tools::histo::axis<double,unsigned int> axis_t;
 90    {std::string line;                              89    {std::string line;
 91     while(read_header_line(m_reader,file_sz,li     90     while(read_header_line(m_reader,file_sz,line)) {
 92 //      a_out << "line : " << sout(s) << std::     91 //      a_out << "line : " << sout(s) << std::endl;
 93       std::vector<std::string> _words;             92       std::vector<std::string> _words;
 94       words(line," ",false,_words);                93       words(line," ",false,_words);
 95       if(!_words.size()) {                         94       if(!_words.size()) {
 96         a_out << "tools::rcsv::histo::read : s     95         a_out << "tools::rcsv::histo::read : syntax error : empty header line." << std::endl;
 97         return false;                              96         return false;
 98       }                                            97       }
 99       if((_words[0]=="#class")) {                  98       if((_words[0]=="#class")) {
100         if(_words.size()!=2) {                     99         if(_words.size()!=2) {
101           a_out << "tools::rcsv::histo::read :    100           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
102           return false;                           101           return false;
103         }                                         102         }
104         _class = _words[1];                       103         _class = _words[1];
105       } else if(_words[0]=="#title") {            104       } else if(_words[0]=="#title") {
106         if(_words.size()<1) {                     105         if(_words.size()<1) {
107           a_out << "tools::rcsv::histo::read :    106           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
108           return false;                           107           return false;
109         }                                         108         }
110         if(_words.size()==1)  {                   109         if(_words.size()==1)  {
111           hdata.m_title.clear();                  110           hdata.m_title.clear();
112         } else {                                  111         } else {
113           std::string::size_type pos = line.fi    112           std::string::size_type pos = line.find(_words[0]);
114           pos += _words[0].size()+1;              113           pos += _words[0].size()+1;
115           hdata.m_title = line.substr(pos,line    114           hdata.m_title = line.substr(pos,line.size()-pos);
116         }                                         115         }
117       } else if(_words[0]=="#dimension") {        116       } else if(_words[0]=="#dimension") {
118         if(_words.size()!=2) {                    117         if(_words.size()!=2) {
119           a_out << "tools::rcsv::histo::read :    118           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
120           return false;                           119           return false;
121         }                                         120         }
122         if(!to(_words[1],hdata.m_dimension)) { << 121         to(_words[1],hdata.m_dimension);
123           a_out << "tools::rcsv::histo::read : << 
124           return false;                        << 
125         }                                      << 
126       } else if(_words[0]=="#annotation") {       122       } else if(_words[0]=="#annotation") {
127         if(_words.size()<2) {                     123         if(_words.size()<2) {
128           a_out << "tools::rcsv::histo::read :    124           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
129           return false;                           125           return false;
130         }                                         126         }
131         if(_words.size()==2) {                    127         if(_words.size()==2) {
132           hdata.m_annotations[_words[1]] = std    128           hdata.m_annotations[_words[1]] = std::string();
133         } else {                                  129         } else {
134           std::string::size_type pos = line.fi    130           std::string::size_type pos = line.find(_words[1]);
135           pos += _words[1].size()+1;              131           pos += _words[1].size()+1;
136           hdata.m_annotations[_words[1]] = lin    132           hdata.m_annotations[_words[1]] = line.substr(pos,line.size()-pos);
137         }                                         133         }
138       } else if(_words[0]=="#axis") {             134       } else if(_words[0]=="#axis") {
139         if(_words.size()<2) {                     135         if(_words.size()<2) {
140           a_out << "tools::rcsv::histo::read :    136           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
141           return false;                           137           return false;
142         }                                         138         }
143         if(_words[1]=="fixed") {                  139         if(_words[1]=="fixed") {
144           if(_words.size()!=5) {                  140           if(_words.size()!=5) {
145             a_out << "tools::rcsv::histo::read    141             a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
146             return false;                         142             return false;
147           }                                       143           }
148           unsigned int number_of_bins;            144           unsigned int number_of_bins;
149           if(!to(_words[2],number_of_bins)) {     145           if(!to(_words[2],number_of_bins)) {
150             a_out << "tools::rcsv::histo::read    146             a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
151             return false;                         147             return false;
152           }                                       148           }
153           double minimum_value;                   149           double minimum_value;
154           if(!to(_words[3],minimum_value)) {      150           if(!to(_words[3],minimum_value)) {
155             a_out << "tools::rcsv::histo::read    151             a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
156             return false;                         152             return false;
157           }                                       153           }
158           double maximum_value;                   154           double maximum_value;
159           if(!to(_words[4],maximum_value)) {      155           if(!to(_words[4],maximum_value)) {
160             a_out << "tools::rcsv::histo::read    156             a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
161             return false;                         157             return false;
162           }                                       158           }
163           axis_t axis;                            159           axis_t axis;
164           if(!axis.configure(number_of_bins,mi    160           if(!axis.configure(number_of_bins,minimum_value,maximum_value)) {
165             a_out << "tools::rcsv::histo::read    161             a_out << "tools::rcsv::histo::read : bad axis values in line " << sout(line) << std::endl;
166             return false;                         162             return false;
167           }                                       163           }
168           hdata.m_axes.push_back(axis);           164           hdata.m_axes.push_back(axis);
169         } else if(_words[1]=="edges") {           165         } else if(_words[1]=="edges") {
170           std::vector<double> edges;              166           std::vector<double> edges;
171           double value;                           167           double value;
172           for(unsigned int index=2;index<_word    168           for(unsigned int index=2;index<_words.size();index++) {
173             if(!to(_words[index],value)) {        169             if(!to(_words[index],value)) {
174               a_out << "tools::rcsv::histo::re    170               a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
175               return false;                       171               return false;
176             }                                     172             }
177             edges.push_back(value);               173             edges.push_back(value);
178           }                                       174           }
179           axis_t axis;                            175           axis_t axis;
180           if(!axis.configure(edges)) {            176           if(!axis.configure(edges)) {
181             a_out << "tools::rcsv::histo::read    177             a_out << "tools::rcsv::histo::read : bad axis values in line " << sout(line) << std::endl;
182             return false;                         178             return false;
183           }                                       179           }
184           hdata.m_axes.push_back(axis);           180           hdata.m_axes.push_back(axis);
185         } else {                                  181         } else {
186           a_out << "tools::rcsv::histo::read :    182           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
187           return false;                           183           return false;
188         }                                         184         }
189                                                   185 
190       } else if(_words[0]=="#planes_Sxyw") {      186       } else if(_words[0]=="#planes_Sxyw") {
191         std::vector<double> planes;               187         std::vector<double> planes;
192         double value;                             188         double value;
193         for(unsigned int index=1;index<_words.    189         for(unsigned int index=1;index<_words.size();index++) {
194           if(!to(_words[index],value)) {          190           if(!to(_words[index],value)) {
195             a_out << "tools::rcsv::histo::read    191             a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
196             return false;                         192             return false;
197           }                                       193           }
198           planes.push_back(value);                194           planes.push_back(value);
199         }                                         195         }
200         hdata.m_in_range_plane_Sxyw = std::mov << 196         hdata.m_in_range_plane_Sxyw = planes;
201                                                   197 
202       } else if(_words[0]=="#bin_number") {       198       } else if(_words[0]=="#bin_number") {
203         if(_words.size()!=2) {                    199         if(_words.size()!=2) {
204           a_out << "tools::rcsv::histo::read :    200           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
205           return false;                           201           return false;
206         }                                         202         }
207         if(!to(_words[1],hdata.m_bin_number))  << 203         to(_words[1],hdata.m_bin_number);
208           a_out << "tools::rcsv::histo::read : << 
209           return false;                        << 
210         }                                      << 
211       } else if(_words[0]=="#cut_v") {            204       } else if(_words[0]=="#cut_v") {
212         if(_words.size()!=2) {                    205         if(_words.size()!=2) {
213           a_out << "tools::rcsv::histo::read :    206           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
214           return false;                           207           return false;
215         }                                         208         }
216         if(!to(_words[1],_cut_v)) {               209         if(!to(_words[1],_cut_v)) {
217           a_out << "tools::rcsv::histo::read :    210           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
218           return false;                           211           return false;
219         }                                         212         }
220         is_profile = true;                        213         is_profile = true;
221       } else if(_words[0]=="#min_v") {            214       } else if(_words[0]=="#min_v") {
222         if(_words.size()!=2) {                    215         if(_words.size()!=2) {
223           a_out << "tools::rcsv::histo::read :    216           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
224           return false;                           217           return false;
225         }                                         218         }
226         if(!to(_words[1],_min_v)) {               219         if(!to(_words[1],_min_v)) {
227           a_out << "tools::rcsv::histo::read :    220           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
228           return false;                           221           return false;
229         }                                         222         }
230       } else if(_words[0]=="#max_v") {            223       } else if(_words[0]=="#max_v") {
231         if(_words.size()!=2) {                    224         if(_words.size()!=2) {
232           a_out << "tools::rcsv::histo::read :    225           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
233           return false;                           226           return false;
234         }                                         227         }
235         if(!to(_words[1],_max_v)) {               228         if(!to(_words[1],_max_v)) {
236           a_out << "tools::rcsv::histo::read :    229           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
237           return false;                           230           return false;
238         }                                         231         }
239       } else {                                    232       } else {
240         a_out << "tools::rcsv::histo::read : s    233         a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
241         return false;                             234         return false;
242       }                                           235       }
243     }}                                            236     }}
244                                                   237 
245     if(a_verbose) {                               238     if(a_verbose) {
246       a_out << "class " << _class << std::endl    239       a_out << "class " << _class << std::endl;
247       a_out << "title " << hdata.m_title << st    240       a_out << "title " << hdata.m_title << std::endl;
248       tools_mforcit(std::string,std::string,hd    241       tools_mforcit(std::string,std::string,hdata.m_annotations,it) {
249          a_out << "annotation " << (*it).first    242          a_out << "annotation " << (*it).first << " " << sout((*it).second) << std::endl;
250       }                                           243       }
251     }                                             244     }
252                                                   245 
253     if(!hdata.m_dimension) {                      246     if(!hdata.m_dimension) {
254       a_out << "tools::rcsv::histo::read : nul    247       a_out << "tools::rcsv::histo::read : null dimension." << std::endl;
255       return false;                               248       return false;
256     }                                             249     }
257                                                   250 
258     // csv labels :                               251     // csv labels :
259     std::vector<std::string> labels;              252     std::vector<std::string> labels;
260    {std::string line;                             253    {std::string line;
261     if(!read_line(m_reader,file_sz,line)) {       254     if(!read_line(m_reader,file_sz,line)) {
262       a_out << "tools::rcsv::histo::read :"       255       a_out << "tools::rcsv::histo::read :"
263             << " syntax error in " << sout(lin    256             << " syntax error in " << sout(line)
264             << ". Can't read labels."             257             << ". Can't read labels."
265             << std::endl;                         258             << std::endl;
266       return false;                               259       return false;
267     }                                             260     }
268     if(a_verbose) a_out << "labels " << sout(l    261     if(a_verbose) a_out << "labels " << sout(line) << std::endl;
269     words(line,",",false,labels);}                262     words(line,",",false,labels);}
270                                                   263 
271     unsigned int valn = 3+2*hdata.m_dimension;    264     unsigned int valn = 3+2*hdata.m_dimension;
272                                                   265 
273     if(is_profile) valn += 2;                     266     if(is_profile) valn += 2;
274     std::vector<double> _bin_Svw;                 267     std::vector<double> _bin_Svw;
275     std::vector<double> _bin_Sv2w;                268     std::vector<double> _bin_Sv2w;
276                                                   269 
277     if(labels.size()!=valn) {                     270     if(labels.size()!=valn) {
278       a_out << "tools::rcsv::histo::read :"       271       a_out << "tools::rcsv::histo::read :"
279             << " bad number of labels " << lab    272             << " bad number of labels " << labels.size() << ". Expected " << valn << "."
280             << std::endl;                         273             << std::endl;
281       return false;                               274       return false;
282     }                                             275     }
283                                                   276 
284     // csv data (bins) :                          277     // csv data (bins) :
285    {std::vector<double> vals;                     278    {std::vector<double> vals;
286     unsigned int nline = 0;                       279     unsigned int nline = 0;
287     std::vector<double> bin_Sxw(hdata.m_dimens    280     std::vector<double> bin_Sxw(hdata.m_dimension);
288     std::vector<double> bin_Sx2w(hdata.m_dimen    281     std::vector<double> bin_Sx2w(hdata.m_dimension);
289     while(read_data_line(m_reader,file_sz,labe    282     while(read_data_line(m_reader,file_sz,labels.size(),vals)) {
290 /*                                                283 /*
291       for(unsigned int index=0;index<vals.size    284       for(unsigned int index=0;index<vals.size();index++) {
292         a_out << vals[index] << " ";              285         a_out << vals[index] << " ";
293       }                                           286       }
294       a_out << std::endl;                         287       a_out << std::endl;
295 */                                                288 */
296       if(vals.size()!=valn) {                     289       if(vals.size()!=valn) {
297          a_out << "tools::rcsv::histo::read :"    290          a_out << "tools::rcsv::histo::read :"
298                << " bad number of items in dat    291                << " bad number of items in data line " << vals.size() << ". Expected " << valn << "."
299                << std::endl;                      292                << std::endl;
300          return false;                            293          return false;
301       }                                           294       }
302       unsigned int ival = 0;                      295       unsigned int ival = 0;
303       hdata.m_bin_entries.push_back(static_cas    296       hdata.m_bin_entries.push_back(static_cast<unsigned int>(vals[ival++]));
304       hdata.m_bin_Sw.push_back(vals[ival++]);     297       hdata.m_bin_Sw.push_back(vals[ival++]);
305       hdata.m_bin_Sw2.push_back(vals[ival++]);    298       hdata.m_bin_Sw2.push_back(vals[ival++]);
306       if(is_profile) {                            299       if(is_profile) {
307         _bin_Svw.push_back(vals[ival++]);         300         _bin_Svw.push_back(vals[ival++]);
308         _bin_Sv2w.push_back(vals[ival++]);        301         _bin_Sv2w.push_back(vals[ival++]);
309       }                                           302       }
310      {for(unsigned int iaxis=0;iaxis<hdata.m_d    303      {for(unsigned int iaxis=0;iaxis<hdata.m_dimension;iaxis++) {
311         bin_Sxw[iaxis] = vals[ival++];            304         bin_Sxw[iaxis] = vals[ival++];
312         bin_Sx2w[iaxis] = vals[ival++];           305         bin_Sx2w[iaxis] = vals[ival++];
313       }}                                          306       }}
314       hdata.m_bin_Sxw.push_back(bin_Sxw);         307       hdata.m_bin_Sxw.push_back(bin_Sxw);
315       hdata.m_bin_Sx2w.push_back(bin_Sx2w);       308       hdata.m_bin_Sx2w.push_back(bin_Sx2w);
316       nline++;                                    309       nline++;
317     }                                             310     }
318     if(nline!=hdata.m_bin_number) {               311     if(nline!=hdata.m_bin_number) {
319       a_out << "tools::rcsv::histo::read : bad    312       a_out << "tools::rcsv::histo::read : bad data line number " << nline << ". Expected " << hdata.m_bin_number << "."
320             << std::endl;                         313             << std::endl;
321       return false;                               314       return false;
322     }}                                            315     }}
323                                                   316 
324     if(hdata.m_axes.size()!=hdata.m_dimension)    317     if(hdata.m_axes.size()!=hdata.m_dimension) {
325       a_out << "tools::rcsv::histo::read : inc    318       a_out << "tools::rcsv::histo::read : inconsistent axes data." << std::endl;
326       return false;                               319       return false;
327     }                                             320     }
328                                                   321 
329     hdata.m_axes[0].m_offset = 1;                 322     hdata.m_axes[0].m_offset = 1;
330    {for(unsigned int iaxis=1;iaxis<hdata.m_dim    323    {for(unsigned int iaxis=1;iaxis<hdata.m_dimension;iaxis++) {
331       hdata.m_axes[iaxis].m_offset = hdata.m_a    324       hdata.m_axes[iaxis].m_offset = hdata.m_axes[iaxis-1].m_offset * (hdata.m_axes[iaxis-1].bins()+2);
332     }}                                            325     }}
333                                                   326 
334     hdata.update_fast_getters(); //important.     327     hdata.update_fast_getters(); //important.
335                                                   328 
336     tools::histo::profile_data<double,unsigned    329     tools::histo::profile_data<double,unsigned int,unsigned int,double,double> pdata(hdata); //to be filled correctly.
337     if(is_profile) {                              330     if(is_profile) {
338       pdata.m_is_profile = true;                  331       pdata.m_is_profile = true;
339       pdata.m_bin_Svw = std::move(_bin_Svw);   << 332       pdata.m_bin_Svw = _bin_Svw;
340       pdata.m_bin_Sv2w = std::move(_bin_Sv2w); << 333       pdata.m_bin_Sv2w = _bin_Sv2w;
341       pdata.m_cut_v = _cut_v;                     334       pdata.m_cut_v = _cut_v;
342       pdata.m_min_v = _min_v;                     335       pdata.m_min_v = _min_v;
343       pdata.m_max_v = _max_v;                     336       pdata.m_max_v = _max_v;
344     }                                             337     }
345                                                   338 
346     if(_class==tools::histo::h1d::s_class()) {    339     if(_class==tools::histo::h1d::s_class()) {
347       if(hdata.m_dimension!=1) {                  340       if(hdata.m_dimension!=1) {
348         a_out << "tools::rcsv::histo::read :"     341         a_out << "tools::rcsv::histo::read :"
349               << " inconsistent dimension data    342               << " inconsistent dimension data."
350               << std::endl;                       343               << std::endl;
351         return false;                             344         return false;
352       }                                           345       }
353       tools::histo::h1d* h = new tools::histo:    346       tools::histo::h1d* h = new tools::histo::h1d("",10,0,1);
354       h->copy_from_data(hdata);                   347       h->copy_from_data(hdata);
355       //if(a_verbose) h->hprint(a_out);           348       //if(a_verbose) h->hprint(a_out);
356       if(a_verbose) {                             349       if(a_verbose) {
357         a_out << "h1d : " << h->title()           350         a_out << "h1d : " << h->title()
358               << ", all entries " << h->all_en    351               << ", all entries " << h->all_entries()
359               << ", entries " << h->entries()     352               << ", entries " << h->entries()
360               << ", mean " << h->mean() << ",     353               << ", mean " << h->mean() << ", rms " << h->rms()
361               << std::endl;                       354               << std::endl;
362       }                                           355       }
363       a_class = std::move(_class);             << 356       a_class = _class;
364       a_obj = h;                                  357       a_obj = h;
365                                                   358 
366     } else if(_class==tools::histo::h2d::s_cla    359     } else if(_class==tools::histo::h2d::s_class()) {
367       if(hdata.m_dimension!=2) {                  360       if(hdata.m_dimension!=2) {
368         a_out << "tools::rcsv::histo::read :"     361         a_out << "tools::rcsv::histo::read :"
369               << " inconsistent dimension data    362               << " inconsistent dimension data."
370               << std::endl;                       363               << std::endl;
371         return false;                             364         return false;
372       }                                           365       }
373       tools::histo::h2d* h = new tools::histo:    366       tools::histo::h2d* h = new tools::histo::h2d("",10,0,1,10,0,1);
374       h->copy_from_data(hdata);                   367       h->copy_from_data(hdata);
375       //if(a_verbose) h->hprint(a_out);           368       //if(a_verbose) h->hprint(a_out);
376       if(a_verbose) {                             369       if(a_verbose) {
377         a_out << "h2d : " << h->title()           370         a_out << "h2d : " << h->title()
378               << ", all entries " << h->all_en    371               << ", all entries " << h->all_entries()
379               << ", entries " << h->entries()     372               << ", entries " << h->entries()
380               << ", mean_x " << h->mean_x() <<    373               << ", mean_x " << h->mean_x() << ", rms_x " << h->rms_x()
381               << ", mean_y " << h->mean_y() <<    374               << ", mean_y " << h->mean_y() << ", rms_y " << h->rms_y()
382               << std::endl;                       375               << std::endl;
383       }                                           376       }
384       a_class = std::move(_class);             << 377       a_class = _class;
385       a_obj = h;                                  378       a_obj = h;
386                                                   379 
387     } else if(_class==tools::histo::h3d::s_cla    380     } else if(_class==tools::histo::h3d::s_class()) {
388       if(hdata.m_dimension!=3) {                  381       if(hdata.m_dimension!=3) {
389         a_out << "tools::rcsv::histo::read :"     382         a_out << "tools::rcsv::histo::read :"
390               << " inconsistent dimension data    383               << " inconsistent dimension data."
391               << std::endl;                       384               << std::endl;
392         return false;                             385         return false;
393       }                                           386       }
394       tools::histo::h3d* h = new tools::histo:    387       tools::histo::h3d* h = new tools::histo::h3d("",10,0,1,10,0,1,10,0,1);
395       h->copy_from_data(hdata);                   388       h->copy_from_data(hdata);
396       //if(a_verbose) h->hprint(a_out);           389       //if(a_verbose) h->hprint(a_out);
397       if(a_verbose) {                             390       if(a_verbose) {
398         a_out << "h3d : " << h->title()           391         a_out << "h3d : " << h->title()
399               << ", all entries " << h->all_en    392               << ", all entries " << h->all_entries()
400               << ", entries " << h->entries()     393               << ", entries " << h->entries()
401               << ", mean_x " << h->mean_x() <<    394               << ", mean_x " << h->mean_x() << ", rms_x " << h->rms_x()
402               << ", mean_y " << h->mean_y() <<    395               << ", mean_y " << h->mean_y() << ", rms_y " << h->rms_y()
403               << ", mean_z " << h->mean_z() <<    396               << ", mean_z " << h->mean_z() << ", rms_z " << h->rms_z()
404               << std::endl;                       397               << std::endl;
405       }                                           398       }
406       a_class = std::move(_class);             << 399       a_class = _class;
407       a_obj = h;                                  400       a_obj = h;
408                                                   401 
409     } else if(_class==tools::histo::p1d::s_cla    402     } else if(_class==tools::histo::p1d::s_class()) {
410       if(hdata.m_dimension!=1) {                  403       if(hdata.m_dimension!=1) {
411         a_out << "tools::rcsv::histo::read :"     404         a_out << "tools::rcsv::histo::read :"
412               << " inconsistent dimension data    405               << " inconsistent dimension data."
413               << std::endl;                       406               << std::endl;
414         return false;                             407         return false;
415       }                                           408       }
416       tools::histo::p1d* h = new tools::histo:    409       tools::histo::p1d* h = new tools::histo::p1d("",10,0,1);
417       h->copy_from_data(pdata);                   410       h->copy_from_data(pdata);
418       //if(a_verbose) h->hprint(a_out);           411       //if(a_verbose) h->hprint(a_out);
419       if(a_verbose) {                             412       if(a_verbose) {
420         a_out << "p1d : " << h->title()           413         a_out << "p1d : " << h->title()
421               << ", all entries " << h->all_en    414               << ", all entries " << h->all_entries()
422               << ", entries " << h->entries()     415               << ", entries " << h->entries()
423               << ", mean " << h->mean() << ",     416               << ", mean " << h->mean() << ", rms " << h->rms()
424               << std::endl;                       417               << std::endl;
425       }                                           418       }
426       a_class = std::move(_class);             << 419       a_class = _class;
427       a_obj = h;                                  420       a_obj = h;
428                                                   421 
429     } else if(_class==tools::histo::p2d::s_cla    422     } else if(_class==tools::histo::p2d::s_class()) {
430       if(hdata.m_dimension!=2) {                  423       if(hdata.m_dimension!=2) {
431         a_out << "tools::rcsv::histo::read :"     424         a_out << "tools::rcsv::histo::read :"
432               << " inconsistent dimension data    425               << " inconsistent dimension data."
433               << std::endl;                       426               << std::endl;
434         return false;                             427         return false;
435       }                                           428       }
436       tools::histo::p2d* h = new tools::histo:    429       tools::histo::p2d* h = new tools::histo::p2d("",10,0,1,10,0,1);
437       h->copy_from_data(pdata);                   430       h->copy_from_data(pdata);
438       //if(a_verbose) h->hprint(a_out);           431       //if(a_verbose) h->hprint(a_out);
439       if(a_verbose) {                             432       if(a_verbose) {
440         a_out << "p2d : " << h->title()           433         a_out << "p2d : " << h->title()
441               << ", all entries " << h->all_en    434               << ", all entries " << h->all_entries()
442               << ", entries " << h->entries()     435               << ", entries " << h->entries()
443               << ", mean_x " << h->mean_x() <<    436               << ", mean_x " << h->mean_x() << ", rms_x " << h->rms_x()
444               << ", mean_y " << h->mean_y() <<    437               << ", mean_y " << h->mean_y() << ", rms_y " << h->rms_y()
445               << std::endl;                       438               << std::endl;
446       }                                           439       }
447       a_class = std::move(_class);             << 440       a_class = _class;
448       a_obj = h;                                  441       a_obj = h;
449                                                   442 
450 /*                                                443 /*
451     } else if(_class==tools::histo::h1df::s_cl    444     } else if(_class==tools::histo::h1df::s_class()) {
452       if(hdata.m_dimension!=1) {                  445       if(hdata.m_dimension!=1) {
453         a_out << "tools::rcsv::histo::read :"     446         a_out << "tools::rcsv::histo::read :"
454               << " inconsistent dimension data    447               << " inconsistent dimension data."
455               << std::endl;                       448               << std::endl;
456         return false;                             449         return false;
457       }                                           450       }
458       tools::histo::h1df* h = new tools::histo    451       tools::histo::h1df* h = new tools::histo::h1df("",10,0,1);
459       h->copy_from_data(hdata);                   452       h->copy_from_data(hdata);
460       //return h; //give ownership to caller.     453       //return h; //give ownership to caller.
461       if(a_verbose) h->hprint(a_out);             454       if(a_verbose) h->hprint(a_out);
462 */                                                455 */
463                                                   456 
464     } else {                                      457     } else {
465       a_out << "tools::rcsv::histo::read : unk    458       a_out << "tools::rcsv::histo::read : unknown class " << sout(_class) << std::endl;
466       return false;                               459       return false;
467     }                                             460     }
468                                                   461 
469     return true;                                  462     return true;
470   }                                               463   }
471 protected:                                        464 protected:
472   static bool read_line(std::istream& a_reader    465   static bool read_line(std::istream& a_reader,std::streampos a_sz,std::string& a_s){
473     a_s.clear();                                  466     a_s.clear();
474     char c;                                       467     char c;
475     while(true) {                                 468     while(true) {
476       if(a_reader.tellg()>=a_sz) {a_s.clear();    469       if(a_reader.tellg()>=a_sz) {a_s.clear();return false;}
477       a_reader.get(c);                            470       a_reader.get(c);
478       if(c==CR()) continue;                       471       if(c==CR()) continue;
479       if(c==LF()) break; //eol.                   472       if(c==LF()) break; //eol.
480       a_s += c;                                   473       a_s += c;
481     }                                             474     }
482     return true;                                  475     return true;
483   }                                               476   }
484                                                   477 
485   static bool read_header_line(std::istream& a    478   static bool read_header_line(std::istream& a_reader,std::streampos a_sz,std::string& a_s){
486     //we should be at bol.                        479     //we should be at bol.
487     //ret true = we had a commented line, fals    480     //ret true = we had a commented line, false : a data line or nothing.
488     if(a_reader.tellg()>=a_sz) {a_s.clear();re    481     if(a_reader.tellg()>=a_sz) {a_s.clear();return false;}
489     char c;                                       482     char c;
490     a_reader.get(c);                              483     a_reader.get(c);
491     a_reader.putback(c);                          484     a_reader.putback(c);
492     if(c!='#') {a_s.clear();return false;}        485     if(c!='#') {a_s.clear();return false;}
493     return read_line(a_reader,a_sz,a_s);          486     return read_line(a_reader,a_sz,a_s);
494   }                                               487   }
495                                                   488 
496   static bool _read(std::istream& a_reader,dou    489   static bool _read(std::istream& a_reader,double& a_v) {
497     a_reader >> a_v;                              490     a_reader >> a_v;
498     if(a_reader.tellg()==std::streampos(-1)) {    491     if(a_reader.tellg()==std::streampos(-1)) {a_v = 0;return false;}
499     //std::cout << "debug : _read(double) " <<    492     //std::cout << "debug : _read(double) " << a_v << std::endl;
500     return true;                                  493     return true;
501   }                                               494   }
502                                                   495 
503   static bool read_data_line(std::istream& a_r    496   static bool read_data_line(std::istream& a_reader,std::streampos a_sz,size_t a_number,std::vector<double>& a_vals) {
504     a_vals.clear();                               497     a_vals.clear();
505     for(size_t index=0;index<a_number;index++)    498     for(size_t index=0;index<a_number;index++) {
506       double v;                                   499       double v;
507       if(!_read(a_reader,v)) return false;        500       if(!_read(a_reader,v)) return false;
508       a_vals.push_back(v);                        501       a_vals.push_back(v);
509       if(index==(a_number-1)) { //read up to L    502       if(index==(a_number-1)) { //read up to LF()
510         char c;                                   503         char c;
511         while(true){                              504         while(true){
512           if(a_reader.tellg()>=a_sz) break;       505           if(a_reader.tellg()>=a_sz) break;
513           a_reader.get(c);                        506           a_reader.get(c);
514           if(c==LF()) break;                      507           if(c==LF()) break;
515         }                                         508         }
516       } else { //read sep :                       509       } else { //read sep :
517         char sep;                                 510         char sep;
518         a_reader.get(sep);                        511         a_reader.get(sep);
519       }                                           512       }
520     }                                             513     }
521     return true;                                  514     return true;
522   }                                               515   }
523 protected:                                        516 protected:
524   std::istream& m_reader;                         517   std::istream& m_reader;
525 };                                                518 };
526                                                   519 
527 }}                                                520 }}
528                                                   521 
529 #endif                                            522 #endif