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.2.1)


  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         if(!to(_words[1],hdata.m_dimension)) {
123           a_out << "tools::rcsv::histo::read :    122           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
124           return false;                           123           return false;
125         }                                         124         }
126       } else if(_words[0]=="#annotation") {       125       } else if(_words[0]=="#annotation") {
127         if(_words.size()<2) {                     126         if(_words.size()<2) {
128           a_out << "tools::rcsv::histo::read :    127           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
129           return false;                           128           return false;
130         }                                         129         }
131         if(_words.size()==2) {                    130         if(_words.size()==2) {
132           hdata.m_annotations[_words[1]] = std    131           hdata.m_annotations[_words[1]] = std::string();
133         } else {                                  132         } else {
134           std::string::size_type pos = line.fi    133           std::string::size_type pos = line.find(_words[1]);
135           pos += _words[1].size()+1;              134           pos += _words[1].size()+1;
136           hdata.m_annotations[_words[1]] = lin    135           hdata.m_annotations[_words[1]] = line.substr(pos,line.size()-pos);
137         }                                         136         }
138       } else if(_words[0]=="#axis") {             137       } else if(_words[0]=="#axis") {
139         if(_words.size()<2) {                     138         if(_words.size()<2) {
140           a_out << "tools::rcsv::histo::read :    139           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
141           return false;                           140           return false;
142         }                                         141         }
143         if(_words[1]=="fixed") {                  142         if(_words[1]=="fixed") {
144           if(_words.size()!=5) {                  143           if(_words.size()!=5) {
145             a_out << "tools::rcsv::histo::read    144             a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
146             return false;                         145             return false;
147           }                                       146           }
148           unsigned int number_of_bins;            147           unsigned int number_of_bins;
149           if(!to(_words[2],number_of_bins)) {     148           if(!to(_words[2],number_of_bins)) {
150             a_out << "tools::rcsv::histo::read    149             a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
151             return false;                         150             return false;
152           }                                       151           }
153           double minimum_value;                   152           double minimum_value;
154           if(!to(_words[3],minimum_value)) {      153           if(!to(_words[3],minimum_value)) {
155             a_out << "tools::rcsv::histo::read    154             a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
156             return false;                         155             return false;
157           }                                       156           }
158           double maximum_value;                   157           double maximum_value;
159           if(!to(_words[4],maximum_value)) {      158           if(!to(_words[4],maximum_value)) {
160             a_out << "tools::rcsv::histo::read    159             a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
161             return false;                         160             return false;
162           }                                       161           }
163           axis_t axis;                            162           axis_t axis;
164           if(!axis.configure(number_of_bins,mi    163           if(!axis.configure(number_of_bins,minimum_value,maximum_value)) {
165             a_out << "tools::rcsv::histo::read    164             a_out << "tools::rcsv::histo::read : bad axis values in line " << sout(line) << std::endl;
166             return false;                         165             return false;
167           }                                       166           }
168           hdata.m_axes.push_back(axis);           167           hdata.m_axes.push_back(axis);
169         } else if(_words[1]=="edges") {           168         } else if(_words[1]=="edges") {
170           std::vector<double> edges;              169           std::vector<double> edges;
171           double value;                           170           double value;
172           for(unsigned int index=2;index<_word    171           for(unsigned int index=2;index<_words.size();index++) {
173             if(!to(_words[index],value)) {        172             if(!to(_words[index],value)) {
174               a_out << "tools::rcsv::histo::re    173               a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
175               return false;                       174               return false;
176             }                                     175             }
177             edges.push_back(value);               176             edges.push_back(value);
178           }                                       177           }
179           axis_t axis;                            178           axis_t axis;
180           if(!axis.configure(edges)) {            179           if(!axis.configure(edges)) {
181             a_out << "tools::rcsv::histo::read    180             a_out << "tools::rcsv::histo::read : bad axis values in line " << sout(line) << std::endl;
182             return false;                         181             return false;
183           }                                       182           }
184           hdata.m_axes.push_back(axis);           183           hdata.m_axes.push_back(axis);
185         } else {                                  184         } else {
186           a_out << "tools::rcsv::histo::read :    185           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
187           return false;                           186           return false;
188         }                                         187         }
189                                                   188 
190       } else if(_words[0]=="#planes_Sxyw") {      189       } else if(_words[0]=="#planes_Sxyw") {
191         std::vector<double> planes;               190         std::vector<double> planes;
192         double value;                             191         double value;
193         for(unsigned int index=1;index<_words.    192         for(unsigned int index=1;index<_words.size();index++) {
194           if(!to(_words[index],value)) {          193           if(!to(_words[index],value)) {
195             a_out << "tools::rcsv::histo::read    194             a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
196             return false;                         195             return false;
197           }                                       196           }
198           planes.push_back(value);                197           planes.push_back(value);
199         }                                         198         }
200         hdata.m_in_range_plane_Sxyw = std::mov << 199         hdata.m_in_range_plane_Sxyw = planes;
201                                                   200 
202       } else if(_words[0]=="#bin_number") {       201       } else if(_words[0]=="#bin_number") {
203         if(_words.size()!=2) {                    202         if(_words.size()!=2) {
204           a_out << "tools::rcsv::histo::read :    203           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
205           return false;                           204           return false;
206         }                                         205         }
207         if(!to(_words[1],hdata.m_bin_number))     206         if(!to(_words[1],hdata.m_bin_number)) {
208           a_out << "tools::rcsv::histo::read :    207           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
209           return false;                           208           return false;
210         }                                         209         }
211       } else if(_words[0]=="#cut_v") {            210       } else if(_words[0]=="#cut_v") {
212         if(_words.size()!=2) {                    211         if(_words.size()!=2) {
213           a_out << "tools::rcsv::histo::read :    212           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
214           return false;                           213           return false;
215         }                                         214         }
216         if(!to(_words[1],_cut_v)) {               215         if(!to(_words[1],_cut_v)) {
217           a_out << "tools::rcsv::histo::read :    216           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
218           return false;                           217           return false;
219         }                                         218         }
220         is_profile = true;                        219         is_profile = true;
221       } else if(_words[0]=="#min_v") {            220       } else if(_words[0]=="#min_v") {
222         if(_words.size()!=2) {                    221         if(_words.size()!=2) {
223           a_out << "tools::rcsv::histo::read :    222           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
224           return false;                           223           return false;
225         }                                         224         }
226         if(!to(_words[1],_min_v)) {               225         if(!to(_words[1],_min_v)) {
227           a_out << "tools::rcsv::histo::read :    226           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
228           return false;                           227           return false;
229         }                                         228         }
230       } else if(_words[0]=="#max_v") {            229       } else if(_words[0]=="#max_v") {
231         if(_words.size()!=2) {                    230         if(_words.size()!=2) {
232           a_out << "tools::rcsv::histo::read :    231           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
233           return false;                           232           return false;
234         }                                         233         }
235         if(!to(_words[1],_max_v)) {               234         if(!to(_words[1],_max_v)) {
236           a_out << "tools::rcsv::histo::read :    235           a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
237           return false;                           236           return false;
238         }                                         237         }
239       } else {                                    238       } else {
240         a_out << "tools::rcsv::histo::read : s    239         a_out << "tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
241         return false;                             240         return false;
242       }                                           241       }
243     }}                                            242     }}
244                                                   243 
245     if(a_verbose) {                               244     if(a_verbose) {
246       a_out << "class " << _class << std::endl    245       a_out << "class " << _class << std::endl;
247       a_out << "title " << hdata.m_title << st    246       a_out << "title " << hdata.m_title << std::endl;
248       tools_mforcit(std::string,std::string,hd    247       tools_mforcit(std::string,std::string,hdata.m_annotations,it) {
249          a_out << "annotation " << (*it).first    248          a_out << "annotation " << (*it).first << " " << sout((*it).second) << std::endl;
250       }                                           249       }
251     }                                             250     }
252                                                   251 
253     if(!hdata.m_dimension) {                      252     if(!hdata.m_dimension) {
254       a_out << "tools::rcsv::histo::read : nul    253       a_out << "tools::rcsv::histo::read : null dimension." << std::endl;
255       return false;                               254       return false;
256     }                                             255     }
257                                                   256 
258     // csv labels :                               257     // csv labels :
259     std::vector<std::string> labels;              258     std::vector<std::string> labels;
260    {std::string line;                             259    {std::string line;
261     if(!read_line(m_reader,file_sz,line)) {       260     if(!read_line(m_reader,file_sz,line)) {
262       a_out << "tools::rcsv::histo::read :"       261       a_out << "tools::rcsv::histo::read :"
263             << " syntax error in " << sout(lin    262             << " syntax error in " << sout(line)
264             << ". Can't read labels."             263             << ". Can't read labels."
265             << std::endl;                         264             << std::endl;
266       return false;                               265       return false;
267     }                                             266     }
268     if(a_verbose) a_out << "labels " << sout(l    267     if(a_verbose) a_out << "labels " << sout(line) << std::endl;
269     words(line,",",false,labels);}                268     words(line,",",false,labels);}
270                                                   269 
271     unsigned int valn = 3+2*hdata.m_dimension;    270     unsigned int valn = 3+2*hdata.m_dimension;
272                                                   271 
273     if(is_profile) valn += 2;                     272     if(is_profile) valn += 2;
274     std::vector<double> _bin_Svw;                 273     std::vector<double> _bin_Svw;
275     std::vector<double> _bin_Sv2w;                274     std::vector<double> _bin_Sv2w;
276                                                   275 
277     if(labels.size()!=valn) {                     276     if(labels.size()!=valn) {
278       a_out << "tools::rcsv::histo::read :"       277       a_out << "tools::rcsv::histo::read :"
279             << " bad number of labels " << lab    278             << " bad number of labels " << labels.size() << ". Expected " << valn << "."
280             << std::endl;                         279             << std::endl;
281       return false;                               280       return false;
282     }                                             281     }
283                                                   282 
284     // csv data (bins) :                          283     // csv data (bins) :
285    {std::vector<double> vals;                     284    {std::vector<double> vals;
286     unsigned int nline = 0;                       285     unsigned int nline = 0;
287     std::vector<double> bin_Sxw(hdata.m_dimens    286     std::vector<double> bin_Sxw(hdata.m_dimension);
288     std::vector<double> bin_Sx2w(hdata.m_dimen    287     std::vector<double> bin_Sx2w(hdata.m_dimension);
289     while(read_data_line(m_reader,file_sz,labe    288     while(read_data_line(m_reader,file_sz,labels.size(),vals)) {
290 /*                                                289 /*
291       for(unsigned int index=0;index<vals.size    290       for(unsigned int index=0;index<vals.size();index++) {
292         a_out << vals[index] << " ";              291         a_out << vals[index] << " ";
293       }                                           292       }
294       a_out << std::endl;                         293       a_out << std::endl;
295 */                                                294 */
296       if(vals.size()!=valn) {                     295       if(vals.size()!=valn) {
297          a_out << "tools::rcsv::histo::read :"    296          a_out << "tools::rcsv::histo::read :"
298                << " bad number of items in dat    297                << " bad number of items in data line " << vals.size() << ". Expected " << valn << "."
299                << std::endl;                      298                << std::endl;
300          return false;                            299          return false;
301       }                                           300       }
302       unsigned int ival = 0;                      301       unsigned int ival = 0;
303       hdata.m_bin_entries.push_back(static_cas    302       hdata.m_bin_entries.push_back(static_cast<unsigned int>(vals[ival++]));
304       hdata.m_bin_Sw.push_back(vals[ival++]);     303       hdata.m_bin_Sw.push_back(vals[ival++]);
305       hdata.m_bin_Sw2.push_back(vals[ival++]);    304       hdata.m_bin_Sw2.push_back(vals[ival++]);
306       if(is_profile) {                            305       if(is_profile) {
307         _bin_Svw.push_back(vals[ival++]);         306         _bin_Svw.push_back(vals[ival++]);
308         _bin_Sv2w.push_back(vals[ival++]);        307         _bin_Sv2w.push_back(vals[ival++]);
309       }                                           308       }
310      {for(unsigned int iaxis=0;iaxis<hdata.m_d    309      {for(unsigned int iaxis=0;iaxis<hdata.m_dimension;iaxis++) {
311         bin_Sxw[iaxis] = vals[ival++];            310         bin_Sxw[iaxis] = vals[ival++];
312         bin_Sx2w[iaxis] = vals[ival++];           311         bin_Sx2w[iaxis] = vals[ival++];
313       }}                                          312       }}
314       hdata.m_bin_Sxw.push_back(bin_Sxw);         313       hdata.m_bin_Sxw.push_back(bin_Sxw);
315       hdata.m_bin_Sx2w.push_back(bin_Sx2w);       314       hdata.m_bin_Sx2w.push_back(bin_Sx2w);
316       nline++;                                    315       nline++;
317     }                                             316     }
318     if(nline!=hdata.m_bin_number) {               317     if(nline!=hdata.m_bin_number) {
319       a_out << "tools::rcsv::histo::read : bad    318       a_out << "tools::rcsv::histo::read : bad data line number " << nline << ". Expected " << hdata.m_bin_number << "."
320             << std::endl;                         319             << std::endl;
321       return false;                               320       return false;
322     }}                                            321     }}
323                                                   322 
324     if(hdata.m_axes.size()!=hdata.m_dimension)    323     if(hdata.m_axes.size()!=hdata.m_dimension) {
325       a_out << "tools::rcsv::histo::read : inc    324       a_out << "tools::rcsv::histo::read : inconsistent axes data." << std::endl;
326       return false;                               325       return false;
327     }                                             326     }
328                                                   327 
329     hdata.m_axes[0].m_offset = 1;                 328     hdata.m_axes[0].m_offset = 1;
330    {for(unsigned int iaxis=1;iaxis<hdata.m_dim    329    {for(unsigned int iaxis=1;iaxis<hdata.m_dimension;iaxis++) {
331       hdata.m_axes[iaxis].m_offset = hdata.m_a    330       hdata.m_axes[iaxis].m_offset = hdata.m_axes[iaxis-1].m_offset * (hdata.m_axes[iaxis-1].bins()+2);
332     }}                                            331     }}
333                                                   332 
334     hdata.update_fast_getters(); //important.     333     hdata.update_fast_getters(); //important.
335                                                   334 
336     tools::histo::profile_data<double,unsigned    335     tools::histo::profile_data<double,unsigned int,unsigned int,double,double> pdata(hdata); //to be filled correctly.
337     if(is_profile) {                              336     if(is_profile) {
338       pdata.m_is_profile = true;                  337       pdata.m_is_profile = true;
339       pdata.m_bin_Svw = std::move(_bin_Svw);   << 338       pdata.m_bin_Svw = _bin_Svw;
340       pdata.m_bin_Sv2w = std::move(_bin_Sv2w); << 339       pdata.m_bin_Sv2w = _bin_Sv2w;
341       pdata.m_cut_v = _cut_v;                     340       pdata.m_cut_v = _cut_v;
342       pdata.m_min_v = _min_v;                     341       pdata.m_min_v = _min_v;
343       pdata.m_max_v = _max_v;                     342       pdata.m_max_v = _max_v;
344     }                                             343     }
345                                                   344 
346     if(_class==tools::histo::h1d::s_class()) {    345     if(_class==tools::histo::h1d::s_class()) {
347       if(hdata.m_dimension!=1) {                  346       if(hdata.m_dimension!=1) {
348         a_out << "tools::rcsv::histo::read :"     347         a_out << "tools::rcsv::histo::read :"
349               << " inconsistent dimension data    348               << " inconsistent dimension data."
350               << std::endl;                       349               << std::endl;
351         return false;                             350         return false;
352       }                                           351       }
353       tools::histo::h1d* h = new tools::histo:    352       tools::histo::h1d* h = new tools::histo::h1d("",10,0,1);
354       h->copy_from_data(hdata);                   353       h->copy_from_data(hdata);
355       //if(a_verbose) h->hprint(a_out);           354       //if(a_verbose) h->hprint(a_out);
356       if(a_verbose) {                             355       if(a_verbose) {
357         a_out << "h1d : " << h->title()           356         a_out << "h1d : " << h->title()
358               << ", all entries " << h->all_en    357               << ", all entries " << h->all_entries()
359               << ", entries " << h->entries()     358               << ", entries " << h->entries()
360               << ", mean " << h->mean() << ",     359               << ", mean " << h->mean() << ", rms " << h->rms()
361               << std::endl;                       360               << std::endl;
362       }                                           361       }
363       a_class = std::move(_class);             << 362       a_class = _class;
364       a_obj = h;                                  363       a_obj = h;
365                                                   364 
366     } else if(_class==tools::histo::h2d::s_cla    365     } else if(_class==tools::histo::h2d::s_class()) {
367       if(hdata.m_dimension!=2) {                  366       if(hdata.m_dimension!=2) {
368         a_out << "tools::rcsv::histo::read :"     367         a_out << "tools::rcsv::histo::read :"
369               << " inconsistent dimension data    368               << " inconsistent dimension data."
370               << std::endl;                       369               << std::endl;
371         return false;                             370         return false;
372       }                                           371       }
373       tools::histo::h2d* h = new tools::histo:    372       tools::histo::h2d* h = new tools::histo::h2d("",10,0,1,10,0,1);
374       h->copy_from_data(hdata);                   373       h->copy_from_data(hdata);
375       //if(a_verbose) h->hprint(a_out);           374       //if(a_verbose) h->hprint(a_out);
376       if(a_verbose) {                             375       if(a_verbose) {
377         a_out << "h2d : " << h->title()           376         a_out << "h2d : " << h->title()
378               << ", all entries " << h->all_en    377               << ", all entries " << h->all_entries()
379               << ", entries " << h->entries()     378               << ", entries " << h->entries()
380               << ", mean_x " << h->mean_x() <<    379               << ", mean_x " << h->mean_x() << ", rms_x " << h->rms_x()
381               << ", mean_y " << h->mean_y() <<    380               << ", mean_y " << h->mean_y() << ", rms_y " << h->rms_y()
382               << std::endl;                       381               << std::endl;
383       }                                           382       }
384       a_class = std::move(_class);             << 383       a_class = _class;
385       a_obj = h;                                  384       a_obj = h;
386                                                   385 
387     } else if(_class==tools::histo::h3d::s_cla    386     } else if(_class==tools::histo::h3d::s_class()) {
388       if(hdata.m_dimension!=3) {                  387       if(hdata.m_dimension!=3) {
389         a_out << "tools::rcsv::histo::read :"     388         a_out << "tools::rcsv::histo::read :"
390               << " inconsistent dimension data    389               << " inconsistent dimension data."
391               << std::endl;                       390               << std::endl;
392         return false;                             391         return false;
393       }                                           392       }
394       tools::histo::h3d* h = new tools::histo:    393       tools::histo::h3d* h = new tools::histo::h3d("",10,0,1,10,0,1,10,0,1);
395       h->copy_from_data(hdata);                   394       h->copy_from_data(hdata);
396       //if(a_verbose) h->hprint(a_out);           395       //if(a_verbose) h->hprint(a_out);
397       if(a_verbose) {                             396       if(a_verbose) {
398         a_out << "h3d : " << h->title()           397         a_out << "h3d : " << h->title()
399               << ", all entries " << h->all_en    398               << ", all entries " << h->all_entries()
400               << ", entries " << h->entries()     399               << ", entries " << h->entries()
401               << ", mean_x " << h->mean_x() <<    400               << ", mean_x " << h->mean_x() << ", rms_x " << h->rms_x()
402               << ", mean_y " << h->mean_y() <<    401               << ", mean_y " << h->mean_y() << ", rms_y " << h->rms_y()
403               << ", mean_z " << h->mean_z() <<    402               << ", mean_z " << h->mean_z() << ", rms_z " << h->rms_z()
404               << std::endl;                       403               << std::endl;
405       }                                           404       }
406       a_class = std::move(_class);             << 405       a_class = _class;
407       a_obj = h;                                  406       a_obj = h;
408                                                   407 
409     } else if(_class==tools::histo::p1d::s_cla    408     } else if(_class==tools::histo::p1d::s_class()) {
410       if(hdata.m_dimension!=1) {                  409       if(hdata.m_dimension!=1) {
411         a_out << "tools::rcsv::histo::read :"     410         a_out << "tools::rcsv::histo::read :"
412               << " inconsistent dimension data    411               << " inconsistent dimension data."
413               << std::endl;                       412               << std::endl;
414         return false;                             413         return false;
415       }                                           414       }
416       tools::histo::p1d* h = new tools::histo:    415       tools::histo::p1d* h = new tools::histo::p1d("",10,0,1);
417       h->copy_from_data(pdata);                   416       h->copy_from_data(pdata);
418       //if(a_verbose) h->hprint(a_out);           417       //if(a_verbose) h->hprint(a_out);
419       if(a_verbose) {                             418       if(a_verbose) {
420         a_out << "p1d : " << h->title()           419         a_out << "p1d : " << h->title()
421               << ", all entries " << h->all_en    420               << ", all entries " << h->all_entries()
422               << ", entries " << h->entries()     421               << ", entries " << h->entries()
423               << ", mean " << h->mean() << ",     422               << ", mean " << h->mean() << ", rms " << h->rms()
424               << std::endl;                       423               << std::endl;
425       }                                           424       }
426       a_class = std::move(_class);             << 425       a_class = _class;
427       a_obj = h;                                  426       a_obj = h;
428                                                   427 
429     } else if(_class==tools::histo::p2d::s_cla    428     } else if(_class==tools::histo::p2d::s_class()) {
430       if(hdata.m_dimension!=2) {                  429       if(hdata.m_dimension!=2) {
431         a_out << "tools::rcsv::histo::read :"     430         a_out << "tools::rcsv::histo::read :"
432               << " inconsistent dimension data    431               << " inconsistent dimension data."
433               << std::endl;                       432               << std::endl;
434         return false;                             433         return false;
435       }                                           434       }
436       tools::histo::p2d* h = new tools::histo:    435       tools::histo::p2d* h = new tools::histo::p2d("",10,0,1,10,0,1);
437       h->copy_from_data(pdata);                   436       h->copy_from_data(pdata);
438       //if(a_verbose) h->hprint(a_out);           437       //if(a_verbose) h->hprint(a_out);
439       if(a_verbose) {                             438       if(a_verbose) {
440         a_out << "p2d : " << h->title()           439         a_out << "p2d : " << h->title()
441               << ", all entries " << h->all_en    440               << ", all entries " << h->all_entries()
442               << ", entries " << h->entries()     441               << ", entries " << h->entries()
443               << ", mean_x " << h->mean_x() <<    442               << ", mean_x " << h->mean_x() << ", rms_x " << h->rms_x()
444               << ", mean_y " << h->mean_y() <<    443               << ", mean_y " << h->mean_y() << ", rms_y " << h->rms_y()
445               << std::endl;                       444               << std::endl;
446       }                                           445       }
447       a_class = std::move(_class);             << 446       a_class = _class;
448       a_obj = h;                                  447       a_obj = h;
449                                                   448 
450 /*                                                449 /*
451     } else if(_class==tools::histo::h1df::s_cl    450     } else if(_class==tools::histo::h1df::s_class()) {
452       if(hdata.m_dimension!=1) {                  451       if(hdata.m_dimension!=1) {
453         a_out << "tools::rcsv::histo::read :"     452         a_out << "tools::rcsv::histo::read :"
454               << " inconsistent dimension data    453               << " inconsistent dimension data."
455               << std::endl;                       454               << std::endl;
456         return false;                             455         return false;
457       }                                           456       }
458       tools::histo::h1df* h = new tools::histo    457       tools::histo::h1df* h = new tools::histo::h1df("",10,0,1);
459       h->copy_from_data(hdata);                   458       h->copy_from_data(hdata);
460       //return h; //give ownership to caller.     459       //return h; //give ownership to caller.
461       if(a_verbose) h->hprint(a_out);             460       if(a_verbose) h->hprint(a_out);
462 */                                                461 */
463                                                   462 
464     } else {                                      463     } else {
465       a_out << "tools::rcsv::histo::read : unk    464       a_out << "tools::rcsv::histo::read : unknown class " << sout(_class) << std::endl;
466       return false;                               465       return false;
467     }                                             466     }
468                                                   467 
469     return true;                                  468     return true;
470   }                                               469   }
471 protected:                                        470 protected:
472   static bool read_line(std::istream& a_reader    471   static bool read_line(std::istream& a_reader,std::streampos a_sz,std::string& a_s){
473     a_s.clear();                                  472     a_s.clear();
474     char c;                                       473     char c;
475     while(true) {                                 474     while(true) {
476       if(a_reader.tellg()>=a_sz) {a_s.clear();    475       if(a_reader.tellg()>=a_sz) {a_s.clear();return false;}
477       a_reader.get(c);                            476       a_reader.get(c);
478       if(c==CR()) continue;                       477       if(c==CR()) continue;
479       if(c==LF()) break; //eol.                   478       if(c==LF()) break; //eol.
480       a_s += c;                                   479       a_s += c;
481     }                                             480     }
482     return true;                                  481     return true;
483   }                                               482   }
484                                                   483 
485   static bool read_header_line(std::istream& a    484   static bool read_header_line(std::istream& a_reader,std::streampos a_sz,std::string& a_s){
486     //we should be at bol.                        485     //we should be at bol.
487     //ret true = we had a commented line, fals    486     //ret true = we had a commented line, false : a data line or nothing.
488     if(a_reader.tellg()>=a_sz) {a_s.clear();re    487     if(a_reader.tellg()>=a_sz) {a_s.clear();return false;}
489     char c;                                       488     char c;
490     a_reader.get(c);                              489     a_reader.get(c);
491     a_reader.putback(c);                          490     a_reader.putback(c);
492     if(c!='#') {a_s.clear();return false;}        491     if(c!='#') {a_s.clear();return false;}
493     return read_line(a_reader,a_sz,a_s);          492     return read_line(a_reader,a_sz,a_s);
494   }                                               493   }
495                                                   494 
496   static bool _read(std::istream& a_reader,dou    495   static bool _read(std::istream& a_reader,double& a_v) {
497     a_reader >> a_v;                              496     a_reader >> a_v;
498     if(a_reader.tellg()==std::streampos(-1)) {    497     if(a_reader.tellg()==std::streampos(-1)) {a_v = 0;return false;}
499     //std::cout << "debug : _read(double) " <<    498     //std::cout << "debug : _read(double) " << a_v << std::endl;
500     return true;                                  499     return true;
501   }                                               500   }
502                                                   501 
503   static bool read_data_line(std::istream& a_r    502   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();                               503     a_vals.clear();
505     for(size_t index=0;index<a_number;index++)    504     for(size_t index=0;index<a_number;index++) {
506       double v;                                   505       double v;
507       if(!_read(a_reader,v)) return false;        506       if(!_read(a_reader,v)) return false;
508       a_vals.push_back(v);                        507       a_vals.push_back(v);
509       if(index==(a_number-1)) { //read up to L    508       if(index==(a_number-1)) { //read up to LF()
510         char c;                                   509         char c;
511         while(true){                              510         while(true){
512           if(a_reader.tellg()>=a_sz) break;       511           if(a_reader.tellg()>=a_sz) break;
513           a_reader.get(c);                        512           a_reader.get(c);
514           if(c==LF()) break;                      513           if(c==LF()) break;
515         }                                         514         }
516       } else { //read sep :                       515       } else { //read sep :
517         char sep;                                 516         char sep;
518         a_reader.get(sep);                        517         a_reader.get(sep);
519       }                                           518       }
520     }                                             519     }
521     return true;                                  520     return true;
522   }                                               521   }
523 protected:                                        522 protected:
524   std::istream& m_reader;                         523   std::istream& m_reader;
525 };                                                524 };
526                                                   525 
527 }}                                                526 }}
528                                                   527 
529 #endif                                            528 #endif