Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/g4tools/include/tools/store/osc_streamers

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/store/osc_streamers (Version 11.3.0) and /externals/g4tools/include/tools/store/osc_streamers (Version 9.6.p3)


  1 // Copyright (C) 2010, Guy Barrand. All rights    
  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::Anno    
 30   return s_v;                                     
 31 }                                                 
 32 inline const std::string& s_base_histogram() {    
 33   static const std::string s_v("BatchLab::Base    
 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::Hist    
 43   return s_v;                                     
 44 }                                                 
 45                                                   
 46 inline const std::string& s_h2d() {               
 47   static const std::string s_v("BatchLab::Hist    
 48   return s_v;                                     
 49 }                                                 
 50                                                   
 51 inline const std::string& s_h3d() {               
 52   static const std::string s_v("BatchLab::Hist    
 53   return s_v;                                     
 54 }                                                 
 55                                                   
 56 inline const std::string& s_p1d() {               
 57   static const std::string s_v("BatchLab::Prof    
 58   return s_v;                                     
 59 }                                                 
 60                                                   
 61 inline const std::string& s_p2d() {               
 62   static const std::string s_v("BatchLab::Prof    
 63   return s_v;                                     
 64 }                                                 
 65                                                   
 66 class Axis : public virtual istorable {           
 67 public:                                           
 68   TOOLS_SCLASS(tools::osc::Axis)                  
 69 protected:                                        
 70   virtual void* cast(const std::string& a_clas    
 71     if(void* p = cmp_cast<Axis>(this,a_class))    
 72     return 0;                                     
 73   }                                               
 74   virtual const std::string& store_cls() const    
 75   virtual bool visit(iobj_const_visitor& a_v)     
 76     if(!a_v.begin(*this,s_axis(),Axis::s_visit    
 77                                                   
 78     int version = 1;                              
 79     if(!a_v.visit("fVersion",version)) return     
 80                                                   
 81     if(!a_v.visit("fOffset",m_axis.m_offset))     
 82     if(!a_v.visit("fNumberOfBins",(int)m_axis.    
 83     if(!a_v.visit("fMinimumValue",m_axis.m_min    
 84     if(!a_v.visit("fMaximumValue",m_axis.m_max    
 85     if(!a_v.visit("fFixed",m_axis.m_fixed)) re    
 86     if(!a_v.visit("fBinWidth",m_axis.m_bin_wid    
 87     if(!a_v.visit("fEdges",m_axis.m_edges)) re    
 88                                                   
 89     if(!a_v.end(*this)) return false;             
 90     return true;                                  
 91   }                                               
 92   static bool s_visit(const istorable& a_o,iob    
 93     const Axis* local = safe_cast<istorable,Ax    
 94     if(!local) return false;                      
 95     return local->Axis::visit(a_v); //IMPORTAN    
 96   }                                               
 97 public:                                           
 98   Axis(const histo::axis<double,unsigned int>&    
 99   virtual ~Axis(){}                               
100 private:                                          
101   Axis(const Axis& a_from):istorable(a_from),m    
102   Axis& operator=(const Axis&){return *this;}     
103 protected:                                        
104   const histo::axis<double,unsigned int>& m_ax    
105 };                                                
106                                                   
107                                                   
108 inline bool Axis_read(iobj_visitor& a_visitor,    
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    
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))    
121   if(!a_visitor.visit(a_axis.m_maximum_value))    
122   if(!a_visitor.visit(a_axis.m_fixed)) return     
123   if(!a_visitor.visit(a_axis.m_bin_width)) ret    
124   if(!a_visitor.visit(a_axis.m_edges)) return     
125                                                   
126   //if(!a_visitor.end(*this)) return false;       
127   return true;                                    
128 }                                                 
129                                                   
130 class Item : public virtual istorable {           
131 public:                                           
132   TOOLS_SCLASS(tools::osc::Item)                  
133 protected:                                        
134   virtual void* cast(const std::string& a_clas    
135     if(void* p = cmp_cast<Item>(this,a_class))    
136     return 0;                                     
137   }                                               
138 public:                                           
139   virtual const std::string& store_cls() const    
140   virtual bool visit(iobj_const_visitor& a_vis    
141     if(!a_visitor.begin(*this,s_item(),Item::s    
142                                                   
143     int version = 1;                              
144     if(!a_visitor.visit("fVersion",version)) r    
145                                                   
146     if(!a_visitor.visit("fKey",fKey)) return f    
147     if(!a_visitor.visit("fValue",fValue)) retu    
148     if(!a_visitor.visit("fSticky",fSticky)) re    
149                                                   
150     if(!a_visitor.end(*this)) return false;       
151     return true;                                  
152   }                                               
153   static bool s_visit(const istorable& a_o,iob    
154     const Item* local = safe_cast<istorable,It    
155     if(!local) return false;                      
156     return local->Item::visit(a_v); //IMPORTAN    
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::stri    
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:                                           
201   TOOLS_T_SCLASS(T,tools::osc::Vector)            
202 protected:                                        
203   virtual void* cast(const std::string& a_clas    
204     if(void* p = cmp_cast<Vector>(this,a_class    
205     return 0;                                     
206   }                                               
207   virtual const std::string& store_cls() const    
208     static const std::string s_v("BatchLab::Ve    
209     return s_v;                                   
210   }                                               
211   virtual bool visit(iobj_const_visitor& a_v)     
212     if(!a_v.begin(*this,Vector<T>::store_cls()    
213                                                   
214     int version = 1;                              
215     if(!a_v.visit("fVersion",version)) return     
216                                                   
217     unsigned int number = (unsigned int)m_vec.    
218     if(!a_v.visit("fSize",number)) return fals    
219                                                   
220     std::string stmp;                             
221     for(unsigned int index=0;index<number;inde    
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,iob    
231     const Vector* local = safe_cast<istorable,    
232     if(!local) return false;                      
233     return local->Vector<T>::visit(a_v); //IMP    
234   }                                               
235 public:                                           
236   Vector(const std::vector<T>& a_vec,const std    
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    
242   Vector& operator=(const Vector&){return *thi    
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_vi    
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:                                           
273   TOOLS_SCLASS(tools::osc::Annotation)            
274 protected:                                        
275   virtual void* cast(const std::string& a_clas    
276     if(void* p = cmp_cast<Annotation>(this,a_c    
277     return 0;                                     
278   }                                               
279   virtual const std::string& store_cls() const    
280   virtual bool visit(iobj_const_visitor& a_v)     
281     if(!a_v.begin(*this,s_annotation(),Annotat    
282                                                   
283     int version = 1;                              
284     if(!a_v.visit("fVersion",version)) return     
285                                                   
286     Vector<Item> v(m_items,s_item());             
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,iob    
293     const Annotation* local = safe_cast<istora    
294     if(!local) return false;                      
295     return local->Annotation::visit(a_v); //IM    
296   }                                               
297 public:                                           
298   Annotation(){}                                  
299   virtual ~Annotation(){}                         
300 private:                                          
301   Annotation(const Annotation& a_from):istorab    
302   Annotation& operator=(const Annotation&){ret    
303 public:                                           
304   std::vector<Item> m_items;                      
305 };                                                
306                                                   
307 inline bool Annotation_read(iobj_visitor& a_vi    
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))    
313   //if(!a_visitor.end(*this)) return false;       
314   return true;                                    
315 }                                                 
316                                                   
317 inline void map2vec(const std::map<std::string    
318   a_out.clear();                                  
319   std::map<std::string,std::string>::const_ite    
320   for(it=a_in.begin();it!=a_in.end();++it) {      
321     a_out.push_back(Item((*it).first,(*it).sec    
322   }                                               
323 }                                                 
324                                                   
325 typedef histo::histo_data<double,unsigned int,    
326                                                   
327 template <class HIST>                             
328 class BaseHistogram : public virtual istorable    
329 public:                                           
330   TOOLS_T_SCLASS(HIST,tools::osc::BaseHistogra    
331 protected:                                        
332   virtual void* cast(const std::string& a_clas    
333     if(void* p = cmp_cast<BaseHistogram>(this,    
334     return 0;                                     
335   }                                               
336 public:                                           
337   virtual const std::string& store_cls() const    
338   virtual bool visit(iobj_const_visitor& a_v)     
339     if(!a_v.begin(*this,s_base_histogram(),Bas    
340                                                   
341     int version = 1;                              
342     if(!a_v.visit("fVersion",version)) return     
343                                                   
344     Annotation ano;                               
345     map2vec(m_hist.annotations(),ano.m_items);    
346     if(!a_v.visit("fAnnotation",ano)) return f    
347                                                   
348     if(!a_v.end(*this)) return false;             
349     return true;                                  
350   }                                               
351 protected:                                        
352   static bool s_visit(const istorable& a_o,iob    
353     const BaseHistogram* local =                  
354       safe_cast<istorable,BaseHistogram>(a_o);    
355     if(!local) return false;                      
356     return local->BaseHistogram::visit(a_v); /    
357   }                                               
358 public:                                           
359   BaseHistogram(const HIST& a_hist):m_hist(a_h    
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    
366 protected:                                        
367   const HIST& m_hist;                             
368 };                                                
369                                                   
370 inline bool BaseHistogram_read(iobj_visitor& a    
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,    
384   if(!a_visitor.visit("fTitle",a_hist.title())    
385   if(!a_visitor.visit("fDimension",(int)a_hist    
386   if(!a_visitor.visit("fBinNumber",(int)a_hist    
387                                                   
388   std::vector<int> bins_entries;                  
389   convert<unsigned int,int>(a_hist.bins_entrie    
390   if(!a_visitor.visit("fBinEntries",bins_entri    
391                                                   
392   if(!a_visitor.visit("fBinSw",a_hist.bins_sum    
393   if(!a_visitor.visit("fBinSw2",a_hist.bins_su    
394   if(!a_visitor.visit("fBinSxw",a_hist.bins_su    
395   if(!a_visitor.visit("fBinSx2w",a_hist.bins_s    
396  {std::string name;                               
397   for(unsigned int iaxis=0;iaxis<a_hist.dimens    
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 fal    
402   }}                                              
403  {int dummy = 0;                                  
404   if(!a_visitor.visit("fMode",dummy)) return f    
405   if(!a_visitor.visit("fProfile",false)) retur    
406  {std::vector<double> dummy;                      
407   if(!a_visitor.visit("fBinSvw",dummy)) return    
408   if(!a_visitor.visit("fBinSv2w",dummy)) retur    
409   if(!a_visitor.visit("fCutV",false)) return f    
410  {double dummy = 0;                               
411   if(!a_visitor.visit("fMinV",dummy)) return f    
412   if(!a_visitor.visit("fMaxV",dummy)) return f    
413   // Not written :                                
414   //a_hist.fDoubles                               
415   //a_hist.fInts                                  
416   return true;                                    
417 }                                                 
418                                                   
419 inline bool readHistogram(hd_data& aData,iobj_    
420   if(!a_visitor.visit(aData.m_title)) return f    
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_en    
432                                                   
433   if(!a_visitor.visit(aData.m_bin_Sw)) return     
434   if(!a_visitor.visit(aData.m_bin_Sw2)) return    
435   if(!a_visitor.visit(aData.m_bin_Sxw)) return    
436   if(!a_visitor.visit(aData.m_bin_Sx2w)) retur    
437   aData.m_axes.clear();                           
438   for(unsigned int iaxis=0;iaxis<aData.m_dimen    
439     histo::axis<double,unsigned int> baxis;       
440     if(!Axis_read(a_visitor,baxis)) return fal    
441     aData.m_axes.push_back(baxis);                
442   }                                               
443  {int dummy;                                      
444   if(!a_visitor.visit(dummy)) return false;} /    
445                                                   
446  {bool dummy;                                     
447   if(!a_visitor.visit(dummy)) return false;} /    
448                                                   
449  {std::vector<double> dummy;                      
450   if(!a_visitor.visit(dummy)) return false;} /    
451                                                   
452  {std::vector<double> dummy;                      
453   if(!a_visitor.visit(dummy)) return false;} /    
454                                                   
455  {bool dummy;                                     
456   if(!a_visitor.visit(dummy)) return false;} /    
457                                                   
458  {double dummy;                                   
459   if(!a_visitor.visit(dummy)) return false;} /    
460                                                   
461  {double dummy;                                   
462   if(!a_visitor.visit(dummy)) return false;} /    
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:                                           
475   TOOLS_T_SCLASS(HIST,tools::osc::Histogram)      
476 protected:                                        
477   virtual void* cast(const std::string& a_clas    
478     if(void* p = cmp_cast<Histogram>(this,a_cl    
479     return 0;                                     
480   }                                               
481 public:                                           
482   virtual const std::string& store_cls() const    
483   virtual bool visit(iobj_const_visitor& a_v)     
484     if(!a_v.begin(*this,m_cls,Histogram::s_vis    
485                                                   
486     int version = 1;                              
487     if(!a_v.visit("fVersion",version)) return     
488                                                   
489     BaseHistogram<HIST> bh(m_hist);               
490     if(!bh.visit(a_v)) return false;              
491                                                   
492     if(!visitHistogram(m_hist,a_v)) return fal    
493                                                   
494     if(!a_v.end(*this)) return false;             
495     return true;                                  
496   }                                               
497 protected:                                        
498   static bool s_visit(const istorable& a_o,iob    
499     const Histogram* local = safe_cast<istorab    
500     if(!local) return false;                      
501     return local->Histogram::visit(a_v); //IMP    
502   }                                               
503 public:                                           
504   Histogram(const HIST& a_hist,const std::stri    
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,cons    
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    
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 byteswa    
535     a_visitor.out() << "tools::osc::read :"       
536                     << " unexpected version "     
537                     << std::endl;                 
538     return false;                                 
539   }                                               
540                                                   
541   if(!BaseHistogram_read(a_visitor)) return fa    
542                                                   
543   hd_data hdata;                                  
544   if(!readHistogram(hdata,a_visitor)) return f    
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,cons    
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    
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 byteswa    
569     a_visitor.out() << "tools::osc::read :"       
570                     << " unexpected version "     
571                     << std::endl;                 
572     return false;                                 
573   }                                               
574                                                   
575   if(!BaseHistogram_read(a_visitor)) return fa    
576                                                   
577   hd_data hdata;                                  
578   if(!readHistogram(hdata,a_visitor)) return f    
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,cons    
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    
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 byteswa    
604     a_visitor.out() << "tools::osc::read :"       
605                     << " unexpected version "     
606                     << std::endl;                 
607     return false;                                 
608   }                                               
609                                                   
610   if(!BaseHistogram_read(a_visitor)) return fa    
611                                                   
612   hd_data hdata;                                  
613   if(!readHistogram(hdata,a_visitor)) return f    
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                                                   
626 typedef histo::profile_data<double,unsigned in    
627                                                   
628 template <class PROF>                             
629 inline bool visitProfile(const PROF& a_prof,io    
630   if(!a_visitor.visit("fTitle",a_prof.title())    
631   if(!a_visitor.visit("fDimension",(int)a_prof    
632   if(!a_visitor.visit("fBinNumber",(int)a_prof    
633                                                   
634   std::vector<int> bins_entries;                  
635   convert<unsigned int,int>(a_prof.bins_entrie    
636   if(!a_visitor.visit("fBinEntries",bins_entri    
637                                                   
638   if(!a_visitor.visit("fBinSw",a_prof.bins_sum    
639   if(!a_visitor.visit("fBinSw2",a_prof.bins_su    
640   if(!a_visitor.visit("fBinSxw",a_prof.bins_su    
641   if(!a_visitor.visit("fBinSx2w",a_prof.bins_s    
642   std::string name;                               
643   for(unsigned int iaxis=0;iaxis<a_prof.dimens    
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 fal    
648   }                                               
649  {int dummy = 0;                                  
650   if(!a_visitor.visit("fMode",dummy)) return f    
651   if(!a_visitor.visit("fProfile",true)) return    
652   if(!a_visitor.visit("fBinSvw",a_prof.bins_su    
653   if(!a_visitor.visit("fBinSv2w",a_prof.bins_s    
654   if(!a_visitor.visit("fCutV",a_prof.cut_v()))    
655   if(!a_visitor.visit("fMinV",a_prof.min_v()))    
656   if(!a_visitor.visit("fMaxV",a_prof.max_v()))    
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:                                           
666   TOOLS_T_SCLASS(PROF,tools::osc::Profile)        
667 protected:                                        
668   virtual void* cast(const std::string& a_clas    
669     if(void* p = cmp_cast<Profile>(this,a_clas    
670     return 0;                                     
671   }                                               
672 public:                                           
673   virtual const std::string& store_cls() const    
674   virtual bool visit(iobj_const_visitor& a_v)     
675     if(!a_v.begin(*this,m_cls,Profile::s_visit    
676                                                   
677     int version = 1;                              
678     if(!a_v.visit("fVersion",version)) return     
679                                                   
680     BaseHistogram<PROF> bh(m_hist);               
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,iob    
690     const Profile* local = safe_cast<istorable    
691     if(!local) return false;                      
692     return local->Profile::visit(a_v); //IMPOR    
693   }                                               
694 public:                                           
695   Profile(const PROF& a_hist,const std::string    
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_vi    
714   if(!a_visitor.visit(aData.m_title)) return f    
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_en    
727                                                   
728   if(!a_visitor.visit(aData.m_bin_Sw)) return     
729   if(!a_visitor.visit(aData.m_bin_Sw2)) return    
730   if(!a_visitor.visit(aData.m_bin_Sxw)) return    
731   if(!a_visitor.visit(aData.m_bin_Sx2w)) retur    
732   aData.m_axes.clear();                           
733   for(unsigned int iaxis=0;iaxis<aData.m_dimen    
734     histo::axis<double,unsigned int> baxis;       
735     if(!Axis_read(a_visitor,baxis)) return fal    
736     aData.m_axes.push_back(baxis);                
737   }                                               
738  {int dummy;                                      
739   if(!a_visitor.visit(dummy)) return false;} /    
740   if(!a_visitor.visit(aData.m_is_profile)) ret    
741   if(!a_visitor.visit(aData.m_bin_Svw)) return    
742   if(!a_visitor.visit(aData.m_bin_Sv2w)) retur    
743   if(!a_visitor.visit(aData.m_cut_v)) return f    
744   if(!a_visitor.visit(aData.m_min_v)) return f    
745   if(!a_visitor.visit(aData.m_max_v)) return f    
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,cons    
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    
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 byteswa    
769     a_visitor.out() << "tools::osc::read :"       
770                     << " unexpected version "     
771                     << std::endl;                 
772     return false;                                 
773   }                                               
774                                                   
775                                                   
776   if(!BaseHistogram_read(a_visitor)) return fa    
777                                                   
778   pd_data hdata;                                  
779   if(!readProfile(hdata,a_visitor)) return fal    
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,cons    
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    
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 byteswa    
803     a_visitor.out() << "tools::osc::read :"       
804                     << " unexpected version "     
805                     << std::endl;                 
806     return false;                                 
807   }                                               
808                                                   
809                                                   
810   if(!BaseHistogram_read(a_visitor)) return fa    
811                                                   
812   pd_data hdata;                                  
813   if(!readProfile(hdata,a_visitor)) return fal    
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::stri    
830   :parent(m_cp,a_cls) //give ref of m_cp to Hi    
831   ,m_cp(a_h)   //do a local copy.                 
832   //WARNING : the upper is ok as long as Histo    
833   //          else than keeping the ref to m_c    
834   //          something on an empty histo (and    
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   {}                                              
844   Histogram_cp& operator=(const Histogram_cp&     
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    
858   :parent(m_cp,a_cls) //give ref of m_cp to Pr    
859   ,m_cp(a_p)   //do a local copy.                 
860   //WARNING : the upper is ok as long as Profi    
861   //          else than keeping the ref to m_c    
862   //          something on an empty histo (and    
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_fr    
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