g4tools  5.4.0
osc_streamers
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_store_osc_streamers
5 #define tools_store_osc_streamers
6 
7 #include "iobj_const_visitor"
8 #include "iobj_visitor"
9 
10 #include "../histo/h1d"
11 #include "../histo/h2d"
12 #include "../histo/h3d"
13 #include "../histo/p1d"
14 #include "../histo/p2d"
15 #include "../vmanip"
16 #include "../sto"
17 #include "../num2s"
18 #include "../S_STRING"
19 #include "../scast"
20 
21 namespace tools {
22 namespace osc {
23 
24 inline const std::string& s_axis() {
25  static const std::string s_v("BatchLab::Axis");
26  return s_v;
27 }
28 inline const std::string& s_annotation() {
29  static const std::string s_v("BatchLab::Annotation");
30  return s_v;
31 }
32 inline const std::string& s_base_histogram() {
33  static const std::string s_v("BatchLab::BaseHistogram");
34  return s_v;
35 }
36 inline const std::string& s_item() {
37  static const std::string s_v("BatchLab::Item");
38  return s_v;
39 }
40 
41 inline const std::string& s_h1d() {
42  static const std::string s_v("BatchLab::Histogram1D");
43  return s_v;
44 }
45 
46 inline const std::string& s_h2d() {
47  static const std::string s_v("BatchLab::Histogram2D");
48  return s_v;
49 }
50 
51 inline const std::string& s_h3d() {
52  static const std::string s_v("BatchLab::Histogram3D");
53  return s_v;
54 }
55 
56 inline const std::string& s_p1d() {
57  static const std::string s_v("BatchLab::Profile1D");
58  return s_v;
59 }
60 
61 inline const std::string& s_p2d() {
62  static const std::string s_v("BatchLab::Profile2D");
63  return s_v;
64 }
65 
66 class Axis : public virtual istorable {
67 public:
69 protected:
70  virtual void* cast(const std::string& a_class) const {
71  if(void* p = cmp_cast<Axis>(this,a_class)) return p;
72  return 0;
73  }
74  virtual const std::string& store_cls() const {return s_axis();}
75  virtual bool visit(iobj_const_visitor& a_v) const {
76  if(!a_v.begin(*this,s_axis(),Axis::s_visit)) return false;
77 
78  int version = 1;
79  if(!a_v.visit("fVersion",version)) return false;
80 
81  if(!a_v.visit("fOffset",m_axis.m_offset)) return false;
82  if(!a_v.visit("fNumberOfBins",(int)m_axis.m_number_of_bins)) return false;
83  if(!a_v.visit("fMinimumValue",m_axis.m_minimum_value)) return false;
84  if(!a_v.visit("fMaximumValue",m_axis.m_maximum_value)) return false;
85  if(!a_v.visit("fFixed",m_axis.m_fixed)) return false;
86  if(!a_v.visit("fBinWidth",m_axis.m_bin_width)) return false;
87  if(!a_v.visit("fEdges",m_axis.m_edges)) return false;
88 
89  if(!a_v.end(*this)) return false;
90  return true;
91  }
92  static bool s_visit(const istorable& a_o,iobj_const_visitor& a_v){
93  const Axis* local = safe_cast<istorable,Axis>(a_o);
94  if(!local) return false;
95  return local->Axis::visit(a_v); //IMPORTANT : have Axis::
96  }
97 public:
98  Axis(const histo::axis<double,unsigned int>& a_axis):m_axis(a_axis){}
99  virtual ~Axis(){}
100 private:
101  Axis(const Axis& a_from):istorable(a_from),m_axis(a_from.m_axis){}
102  Axis& operator=(const Axis&){return *this;}
103 protected:
105 };
106 
107 
109  //if(!a_visitor.begin(*this)) return false;
110 
111  int version;
112  if(!a_visitor.visit(version)) return false;
113 
114  if(!a_visitor.visit(a_axis.m_offset)) return false;
115 
116  {int nbin;
117  if(!a_visitor.visit(nbin)) return false;
118  a_axis.m_number_of_bins = nbin;}
119 
120  if(!a_visitor.visit(a_axis.m_minimum_value)) return false;
121  if(!a_visitor.visit(a_axis.m_maximum_value)) return false;
122  if(!a_visitor.visit(a_axis.m_fixed)) return false;
123  if(!a_visitor.visit(a_axis.m_bin_width)) return false;
124  if(!a_visitor.visit(a_axis.m_edges)) return false;
125 
126  //if(!a_visitor.end(*this)) return false;
127  return true;
128 }
129 
130 class Item : public virtual istorable {
131 public:
133 protected:
134  virtual void* cast(const std::string& a_class) const {
135  if(void* p = cmp_cast<Item>(this,a_class)) return p;
136  return 0;
137  }
138 public:
139  virtual const std::string& store_cls() const {return s_item();}
140  virtual bool visit(iobj_const_visitor& a_visitor) const {
141  if(!a_visitor.begin(*this,s_item(),Item::s_visit)) return false;
142 
143  int version = 1;
144  if(!a_visitor.visit("fVersion",version)) return false;
145 
146  if(!a_visitor.visit("fKey",fKey)) return false;
147  if(!a_visitor.visit("fValue",fValue)) return false;
148  if(!a_visitor.visit("fSticky",fSticky)) return false;
149 
150  if(!a_visitor.end(*this)) return false;
151  return true;
152  }
153  static bool s_visit(const istorable& a_o,iobj_const_visitor& a_v){
154  const Item* local = safe_cast<istorable,Item>(a_o);
155  if(!local) return false;
156  return local->Item::visit(a_v); //IMPORTANT : have Item::
157  }
158 public:
159  virtual bool read(iobj_visitor& a_visitor) {
160  //if(!a_visitor.begin(*this)) return false;
161 
162  int version;
163  if(!a_visitor.visit(version)) return false;
164 
165  if(!a_visitor.visit(fKey)) return false;
166  if(!a_visitor.visit(fValue)) return false;
167  if(!a_visitor.visit(fSticky)) return false;
168 
169  //if(!a_visitor.end(*this)) return false;
170  return true;
171  }
172 public:
173  Item(){}
174  Item(const std::string& aKey,const std::string& aValue,bool aSticky)
175  :fKey(aKey),fValue(aValue),fSticky(aSticky){}
176  virtual ~Item(){}
177 public:
178  Item(const Item& a_from)
179  :istorable(a_from)
180  ,fKey(a_from.fKey)
181  ,fValue(a_from.fValue)
182  ,fSticky(a_from.fSticky)
183  {}
184  Item& operator=(const Item& a_from) {
185  if(&a_from==this) return *this;
186  fKey = a_from.fKey;
187  fValue = a_from.fValue;
188  fSticky = a_from.fSticky;
189  return *this;
190  }
191 public:
192  std::string fKey;
193  std::string fValue;
194  bool fSticky;
195 };
196 
197 
198 template <class T>
199 class Vector : public virtual istorable {
200 public:
202 protected:
203  virtual void* cast(const std::string& a_class) const {
204  if(void* p = cmp_cast<Vector>(this,a_class)) return p;
205  return 0;
206  }
207  virtual const std::string& store_cls() const {
208  static const std::string s_v("BatchLab::Vector<"+m_T+">");
209  return s_v;
210  }
211  virtual bool visit(iobj_const_visitor& a_v) const {
212  if(!a_v.begin(*this,Vector<T>::store_cls(),Vector<T>::s_visit)) return false;
213 
214  int version = 1;
215  if(!a_v.visit("fVersion",version)) return false;
216 
217  unsigned int number = (unsigned int)m_vec.size();
218  if(!a_v.visit("fSize",number)) return false;
219 
220  std::string stmp;
221  for(unsigned int index=0;index<number;index++) {
222  const T& elem = m_vec[index];
223  if(!num2s(index,stmp)) return false;
224  if(!a_v.visit(stmp,elem)) return false;
225  }
226 
227  if(!a_v.end(*this)) return false;
228  return true;
229  }
230  static bool s_visit(const istorable& a_o,iobj_const_visitor& a_v){
231  const Vector* local = safe_cast<istorable,Vector>(a_o);
232  if(!local) return false;
233  return local->Vector<T>::visit(a_v); //IMPORTANT : have Vector::
234  }
235 public:
236  Vector(const std::vector<T>& a_vec,const std::string& a_T)
237  :m_vec(a_vec),m_T(a_T){}
238  virtual ~Vector(){}
239 private:
240  Vector(const Vector& a_from)
241  :istorable(a_from),m_vec(a_from.m_vec),m_T(a_from.m_T){}
242  Vector& operator=(const Vector&){return *this;}
243 protected:
244  const std::vector<T>& m_vec;
245  std::string m_T;
246 };
247 
248 
249 template <class T>
250 inline bool std_vector_read(iobj_visitor& a_visitor,std::vector<T>& a_vec) {
251  a_vec.clear();
252 
253  //if(!a_visitor.begin(*this)) return false;
254 
255  int version;
256  if(!a_visitor.visit(version)) return false;
257 
258  unsigned int number;
259  if(!a_visitor.visit(number)) return false;
260 
261  a_vec.resize(number);
262  for(unsigned int index=0;index<number;index++) {
263  T& elem = a_vec[index];
264  if(!elem.read(a_visitor)) return false;
265  }
266 
267  //if(!a_visitor.end(*this)) return false;
268  return true;
269 }
270 
271 class Annotation : public virtual istorable {
272 public:
274 protected:
275  virtual void* cast(const std::string& a_class) const {
276  if(void* p = cmp_cast<Annotation>(this,a_class)) return p;
277  return 0;
278  }
279  virtual const std::string& store_cls() const {return s_annotation();}
280  virtual bool visit(iobj_const_visitor& a_v) const {
281  if(!a_v.begin(*this,s_annotation(),Annotation::s_visit)) return false;
282 
283  int version = 1;
284  if(!a_v.visit("fVersion",version)) return false;
285 
287  if(!a_v.visit("fItems",v)) return false;
288 
289  if(!a_v.end(*this)) return false;
290  return true;
291  }
292  static bool s_visit(const istorable& a_o,iobj_const_visitor& a_v){
293  const Annotation* local = safe_cast<istorable,Annotation>(a_o);
294  if(!local) return false;
295  return local->Annotation::visit(a_v); //IMPORTANT : have Annotation::
296  }
297 public:
299  virtual ~Annotation(){}
300 private:
301  Annotation(const Annotation& a_from):istorable(a_from){}
302  Annotation& operator=(const Annotation&){return *this;}
303 public:
304  std::vector<Item> m_items;
305 };
306 
307 inline bool Annotation_read(iobj_visitor& a_visitor) {
308  //if(!a_visitor.begin(*this)) return false;
309  int version;
310  if(!a_visitor.visit(version)) return false;
311  std::vector<Item> fItems;
312  if(!std_vector_read<Item>(a_visitor,fItems)) return false;
313  //if(!a_visitor.end(*this)) return false;
314  return true;
315 }
316 
317 inline void map2vec(const std::map<std::string,std::string>& a_in,std::vector<Item>& a_out) {
318  a_out.clear();
319  std::map<std::string,std::string>::const_iterator it;
320  for(it=a_in.begin();it!=a_in.end();++it) {
321  a_out.push_back(Item((*it).first,(*it).second,false));
322  }
323 }
324 
326 
327 template <class HIST>
328 class BaseHistogram : public virtual istorable {
329 public:
331 protected:
332  virtual void* cast(const std::string& a_class) const {
333  if(void* p = cmp_cast<BaseHistogram>(this,a_class)) return p;
334  return 0;
335  }
336 public:
337  virtual const std::string& store_cls() const {return s_base_histogram();}
338  virtual bool visit(iobj_const_visitor& a_v) const {
339  if(!a_v.begin(*this,s_base_histogram(),BaseHistogram::s_visit)) return false;
340 
341  int version = 1;
342  if(!a_v.visit("fVersion",version)) return false;
343 
344  Annotation ano;
345  map2vec(m_hist.annotations(),ano.m_items);
346  if(!a_v.visit("fAnnotation",ano)) return false;
347 
348  if(!a_v.end(*this)) return false;
349  return true;
350  }
351 protected:
352  static bool s_visit(const istorable& a_o,iobj_const_visitor& a_v){
353  const BaseHistogram* local =
354  safe_cast<istorable,BaseHistogram>(a_o);
355  if(!local) return false;
356  return local->BaseHistogram::visit(a_v); //IMPORTANT : have BaseHistogram::
357  }
358 public:
359  BaseHistogram(const HIST& a_hist):m_hist(a_hist){}
360  virtual ~BaseHistogram(){}
361 private:
362  BaseHistogram(const BaseHistogram& a_from)
363  :istorable(a_from),m_hist(a_from.m_hist)
364  {}
365  BaseHistogram& operator=(const BaseHistogram&){return *this;}
366 protected:
367  const HIST& m_hist;
368 };
369 
370 inline bool BaseHistogram_read(iobj_visitor& a_visitor){
371  //if(!a_visitor.begin(*this)) return false;
372 
373  int version;
374  if(!a_visitor.visit(version)) return false;
375 
376  if(!Annotation_read(a_visitor)) return false;
377 
378  //if(!a_visitor.end(*this)) return false;
379  return true;
380 }
381 
382 template <class HIST>
383 inline bool visitHistogram(const HIST& a_hist,iobj_const_visitor& a_visitor){
384  if(!a_visitor.visit("fTitle",a_hist.title())) return false;
385  if(!a_visitor.visit("fDimension",(int)a_hist.dimension())) return false;
386  if(!a_visitor.visit("fBinNumber",(int)a_hist.get_bins())) return false;
387 
388  std::vector<int> bins_entries;
389  convert<unsigned int,int>(a_hist.bins_entries(),bins_entries);
390  if(!a_visitor.visit("fBinEntries",bins_entries)) return false;
391 
392  if(!a_visitor.visit("fBinSw",a_hist.bins_sum_w())) return false;
393  if(!a_visitor.visit("fBinSw2",a_hist.bins_sum_w2())) return false;
394  if(!a_visitor.visit("fBinSxw",a_hist.bins_sum_xw())) return false;
395  if(!a_visitor.visit("fBinSx2w",a_hist.bins_sum_x2w())) return false;
396  {std::string name;
397  for(unsigned int iaxis=0;iaxis<a_hist.dimension();iaxis++) {
398  if(!num2s(iaxis,name)) return false;
399  name = "fAxes_"+name;
400  Axis axis(a_hist.get_axis(iaxis));
401  if(!a_visitor.visit(name,axis)) return false;
402  }}
403  {int dummy = 0;
404  if(!a_visitor.visit("fMode",dummy)) return false;} //m_mode
405  if(!a_visitor.visit("fProfile",false)) return false;
406  {std::vector<double> dummy;
407  if(!a_visitor.visit("fBinSvw",dummy)) return false;
408  if(!a_visitor.visit("fBinSv2w",dummy)) return false;}
409  if(!a_visitor.visit("fCutV",false)) return false;
410  {double dummy = 0;
411  if(!a_visitor.visit("fMinV",dummy)) return false;
412  if(!a_visitor.visit("fMaxV",dummy)) return false;}
413  // Not written :
414  //a_hist.fDoubles
415  //a_hist.fInts
416  return true;
417 }
418 
419 inline bool readHistogram(hd_data& aData,iobj_visitor& a_visitor){
420  if(!a_visitor.visit(aData.m_title)) return false;
421  {int dim;
422  if(!a_visitor.visit(dim)) return false;
423  aData.m_dimension = dim;}
424 
425  {int nbin;
426  if(!a_visitor.visit(nbin)) return false;
427  aData.m_bin_number = nbin;}
428 
429  {std::vector<int> vec;
430  if(!a_visitor.visit(vec)) return false;
431  convert<int,unsigned int>(vec,aData.m_bin_entries);}
432 
433  if(!a_visitor.visit(aData.m_bin_Sw)) return false;
434  if(!a_visitor.visit(aData.m_bin_Sw2)) return false;
435  if(!a_visitor.visit(aData.m_bin_Sxw)) return false;
436  if(!a_visitor.visit(aData.m_bin_Sx2w)) return false;
437  aData.m_axes.clear();
438  for(unsigned int iaxis=0;iaxis<aData.m_dimension;iaxis++) {
440  if(!Axis_read(a_visitor,baxis)) return false;
441  aData.m_axes.push_back(baxis);
442  }
443  {int dummy;
444  if(!a_visitor.visit(dummy)) return false;} //m_mode
445 
446  {bool dummy;
447  if(!a_visitor.visit(dummy)) return false;} //m_is_profile
448 
449  {std::vector<double> dummy;
450  if(!a_visitor.visit(dummy)) return false;} //m_bin_Svw
451 
452  {std::vector<double> dummy;
453  if(!a_visitor.visit(dummy)) return false;} //m_bin_Sv2w
454 
455  {bool dummy;
456  if(!a_visitor.visit(dummy)) return false;} //m_cut_v
457 
458  {double dummy;
459  if(!a_visitor.visit(dummy)) return false;} //aData.m_min_v
460 
461  {double dummy;
462  if(!a_visitor.visit(dummy)) return false;} //aData.m_max_v
463 
464  //aData.fDoubles
465  //aData.fInts
466  //aData.m_coords.resize(aData.m_dimension,0);
467  //aData.m_ints.resize(aData.m_dimension,0);
468 
469  return true;
470 }
471 
472 template <class HIST>
473 class Histogram : public virtual istorable {
474 public:
476 protected:
477  virtual void* cast(const std::string& a_class) const {
478  if(void* p = cmp_cast<Histogram>(this,a_class)) return p;
479  return 0;
480  }
481 public:
482  virtual const std::string& store_cls() const {return m_cls;}
483  virtual bool visit(iobj_const_visitor& a_v) const {
484  if(!a_v.begin(*this,m_cls,Histogram::s_visit)) return false;
485 
486  int version = 1;
487  if(!a_v.visit("fVersion",version)) return false;
488 
490  if(!bh.visit(a_v)) return false;
491 
492  if(!visitHistogram(m_hist,a_v)) return false;
493 
494  if(!a_v.end(*this)) return false;
495  return true;
496  }
497 protected:
498  static bool s_visit(const istorable& a_o,iobj_const_visitor& a_v){
499  const Histogram* local = safe_cast<istorable,Histogram>(a_o);
500  if(!local) return false;
501  return local->Histogram::visit(a_v); //IMPORTANT : have Histogram::
502  }
503 public:
504  Histogram(const HIST& a_hist,const std::string& a_cls)
505  :m_hist(a_hist),m_cls(a_cls){}
506  virtual ~Histogram(){}
507 public:
508  Histogram(const Histogram& a_from)
509  :istorable(a_from)
510  ,m_hist(a_from.m_hist)
511  ,m_cls(a_from.m_cls)
512  {}
513  Histogram& operator=(const Histogram& a_from){
514  m_cls = a_from.m_cls;
515  return *this;
516  }
517 protected:
518  const HIST& m_hist;
519  std::string m_cls;
520 };
521 
522 inline bool visit(iobj_const_visitor& a_v,const histo::h1d& a_histo) {
523  Histogram<histo::h1d> h(a_histo,s_h1d());
524  return h.visit(a_v);
525 }
526 
527 inline bool read(iobj_visitor& a_visitor,histo::h1d& a_histo){
528  //if(!a_visitor.begin(*this)) return false;
529 
530  int version;
531  if(!a_visitor.visit(version)) return false;
532 
533  if(version!=1) {
534  //this may come from an unexpected byteswap.
535  a_visitor.out() << "tools::osc::read :"
536  << " unexpected version " << version
537  << std::endl;
538  return false;
539  }
540 
541  if(!BaseHistogram_read(a_visitor)) return false;
542 
543  hd_data hdata;
544  if(!readHistogram(hdata,a_visitor)) return false;
545 
546  hdata.update_fast_getters();
547  a_histo.copy_from_data(hdata);
548 
549  //fAxis.copy(fHistogram.get_axis(0));
550 
551  //if(!a_visitor.end(*this)) return false;
552 
553  return true;
554 }
555 
556 inline bool visit(iobj_const_visitor& a_v,const histo::h2d& a_histo) {
557  Histogram<histo::h2d> h(a_histo,s_h2d());
558  return h.visit(a_v);
559 }
560 
561 inline bool read(iobj_visitor& a_visitor,histo::h2d& a_histo){
562  //if(!a_visitor.begin(*this)) return false;
563 
564  int version;
565  if(!a_visitor.visit(version)) return false;
566 
567  if(version!=1) {
568  //this may come from an unexpected byteswap.
569  a_visitor.out() << "tools::osc::read :"
570  << " unexpected version " << version
571  << std::endl;
572  return false;
573  }
574 
575  if(!BaseHistogram_read(a_visitor)) return false;
576 
577  hd_data hdata;
578  if(!readHistogram(hdata,a_visitor)) return false;
579 
580  hdata.update_fast_getters();
581  a_histo.copy_from_data(hdata);
582 
583  //fAxisX.copy(fHistogram.get_axis(0));
584  //fAxisY.copy(fHistogram.get_axis(1));
585 
586  //if(!a_visitor.end(*this)) return false;
587 
588  return true;
589 }
590 
591 inline bool visit(iobj_const_visitor& a_v,const histo::h3d& a_histo) {
592  Histogram<histo::h3d> h(a_histo,s_h3d());
593  return h.visit(a_v);
594 }
595 
596 inline bool read(iobj_visitor& a_visitor,histo::h3d& a_histo){
597  //if(!a_visitor.begin(*this)) return false;
598 
599  int version;
600  if(!a_visitor.visit(version)) return false;
601 
602  if(version!=1) {
603  //this may come from an unexpected byteswap.
604  a_visitor.out() << "tools::osc::read :"
605  << " unexpected version " << version
606  << std::endl;
607  return false;
608  }
609 
610  if(!BaseHistogram_read(a_visitor)) return false;
611 
612  hd_data hdata;
613  if(!readHistogram(hdata,a_visitor)) return false;
614  hdata.update_fast_getters();
615  a_histo.copy_from_data(hdata);
616 
617  //fAxisX.copy(fHistogram.get_axis(0));
618  //fAxisY.copy(fHistogram.get_axis(1));
619  //fAxisZ.copy(fHistogram.get_axis(2));
620 
621  //if(!a_visitor.end(*this)) return false;
622 
623  return true;
624 }
625 
627 
628 template <class PROF>
629 inline bool visitProfile(const PROF& a_prof,iobj_const_visitor& a_visitor){
630  if(!a_visitor.visit("fTitle",a_prof.title())) return false;
631  if(!a_visitor.visit("fDimension",(int)a_prof.dimension())) return false;
632  if(!a_visitor.visit("fBinNumber",(int)a_prof.get_bins())) return false;
633 
634  std::vector<int> bins_entries;
635  convert<unsigned int,int>(a_prof.bins_entries(),bins_entries);
636  if(!a_visitor.visit("fBinEntries",bins_entries)) return false;
637 
638  if(!a_visitor.visit("fBinSw",a_prof.bins_sum_w())) return false;
639  if(!a_visitor.visit("fBinSw2",a_prof.bins_sum_w2())) return false;
640  if(!a_visitor.visit("fBinSxw",a_prof.bins_sum_xw())) return false;
641  if(!a_visitor.visit("fBinSx2w",a_prof.bins_sum_x2w())) return false;
642  std::string name;
643  for(unsigned int iaxis=0;iaxis<a_prof.dimension();iaxis++) {
644  if(!num2s(iaxis,name)) return false;
645  name = "fAxes_"+name;
646  Axis axis(a_prof.get_axis(iaxis));
647  if(!a_visitor.visit(name,axis)) return false;
648  }
649  {int dummy = 0;
650  if(!a_visitor.visit("fMode",dummy)) return false;} //m_mode
651  if(!a_visitor.visit("fProfile",true)) return false;
652  if(!a_visitor.visit("fBinSvw",a_prof.bins_sum_vw())) return false;
653  if(!a_visitor.visit("fBinSv2w",a_prof.bins_sum_v2w())) return false;
654  if(!a_visitor.visit("fCutV",a_prof.cut_v())) return false;
655  if(!a_visitor.visit("fMinV",a_prof.min_v())) return false;
656  if(!a_visitor.visit("fMaxV",a_prof.max_v())) return false;
657  // Not written :
658  //a_prof.fDoubles
659  //a_prof.fInts
660  return true;
661 }
662 
663 template <class PROF>
664 class Profile : public virtual istorable {
665 public:
667 protected:
668  virtual void* cast(const std::string& a_class) const {
669  if(void* p = cmp_cast<Profile>(this,a_class)) return p;
670  return 0;
671  }
672 public:
673  virtual const std::string& store_cls() const {return m_cls;}
674  virtual bool visit(iobj_const_visitor& a_v) const {
675  if(!a_v.begin(*this,m_cls,Profile::s_visit)) return false;
676 
677  int version = 1;
678  if(!a_v.visit("fVersion",version)) return false;
679 
681  if(!bh.visit(a_v)) return false;
682 
683  if(!visitProfile(m_hist,a_v)) return false;
684 
685  if(!a_v.end(*this)) return false;
686  return true;
687  }
688 protected:
689  static bool s_visit(const istorable& a_o,iobj_const_visitor& a_v){
690  const Profile* local = safe_cast<istorable,Profile>(a_o);
691  if(!local) return false;
692  return local->Profile::visit(a_v); //IMPORTANT : have Profile::
693  }
694 public:
695  Profile(const PROF& a_hist,const std::string& a_cls)
696  :m_hist(a_hist),m_cls(a_cls){}
697  virtual ~Profile(){}
698 public:
699  Profile(const Profile& a_from)
700  :istorable(a_from)
701  ,m_hist(a_from.m_hist)
702  ,m_cls(a_from.m_cls)
703  {}
704  Profile& operator=(const Profile& a_from){
705  m_cls = a_from.m_cls;
706  return *this;
707  }
708 protected:
709  const PROF& m_hist;
710  std::string m_cls;
711 };
712 
713 inline bool readProfile(pd_data& aData,iobj_visitor& a_visitor){
714  if(!a_visitor.visit(aData.m_title)) return false;
715 
716  {int dim;
717  if(!a_visitor.visit(dim)) return false;
718  aData.m_dimension = dim;}
719 
720  {int nbin;
721  if(!a_visitor.visit(nbin)) return false;
722  aData.m_bin_number = nbin;}
723 
724  {std::vector<int> vec;
725  if(!a_visitor.visit(vec)) return false;
726  convert<int,unsigned int>(vec,aData.m_bin_entries);}
727 
728  if(!a_visitor.visit(aData.m_bin_Sw)) return false;
729  if(!a_visitor.visit(aData.m_bin_Sw2)) return false;
730  if(!a_visitor.visit(aData.m_bin_Sxw)) return false;
731  if(!a_visitor.visit(aData.m_bin_Sx2w)) return false;
732  aData.m_axes.clear();
733  for(unsigned int iaxis=0;iaxis<aData.m_dimension;iaxis++) {
735  if(!Axis_read(a_visitor,baxis)) return false;
736  aData.m_axes.push_back(baxis);
737  }
738  {int dummy;
739  if(!a_visitor.visit(dummy)) return false;} //m_mode
740  if(!a_visitor.visit(aData.m_is_profile)) return false;
741  if(!a_visitor.visit(aData.m_bin_Svw)) return false;
742  if(!a_visitor.visit(aData.m_bin_Sv2w)) return false;
743  if(!a_visitor.visit(aData.m_cut_v)) return false;
744  if(!a_visitor.visit(aData.m_min_v)) return false;
745  if(!a_visitor.visit(aData.m_max_v)) return false;
746 
747  // Not written :
748  //aData.fDoubles
749  //aData.fInts
750  //aData.m_coords.resize(aData.m_dimension,0);
751  //aData.m_ints.resize(aData.m_dimension,0);
752 
753  return true;
754 }
755 
756 inline bool visit(iobj_const_visitor& a_v,const histo::p1d& a_histo) {
757  Profile<histo::p1d> h(a_histo,s_p1d());
758  return h.visit(a_v);
759 }
760 
761 inline bool read(iobj_visitor& a_visitor,histo::p1d& a_histo){
762  //if(!a_visitor.begin(*this)) return false;
763 
764  int version;
765  if(!a_visitor.visit(version)) return false;
766 
767  if(version!=1) {
768  //this may come from an unexpected byteswap.
769  a_visitor.out() << "tools::osc::read :"
770  << " unexpected version " << version
771  << std::endl;
772  return false;
773  }
774 
775 
776  if(!BaseHistogram_read(a_visitor)) return false;
777 
778  pd_data hdata;
779  if(!readProfile(hdata,a_visitor)) return false;
780  hdata.update_fast_getters();
781  a_histo.copy_from_data(hdata);
782 
783  //fAxis.copy(fHistogram.get_axis(0));
784 
785  //if(!a_visitor.end(*this)) return false;
786 
787  return true;
788 }
789 
790 inline bool visit(iobj_const_visitor& a_v,const histo::p2d& a_histo) {
791  Profile<histo::p2d> h(a_histo,s_p2d());
792  return h.visit(a_v);
793 }
794 
795 inline bool read(iobj_visitor& a_visitor,histo::p2d& a_histo){
796  //if(!a_visitor.begin(*this)) return false;
797 
798  int version;
799  if(!a_visitor.visit(version)) return false;
800 
801  if(version!=1) {
802  //this may come from an unexpected byteswap.
803  a_visitor.out() << "tools::osc::read :"
804  << " unexpected version " << version
805  << std::endl;
806  return false;
807  }
808 
809 
810  if(!BaseHistogram_read(a_visitor)) return false;
811 
812  pd_data hdata;
813  if(!readProfile(hdata,a_visitor)) return false;
814  hdata.update_fast_getters();
815  a_histo.copy_from_data(hdata);
816 
817  //fAxisX.copy(a_histo.get_axis(0));
818  //fAxisY.copy(a_histo.get_axis(1));
819 
820  //if(!a_visitor.end(*this)) return false;
821 
822  return true;
823 }
824 
825 template <class HIST>
826 class Histogram_cp : public Histogram<HIST> {
827  typedef Histogram<HIST> parent;
828 public:
829  Histogram_cp(const HIST& a_h,const std::string& a_cls)
830  :parent(m_cp,a_cls) //give ref of m_cp to Histogram.
831  ,m_cp(a_h) //do a local copy.
832  //WARNING : the upper is ok as long as Histogram constructor does nothing
833  // else than keeping the ref to m_cp. Else it would do
834  // something on an empty histo (and not on a copy of the
835  // passed a_data).
836  {}
837  virtual ~Histogram_cp(){}
838 public:
839  Histogram_cp(const Histogram_cp& a_from)
840  :istorable(a_from)
841  ,parent(m_cp,a_from.m_cls)
842  ,m_cp(a_from.m_cp)
843  {}
845  parent::operator=(a_from);
846  m_cp = a_from.m_cp;
847  return *this;
848  }
849 protected:
850  HIST m_cp;
851 };
852 
853 template <class PROF>
854 class Profile_cp : public Profile<PROF> {
855  typedef Profile<PROF> parent;
856 public:
857  Profile_cp(const PROF& a_p,const std::string& a_cls)
858  :parent(m_cp,a_cls) //give ref of m_cp to Profile.
859  ,m_cp(a_p) //do a local copy.
860  //WARNING : the upper is ok as long as Profile constructor does nothing
861  // else than keeping the ref to m_cp. Else it would do
862  // something on an empty histo (and not on a copy of the
863  // passed a_data).
864  {}
865  virtual ~Profile_cp(){}
866 public:
867  Profile_cp(const Profile_cp& a_from)
868  :istorable(a_from)
869  ,parent(m_cp,a_from.m_cls)
870  ,m_cp(a_from.m_cp)
871  {}
872  Profile_cp& operator=(const Profile_cp& a_from){
873  parent::operator=(a_from);
874  m_cp = a_from.m_cp;
875  return *this;
876  }
877 protected:
878  PROF m_cp;
879 };
880 
881 }}
882 
883 #endif
tools::osc::s_annotation
const std::string & s_annotation()
Definition: osc_streamers:28
tools::osc::visitHistogram
bool visitHistogram(const HIST &a_hist, iobj_const_visitor &a_visitor)
Definition: osc_streamers:383
tools::osc::BaseHistogram::m_hist
const HIST & m_hist
Definition: osc_streamers:367
tools::osc::Axis
Definition: osc_streamers:66
tools::histo::axis::m_edges
std::vector< TC > m_edges
Definition: axis:272
tools::osc::Axis::s_visit
static bool s_visit(const istorable &a_o, iobj_const_visitor &a_v)
Definition: osc_streamers:92
tools::osc::Axis::cast
virtual void * cast(const std::string &a_class) const
Definition: osc_streamers:70
tools::iobj_const_visitor
Definition: iobj_const_visitor:27
tools::histo::p1d
Definition: p1d:12
tools::osc::Histogram::store_cls
virtual const std::string & store_cls() const
Definition: osc_streamers:482
iobj_visitor
tools::osc::s_p2d
const std::string & s_p2d()
Definition: osc_streamers:61
tools::osc::visitProfile
bool visitProfile(const PROF &a_prof, iobj_const_visitor &a_visitor)
Definition: osc_streamers:629
tools::histo::profile_data::m_is_profile
bool m_is_profile
Definition: profile_data:73
tools::osc::Histogram_cp::m_cp
HIST m_cp
Definition: osc_streamers:850
tools::osc::Profile::visit
virtual bool visit(iobj_const_visitor &a_v) const
Definition: osc_streamers:674
tools::osc::visit
bool visit(iobj_const_visitor &a_v, const histo::h1d &a_histo)
Definition: osc_streamers:522
tools::iobj_const_visitor::begin
virtual bool begin(const istorable &, const std::string &, local_func)=0
tools::osc::Annotation
Definition: osc_streamers:271
tools::histo::histo_data::update_fast_getters
void update_fast_getters()
Definition: histo_data:103
tools::osc::Histogram
Definition: osc_streamers:473
tools::histo::axis::m_maximum_value
TC m_maximum_value
Definition: axis:267
tools::histo::h1d
Definition: h1d:14
tools::histo::axis::m_offset
TO m_offset
Definition: axis:264
tools::osc::Vector::visit
virtual bool visit(iobj_const_visitor &a_v) const
Definition: osc_streamers:211
tools::osc::Profile::cast
virtual void * cast(const std::string &a_class) const
Definition: osc_streamers:668
tools::histo::histo_data::m_bin_Sx2w
std::vector< std::vector< TC > > m_bin_Sx2w
Definition: histo_data:179
tools::osc::Item::Item
Item(const std::string &aKey, const std::string &aValue, bool aSticky)
Definition: osc_streamers:174
tools::osc::s_h2d
const std::string & s_h2d()
Definition: osc_streamers:46
tools::osc::Item::Item
Item()
Definition: osc_streamers:173
tools::osc::s_h3d
const std::string & s_h3d()
Definition: osc_streamers:51
tools::osc::Annotation_read
bool Annotation_read(iobj_visitor &a_visitor)
Definition: osc_streamers:307
tools::osc::Histogram::m_hist
const HIST & m_hist
Definition: osc_streamers:518
tools::osc::Profile::s_visit
static bool s_visit(const istorable &a_o, iobj_const_visitor &a_v)
Definition: osc_streamers:689
tools::histo::axis< double, unsigned int >
tools::osc::Histogram_cp::Histogram_cp
Histogram_cp(const Histogram_cp &a_from)
Definition: osc_streamers:839
tools::osc::Item::s_visit
static bool s_visit(const istorable &a_o, iobj_const_visitor &a_v)
Definition: osc_streamers:153
tools::osc::Item::operator=
Item & operator=(const Item &a_from)
Definition: osc_streamers:184
tools::osc::BaseHistogram::BaseHistogram
BaseHistogram(const HIST &a_hist)
Definition: osc_streamers:359
tools::osc::map2vec
void map2vec(const std::map< std::string, std::string > &a_in, std::vector< Item > &a_out)
Definition: osc_streamers:317
tools::osc::pd_data
histo::profile_data< double, unsigned int, unsigned int, double, double > pd_data
Definition: osc_streamers:626
tools::osc::BaseHistogram
Definition: osc_streamers:328
tools::osc::Profile_cp::operator=
Profile_cp & operator=(const Profile_cp &a_from)
Definition: osc_streamers:872
tools::histo::p2d
Definition: p2d:12
tools::osc::BaseHistogram::~BaseHistogram
virtual ~BaseHistogram()
Definition: osc_streamers:360
tools::osc::Axis::~Axis
virtual ~Axis()
Definition: osc_streamers:99
tools::osc::Axis_read
bool Axis_read(iobj_visitor &a_visitor, histo::axis< double, unsigned int > &a_axis)
Definition: osc_streamers:108
tools::histo::histo_data::m_bin_entries
std::vector< TN > m_bin_entries
Definition: histo_data:175
tools::osc::Annotation::m_items
std::vector< Item > m_items
Definition: osc_streamers:304
tools::osc::Item::~Item
virtual ~Item()
Definition: osc_streamers:176
tools::osc::Vector::s_visit
static bool s_visit(const istorable &a_o, iobj_const_visitor &a_v)
Definition: osc_streamers:230
tools::osc::BaseHistogram_read
bool BaseHistogram_read(iobj_visitor &a_visitor)
Definition: osc_streamers:370
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::osc::Annotation::Annotation
Annotation()
Definition: osc_streamers:298
tools::osc::Vector::m_T
std::string m_T
Definition: osc_streamers:245
tools::osc::Axis::m_axis
const histo::axis< double, unsigned int > & m_axis
Definition: osc_streamers:104
tools::histo::h2d
Definition: h2d:12
tools::histo::profile_data::m_min_v
TV m_min_v
Definition: profile_data:77
tools::osc::Item
Definition: osc_streamers:130
tools::osc::Histogram::m_cls
std::string m_cls
Definition: osc_streamers:519
tools::osc::Profile::m_hist
const PROF & m_hist
Definition: osc_streamers:709
tools::osc::Histogram_cp::~Histogram_cp
virtual ~Histogram_cp()
Definition: osc_streamers:837
tools::osc::Profile::m_cls
std::string m_cls
Definition: osc_streamers:710
tools::osc::Profile::Profile
Profile(const Profile &a_from)
Definition: osc_streamers:699
tools::histo::profile_data::m_cut_v
bool m_cut_v
Definition: profile_data:76
tools::osc::Histogram::visit
virtual bool visit(iobj_const_visitor &a_v) const
Definition: osc_streamers:483
tools::histo::axis::m_bin_width
TC m_bin_width
Definition: axis:270
tools::osc::Vector::~Vector
virtual ~Vector()
Definition: osc_streamers:238
tools::osc::Annotation::store_cls
virtual const std::string & store_cls() const
Definition: osc_streamers:279
TOOLS_SCLASS
#define TOOLS_SCLASS(a_name)
Definition: S_STRING:41
tools::osc::Histogram_cp
Definition: osc_streamers:826
tools::histo::histo_data::m_title
std::string m_title
Definition: histo_data:171
tools::histo::profile_data
Definition: profile_data:13
tools::osc::Profile::~Profile
virtual ~Profile()
Definition: osc_streamers:697
tools::osc::Histogram::Histogram
Histogram(const Histogram &a_from)
Definition: osc_streamers:508
tools::histo::profile_data::m_bin_Svw
std::vector< TV > m_bin_Svw
Definition: profile_data:74
tools::osc::BaseHistogram::store_cls
virtual const std::string & store_cls() const
Definition: osc_streamers:337
tools::osc::Annotation::s_visit
static bool s_visit(const istorable &a_o, iobj_const_visitor &a_v)
Definition: osc_streamers:292
tools::osc::Item::Item
Item(const Item &a_from)
Definition: osc_streamers:178
tools::histo::p2::copy_from_data
void copy_from_data(const pd_t &a_from)
Definition: p2:101
tools::version
unsigned int version()
Definition: version:14
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::osc::Profile_cp::m_cp
PROF m_cp
Definition: osc_streamers:878
tools::osc::Histogram_cp::Histogram_cp
Histogram_cp(const HIST &a_h, const std::string &a_cls)
Definition: osc_streamers:829
tools::istorable
Definition: iobj_const_visitor:16
tools::osc::Profile_cp::~Profile_cp
virtual ~Profile_cp()
Definition: osc_streamers:865
tools::osc::Item::cast
virtual void * cast(const std::string &a_class) const
Definition: osc_streamers:134
tools::osc::Histogram::Histogram
Histogram(const HIST &a_hist, const std::string &a_cls)
Definition: osc_streamers:504
tools::osc::Annotation::cast
virtual void * cast(const std::string &a_class) const
Definition: osc_streamers:275
tools::osc::s_h1d
const std::string & s_h1d()
Definition: osc_streamers:41
tools::osc::Profile
Definition: osc_streamers:664
tools::osc::Histogram::operator=
Histogram & operator=(const Histogram &a_from)
Definition: osc_streamers:513
tools::osc::Histogram::s_visit
static bool s_visit(const istorable &a_o, iobj_const_visitor &a_v)
Definition: osc_streamers:498
tools::osc::s_base_histogram
const std::string & s_base_histogram()
Definition: osc_streamers:32
tools::histo::histo_data::m_bin_Sxw
std::vector< std::vector< TC > > m_bin_Sxw
Definition: histo_data:178
tools::iobj_const_visitor::visit
virtual bool visit(const std::string &, bool)=0
tools::histo::histo_data< double, unsigned int, unsigned int, double >
tools::osc::Item::fKey
std::string fKey
Definition: osc_streamers:192
tools::osc::std_vector_read
bool std_vector_read(iobj_visitor &a_visitor, std::vector< T > &a_vec)
Definition: osc_streamers:250
tools::histo::histo_data::m_axes
std::vector< axis_t > m_axes
Definition: histo_data:181
tools::histo::axis::m_minimum_value
TC m_minimum_value
Definition: axis:266
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::osc::Histogram_cp::operator=
Histogram_cp & operator=(const Histogram_cp &a_from)
Definition: osc_streamers:844
tools::osc::Vector::Vector
Vector(const std::vector< T > &a_vec, const std::string &a_T)
Definition: osc_streamers:236
tools::osc::Annotation::~Annotation
virtual ~Annotation()
Definition: osc_streamers:299
tools::osc::Vector::cast
virtual void * cast(const std::string &a_class) const
Definition: osc_streamers:203
tools::osc::Vector::m_vec
const std::vector< T > & m_vec
Definition: osc_streamers:244
tools::osc::Vector
Definition: osc_streamers:199
tools::osc::Profile::store_cls
virtual const std::string & store_cls() const
Definition: osc_streamers:673
tools::osc::readProfile
bool readProfile(pd_data &aData, iobj_visitor &a_visitor)
Definition: osc_streamers:713
tools::iobj_visitor::visit
virtual bool visit(bool &)=0
tools::osc::Item::visit
virtual bool visit(iobj_const_visitor &a_visitor) const
Definition: osc_streamers:140
tools::histo::axis::m_number_of_bins
bn_t m_number_of_bins
Definition: axis:265
tools::histo::histo_data::m_bin_Sw2
std::vector< TW > m_bin_Sw2
Definition: histo_data:177
tools::osc::s_item
const std::string & s_item()
Definition: osc_streamers:36
tools::osc::Item::fValue
std::string fValue
Definition: osc_streamers:193
tools::iobj_visitor::out
virtual std::ostream & out() const =0
tools::osc::Item::store_cls
virtual const std::string & store_cls() const
Definition: osc_streamers:139
tools::iobj_const_visitor::end
virtual bool end(const istorable &)=0
tools::osc::Axis::store_cls
virtual const std::string & store_cls() const
Definition: osc_streamers:74
tools::osc::Annotation::visit
virtual bool visit(iobj_const_visitor &a_v) const
Definition: osc_streamers:280
tools::osc::Profile_cp
Definition: osc_streamers:854
tools::histo::h3d
Definition: h3d:12
tools::iobj_visitor
Definition: iobj_visitor:15
TOOLS_T_SCLASS
#define TOOLS_T_SCLASS(a_T, a_name)
Definition: S_STRING:48
tools::histo::h2::copy_from_data
void copy_from_data(const hd_t &a_from)
Definition: h2:34
tools::osc::read
bool read(iobj_visitor &a_visitor, histo::h1d &a_histo)
Definition: osc_streamers:527
iobj_const_visitor
tools::osc::hd_data
histo::histo_data< double, unsigned int, unsigned int, double > hd_data
Definition: osc_streamers:325
tools::osc::Profile::Profile
Profile(const PROF &a_hist, const std::string &a_cls)
Definition: osc_streamers:695
tools::osc::s_p1d
const std::string & s_p1d()
Definition: osc_streamers:56
tools::osc::Profile_cp::Profile_cp
Profile_cp(const Profile_cp &a_from)
Definition: osc_streamers:867
tools::osc::Profile::operator=
Profile & operator=(const Profile &a_from)
Definition: osc_streamers:704
tools::osc::Item::fSticky
bool fSticky
Definition: osc_streamers:194
tools::histo::histo_data::m_bin_number
TO m_bin_number
Definition: histo_data:174
tools::osc::s_axis
const std::string & s_axis()
Definition: osc_streamers:24
tools::osc::readHistogram
bool readHistogram(hd_data &aData, iobj_visitor &a_visitor)
Definition: osc_streamers:419
tools::histo::axis::m_fixed
bool m_fixed
Definition: axis:268
tools::histo::profile_data::m_max_v
TV m_max_v
Definition: profile_data:78
tools::osc::Vector::store_cls
virtual const std::string & store_cls() const
Definition: osc_streamers:207
tools::histo::histo_data::m_dimension
dim_t m_dimension
Definition: histo_data:172
tools::osc::Histogram::cast
virtual void * cast(const std::string &a_class) const
Definition: osc_streamers:477
tools::num2s
bool num2s(unsigned short a_value, std::string &a_s)
Definition: num2s:26
tools::osc::Profile_cp::Profile_cp
Profile_cp(const PROF &a_p, const std::string &a_cls)
Definition: osc_streamers:857
tools::osc::Item::read
virtual bool read(iobj_visitor &a_visitor)
Definition: osc_streamers:159
tools::osc::Axis::visit
virtual bool visit(iobj_const_visitor &a_v) const
Definition: osc_streamers:75
tools::osc::Histogram::~Histogram
virtual ~Histogram()
Definition: osc_streamers:506
tools::osc::BaseHistogram::visit
virtual bool visit(iobj_const_visitor &a_v) const
Definition: osc_streamers:338
tools::osc::BaseHistogram::cast
virtual void * cast(const std::string &a_class) const
Definition: osc_streamers:332
tools::osc::Axis::Axis
Axis(const histo::axis< double, unsigned int > &a_axis)
Definition: osc_streamers:98
tools::osc::BaseHistogram::s_visit
static bool s_visit(const istorable &a_o, iobj_const_visitor &a_v)
Definition: osc_streamers:352