g4tools  5.4.0
aidas
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_xml_aidas
5 #define tools_xml_aidas
6 
7 #include "../raxml_out"
8 
9 #include "../sprintf"
10 #include "../histo/h1d"
11 #include "../histo/h2d"
12 #include "../histo/h3d"
13 #include "../histo/p1d"
14 #include "../histo/p2d"
15 #include "../histo/c1d"
16 #include "../histo/c2d"
17 #include "../histo/c3d"
18 #include "../histo/dps"
19 #include "../aida_ntuple"
20 #include "../S_STRING"
21 #include "../forit"
22 
23 #include "tree"
24 
25 #include <vector>
26 #include <map>
27 
28 namespace tools {
29 namespace xml {
30 
31 class aidas {
32 public:
33  //tree,out,verbose,path.
34  typedef raxml_out (*reader)(tree&,std::ostream&,bool,void*);
35  typedef std::map<std::string,reader> readers;
36 public:
38  {
40  }
41  virtual ~aidas(){
42  m_objects.clear(); //it may delete histos, etc...
43  }
44 protected:
45  aidas(const aidas&){}
46  aidas& operator=(const aidas&){return *this;}
47 public:
48  std::vector<raxml_out>& objects() {return m_objects;}
49 protected:
50  void clear_readers() {m_readers.clear();}
51  void add_reader(const std::string& a_class,
52  reader a_reader,
53  bool a_check = false){
54  if(a_check) {if(find_reader(a_class)) return;}
55  m_readers[a_class] = a_reader;
56  }
57 
58  reader find_reader(const std::string& a_class) const {
59  std::map<std::string,reader>::const_iterator it = m_readers.find(a_class);
60  if(it!=m_readers.end()) return (*it).second;
61  return 0;
62  }
63 
64 protected:
65  TOOLS_CLASS_STRING(aida)
66 
67  TOOLS_CLASS_STRING(annotation)
68  TOOLS_CLASS_STRING(histogram1d)
69  TOOLS_CLASS_STRING(histogram2d)
70  TOOLS_CLASS_STRING(histogram3d)
71  TOOLS_CLASS_STRING(profile1d)
72  TOOLS_CLASS_STRING(profile2d)
73  TOOLS_CLASS_STRING(axis)
74  TOOLS_CLASS_STRING(statistics)
75  TOOLS_CLASS_STRING(statistic)
76  TOOLS_CLASS_STRING(data1d)
77  TOOLS_CLASS_STRING(data2d)
78  TOOLS_CLASS_STRING(data3d)
79  TOOLS_CLASS_STRING(tuple)
80  TOOLS_CLASS_STRING(columns)
81  TOOLS_CLASS_STRING(rows)
83  TOOLS_CLASS_STRING(entryITuple)
84  TOOLS_CLASS_STRING(entryTuple)
85  TOOLS_CLASS_STRING(cloud1d)
86  TOOLS_CLASS_STRING(cloud2d)
87  TOOLS_CLASS_STRING(cloud3d)
88  TOOLS_CLASS_STRING(entries1d)
89  TOOLS_CLASS_STRING(entries2d)
90  TOOLS_CLASS_STRING(entries3d)
91  TOOLS_CLASS_STRING(dataPointSet)
92  TOOLS_CLASS_STRING(dataPoint)
93  //TOOLS_CLASS_STRING(function)
94  //TOOLS_CLASS_STRING(arguments)
95  //TOOLS_CLASS_STRING(argument)
96  //TOOLS_CLASS_STRING(parameters)
97 
98  TOOLS_CLASS_STRING(type)
99  TOOLS_CLASS_STRING(name)
100  TOOLS_CLASS_STRING(path)
101  TOOLS_CLASS_STRING(title)
102  TOOLS_CLASS_STRING(numberOfBins)
103  TOOLS_CLASS_STRING(min)
104  TOOLS_CLASS_STRING(max)
107  TOOLS_CLASS_STRING(entries)
108  TOOLS_CLASS_STRING(mean)
109  TOOLS_CLASS_STRING(rms)
110  TOOLS_CLASS_STRING(height)
111  TOOLS_CLASS_STRING(error)
112  TOOLS_CLASS_STRING(weightedMean)
113  TOOLS_CLASS_STRING(weightedRms)
114  TOOLS_CLASS_STRING(weightedMeanX)
115  TOOLS_CLASS_STRING(weightedMeanY)
116  TOOLS_CLASS_STRING(weightedMeanZ)
117  TOOLS_CLASS_STRING(weightedRmsX)
118  TOOLS_CLASS_STRING(weightedRmsY)
119  TOOLS_CLASS_STRING(weightedRmsZ)
120  TOOLS_CLASS_STRING(booking)
121  TOOLS_CLASS_STRING(default)
122  TOOLS_CLASS_STRING(entry)
123  TOOLS_CLASS_STRING(binBorder)
124  TOOLS_CLASS_STRING(maxEntries)
125  TOOLS_CLASS_STRING(valueX)
126  TOOLS_CLASS_STRING(valueY)
127  TOOLS_CLASS_STRING(valueZ)
128  TOOLS_CLASS_STRING(weight)
129  TOOLS_CLASS_STRING(entry1d)
130  TOOLS_CLASS_STRING(entry2d)
131  TOOLS_CLASS_STRING(entry3d)
132  TOOLS_CLASS_STRING(dimension)
133  TOOLS_CLASS_STRING(errorPlus)
134  TOOLS_CLASS_STRING(errorMinus)
135  TOOLS_CLASS_STRING(measurement)
136 
137  void set_default_tags(std::vector<std::string>& a_tags) {
138  a_tags.clear();
139  a_tags.push_back(s_aida());
140  a_tags.push_back(s_annotation());
141  a_tags.push_back(s_histogram1d());
142  a_tags.push_back(s_histogram2d());
143  a_tags.push_back(s_histogram3d());
144  a_tags.push_back(s_profile1d());
145  a_tags.push_back(s_profile2d());
146  a_tags.push_back(s_axis());
147  a_tags.push_back(s_statistics());
148  a_tags.push_back(s_data1d());
149  a_tags.push_back(s_data2d());
150  a_tags.push_back(s_data3d());
151 
152  a_tags.push_back(s_tuple());
153  a_tags.push_back(s_columns());
154  a_tags.push_back(s_rows());
155  a_tags.push_back(s_row());
156  a_tags.push_back(s_entryITuple()); //aida.dtd spec.
157  a_tags.push_back(s_entryTuple()); //not in aida.dtd ! Back comp.
158 
159  a_tags.push_back(s_cloud1d());
160  a_tags.push_back(s_cloud2d());
161  a_tags.push_back(s_cloud3d());
162  a_tags.push_back(s_entries1d());
163  a_tags.push_back(s_entries2d());
164  a_tags.push_back(s_entries3d());
165  a_tags.push_back(s_dataPointSet());
166  a_tags.push_back(s_dataPoint());
167  //a_tags.push_back(s_function());
168  //a_tags.push_back(s_arguments());
169  //a_tags.push_back(s_argument());
170  //a_tags.push_back(s_parameters());
171  }
172 
174  add_reader(s_histogram1d(),read_h1d);
175  add_reader(s_histogram2d(),read_h2d);
176  add_reader(s_histogram3d(),read_h3d);
177  add_reader(s_profile1d(),read_p1d);
178  add_reader(s_profile2d(),read_p2d);
179  add_reader(s_cloud1d(),read_cloud1d);
180  add_reader(s_cloud2d(),read_cloud2d);
181  add_reader(s_cloud3d(),read_cloud3d);
182  add_reader(s_tuple(),read_ntu);
183  add_reader(s_dataPointSet(),read_dps);
184  //add_reader(s_function(),read_Function);
185  }
186  static raxml_out read_h1d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) {
187  return read_histo(a_tree,a_out,a_verbose,1,false);
188  }
189  static raxml_out read_h2d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) {
190  return read_histo(a_tree,a_out,a_verbose,2,false);
191  }
192  static raxml_out read_h3d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) {
193  return read_histo(a_tree,a_out,a_verbose,3,false);
194  }
195  static raxml_out read_p1d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) {
196  return read_histo(a_tree,a_out,a_verbose,1,true);
197  }
198  static raxml_out read_p2d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) {
199  return read_histo(a_tree,a_out,a_verbose,2,true);
200  }
201 
202  static raxml_out read_cloud1d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) {
203  return read_cloud(a_tree,a_out,a_verbose,1);
204  }
205  static raxml_out read_cloud2d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) {
206  return read_cloud(a_tree,a_out,a_verbose,2);
207  }
208  static raxml_out read_cloud3d(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) {
209  return read_cloud(a_tree,a_out,a_verbose,3);
210  }
211 
212  static raxml_out read_dps(tree& a_tree,std::ostream& a_out,bool a_verbose,void*) {
213  std::string sname;
214  a_tree.attribute_value(s_name(),sname);
215 
216  if(a_verbose) {
217  a_out << "tools::xml::aidas::read_dps :"
218  << " with name " << sout(sname)
219  << "..." << std::endl;
220  }
221 
222  std::string spath;
223  a_tree.attribute_value(s_path(),spath);
224 
225  std::string stitle;
226  a_tree.attribute_value(s_title(),stitle);
227 
228  // Booking parameters :
229  unsigned int dim = 0;
230  if(!a_tree.attribute_value(s_dimension(),dim)) return raxml_out();
231 
232  // Create a BatchLab::DataPointSet :
233  histo::dps* dps = new histo::dps(stitle,dim);
234 
235  // Data sub items :
236  {looper _for(a_tree);
237  while(tree* _tree = _for.next_tree()) {
238  if(!read_dps_data(*_tree,*dps)) {
239  delete dps;
240  return raxml_out();
241  }
242  }}
243 
244  base_handle* hdl = new handle<histo::dps>(dps);
245  std::string sclass = histo::dps::s_class();
246 
247  if(a_verbose) {
248  a_out << "tools::xml::aidas::read_dps :"
249  << " with name " << sout(sname)
250  << " and title " << sout(stitle)
251  << " done." << std::endl;
252  }
253 
254  return raxml_out(hdl,sclass,spath,sname);
255  }
256 
257 protected:
259 public: //used in BatchLab::XML_DataReader.
260  static raxml_out read_histo(tree& a_tree,
261  std::ostream& a_out,bool a_verbose,
262  unsigned int a_dim,bool a_is_prof){
263 
264  std::string sname;
265  a_tree.attribute_value(s_name(),sname);
266 
267  if(a_verbose) {
268  a_out << "tools::xml::aidas::read_histo :"
269  << " with name " << sout(sname)
270  << "..." << std::endl;
271  }
272 
273  std::string spath;
274  a_tree.attribute_value(s_path(),spath);
275 
276  std::string stitle;
277  a_tree.attribute_value(s_title(),stitle);
278 
279  // Booking parameters :
280  std::vector<bn_t> bins(a_dim);
281  std::vector<double> mns(a_dim);
282  std::vector<double> mxs(a_dim);
283  std::vector< std::vector<double> > edges(a_dim);
284 
285  // Jump in subitems to find axes items :
286  int not_found = -1;
287  unsigned int found = 0;
288  bool isVariableBins = false;
289 
290  {looper _for(a_tree);
291  while(tree* _tree = _for.next_tree()) {
292 
293  int iaxis;
294  bn_t num;
295  double mn,mx;
296  std::vector<double> borders;
297  bool variableBins;
298  if(!read_axis(*_tree,a_dim,iaxis,num,mn,mx,borders,variableBins,a_out)) return raxml_out();
299  if(iaxis!=not_found) {
300  if((iaxis<0)||(iaxis>=(int)a_dim)) return raxml_out();
301  bins[iaxis] = num;
302  mns[iaxis] = mn;
303  mxs[iaxis] = mx;
304  edges[iaxis] = borders;
305  if(variableBins) isVariableBins = true;
306  found++;
307  }
308  }}
309 
310  if(found!=a_dim) return raxml_out();
311  if(isVariableBins) {
312  // Axes consistency :
313  for(unsigned int iaxis=0;iaxis<a_dim;iaxis++) {
314  if(edges[iaxis].size()<=2) return raxml_out();
315  }
316  }
317 
318  // Create a native histogram :
319 
320  base_handle* hdl = 0;
321  std::string sclass;
322  if(a_is_prof) {
323  if(a_dim==1) {
324  histo::p1d* histo = 0;
325  if(isVariableBins) {
326  histo = new histo::p1d(stitle,edges[0]);
327  } else {
328  histo = new histo::p1d(stitle,bins[0],mns[0],mxs[0]);
329  }
330 
331  // Sub items :
332  pd_data hd = histo->get_histo_data();
333  if(hd.m_bin_number<=0) {delete histo;return raxml_out();}
334 
335  {looper _for(a_tree);
336  while(tree* _tree = _for.next_tree()) {
337 
338  if(!read_bins(*_tree,hd,a_out,a_is_prof)) {
339  delete histo;
340  return raxml_out();
341  }
342 
343  }}
344 
345  //give histo ownership to the handle.
346  hdl = new handle<histo::p1d>(histo);
347  sclass = histo::p1d::s_class();
348 
349  hd.update_fast_getters();
350  histo->copy_from_data(hd);
351 
352  } else if(a_dim==2) {
353  histo::p2d* histo = 0;
354  if(isVariableBins) {
355  histo = new histo::p2d(stitle,edges[0],edges[1]);
356  } else {
357  histo = new histo::p2d(stitle,bins[0],mns[0],mxs[0],bins[1],mns[1],mxs[1]);
358  }
359 
360  pd_data hd = histo->get_histo_data();
361  if(hd.m_bin_number<=0) {delete histo;return raxml_out();}
362 
363  {looper _for(a_tree);
364  while(tree* _tree = _for.next_tree()) {
365 
366  if(!read_bins(*_tree,hd,a_out,a_is_prof)) {
367  delete histo;
368  return raxml_out();
369  }
370 
371  }}
372 
373  hdl = new handle<histo::p2d>(histo);
374  sclass = histo::p2d::s_class();
375 
376  hd.update_fast_getters();
377  histo->copy_from_data(hd);
378  }
379  } else {
380  if(a_dim==1) {
381  histo::h1d* histo = 0;
382  if(isVariableBins) {
383  histo = new histo::h1d(stitle,edges[0]);
384  } else {
385  histo = new histo::h1d(stitle,bins[0],mns[0],mxs[0]);
386  }
387 
388  pd_data hd(histo->dac());
389  if(hd.m_bin_number<=0) {delete histo;return raxml_out();}
390 
391  {looper _for(a_tree);
392  while(tree* _tree = _for.next_tree()) {
393 
394  if(!read_bins(*_tree,hd,a_out,a_is_prof)) {
395  delete histo;
396  return raxml_out();
397  }
398 
399  }}
400 
401  hdl = new handle<histo::h1d>(histo);
402  sclass = histo::h1d::s_class();
403 
404  hd.update_fast_getters();
405  histo->copy_from_data(hd);
406 
407  } else if(a_dim==2) {
408  histo::h2d* histo = 0;
409  if(isVariableBins) {
410  histo = new histo::h2d(stitle,edges[0],edges[1]);
411  } else {
412  histo = new histo::h2d(stitle,bins[0],mns[0],mxs[0],bins[1],mns[1],mxs[1]);
413  }
414 
415  pd_data hd(histo->dac());
416  if(hd.m_bin_number<=0) {delete histo;return raxml_out();}
417 
418  {looper _for(a_tree);
419  while(tree* _tree = _for.next_tree()) {
420 
421  if(!read_bins(*_tree,hd,a_out,a_is_prof)) {
422  delete histo;
423  return raxml_out();
424  }
425 
426  }}
427 
428  hdl = new handle<histo::h2d>(histo);
429  sclass = histo::h2d::s_class();
430 
431  hd.update_fast_getters();
432  histo->copy_from_data(hd);
433 
434  } else if(a_dim==3) {
435  histo::h3d* histo = 0;
436  if(isVariableBins) {
437  histo = new histo::h3d(stitle,edges[0],edges[1],edges[2]);
438  } else {
439  histo = new histo::h3d(stitle,bins[0],mns[0],mxs[0],
440  bins[1],mns[1],mxs[1],
441  bins[2],mns[2],mxs[2]);
442  }
443 
444  pd_data hd(histo->dac());
445  if(hd.m_bin_number<=0) {delete histo;return raxml_out();}
446 
447  {looper _for(a_tree);
448  while(tree* _tree = _for.next_tree()) {
449 
450  if(!read_bins(*_tree,hd,a_out,a_is_prof)) {
451  delete histo;
452  return raxml_out();
453  }
454 
455  }}
456 
457  hdl = new handle<histo::h3d>(histo);
458  sclass = histo::h3d::s_class();
459 
460  hd.update_fast_getters();
461  histo->copy_from_data(hd);
462 
463  }
464  }
465 
466  if(!hdl) return raxml_out();
467 
468  if(a_verbose) {
469  a_out << "tools::xml::aidas::read_histo :"
470  << " with name " << sout(sname)
471  << " and title " << sout(stitle)
472  << " done." << std::endl;
473  }
474 
475  return raxml_out(hdl,sclass,spath,sname);
476  }
477 
478  static raxml_out read_cloud(tree& a_tree,std::ostream& a_out,bool a_verbose,int a_dim){
479 
480  std::string sname;
481  a_tree.attribute_value(s_name(),sname);
482 
483  if(a_verbose) {
484  a_out << "tools::xml::aidas::read_cloud :"
485  << " name " << sout(sname)
486  << "..." << std::endl;
487  }
488 
489  std::string spath;
490  a_tree.attribute_value(s_path(),spath);
491 
492  std::string stitle;
493  a_tree.attribute_value(s_title(),stitle);
494 
495  std::string svalue;
496 
497  // Booking parameters :
498  int max_entries = -1; //UNLIMITED
499  if(a_tree.attribute_value(s_maxEntries(),svalue)) {
500  int ival;
501  if(!to<int>(svalue,ival)) return raxml_out();
502  max_entries = ival;
503  }
504 
505  base_handle* hdl = 0;
506  std::string sclass;
507 
508  if(a_dim==1) {
509 
510  histo::c1d* cloud = new histo::c1d(stitle,max_entries);
511 
512  // Data sub items :
513  {looper _for(a_tree);
514  while(tree* _tree = _for.next_tree()) {
515  if(!read_cloud_data(*_tree,*cloud,a_verbose,a_out)) {
516  delete cloud;
517  return raxml_out();
518  }
519  }}
520 
521  hdl = new handle<histo::c1d>(cloud);
522  sclass = histo::c1d::s_class();
523 
524  } else if(a_dim==2) {
525 
526  histo::c2d* cloud = new histo::c2d(stitle,max_entries);
527 
528  // Data sub items :
529  {looper _for(a_tree);
530  while(tree* _tree = _for.next_tree()) {
531  if(!read_cloud_data(*_tree,*cloud,a_verbose,a_out)) {
532  delete cloud;
533  return raxml_out();
534  }
535  }}
536 
537  hdl = new handle<histo::c2d>(cloud);
538  sclass = histo::c2d::s_class();
539 
540  } else if(a_dim==3) {
541 
542  histo::c3d* cloud = new histo::c3d(stitle,max_entries);
543 
544  // Data sub items :
545  {looper _for(a_tree);
546  while(tree* _tree = _for.next_tree()) {
547  if(!read_cloud_data(*_tree,*cloud,a_verbose,a_out)) {
548  delete cloud;
549  return raxml_out();
550  }
551  }}
552 
553  hdl = new handle<histo::c3d>(cloud);
554  sclass = histo::c3d::s_class();
555  }
556 
557  if(!hdl) return raxml_out();
558 
559  if(a_verbose) {
560  a_out << "tools::xml::aidas::read_cloud :"
561  << " with name " << sout(sname)
562  << " and title " << sout(stitle)
563  << " done." << std::endl;
564  }
565 
566  return raxml_out(hdl,sclass,spath,sname);
567  }
568 
569 protected:
574  static bool read_axis(
575  tree& a_tree
576  ,unsigned int a_dim
577  ,int& aAxis
578  ,bn_t& aNumberOfBins
579  ,double& aMin
580  ,double& aMax
581  ,std::vector<double>& aEdges
582  ,bool& aVariableBins
583  ,std::ostream& //a_out
584  ){
585  int not_found = -1;
586  aAxis = not_found;
587  aNumberOfBins = 0;
588  aMin = 0;
589  aMax = 0;
590  aEdges.clear();
591  aVariableBins = false;
592 
593  const std::string& tagName = a_tree.tag_name();
594 
595  std::string svalue;
596 
597  if(tagName==s_axis()) {
598 
599  {bn_t ival;
600  if(!a_tree.attribute_value(s_numberOfBins(),svalue)) return false;
601  if(!to<bn_t>(svalue,ival)) return false;
602  aNumberOfBins = ival;}
603 
604  if(!a_tree.attribute_value(s_min(),svalue)) return false;
605  if(!to<double>(svalue,aMin)) return false;
606 
607  if(!a_tree.attribute_value(s_max(),svalue)) return false;
608  if(!to<double>(svalue,aMax)) return false;
609 
610  if(!a_tree.attribute_value(s_direction(),svalue)) return false;
611  if(!axis_index(a_dim,svalue,aAxis)) return false;
612 
613  aEdges.push_back(aMin);
614 
615  {looper _for(a_tree);
616  while(element* _elem = _for.next_element()) {
617  if(_elem->name()==s_binBorder()) {
618  if(!_elem->attribute_value(s_value(),svalue)) return false;
619  double value;
620  if(!to<double>(svalue,value)) return false;
621  aEdges.push_back(value);
622  aVariableBins = true;
623  }
624  }}
625 
626  aEdges.push_back(aMax);
627  if(aVariableBins) { // Variable bins histo.
628  if(aEdges.size()!=aNumberOfBins+1) return false;
629  }
630 
631  }
632 
633  return true;
634  }
635  static bool to_double(const std::string& a_s,double& a_v,std::ostream& a_out,const std::string& a_what) {
636  if(!to<double>(a_s,a_v)) {
637  a_out << "tools::xml::aidas::read_bins :"
638  << " problem converting a " << a_what
639  << " attribute to a double."
640  << " Value was " << sout(a_s) << "."
641  << std::endl;
642  return false;
643  }
644  return true;
645  }
646 
647  static bool read_bins(tree& a_tree,pd_data& aData,std::ostream& a_out,bool a_is_prof){
648  const std::string& tagName = a_tree.tag_name();
649 
650  std::string svalue;
651 
652  if(tagName==s_annotation()) { //FIXME
653 
654  return true;
655 
656  } else if(tagName=="statistics") {
657 
658  if(!a_tree.attribute_value(s_entries(),svalue)) return false;
659  //unsigned int ival;
660  //if(!to<unsigned int>(svalue,ival)) return false;
661  // aData.fEntries = ival;
662 
663  unsigned int found = 0;
664 
665  {looper _for(a_tree);
666  while(element* _elem = _for.next_element()) {
667 
668  if(_elem->name()==s_statistic()) {
669  double mean,rms;
670  if(!_elem->attribute_value(s_mean(),svalue)) return false;
671  if(!to<double>(svalue,mean)) return false;
672 
673  if(!_elem->attribute_value(s_rms(),svalue)) return false;
674  if(!to<double>(svalue,rms)) return false;
675 
676  if(!_elem->attribute_value(s_direction(),svalue)) return false;
677  int iaxis;
678  if(!axis_index(aData.m_dimension,svalue,iaxis)) return false;
679 
680  //aData.m_axes[iaxis].fSxw = mean; //Temporarily put mean on fSxw.
681  //aData.m_axes[iaxis].fSx2w = rms; //Temporarily put mean on fSx2w.
682 
683  found++;
684  }
685  }}
686 
687  if(found!=aData.m_dimension) return false;
688 
689  return true;
690 
691  } else if(tagName==s_axis()) {
692 
693  return true;
694 
695  }
696 
697  unsigned int dimension = 0;
698  if(tagName==s_data1d()) {
699  dimension = 1;
700  } else if(tagName==s_data2d()) {
701  dimension = 2;
702  } else if(tagName==s_data3d()) {
703  dimension = 3;
704  }
705 
706  if(dimension) {
707 
708  if(dimension!=aData.m_dimension) return false;
709 
710  std::string sbin;
711  sprintf(sbin,32,"bin%dd",dimension);
712 
713  {looper _for(a_tree);
714  while(element* _elem = _for.next_element()) {
715 
716  if(_elem->name()==sbin) {
717 
718  std::vector<int> is(dimension);
719 
720  unsigned int entries = 0;
721  double height = 0;
722  double error = 0;
723  double weightedMean = 0;
724  double weightedMeanX = 0;
725  double weightedMeanY = 0;
726  double weightedMeanZ = 0;
727  double weightedRms = 0;
728  double weightedRmsX = 0;
729  double weightedRmsY = 0;
730  double weightedRmsZ = 0;
731  double rms = 0;
732 
733  // Required :
734  if(!_elem->attribute_value(s_entries(),svalue)) {
735  a_out << "tools::xml::aidas::read_bins :"
736  << " a <bin1d> has no " << "entries"
737  << " attribute."
738  << std::endl;
739  return false;
740  }
741  if(!to<unsigned int>(svalue,entries)) {
742  a_out << "tools::xml::aidas::read_bins :"
743  << " problem converting a entries attribute to an unsigned int."
744  << " Value was " << sout(svalue) << "."
745  << std::endl;
746  return false;
747  }
748 
749  // Optional :
750  bool height_given;
751  if(_elem->attribute_value(s_height(),svalue)) { //FIXME : optional ?
752  if(!to_double(svalue,height,a_out,s_height())) return false;
753  height_given = true;
754  } else { // no "height".
755  // It is assumed that at fill time the weight
756  // argument "w" had always been 1.
757  // w = 1
758  // sw = entries*1 = entries
759  height = double(entries);
760  height_given = false;
761  }
762 
763  if(_elem->attribute_value(s_error(),svalue)) { //FIXME : optional ?
764  if(!to_double(svalue,error,a_out,s_error())) return false;
765  } else { // no "error"
766  if(height_given) {
767  // then we are going to have :
768  // sw = height
769  // error = ?
770  // We can assume that at fill time the same weight "w"
771  // had been given to all entries. Then :
772  // sw = entries*w = height
773  // w = height/entries;
774  // sw2 = entries*(w*w) = (height**2)/entries
775  // error = sqrt(sw2) = sqrt((height**2)/entries)
776  if(entries) {
777  error = ::sqrt(::fabs( ((height*height)/entries) ));
778  }
779  } else {
780  // It is assumed that at fill time the weight
781  // argument "w" had always been 1.
782  // w = 1
783  // sw2 = entries*(w*w) = entries;
784  // error = sqrt(sw2) = sqrt(entries);
785  error = ::sqrt(::fabs(double(entries)));
786  }
787  }
788 
789  if(_elem->attribute_value(s_rms(),svalue)) {
790  if(!to_double(svalue,rms,a_out,s_rms())) return false;
791  }
792 
793  if(dimension==1) {
794  if(_elem->attribute_value(s_weightedMean(),svalue)) {
795  if(!to_double(svalue,weightedMean,a_out,s_weightedMean())) return false;
796  }
797  if(_elem->attribute_value(s_weightedRms(),svalue)) {
798  if(!to_double(svalue,weightedRms,a_out,s_weightedRms())) return false;
799  }
800  } else if(dimension==2) {
801  if(_elem->attribute_value(s_weightedMeanX(),svalue)) {
802  if(!to_double(svalue,weightedMeanX,a_out,s_weightedMeanX())) return false;
803  }
804  if(_elem->attribute_value(s_weightedMeanY(),svalue)) {
805  if(!to_double(svalue,weightedMeanY,a_out,s_weightedMeanY())) return false;
806  }
807  if(_elem->attribute_value(s_weightedRmsX(),svalue)) {
808  if(!to_double(svalue,weightedRmsX,a_out,s_weightedRmsX())) return false;
809  }
810  if(_elem->attribute_value(s_weightedRmsY(),svalue)) {
811  if(!to_double(svalue,weightedRmsY,a_out,s_weightedRmsY())) return false;
812  }
813  } else if(dimension==3) {
814  if(_elem->attribute_value(s_weightedMeanX(),svalue)) {
815  if(!to_double(svalue,weightedMeanX,a_out,s_weightedMeanX())) return false;
816  }
817  if(_elem->attribute_value(s_weightedMeanY(),svalue)) {
818  if(!to_double(svalue,weightedMeanY,a_out,s_weightedMeanY())) return false;
819  }
820  if(_elem->attribute_value(s_weightedMeanZ(),svalue)) {
821  if(!to_double(svalue,weightedMeanZ,a_out,s_weightedMeanZ())) return false;
822  }
823  if(_elem->attribute_value(s_weightedRmsX(),svalue)) {
824  if(!to_double(svalue,weightedRmsX,a_out,s_weightedRmsX())) return false;
825  }
826  if(_elem->attribute_value(s_weightedRmsY(),svalue)) {
827  if(!to_double(svalue,weightedRmsY,a_out,s_weightedRmsY())) return false;
828  }
829  if(_elem->attribute_value(s_weightedRmsZ(),svalue)) {
830  if(!to_double(svalue,weightedRmsZ,a_out,s_weightedRmsZ())) return false;
831  }
832  }
833 
834  {for(unsigned int index=0;index<dimension;index++) {
835  std::string s = "binNum";
836  if(dimension!=1) {
837  if(index==0) s += "X";
838  else if(index==1) s += "Y";
839  else if(index==2) s += "Z";
840  }
841  if(!_elem->attribute_value(s,svalue)) {
842  a_out << "tools::xml::aidas::read_bins :"
843  << " a <bin1d> has no " << s << std::endl;
844  return false;
845  }
846  if(svalue=="UNDERFLOW") {
847  is[index] = histo::axis_UNDERFLOW_BIN;
848  } else if(svalue=="OVERFLOW") {
849  is[index] = histo::axis_OVERFLOW_BIN;
850  } else {
851  int ival = 0;
852  if(!to<int>(svalue,ival)) {
853  a_out << "tools::xml::aidas::read_bins :"
854  << " problem converting binNum to an int."
855  << " Value was " << sout(svalue) << "."
856  << std::endl;
857  return false;
858  }
859  int ibin = ival;
860  if( (ibin<0) || (ibin>=(int)aData.m_axes[index].bins()) ) {
861  a_out << "tools::xml::aidas::read_bins :"
862  << " a binNum is out of range."
863  << std::endl;
864  return false;
865  }
866  is[index] = ibin;
867  }
868  }}
869 
870  // If we are here, then we have a valid bin :
871  bn_t offset;
872  histo::get_offset(aData.m_axes,is,offset);
873  aData.m_bin_entries[offset] = entries;
874 
875  if(!a_is_prof) {
876 
877  // From histo::base_histo, we have :
878  // height = sw
879  // error = sqrt(sw)
880  // weightedMean = sxw/sw
881  // weightedRms = sqrt(fabs(sx2w/sw - (sxw/sw)**2))
882 
883  double sw = height;
884  aData.m_bin_Sw[offset] = sw;
885  aData.m_bin_Sw2[offset] = error * error;
886  if(dimension==1) {
887  aData.m_bin_Sxw[offset][0] = weightedMean * sw;
888  aData.m_bin_Sx2w[offset][0] =
889  (weightedRms * weightedRms + weightedMean * weightedMean) * sw;
890  } else if(dimension==2){
891  // X
892  aData.m_bin_Sxw[offset][0] = weightedMeanX * sw;
893  aData.m_bin_Sx2w[offset][0] =
894  (weightedRmsX*weightedRmsX + weightedMeanX*weightedMeanX) * sw;
895  // Y :
896  aData.m_bin_Sxw[offset][1] = weightedMeanY * sw;
897  aData.m_bin_Sx2w[offset][1] =
898  (weightedRmsY*weightedRmsY + weightedMeanY*weightedMeanY) * sw;
899  } else if(dimension==3){
900  // X
901  aData.m_bin_Sxw[offset][0] = weightedMeanX * sw;
902  aData.m_bin_Sx2w[offset][0] =
903  (weightedRmsX*weightedRmsX + weightedMeanX*weightedMeanX) * sw;
904  // Y :
905  aData.m_bin_Sxw[offset][1] = weightedMeanY * sw;
906  aData.m_bin_Sx2w[offset][1] =
907  (weightedRmsY*weightedRmsY + weightedMeanY*weightedMeanY) * sw;
908  // Z :
909  aData.m_bin_Sxw[offset][2] = weightedMeanZ * sw;
910  aData.m_bin_Sx2w[offset][2] =
911  (weightedRmsZ*weightedRmsZ + weightedMeanZ*weightedMeanZ) * sw;
912  }
913 
914  } else { // Profile :
915 
916  // bin writing is :
917  // " height=" << sout(aObj.bin_height(aIndex))
918  // " error=" << sout(aObj.bin_error(aIndex))
919  // " weightedMean=" << sout(aObj.bin_mean(aIndex))
920  // " rms=" << sout(aObj.bin_rms_value(aIndex))
921  // " weightedRms=" << sout(bin_rms(aIndex));
922 
923  // From inlib profile, we have :
924  // height = svw / sw
925  // error = sqrt(fabs(sv2w/sw - (svw/sw)**2))/sqrt(sw)
926  // rms = sqrt(fabs(sv2w/sw - (svw/sw)**2))
927  // weightedMean = sxw/sw
928  // weightedRms = sqrt(fabs(sx2w/sw - (sxw/sw)**2))
929 
930  // Then :
931  // sw = (rms/error)**2
932  // svw = sw * height
933  // sv2w = sw * (rms**2 + height**2)
934  // sxw = weightedMean * sw
935  // sx2w = (weightedRms*weightedRms+weightedMean*weightedMean) * sw;
936 
937  double sw = 0;
938  if(error==0) {
939  // sv2w/sw = (svw/sw)**2
940  // h = svw/sw
941  //FIXME : we lack an info to get sw.
942  // We assume that at fill time weight==1 then :
943  // sw == n
944  sw = (double)entries;
945  } else {
946  double r_e = rms/error;
947  sw = r_e * r_e;
948  }
949  aData.m_bin_Sw[offset] = sw;
950  aData.m_bin_Sw2[offset] = 0; //FIXME
951  if(dimension==1) {
952  aData.m_bin_Sxw[offset][0] = weightedMean * sw;
953  aData.m_bin_Sx2w[offset][0] =
954  (weightedRms * weightedRms + weightedMean * weightedMean) * sw;
955  } else if(dimension==2){
956  aData.m_bin_Sxw[offset][0] = weightedMeanX * sw;
957  aData.m_bin_Sxw[offset][1] = weightedMeanY * sw;
958  aData.m_bin_Sx2w[offset][0] =
959  (weightedRmsX*weightedRmsX + weightedMeanX*weightedMeanX) * sw;
960  aData.m_bin_Sx2w[offset][1] =
961  (weightedRmsY*weightedRmsY + weightedMeanY*weightedMeanY) * sw;
962  }
963  aData.m_bin_Svw[offset] = sw * height;
964  aData.m_bin_Sv2w[offset] = sw * (rms * rms + height * height);
965 
966  }
967  }
968  }}
969 
970  return true;
971  }
972 
973  return false;
974  }
975 
976  static bool axis_index(unsigned int a_dim,const std::string& a_axis,int& a_index) {
977  if(a_dim==1) {
978  if(a_axis=="x") {a_index = 0;return true;}
979  } else if(a_dim==2) {
980  if(a_axis=="x") {a_index = 0;return true;}
981  else if(a_axis=="y") {a_index = 1;return true;}
982  } else if(a_dim==3) {
983  if(a_axis=="x") {a_index = 0;return true;}
984  else if(a_axis=="y") {a_index = 1;return true;}
985  else if(a_axis=="z") {a_index = 2;return true;}
986  }
987  return false;
988  }
989 
993  class colbook {
994  public:
995  colbook(const std::string& a_type,
996  const std::string& a_name,
997  const std::string& a_s,
998  bool a_ntu)
999  :m_type(a_type),m_name(a_name),m_def_or_bkg(a_s),m_ntu(a_ntu){}
1000  public:
1001  colbook(const colbook& a_from)
1002  :m_type(a_from.m_type)
1003  ,m_name(a_from.m_name)
1004  ,m_def_or_bkg(a_from.m_def_or_bkg)
1005  ,m_ntu(a_from.m_ntu)
1006  {}
1007 
1008  colbook& operator=(const colbook& a_from){
1009  if(&a_from==this) return *this;
1010  m_type = a_from.m_type;
1011  m_name = a_from.m_name;
1012  m_def_or_bkg = a_from.m_def_or_bkg;
1013  m_ntu = a_from.m_ntu;
1014  return *this;
1015  }
1016  public:
1017  const std::string& type() const {return m_type;}
1018  const std::string& name() const {return m_name;}
1019  const std::string& def_or_bkg() const {return m_def_or_bkg;}
1020  bool is_ntu() const {return m_ntu;}
1021  protected:
1022  std::string m_type;
1023  std::string m_name;
1024  std::string m_def_or_bkg;
1025  bool m_ntu;
1026  };
1027 
1028  static bool read_ntu_columns(tree& a_tree,
1029  bool& a_found,
1030  std::vector<colbook>& a_booking,
1031  std::ostream& a_out){
1032  a_found = false;
1033  a_booking.clear();
1034 
1035  const std::string& tag_name = a_tree.tag_name();
1036 
1037  if(tag_name=="columns") {
1038 
1039  {looper _for(a_tree);
1040  while(element* _elem = _for.next_element()) {
1041 
1042  if(_elem->name()=="column") {
1043  std::string stype;
1044  if(!_elem->attribute_value(s_type(),stype)) {
1045  a_out << "tools::xml::aidas::read_ntu_columns :"
1046  << " atb type missing on <column>"
1047  << std::endl;
1048  return false;
1049  }
1050  std::string sname;
1051  if(!_elem->attribute_value(s_name(),sname)) {
1052  a_out << "tools::xml::aidas::read_ntu_columns :"
1053  << " atb name missing on <column>"
1054  << std::endl;
1055  return false;
1056  }
1057 
1058  std::string s;
1059  if(_elem->attribute_value(s_booking(),s)) {
1060  a_booking.push_back(colbook(stype,sname,s,true));
1061  } else if(_elem->attribute_value(s_default(),s)) {
1062  a_booking.push_back(colbook(stype,sname,s,false));
1063  } else {
1064  a_booking.push_back(colbook(stype,sname,"",false));
1065  }
1066  }
1067 
1068  }}
1069 
1070  a_found = true;
1071  }
1072  return true;
1073  }
1074 
1075  static bool read_ntu_rows(tree& a_tree,
1076  aida::base_ntu& a_ntu,
1077  bool& a_found,
1078  std::ostream& a_out){
1079  a_found = false;
1080 
1081  const std::string& tag_name = a_tree.tag_name();
1082 
1083  if(tag_name==s_annotation()) { //FIXME
1084 
1085  return true;
1086 
1087  } else if(tag_name==s_columns()) {
1088 
1089  return true;
1090 
1091  } else if(tag_name==s_rows()) {
1092 
1093  // Sub items :
1094  {looper _for(a_tree);
1095  while(tree* _tree = _for.next_tree()) {
1096 
1097  if(!read_ntu_rows(*_tree,a_ntu,a_found,a_out)) {
1098  a_out << "tools::xml::aidas::read_ntu_rows :"
1099  << " sub read_ntu_rows failed."
1100  << std::endl;
1101  return false;
1102  }
1103 
1104  }}
1105 
1106  a_found = true;
1107 
1108  return true;
1109 
1110  } else if(tag_name==s_row()) {
1111 
1112  const std::vector<aida::base_col*>& cols = a_ntu.columns();
1113 
1114  std::vector<unsigned int> intus;
1115  std::vector<unsigned int> inot_ntus;
1116  {unsigned int index = 0;
1117  tools_vforcit(aida::base_col*,cols,it) {
1118  if(safe_cast<aida::base_col,aida::aida_col_ntu>(*(*it))) {
1119  intus.push_back(index);
1120  } else {
1121  inot_ntus.push_back(index);
1122  }
1123  index++;
1124  }}
1125 
1126  std::string svalue;
1127 
1128  {unsigned int icol = 0;
1129 
1130  {looper _for(a_tree);
1131  while(element* _elem = _for.next_element()) {
1132 
1133  if(_elem->name()==s_entry()) {
1134  if(!_elem->attribute_value(s_value(),svalue)) {
1135  a_out << "tools::xml::aidas::read_ntu_rows :"
1136  << " can't get \"value\" attribute." << std::endl;
1137  return false;
1138  }
1139  if(icol>=inot_ntus.size()) {
1140  a_out << "tools::xml::aidas::read_ntu_rows :"
1141  << " too much <entry>." << std::endl;
1142  return false;
1143  }
1144  if(inot_ntus[icol]>=cols.size()) {
1145  a_out << "tools::xml::aidas::read_ntu_rows :"
1146  << " too much <entry>." << std::endl;
1147  return false;
1148  }
1149 
1150  aida::base_col* bcol = cols[inot_ntus[icol]];
1151 
1152  aida::aida_base_col* abcol =
1153  safe_cast<aida::base_col,aida::aida_base_col>(*bcol);
1154 
1155  if(!abcol->s_fill(svalue)) {
1156  a_out << "tools::xml::aidas::read_ntu_rows :"
1157  << " can't get \"value\" attribute." << std::endl;
1158  return false;
1159  }
1160  icol++;
1161  }
1162 
1163  }}}
1164 
1165  // Sub items (entryITuple) :
1166  {unsigned int icol = 0;
1167 
1168  {looper _for(a_tree);
1169  while(tree* _tree = _for.next_tree()) {
1170 
1171  const std::string& _tag_name = _tree->tag_name();
1172  if( (_tag_name==s_entryITuple()) || //aida.dtd spec.
1173  (_tag_name==s_entryTuple()) ){ //backward comp.
1174  if(icol>=intus.size()) {
1175  a_out << "tools::xml::aidas::read_ntu_rows :"
1176  << " too much <entry>." << std::endl;
1177  return false;
1178  }
1179  if(intus[icol]>=cols.size()) {
1180  a_out << "tools::xml::aidas::read_ntu_rows :"
1181  << " too much <entry>." << std::endl;
1182  return false;
1183  }
1184 
1185  aida::base_col* bcol = cols[intus[icol]];
1186  aida::aida_col_ntu* col_ntu = safe_cast<aida::base_col,aida::aida_col_ntu>(*bcol);
1187  if(!col_ntu) {
1188  a_out << "tools::xml::aidas::read_ntu_rows :"
1189  << " can't cast to bcol_ntu."
1190  << std::endl;
1191  return false;
1192  }
1193  aida::base_ntu* ntu = col_ntu->get_to_fill();
1194  if(!ntu) {
1195  a_out << "tools::xml::aidas::read_ntu_rows :"
1196  << " get_to_fill() returned null."
1197  << std::endl;
1198  return false;
1199  }
1200 
1201  {looper _for2(*_tree);
1202  while(tree* _tree2 = _for2.next_tree()) {
1203  bool found;
1204  if(!read_ntu_rows(*_tree2,*ntu,found,a_out)) return false;
1205  }}
1206 
1207  icol++;
1208  }
1209 
1210  }}}
1211 
1212  if(!a_ntu.add_row()) {
1213  a_out << "tools::xml::aidas::read_ntu_rows :"
1214  << " can't add row to ntuple."
1215  << std::endl;
1216  return false;
1217  }
1218 
1219  return true;
1220 
1221  }
1222 
1223  a_out << "tools::xml::aidas::read_ntu_rows :"
1224  << " unknown item class " << sout(tag_name) << std::endl;
1225 
1226  return false;
1227  }
1228 
1229  static raxml_out read_ntu(tree& a_tree,std::ostream& a_out,bool a_verbose,void*){
1230  std::string sname;
1231  a_tree.attribute_value(s_name(),sname);
1232 
1233  if(a_verbose) {
1234  a_out << "tools::xml::aidas::read_ntu :"
1235  << " with name " << sout(sname)
1236  << "..." << std::endl;
1237  }
1238 
1239  std::string spath;
1240  a_tree.attribute_value(s_path(),spath);
1241 
1242  std::string stitle;
1243  a_tree.attribute_value(s_title(),stitle);
1244 
1245  //FIXME annotation
1246 
1247  // Booking parameters :
1248  std::vector<colbook> booking;
1249 
1250  // Jump in subitems to find columns items :
1251  bool found = false;
1252 
1253  {looper _for(a_tree);
1254  while(tree* _tree = _for.next_tree()) {
1255  if(!read_ntu_columns(*_tree,found,booking,a_out)) return raxml_out();
1256  if(found) break;
1257  }}
1258 
1259  if(!found) {
1260  a_out << "tools::xml::aidas::read_ntu :"
1261  << " for ntuple name " << sout(sname)
1262  << " unable to read columns..." << std::endl;
1263  return raxml_out();
1264  }
1265 
1266  // Create a aida::ntuple :
1267  aida::ntuple* ntu = new aida::ntuple(a_out,stitle);
1268  {tools_vforcit(colbook,booking,it) {
1269  if(!aida::create_col(*ntu,
1270  (*it).type(),
1271  (*it).name(),
1272  (*it).def_or_bkg(),
1273  (*it).is_ntu())){
1274  delete ntu;
1275  return raxml_out();
1276  }
1277  }}
1278 
1279  if(!ntu->columns().size()) { //??? we could have an empty ntu !
1280  a_out << "tools::xml::aidas::read_ntu :"
1281  << " for ntuple name " << sout(sname)
1282  << " unable to create a aida::ntuple." << std::endl;
1283  delete ntu;
1284  return raxml_out();
1285  }
1286 
1287  // Get rows in sub items :
1288  found = false;
1289 
1290  {looper _for(a_tree);
1291  while(tree* _tree = _for.next_tree()) {
1292 
1293  if(!read_ntu_rows(*_tree,*ntu,found,a_out)) {
1294  a_out << "tools::xml::aidas::read_ntu :"
1295  << " for ntuple name " << sout(sname)
1296  << " unable to read rows." << std::endl;
1297  delete ntu;
1298  return raxml_out();
1299  }
1300  if(found) break;
1301 
1302  }}
1303 
1304  if(a_verbose) {
1305  a_out << "tools::xml::aidas::read_ntu :"
1306  << " name " << sout(sname)
1307  << " done." << std::endl;
1308  }
1309 
1310  std::string sclass = aida::ntuple::s_class();
1311  return raxml_out(new handle<aida::ntuple>(ntu),sclass,spath,sname);
1312  }
1313 
1317 
1318  static bool read_cloud_data(tree& a_tree,
1319  histo::c1d& aCloud,bool a_verbose,
1320  std::ostream& a_out){
1321  const std::string& tagName = a_tree.tag_name();
1322 
1323  std::string svalue;
1324 
1325  if(tagName==s_annotation()) { //FIXME
1326 
1327  return true;
1328 
1329  } else if(tagName==s_entries1d()) {
1330 
1331  {looper _for(a_tree);
1332  while(element* _elem = _for.next_element()) {
1333  if(_elem->name()==s_entry1d()) {
1334  double x;
1335  if(!_elem->attribute_value(s_valueX(),x)) return false;
1336  double w = 1;
1337  if(_elem->attribute_value(s_weight(),svalue)) {
1338  if(!to<double>(svalue,w)) return false;
1339  }
1340  if(!aCloud.fill(x,w)) return false;
1341  }
1342  }}
1343  return true;
1344 
1345  } else if(tagName==s_histogram1d()) {
1346 
1347  raxml_out ro = read_h1d(a_tree,a_out,a_verbose,0);
1348  if(ro.cls()==histo::h1d::s_class()) {
1349  histo::h1d* h = (histo::h1d*)ro.object();
1350  if(h) {
1351  aCloud.set_histogram(h);
1352  ro.disown();
1353  }
1354  }
1355  return true;
1356 
1357  }
1358 
1359  return false;
1360  }
1361 
1362  static bool read_cloud_data(tree& a_tree,
1363  histo::c2d& aCloud,
1364  bool a_verbose,
1365  std::ostream& a_out){
1366  const std::string& tagName = a_tree.tag_name();
1367 
1368  std::string svalue;
1369 
1370  if(tagName==s_annotation()) { //FIXME
1371 
1372  return true;
1373 
1374  } else if(tagName==s_entries2d()) {
1375 
1376  {looper _for(a_tree);
1377  while(element* _elem = _for.next_element()) {
1378  if(_elem->name()==s_entry2d()) {
1379  double x;
1380  if(!_elem->attribute_value(s_valueX(),x)) return false;
1381  double y;
1382  if(!_elem->attribute_value(s_valueY(),y)) return false;
1383  double w = 1;
1384  if(_elem->attribute_value(s_weight(),svalue)) {
1385  if(!to<double>(svalue,w)) return false;
1386  }
1387  if(!aCloud.fill(x,y,w)) return false;
1388  }
1389  }}
1390  return true;
1391 
1392  } else if(tagName==s_histogram2d()) {
1393 
1394  raxml_out ro = read_h2d(a_tree,a_out,a_verbose,0);
1395  if(ro.cls()==histo::h2d::s_class()) {
1396  histo::h2d* h = (histo::h2d*)ro.object();
1397  if(h) {
1398  aCloud.set_histogram(h);
1399  ro.disown();
1400  }
1401  }
1402  return true;
1403 
1404  }
1405 
1406  return false;
1407  }
1408 
1409  static bool read_cloud_data(tree& a_tree,
1410  histo::c3d& aCloud,
1411  bool a_verbose,
1412  std::ostream& a_out){
1413  const std::string& tagName = a_tree.tag_name();
1414 
1415  std::string svalue;
1416 
1417  if(tagName==s_annotation()) { //FIXME
1418 
1419  return true;
1420 
1421  } else if(tagName==s_entries3d()) {
1422 
1423  {looper _for(a_tree);
1424  while(element* _elem = _for.next_element()) {
1425  if(_elem->name()==s_entry3d()) {
1426  double x;
1427  if(!_elem->attribute_value(s_valueX(),x)) return false;
1428  double y;
1429  if(!_elem->attribute_value(s_valueY(),y)) return false;
1430  double z;
1431  if(!_elem->attribute_value(s_valueZ(),z)) return false;
1432  double w = 1;
1433  if(_elem->attribute_value(s_weight(),svalue)) {
1434  if(!to<double>(svalue,w)) return false;
1435  }
1436  if(!aCloud.fill(x,y,z,w)) return false;
1437  }
1438  }}
1439  return true;
1440 
1441  } else if(tagName==s_histogram3d()) {
1442 
1443  raxml_out ro = read_h3d(a_tree,a_out,a_verbose,0);
1444  if(ro.cls()==histo::h3d::s_class()) {
1445  histo::h3d* h = (histo::h3d*)ro.object();
1446  if(h) {
1447  aCloud.set_histogram(h);
1448  ro.disown();
1449  }
1450  }
1451  return true;
1452 
1453  }
1454 
1455  return false;
1456  }
1457 
1458  static bool read_dps_data(tree& a_tree,histo::dps& a_dps){
1459  const std::string& tagName = a_tree.tag_name();
1460 
1461  std::string svalue;
1462 
1463  if(tagName==s_annotation()) { //FIXME
1464 
1465  return true;
1466 
1467  } else if(tagName==s_dataPoint()) {
1468 
1469  histo::data_point& point = a_dps.add_point();
1470 
1471  unsigned int coord = 0;
1472 
1473  {looper _for(a_tree);
1474  while(element* _elem = _for.next_element()) {
1475  if(_elem->name()==s_measurement()) {
1476  if(coord>=a_dps.dimension()) return false;
1477  double value;
1478  if(!_elem->attribute_value(s_value(),value)) return false;
1479  double errorPlus = 0;
1480  if(_elem->attribute_value(s_errorPlus(),svalue)) {
1481  if(!to<double>(svalue,errorPlus)) return false;
1482  }
1483  double errorMinus = 0;
1484  if(_elem->attribute_value(s_errorMinus(),svalue)) {
1485  if(!to<double>(svalue,errorMinus)) return false;
1486  }
1487 
1488  histo::measurement& m = point.coordinate(coord);
1489  m.set_value(value);
1490  m.set_error_plus(errorPlus);
1491  m.set_error_minus(errorMinus);
1492 
1493  coord++;
1494  }
1495  }}
1496  return true;
1497 
1498  }
1499 
1500  return false;
1501  }
1502 
1503 
1504 protected:
1506  std::vector<raxml_out> m_objects;
1507 };
1508 
1509 }}
1510 
1511 #endif
tools::osc::s_annotation
const std::string & s_annotation()
Definition: osc_streamers:28
tools::base_handle
Definition: handle:15
tools::xml::aidas::read_ntu
static raxml_out read_ntu(tree &a_tree, std::ostream &a_out, bool a_verbose, void *)
Definition: aidas:1229
tools::direction
void direction(const VEC3 &a_p0, const VEC3 &a_p1, const VEC3 &a_p2, VEC3 &a_value)
Definition: vec3:344
tools::xml::element
Definition: element:26
tools::jpeg::is
bool is(const std::string &a_file)
Definition: jpeg:216
tools::xml::aidas::read_cloud_data
static bool read_cloud_data(tree &a_tree, histo::c2d &aCloud, bool a_verbose, std::ostream &a_out)
Definition: aidas:1362
tools::histo::p1d
Definition: p1d:12
tools::xml::aidas::clear_readers
void clear_readers()
Definition: aidas:50
tools::histo::dps::dimension
unsigned int dimension() const
Definition: dps:151
tools::histo::h3d::s_class
static const std::string & s_class()
Definition: h3d:15
tools::xml::aidas::read_dps
static raxml_out read_dps(tree &a_tree, std::ostream &a_out, bool a_verbose, void *)
Definition: aidas:212
tools::value
Definition: value:18
tools::xml::aidas::read_cloud_data
static bool read_cloud_data(tree &a_tree, histo::c1d &aCloud, bool a_verbose, std::ostream &a_out)
read cloud ////////////////////////////////////////////////
Definition: aidas:1318
tools::xml::aidas::find_reader
reader find_reader(const std::string &a_class) const
Definition: aidas:58
tools::histo::measurement::set_value
void set_value(double a_v)
Definition: dps:66
tools::xml::aidas::colbook::colbook
colbook(const colbook &a_from)
Definition: aidas:1001
tools::xml::aidas::colbook::colbook
colbook(const std::string &a_type, const std::string &a_name, const std::string &a_s, bool a_ntu)
Definition: aidas:995
tools::histo::histo_data::update_fast_getters
void update_fast_getters()
Definition: histo_data:103
tools::histo::c1d
Definition: c1d:16
tools::histo::h1d
Definition: h1d:14
tools::histo::data_point
Definition: dps:75
tools::xml::aidas::colbook::m_name
std::string m_name
Definition: aidas:1023
TOOLS_CLASS_STRING
#define TOOLS_CLASS_STRING(a_name)
Definition: S_STRING:11
tools::aida::aida_base_col
Definition: aida_ntuple:317
tools::histo::axis_UNDERFLOW_BIN
@ axis_UNDERFLOW_BIN
Definition: axis:13
tools::aida::ntuple
Definition: aida_ntuple:503
tools::histo::histo_data::m_bin_Sx2w
std::vector< std::vector< TC > > m_bin_Sx2w
Definition: histo_data:179
tools::histo::p1d::s_class
static const std::string & s_class()
Definition: p1d:15
tools::histo::c1d::set_histogram
bool set_histogram(h1d *a_histo)
Definition: c1d:68
tools::histo::get_offset
bool get_offset(const std::vector< axis< TC, TO > > &a_axes, const std::vector< int > &a_is, TO &a_offset)
Definition: axes:50
tools::xml::aidas::colbook::def_or_bkg
const std::string & def_or_bkg() const
Definition: aidas:1019
tools::histo::h2d::s_class
static const std::string & s_class()
Definition: h2d:15
tools::xml::aidas::read_dps_data
static bool read_dps_data(tree &a_tree, histo::dps &a_dps)
Definition: aidas:1458
tools::xml::aidas::colbook::operator=
colbook & operator=(const colbook &a_from)
Definition: aidas:1008
tools::raxml_out::disown
void disown()
Definition: raxml_out:46
tools::histo::base_histo::dac
const hd_t & dac() const
Definition: base_histo:56
tools::xml::aidas
Definition: aidas:31
tools::xml::aidas::aidas
aidas()
Definition: aidas:37
tools::histo::p2d
Definition: p2d:12
tools::histo::c2d::fill
bool fill(double, double, double=1)
Definition: c2d:274
tools::aida::base_ntu::add_row
bool add_row()
Definition: aida_ntuple:211
tools::xml::aidas::m_readers
readers m_readers
Definition: aidas:1505
tools::histo::histo_data::m_bin_entries
std::vector< TN > m_bin_entries
Definition: histo_data:175
tools::xml::aidas::add_reader
void add_reader(const std::string &a_class, reader a_reader, bool a_check=false)
Definition: aidas:51
tools::xml::aidas::colbook::m_ntu
bool m_ntu
Definition: aidas:1025
tools::xml::tree::attribute_value
bool attribute_value(const std::string &a_atb, std::string &a_value) const
Definition: tree:130
tools::raxml_out
Definition: raxml_out:11
tools::mn
T mn(const T &a, const T &b)
Definition: mnmx:10
tools::histo::c1d::s_class
static const std::string & s_class()
Definition: c1d:18
tools::mx
T mx(const T &a, const T &b)
Definition: mnmx:13
tools::histo::histo_data::m_bin_Sw
std::vector< TW > m_bin_Sw
Definition: histo_data:176
tools::histo::profile_data::m_bin_Sv2w
std::vector< TV > m_bin_Sv2w
Definition: profile_data:75
tools::raxml_out::object
void * object() const
Definition: raxml_out:39
tools::xml::aidas::read_ntu_rows
static bool read_ntu_rows(tree &a_tree, aida::base_ntu &a_ntu, bool &a_found, std::ostream &a_out)
Definition: aidas:1075
tools::histo::c2d
Definition: c2d:16
tools::xml::aidas::read_cloud2d
static raxml_out read_cloud2d(tree &a_tree, std::ostream &a_out, bool a_verbose, void *)
Definition: aidas:205
tools::histo::h2d
Definition: h2d:12
tools::xml::aidas::to_double
static bool to_double(const std::string &a_s, double &a_v, std::ostream &a_out, const std::string &a_what)
Definition: aidas:635
tools::aida::aida_col_ntu::get_to_fill
virtual base_ntu * get_to_fill()
Definition: aida_ntuple:692
tools::xml::aidas::read_h3d
static raxml_out read_h3d(tree &a_tree, std::ostream &a_out, bool a_verbose, void *)
Definition: aidas:192
tools::histo::axis_OVERFLOW_BIN
@ axis_OVERFLOW_BIN
Definition: axis:13
tree
tools::xml::looper
Definition: tree:956
tools::xml::aidas::reader
raxml_out(* reader)(tree &, std::ostream &, bool, void *)
Definition: aidas:34
tools::xml::aidas::read_bins
static bool read_bins(tree &a_tree, pd_data &aData, std::ostream &a_out, bool a_is_prof)
Definition: aidas:647
tools::aida::aida_base_col::s_fill
virtual bool s_fill(const std::string &)=0
tools::xml::aidas::read_cloud1d
static raxml_out read_cloud1d(tree &a_tree, std::ostream &a_out, bool a_verbose, void *)
Definition: aidas:202
tools::xml::aidas::~aidas
virtual ~aidas()
Definition: aidas:41
tools::histo::profile_data
Definition: profile_data:13
tools::histo::c3d::s_class
static const std::string & s_class()
Definition: c3d:18
tools::histo::profile_data::m_bin_Svw
std::vector< TV > m_bin_Svw
Definition: profile_data:74
tools::xml::looper::next_element
element * next_element()
Definition: tree:977
tools::xml::aidas::readers
std::map< std::string, reader > readers
Definition: aidas:35
tools::histo::dps::s_class
static const std::string & s_class()
Definition: dps:121
tools::histo::p2d::s_class
static const std::string & s_class()
Definition: p2d:15
tools::aida::ntuple::s_class
static const std::string & s_class()
Definition: aida_ntuple:507
tools::sout
Definition: sout:17
tools::histo::p2::copy_from_data
void copy_from_data(const pd_t &a_from)
Definition: p2:101
tools::xml::aidas::read_ntu_columns
static bool read_ntu_columns(tree &a_tree, bool &a_found, std::vector< colbook > &a_booking, std::ostream &a_out)
Definition: aidas:1028
tools::histo::c2d::set_histogram
bool set_histogram(h2d *a_histo)
Definition: c2d:58
tools::histo::h3::copy_from_data
void copy_from_data(const hd_t &a_from)
Definition: h3:34
tools::histo::p1::copy_from_data
void copy_from_data(const pd_t &a_from)
Definition: p1:109
tools::aida::aida_col_ntu
some special column that can't be done with aida_col<T> ////
Definition: aida_ntuple:647
tools::xml::aidas::colbook::m_def_or_bkg
std::string m_def_or_bkg
Definition: aidas:1024
tools::file::size
bool size(const std::string &a_file, long &a_size)
Definition: fsize:13
tools::xml::aidas::read_h2d
static raxml_out read_h2d(tree &a_tree, std::ostream &a_out, bool a_verbose, void *)
Definition: aidas:189
tools::histo::c1d::fill
bool fill(double aX, double aW=1)
Definition: c1d:75
tools::xml::aidas::read_cloud
static raxml_out read_cloud(tree &a_tree, std::ostream &a_out, bool a_verbose, int a_dim)
Definition: aidas:478
tools::xml::tree
Definition: tree:47
tools::histo::histo_data::m_bin_Sxw
std::vector< std::vector< TC > > m_bin_Sxw
Definition: histo_data:178
tools::xml::aidas::read_p1d
static raxml_out read_p1d(tree &a_tree, std::ostream &a_out, bool a_verbose, void *)
Definition: aidas:195
tools::histo::measurement::set_error_minus
void set_error_minus(double a_v)
Definition: dps:68
tools::aida::base_col
Definition: aida_ntuple:29
tools::xml::aidas::axis_index
static bool axis_index(unsigned int a_dim, const std::string &a_axis, int &a_index)
Definition: aidas:976
tools::xml::aidas::add_default_readers
void add_default_readers()
Definition: aidas:173
tools::histo::dps::add_point
data_point & add_point()
Definition: dps:164
tools::histo::histo_data::m_axes
std::vector< axis_t > m_axes
Definition: histo_data:181
tools::histo::h1d::s_class
static const std::string & s_class()
Definition: h1d:17
tools::xml::aidas::aidas
aidas(const aidas &)
Definition: aidas:45
tools::raxml_out::cls
const std::string & cls() const
Definition: raxml_out:43
tools::xml::aidas::operator=
aidas & operator=(const aidas &)
Definition: aidas:46
tools::histo::h1::copy_from_data
void copy_from_data(const hd_t &a_from)
Definition: h1:40
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::xml::aidas::objects
std::vector< raxml_out > & objects()
Definition: aidas:48
tools::histo::axis::bn_t
unsigned int bn_t
Definition: axis:21
tools::xml::aidas::colbook
read ntuple ///////////////////////////////////////////////
Definition: aidas:993
tools::xml::aidas::read_cloud_data
static bool read_cloud_data(tree &a_tree, histo::c3d &aCloud, bool a_verbose, std::ostream &a_out)
Definition: aidas:1409
tools::xml::aidas::colbook::is_ntu
bool is_ntu() const
Definition: aidas:1020
tools::histo::histo_data::m_bin_Sw2
std::vector< TW > m_bin_Sw2
Definition: histo_data:177
tools::xml::aidas::read_h1d
static raxml_out read_h1d(tree &a_tree, std::ostream &a_out, bool a_verbose, void *)
Definition: aidas:186
tools::xml::aidas::colbook::m_type
std::string m_type
Definition: aidas:1022
tools::sprintf
bool sprintf(std::string &a_string, int a_length, const char *a_format,...)
Definition: sprintf:34
tools::xml::aidas::set_default_tags
void set_default_tags(std::vector< std::string > &a_tags)
Definition: aidas:137
tools::histo::c3d::fill
bool fill(double, double, double, double=1)
Definition: c3d:356
tools::histo::p1::get_histo_data
pd_t get_histo_data() const
Definition: p1:117
tools::histo::measurement
Definition: dps:20
tools::xml::aidas::m_objects
std::vector< raxml_out > m_objects
Definition: aidas:1506
tools::histo::c3d
Definition: c3d:16
tools::file::found
bool found(const std::string &a_file, const std::string &a_what, std::vector< std::string > &a_found)
Definition: file:507
tools::histo::h3d
Definition: h3d:12
tools::xml::aidas::read_axis
static bool read_axis(tree &a_tree, unsigned int a_dim, int &aAxis, bn_t &aNumberOfBins, double &aMin, double &aMax, std::vector< double > &aEdges, bool &aVariableBins, std::ostream &)
read histo ////////////////////////////////////////////////
Definition: aidas:574
tools::xml::aidas::read_histo
static raxml_out read_histo(tree &a_tree, std::ostream &a_out, bool a_verbose, unsigned int a_dim, bool a_is_prof)
Definition: aidas:260
tools::xml::aidas::pd_data
histo::profile_data< double, unsigned int, unsigned int, double, double > pd_data
Definition: aidas:570
tools::xml::looper::next_tree
tree * next_tree()
Definition: tree:970
tools::xml::tree::tag_name
const std::string & tag_name() const
Definition: tree:128
tools::aida::base_ntu
Definition: aida_ntuple:85
tools::histo::h2::copy_from_data
void copy_from_data(const hd_t &a_from)
Definition: h2:34
tools::histo::measurement::set_error_plus
void set_error_plus(double a_v)
Definition: dps:67
tools::handle
Definition: handle:58
tools::histo::p2::get_histo_data
pd_t get_histo_data() const
Definition: p2:109
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::histo::histo_data::m_bin_number
TO m_bin_number
Definition: histo_data:174
tools::stype
const std::string & stype(const mat4f &)
Definition: mat4f:73
tools::osc::s_axis
const std::string & s_axis()
Definition: osc_streamers:24
tools::aida::base_ntu::columns
const std::vector< base_col * > & columns() const
Definition: aida_ntuple:153
tools::histo::dps
Definition: dps:119
tools::histo::c2d::s_class
static const std::string & s_class()
Definition: c2d:18
tools::histo::data_point::coordinate
measurement & coordinate(unsigned int a_coord)
Definition: dps:106
tools::histo::histo_data::m_dimension
dim_t m_dimension
Definition: histo_data:172
tools::aida::create_col
bool create_col(ntuple &a_ntu, const std::string &a_type, const std::string &a_name, const std::string &a_s, bool a_is_ntu)
Definition: aida_ntuple:822
tools::xml::aidas::colbook::type
const std::string & type() const
Definition: aidas:1017
tools::xml::aidas::read_p2d
static raxml_out read_p2d(tree &a_tree, std::ostream &a_out, bool a_verbose, void *)
Definition: aidas:198
tools::xml::aidas::bn_t
histo::axis< double, unsigned int >::bn_t bn_t
Definition: aidas:258
tools::xml::aidas::colbook::name
const std::string & name() const
Definition: aidas:1018
tools::histo::c3d::set_histogram
bool set_histogram(h3d *a_histo)
Definition: c3d:68
tools::xml::aidas::read_cloud3d
static raxml_out read_cloud3d(tree &a_tree, std::ostream &a_out, bool a_verbose, void *)
Definition: aidas:208