66 std::streampos file_sz = 0;
72 a_out <<
"tools::rcsv::histo::read : stream is empty." << std::endl;
75 if(a_verbose) a_out <<
"file size is " << file_sz << std::endl;
81 bool is_profile =
false;
92 std::vector<std::string> _words;
93 words(line,
" ",
false,_words);
95 a_out <<
"tools::rcsv::histo::read : syntax error : empty header line." << std::endl;
98 if((_words[0]==
"#class")) {
99 if(_words.size()!=2) {
100 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
104 }
else if(_words[0]==
"#title") {
105 if(_words.size()<1) {
106 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
109 if(_words.size()==1) {
112 std::string::size_type pos = line.find(_words[0]);
113 pos += _words[0].size()+1;
114 hdata.
m_title = line.substr(pos,line.size()-pos);
116 }
else if(_words[0]==
"#dimension") {
117 if(_words.size()!=2) {
118 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
122 }
else if(_words[0]==
"#annotation") {
123 if(_words.size()<2) {
124 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
127 if(_words.size()==2) {
130 std::string::size_type pos = line.find(_words[1]);
131 pos += _words[1].size()+1;
132 hdata.
m_annotations[_words[1]] = line.substr(pos,line.size()-pos);
134 }
else if(_words[0]==
"#axis") {
135 if(_words.size()<2) {
136 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
139 if(_words[1]==
"fixed") {
140 if(_words.size()!=5) {
141 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
144 unsigned int number_of_bins;
145 if(!
to(_words[2],number_of_bins)) {
146 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
149 double minimum_value;
150 if(!
to(_words[3],minimum_value)) {
151 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
154 double maximum_value;
155 if(!
to(_words[4],maximum_value)) {
156 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
160 if(!axis.configure(number_of_bins,minimum_value,maximum_value)) {
161 a_out <<
"tools::rcsv::histo::read : bad axis values in line " << sout(line) << std::endl;
164 hdata.
m_axes.push_back(axis);
165 }
else if(_words[1]==
"edges") {
166 std::vector<double> edges;
168 for(
unsigned int index=2;index<_words.size();index++) {
169 if(!
to(_words[index],value)) {
170 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
173 edges.push_back(value);
176 if(!axis.configure(edges)) {
177 a_out <<
"tools::rcsv::histo::read : bad axis values in line " << sout(line) << std::endl;
180 hdata.
m_axes.push_back(axis);
182 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
186 }
else if(_words[0]==
"#planes_Sxyw") {
187 std::vector<double> planes;
189 for(
unsigned int index=1;index<_words.size();index++) {
190 if(!
to(_words[index],value)) {
191 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
194 planes.push_back(value);
198 }
else if(_words[0]==
"#bin_number") {
199 if(_words.size()!=2) {
200 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
204 }
else if(_words[0]==
"#cut_v") {
205 if(_words.size()!=2) {
206 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
209 if(!
to(_words[1],_cut_v)) {
210 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
214 }
else if(_words[0]==
"#min_v") {
215 if(_words.size()!=2) {
216 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
219 if(!
to(_words[1],_min_v)) {
220 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
223 }
else if(_words[0]==
"#max_v") {
224 if(_words.size()!=2) {
225 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
228 if(!
to(_words[1],_max_v)) {
229 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
233 a_out <<
"tools::rcsv::histo::read : syntax error in " << sout(line) << std::endl;
239 a_out <<
"class " << _class << std::endl;
240 a_out <<
"title " << hdata.
m_title << std::endl;
242 a_out <<
"annotation " << (*it).first <<
" " << sout((*it).second) << std::endl;
247 a_out <<
"tools::rcsv::histo::read : null dimension." << std::endl;
252 std::vector<std::string> labels;
255 a_out <<
"tools::rcsv::histo::read :"
256 <<
" syntax error in " << sout(line)
257 <<
". Can't read labels."
261 if(a_verbose) a_out <<
"labels " << sout(line) << std::endl;
262 words(line,
",",
false,labels);}
266 if(is_profile) valn += 2;
267 std::vector<double> _bin_Svw;
268 std::vector<double> _bin_Sv2w;
270 if(labels.size()!=valn) {
271 a_out <<
"tools::rcsv::histo::read :"
272 <<
" bad number of labels " << labels.size() <<
". Expected " << valn <<
"."
278 {std::vector<double> vals;
279 unsigned int nline = 0;
289 if(vals.size()!=valn) {
290 a_out <<
"tools::rcsv::histo::read :"
291 <<
" bad number of items in data line " << vals.size() <<
". Expected " << valn <<
"."
295 unsigned int ival = 0;
296 hdata.
m_bin_entries.push_back(
static_cast<unsigned int>(vals[ival++]));
297 hdata.
m_bin_Sw.push_back(vals[ival++]);
300 _bin_Svw.push_back(vals[ival++]);
301 _bin_Sv2w.push_back(vals[ival++]);
303 {
for(
unsigned int iaxis=0;iaxis<hdata.
m_dimension;iaxis++) {
304 bin_Sxw[iaxis] = vals[ival++];
305 bin_Sx2w[iaxis] = vals[ival++];
312 a_out <<
"tools::rcsv::histo::read : bad data line number " << nline <<
". Expected " << hdata.
m_bin_number <<
"."
318 a_out <<
"tools::rcsv::histo::read : inconsistent axes data." << std::endl;
322 hdata.
m_axes[0].m_offset = 1;
323 {
for(
unsigned int iaxis=1;iaxis<hdata.
m_dimension;iaxis++) {
324 hdata.
m_axes[iaxis].m_offset = hdata.
m_axes[iaxis-1].m_offset * (hdata.
m_axes[iaxis-1].bins()+2);
331 pdata.m_is_profile =
true;
332 pdata.m_bin_Svw = _bin_Svw;
333 pdata.m_bin_Sv2w = _bin_Sv2w;
334 pdata.m_cut_v = _cut_v;
335 pdata.m_min_v = _min_v;
336 pdata.m_max_v = _max_v;
341 a_out <<
"tools::rcsv::histo::read :"
342 <<
" inconsistent dimension data."
350 a_out <<
"h1d : " << h->
title()
352 <<
", entries " << h->
entries()
353 <<
", mean " << h->
mean() <<
", rms " << h->
rms()
361 a_out <<
"tools::rcsv::histo::read :"
362 <<
" inconsistent dimension data."
370 a_out <<
"h2d : " << h->
title()
372 <<
", entries " << h->
entries()
373 <<
", mean_x " << h->
mean_x() <<
", rms_x " << h->
rms_x()
374 <<
", mean_y " << h->
mean_y() <<
", rms_y " << h->
rms_y()
382 a_out <<
"tools::rcsv::histo::read :"
383 <<
" inconsistent dimension data."
391 a_out <<
"h3d : " << h->
title()
393 <<
", entries " << h->
entries()
394 <<
", mean_x " << h->
mean_x() <<
", rms_x " << h->
rms_x()
395 <<
", mean_y " << h->
mean_y() <<
", rms_y " << h->
rms_y()
396 <<
", mean_z " << h->
mean_z() <<
", rms_z " << h->
rms_z()
404 a_out <<
"tools::rcsv::histo::read :"
405 <<
" inconsistent dimension data."
413 a_out <<
"p1d : " << h->
title()
415 <<
", entries " << h->
entries()
416 <<
", mean " << h->
mean() <<
", rms " << h->
rms()
424 a_out <<
"tools::rcsv::histo::read :"
425 <<
" inconsistent dimension data."
433 a_out <<
"p2d : " << h->
title()
435 <<
", entries " << h->
entries()
436 <<
", mean_x " << h->
mean_x() <<
", rms_x " << h->
rms_x()
437 <<
", mean_y " << h->
mean_y() <<
", rms_y " << h->
rms_y()
458 a_out <<
"tools::rcsv::histo::read : unknown class " << sout(_class) << std::endl;