Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/store/osc_streamers is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_store_osc_streamers
0005 #define tools_store_osc_streamers
0006 
0007 #include "iobj_const_visitor"
0008 #include "iobj_visitor"
0009 
0010 #include "../histo/h1d"
0011 #include "../histo/h2d"
0012 #include "../histo/h3d"
0013 #include "../histo/p1d"
0014 #include "../histo/p2d"
0015 #include "../vmanip"
0016 #include "../sto"
0017 #include "../num2s"
0018 #include "../S_STRING"
0019 #include "../scast"
0020 
0021 namespace tools {
0022 namespace osc {
0023 
0024 inline const std::string& s_axis() {
0025   static const std::string s_v("BatchLab::Axis");
0026   return s_v;
0027 }
0028 inline const std::string& s_annotation() {
0029   static const std::string s_v("BatchLab::Annotation");
0030   return s_v;
0031 }
0032 inline const std::string& s_base_histogram() {
0033   static const std::string s_v("BatchLab::BaseHistogram");
0034   return s_v;
0035 }
0036 inline const std::string& s_item() {
0037   static const std::string s_v("BatchLab::Item");
0038   return s_v;
0039 }
0040 
0041 inline const std::string& s_h1d() {
0042   static const std::string s_v("BatchLab::Histogram1D");
0043   return s_v;
0044 }
0045 
0046 inline const std::string& s_h2d() {
0047   static const std::string s_v("BatchLab::Histogram2D");
0048   return s_v;
0049 }
0050 
0051 inline const std::string& s_h3d() {
0052   static const std::string s_v("BatchLab::Histogram3D");
0053   return s_v;
0054 }
0055 
0056 inline const std::string& s_p1d() {
0057   static const std::string s_v("BatchLab::Profile1D");
0058   return s_v;
0059 }
0060 
0061 inline const std::string& s_p2d() {
0062   static const std::string s_v("BatchLab::Profile2D");
0063   return s_v;
0064 }
0065 
0066 class Axis : public virtual istorable {
0067 public:
0068   TOOLS_SCLASS(tools::osc::Axis)
0069 protected:
0070   virtual void* cast(const std::string& a_class) const {
0071     if(void* p = cmp_cast<Axis>(this,a_class)) return p;
0072     return 0;
0073   }
0074   virtual const std::string& store_cls() const {return s_axis();}
0075   virtual bool visit(iobj_const_visitor& a_v) const {
0076     if(!a_v.begin(*this,s_axis(),Axis::s_visit)) return false;
0077 
0078     int version = 1;
0079     if(!a_v.visit("fVersion",version)) return false;
0080 
0081     if(!a_v.visit("fOffset",m_axis.m_offset)) return false;
0082     if(!a_v.visit("fNumberOfBins",(int)m_axis.m_number_of_bins)) return false;
0083     if(!a_v.visit("fMinimumValue",m_axis.m_minimum_value)) return false;
0084     if(!a_v.visit("fMaximumValue",m_axis.m_maximum_value)) return false;
0085     if(!a_v.visit("fFixed",m_axis.m_fixed)) return false;
0086     if(!a_v.visit("fBinWidth",m_axis.m_bin_width)) return false;
0087     if(!a_v.visit("fEdges",m_axis.m_edges)) return false;
0088 
0089     if(!a_v.end(*this)) return false;
0090     return true;
0091   }
0092   static bool s_visit(const istorable& a_o,iobj_const_visitor& a_v){
0093     const Axis* local = safe_cast<istorable,Axis>(a_o);
0094     if(!local) return false;
0095     return local->Axis::visit(a_v); //IMPORTANT : have Axis::
0096   }
0097 public:
0098   Axis(const histo::axis<double,unsigned int>& a_axis):m_axis(a_axis){}
0099   virtual ~Axis(){}
0100 private:
0101   Axis(const Axis& a_from):istorable(a_from),m_axis(a_from.m_axis){}
0102   Axis& operator=(const Axis&){return *this;}
0103 protected:
0104   const histo::axis<double,unsigned int>& m_axis;
0105 };
0106 
0107 
0108 inline bool Axis_read(iobj_visitor& a_visitor,histo::axis<double,unsigned int>& a_axis){
0109   //if(!a_visitor.begin(*this)) return false;
0110 
0111   int version;
0112   if(!a_visitor.visit(version)) return false;
0113 
0114   if(!a_visitor.visit(a_axis.m_offset)) return false;
0115 
0116  {int nbin;
0117   if(!a_visitor.visit(nbin)) return false;
0118   a_axis.m_number_of_bins = nbin;}
0119 
0120   if(!a_visitor.visit(a_axis.m_minimum_value)) return false;
0121   if(!a_visitor.visit(a_axis.m_maximum_value)) return false;
0122   if(!a_visitor.visit(a_axis.m_fixed)) return false;
0123   if(!a_visitor.visit(a_axis.m_bin_width)) return false;
0124   if(!a_visitor.visit(a_axis.m_edges)) return false;
0125 
0126   //if(!a_visitor.end(*this)) return false;
0127   return true;
0128 }
0129 
0130 class Item : public virtual istorable {
0131 public:
0132   TOOLS_SCLASS(tools::osc::Item)
0133 protected:
0134   virtual void* cast(const std::string& a_class) const {
0135     if(void* p = cmp_cast<Item>(this,a_class)) return p;
0136     return 0;
0137   }
0138 public:
0139   virtual const std::string& store_cls() const {return s_item();}
0140   virtual bool visit(iobj_const_visitor& a_visitor) const {
0141     if(!a_visitor.begin(*this,s_item(),Item::s_visit)) return false;
0142 
0143     int version = 1;
0144     if(!a_visitor.visit("fVersion",version)) return false;
0145 
0146     if(!a_visitor.visit("fKey",fKey)) return false;
0147     if(!a_visitor.visit("fValue",fValue)) return false;
0148     if(!a_visitor.visit("fSticky",fSticky)) return false;
0149 
0150     if(!a_visitor.end(*this)) return false;
0151     return true;
0152   }
0153   static bool s_visit(const istorable& a_o,iobj_const_visitor& a_v){
0154     const Item* local = safe_cast<istorable,Item>(a_o);
0155     if(!local) return false;
0156     return local->Item::visit(a_v); //IMPORTANT : have Item::
0157   }
0158 public:
0159   virtual bool read(iobj_visitor& a_visitor) {
0160     //if(!a_visitor.begin(*this)) return false;
0161 
0162     int version;
0163     if(!a_visitor.visit(version)) return false;
0164 
0165     if(!a_visitor.visit(fKey)) return false;
0166     if(!a_visitor.visit(fValue)) return false;
0167     if(!a_visitor.visit(fSticky)) return false;
0168 
0169     //if(!a_visitor.end(*this)) return false;
0170     return true;
0171   }
0172 public:
0173   Item(){}
0174   Item(const std::string& aKey,const std::string& aValue,bool aSticky)
0175   :fKey(aKey),fValue(aValue),fSticky(aSticky){}
0176   virtual ~Item(){}
0177 public:
0178   Item(const Item& a_from)
0179   :istorable(a_from)
0180   ,fKey(a_from.fKey)
0181   ,fValue(a_from.fValue)
0182   ,fSticky(a_from.fSticky)
0183   {}
0184   Item& operator=(const Item& a_from) {
0185     if(&a_from==this) return *this;
0186     fKey = a_from.fKey;
0187     fValue = a_from.fValue;
0188     fSticky = a_from.fSticky;
0189     return *this;
0190   }
0191 public:
0192   std::string fKey;
0193   std::string fValue;
0194   bool fSticky;
0195 };
0196 
0197 
0198 template <class T>
0199 class Vector : public virtual istorable {
0200 public:
0201   TOOLS_T_SCLASS(T,tools::osc::Vector)
0202 protected:
0203   virtual void* cast(const std::string& a_class) const {
0204     if(void* p = cmp_cast<Vector>(this,a_class)) return p;
0205     return 0;
0206   }
0207   virtual const std::string& store_cls() const {
0208     static const std::string s_v("BatchLab::Vector<"+m_T+">");
0209     return s_v;
0210   }
0211   virtual bool visit(iobj_const_visitor& a_v) const {
0212     if(!a_v.begin(*this,Vector<T>::store_cls(),Vector<T>::s_visit)) return false;
0213 
0214     int version = 1;
0215     if(!a_v.visit("fVersion",version)) return false;
0216 
0217     unsigned int number = (unsigned int)m_vec.size();
0218     if(!a_v.visit("fSize",number)) return false;
0219 
0220     std::string stmp;
0221     for(unsigned int index=0;index<number;index++) {
0222       const T& elem = m_vec[index];
0223       if(!num2s(index,stmp)) return false;
0224       if(!a_v.visit(stmp,elem)) return false;
0225     }
0226 
0227     if(!a_v.end(*this)) return false;
0228     return true;
0229   }
0230   static bool s_visit(const istorable& a_o,iobj_const_visitor& a_v){
0231     const Vector* local = safe_cast<istorable,Vector>(a_o);
0232     if(!local) return false;
0233     return local->Vector<T>::visit(a_v); //IMPORTANT : have Vector::
0234   }
0235 public:
0236   Vector(const std::vector<T>& a_vec,const std::string& a_T)
0237   :m_vec(a_vec),m_T(a_T){}
0238   virtual ~Vector(){}
0239 private:
0240   Vector(const Vector& a_from)
0241   :istorable(a_from),m_vec(a_from.m_vec),m_T(a_from.m_T){}
0242   Vector& operator=(const Vector&){return *this;}
0243 protected:
0244   const std::vector<T>& m_vec;
0245   std::string m_T;
0246 };
0247 
0248 
0249 template <class T>
0250 inline bool std_vector_read(iobj_visitor& a_visitor,std::vector<T>& a_vec) {
0251   a_vec.clear();
0252 
0253   //if(!a_visitor.begin(*this)) return false;
0254 
0255   int version;
0256   if(!a_visitor.visit(version)) return false;
0257 
0258   unsigned int number;
0259   if(!a_visitor.visit(number)) return false;
0260 
0261   a_vec.resize(number);
0262   for(unsigned int index=0;index<number;index++) {
0263     T& elem = a_vec[index];
0264     if(!elem.read(a_visitor)) return false;
0265   }
0266 
0267   //if(!a_visitor.end(*this)) return false;
0268   return true;
0269 }
0270 
0271 class Annotation : public virtual istorable {
0272 public:
0273   TOOLS_SCLASS(tools::osc::Annotation)
0274 protected:
0275   virtual void* cast(const std::string& a_class) const {
0276     if(void* p = cmp_cast<Annotation>(this,a_class)) return p;
0277     return 0;
0278   }
0279   virtual const std::string& store_cls() const {return s_annotation();}
0280   virtual bool visit(iobj_const_visitor& a_v) const {
0281     if(!a_v.begin(*this,s_annotation(),Annotation::s_visit)) return false;
0282 
0283     int version = 1;
0284     if(!a_v.visit("fVersion",version)) return false;
0285 
0286     Vector<Item> v(m_items,s_item());
0287     if(!a_v.visit("fItems",v)) return false;
0288 
0289     if(!a_v.end(*this)) return false;
0290     return true;
0291   }
0292   static bool s_visit(const istorable& a_o,iobj_const_visitor& a_v){
0293     const Annotation* local = safe_cast<istorable,Annotation>(a_o);
0294     if(!local) return false;
0295     return local->Annotation::visit(a_v); //IMPORTANT : have Annotation::
0296   }
0297 public:
0298   Annotation(){}
0299   virtual ~Annotation(){}
0300 private:
0301   Annotation(const Annotation& a_from):istorable(a_from){}
0302   Annotation& operator=(const Annotation&){return *this;}
0303 public:
0304   std::vector<Item> m_items;
0305 };
0306 
0307 inline bool Annotation_read(iobj_visitor& a_visitor) {
0308   //if(!a_visitor.begin(*this)) return false;
0309   int version;
0310   if(!a_visitor.visit(version)) return false;
0311   std::vector<Item> fItems;
0312   if(!std_vector_read<Item>(a_visitor,fItems)) return false;
0313   //if(!a_visitor.end(*this)) return false;
0314   return true;
0315 }
0316 
0317 inline void map2vec(const std::map<std::string,std::string>& a_in,std::vector<Item>& a_out) {
0318   a_out.clear();
0319   std::map<std::string,std::string>::const_iterator it;
0320   for(it=a_in.begin();it!=a_in.end();++it) {
0321     a_out.push_back(Item((*it).first,(*it).second,false));
0322   }
0323 }
0324 
0325 typedef histo::histo_data<double,unsigned int,unsigned int,double> hd_data;
0326 
0327 template <class HIST>
0328 class BaseHistogram : public virtual istorable {
0329 public:
0330   TOOLS_T_SCLASS(HIST,tools::osc::BaseHistogram)
0331 protected:
0332   virtual void* cast(const std::string& a_class) const {
0333     if(void* p = cmp_cast<BaseHistogram>(this,a_class)) return p;
0334     return 0;
0335   }
0336 public:
0337   virtual const std::string& store_cls() const {return s_base_histogram();}
0338   virtual bool visit(iobj_const_visitor& a_v) const {
0339     if(!a_v.begin(*this,s_base_histogram(),BaseHistogram::s_visit)) return false;
0340 
0341     int version = 1;
0342     if(!a_v.visit("fVersion",version)) return false;
0343 
0344     Annotation ano;
0345     map2vec(m_hist.annotations(),ano.m_items);
0346     if(!a_v.visit("fAnnotation",ano)) return false;
0347 
0348     if(!a_v.end(*this)) return false;
0349     return true;
0350   }
0351 protected:
0352   static bool s_visit(const istorable& a_o,iobj_const_visitor& a_v){
0353     const BaseHistogram* local =
0354       safe_cast<istorable,BaseHistogram>(a_o);
0355     if(!local) return false;
0356     return local->BaseHistogram::visit(a_v); //IMPORTANT : have BaseHistogram::
0357   }
0358 public:
0359   BaseHistogram(const HIST& a_hist):m_hist(a_hist){}
0360   virtual ~BaseHistogram(){}
0361 private:
0362   BaseHistogram(const BaseHistogram& a_from)
0363   :istorable(a_from),m_hist(a_from.m_hist)
0364   {}
0365   BaseHistogram& operator=(const BaseHistogram&){return *this;}
0366 protected:
0367   const HIST& m_hist;
0368 };
0369 
0370 inline bool BaseHistogram_read(iobj_visitor& a_visitor){
0371   //if(!a_visitor.begin(*this)) return false;
0372 
0373   int version;
0374   if(!a_visitor.visit(version)) return false;
0375 
0376   if(!Annotation_read(a_visitor)) return false;
0377 
0378   //if(!a_visitor.end(*this)) return false;
0379   return true;
0380 }
0381 
0382 template <class HIST>
0383 inline bool visitHistogram(const HIST& a_hist,iobj_const_visitor& a_visitor){
0384   if(!a_visitor.visit("fTitle",a_hist.title())) return false;
0385   if(!a_visitor.visit("fDimension",(int)a_hist.dimension())) return false;
0386   if(!a_visitor.visit("fBinNumber",(int)a_hist.get_bins())) return false;
0387 
0388   std::vector<int> bins_entries;
0389   convert<unsigned int,int>(a_hist.bins_entries(),bins_entries);
0390   if(!a_visitor.visit("fBinEntries",bins_entries)) return false;
0391 
0392   if(!a_visitor.visit("fBinSw",a_hist.bins_sum_w())) return false;
0393   if(!a_visitor.visit("fBinSw2",a_hist.bins_sum_w2())) return false;
0394   if(!a_visitor.visit("fBinSxw",a_hist.bins_sum_xw())) return false;
0395   if(!a_visitor.visit("fBinSx2w",a_hist.bins_sum_x2w())) return false;
0396  {std::string name;
0397   for(unsigned int iaxis=0;iaxis<a_hist.dimension();iaxis++) {
0398     if(!num2s(iaxis,name)) return false;
0399     name = "fAxes_"+name;
0400     Axis axis(a_hist.get_axis(iaxis));
0401     if(!a_visitor.visit(name,axis)) return false;
0402   }}
0403  {int dummy = 0;
0404   if(!a_visitor.visit("fMode",dummy)) return false;} //m_mode
0405   if(!a_visitor.visit("fProfile",false)) return false;
0406  {std::vector<double> dummy;
0407   if(!a_visitor.visit("fBinSvw",dummy)) return false;
0408   if(!a_visitor.visit("fBinSv2w",dummy)) return false;}
0409   if(!a_visitor.visit("fCutV",false)) return false;
0410  {double dummy = 0;
0411   if(!a_visitor.visit("fMinV",dummy)) return false;
0412   if(!a_visitor.visit("fMaxV",dummy)) return false;}
0413   // Not written :
0414   //a_hist.fDoubles
0415   //a_hist.fInts
0416   return true;
0417 }
0418 
0419 inline bool readHistogram(hd_data& aData,iobj_visitor& a_visitor){
0420   if(!a_visitor.visit(aData.m_title)) return false;
0421  {int dim;
0422   if(!a_visitor.visit(dim)) return false;
0423   aData.m_dimension = dim;}
0424 
0425  {int nbin;
0426   if(!a_visitor.visit(nbin)) return false;
0427   aData.m_bin_number = nbin;}
0428 
0429  {std::vector<int> vec;
0430   if(!a_visitor.visit(vec)) return false;
0431   convert<int,unsigned int>(vec,aData.m_bin_entries);}
0432 
0433   if(!a_visitor.visit(aData.m_bin_Sw)) return false;
0434   if(!a_visitor.visit(aData.m_bin_Sw2)) return false;
0435   if(!a_visitor.visit(aData.m_bin_Sxw)) return false;
0436   if(!a_visitor.visit(aData.m_bin_Sx2w)) return false;
0437   aData.m_axes.clear();
0438   for(unsigned int iaxis=0;iaxis<aData.m_dimension;iaxis++) {
0439     histo::axis<double,unsigned int> baxis;
0440     if(!Axis_read(a_visitor,baxis)) return false;
0441     aData.m_axes.push_back(baxis);
0442   }
0443  {int dummy;
0444   if(!a_visitor.visit(dummy)) return false;} //m_mode
0445 
0446  {bool dummy;
0447   if(!a_visitor.visit(dummy)) return false;} //m_is_profile
0448 
0449  {std::vector<double> dummy;
0450   if(!a_visitor.visit(dummy)) return false;} //m_bin_Svw
0451 
0452  {std::vector<double> dummy;
0453   if(!a_visitor.visit(dummy)) return false;} //m_bin_Sv2w
0454 
0455  {bool dummy;
0456   if(!a_visitor.visit(dummy)) return false;} //m_cut_v
0457 
0458  {double dummy;
0459   if(!a_visitor.visit(dummy)) return false;} //aData.m_min_v
0460 
0461  {double dummy;
0462   if(!a_visitor.visit(dummy)) return false;} //aData.m_max_v
0463 
0464   //aData.fDoubles
0465   //aData.fInts
0466   //aData.m_coords.resize(aData.m_dimension,0);
0467   //aData.m_ints.resize(aData.m_dimension,0);
0468 
0469   return true;
0470 }
0471 
0472 template <class HIST>
0473 class Histogram : public virtual istorable {
0474 public:
0475   TOOLS_T_SCLASS(HIST,tools::osc::Histogram)
0476 protected:
0477   virtual void* cast(const std::string& a_class) const {
0478     if(void* p = cmp_cast<Histogram>(this,a_class)) return p;
0479     return 0;
0480   }
0481 public:
0482   virtual const std::string& store_cls() const {return m_cls;}
0483   virtual bool visit(iobj_const_visitor& a_v) const {
0484     if(!a_v.begin(*this,m_cls,Histogram::s_visit)) return false;
0485 
0486     int version = 1;
0487     if(!a_v.visit("fVersion",version)) return false;
0488 
0489     BaseHistogram<HIST> bh(m_hist);
0490     if(!bh.visit(a_v)) return false;
0491 
0492     if(!visitHistogram(m_hist,a_v)) return false;
0493 
0494     if(!a_v.end(*this)) return false;
0495     return true;
0496   }
0497 protected:
0498   static bool s_visit(const istorable& a_o,iobj_const_visitor& a_v){
0499     const Histogram* local = safe_cast<istorable,Histogram>(a_o);
0500     if(!local) return false;
0501     return local->Histogram::visit(a_v); //IMPORTANT : have Histogram::
0502   }
0503 public:
0504   Histogram(const HIST& a_hist,const std::string& a_cls)
0505   :m_hist(a_hist),m_cls(a_cls){}
0506   virtual ~Histogram(){}
0507 public:
0508   Histogram(const Histogram& a_from)
0509   :istorable(a_from)
0510   ,m_hist(a_from.m_hist)
0511   ,m_cls(a_from.m_cls)
0512   {}
0513   Histogram& operator=(const Histogram& a_from){
0514     m_cls = a_from.m_cls;
0515     return *this;
0516   }
0517 protected:
0518   const HIST& m_hist;
0519   std::string m_cls;
0520 };
0521 
0522 inline bool visit(iobj_const_visitor& a_v,const histo::h1d& a_histo) {
0523   Histogram<histo::h1d> h(a_histo,s_h1d());
0524   return h.visit(a_v);
0525 }
0526 
0527 inline bool read(iobj_visitor& a_visitor,histo::h1d& a_histo){
0528   //if(!a_visitor.begin(*this)) return false;
0529 
0530   int version;
0531   if(!a_visitor.visit(version)) return false;
0532 
0533   if(version!=1) {
0534     //this may come from an unexpected byteswap.
0535     a_visitor.out() << "tools::osc::read :"
0536                     << " unexpected version " << version
0537                     << std::endl;
0538     return false;
0539   }
0540 
0541   if(!BaseHistogram_read(a_visitor)) return false;
0542 
0543   hd_data hdata;
0544   if(!readHistogram(hdata,a_visitor)) return false;
0545 
0546   hdata.update_fast_getters();
0547   a_histo.copy_from_data(hdata);
0548 
0549   //fAxis.copy(fHistogram.get_axis(0));
0550 
0551   //if(!a_visitor.end(*this)) return false;
0552 
0553   return true;
0554 }
0555 
0556 inline bool visit(iobj_const_visitor& a_v,const histo::h2d& a_histo) {
0557   Histogram<histo::h2d> h(a_histo,s_h2d());
0558   return h.visit(a_v);
0559 }
0560 
0561 inline bool read(iobj_visitor& a_visitor,histo::h2d& a_histo){
0562   //if(!a_visitor.begin(*this)) return false;
0563 
0564   int version;
0565   if(!a_visitor.visit(version)) return false;
0566 
0567   if(version!=1) {
0568     //this may come from an unexpected byteswap.
0569     a_visitor.out() << "tools::osc::read :"
0570                     << " unexpected version " << version
0571                     << std::endl;
0572     return false;
0573   }
0574 
0575   if(!BaseHistogram_read(a_visitor)) return false;
0576 
0577   hd_data hdata;
0578   if(!readHistogram(hdata,a_visitor)) return false;
0579 
0580   hdata.update_fast_getters();
0581   a_histo.copy_from_data(hdata);
0582 
0583   //fAxisX.copy(fHistogram.get_axis(0));
0584   //fAxisY.copy(fHistogram.get_axis(1));
0585 
0586   //if(!a_visitor.end(*this)) return false;
0587 
0588   return true;
0589 }
0590 
0591 inline bool visit(iobj_const_visitor& a_v,const histo::h3d& a_histo) {
0592   Histogram<histo::h3d> h(a_histo,s_h3d());
0593   return h.visit(a_v);
0594 }
0595 
0596 inline bool read(iobj_visitor& a_visitor,histo::h3d& a_histo){
0597   //if(!a_visitor.begin(*this)) return false;
0598 
0599   int version;
0600   if(!a_visitor.visit(version)) return false;
0601 
0602   if(version!=1) {
0603     //this may come from an unexpected byteswap.
0604     a_visitor.out() << "tools::osc::read :"
0605                     << " unexpected version " << version
0606                     << std::endl;
0607     return false;
0608   }
0609 
0610   if(!BaseHistogram_read(a_visitor)) return false;
0611 
0612   hd_data hdata;
0613   if(!readHistogram(hdata,a_visitor)) return false;
0614   hdata.update_fast_getters();
0615   a_histo.copy_from_data(hdata);
0616 
0617   //fAxisX.copy(fHistogram.get_axis(0));
0618   //fAxisY.copy(fHistogram.get_axis(1));
0619   //fAxisZ.copy(fHistogram.get_axis(2));
0620 
0621   //if(!a_visitor.end(*this)) return false;
0622 
0623   return true;
0624 }
0625 
0626 typedef histo::profile_data<double,unsigned int,unsigned int,double,double> pd_data;
0627 
0628 template <class PROF>
0629 inline bool visitProfile(const PROF& a_prof,iobj_const_visitor& a_visitor){
0630   if(!a_visitor.visit("fTitle",a_prof.title())) return false;
0631   if(!a_visitor.visit("fDimension",(int)a_prof.dimension())) return false;
0632   if(!a_visitor.visit("fBinNumber",(int)a_prof.get_bins())) return false;
0633 
0634   std::vector<int> bins_entries;
0635   convert<unsigned int,int>(a_prof.bins_entries(),bins_entries);
0636   if(!a_visitor.visit("fBinEntries",bins_entries)) return false;
0637 
0638   if(!a_visitor.visit("fBinSw",a_prof.bins_sum_w())) return false;
0639   if(!a_visitor.visit("fBinSw2",a_prof.bins_sum_w2())) return false;
0640   if(!a_visitor.visit("fBinSxw",a_prof.bins_sum_xw())) return false;
0641   if(!a_visitor.visit("fBinSx2w",a_prof.bins_sum_x2w())) return false;
0642   std::string name;
0643   for(unsigned int iaxis=0;iaxis<a_prof.dimension();iaxis++) {
0644     if(!num2s(iaxis,name)) return false;
0645     name = "fAxes_"+name;
0646     Axis axis(a_prof.get_axis(iaxis));
0647     if(!a_visitor.visit(name,axis)) return false;
0648   }
0649  {int dummy = 0;
0650   if(!a_visitor.visit("fMode",dummy)) return false;} //m_mode
0651   if(!a_visitor.visit("fProfile",true)) return false;
0652   if(!a_visitor.visit("fBinSvw",a_prof.bins_sum_vw())) return false;
0653   if(!a_visitor.visit("fBinSv2w",a_prof.bins_sum_v2w())) return false;
0654   if(!a_visitor.visit("fCutV",a_prof.cut_v())) return false;
0655   if(!a_visitor.visit("fMinV",a_prof.min_v())) return false;
0656   if(!a_visitor.visit("fMaxV",a_prof.max_v())) return false;
0657   // Not written :
0658   //a_prof.fDoubles
0659   //a_prof.fInts
0660   return true;
0661 }
0662 
0663 template <class PROF>
0664 class Profile : public virtual istorable {
0665 public:
0666   TOOLS_T_SCLASS(PROF,tools::osc::Profile)
0667 protected:
0668   virtual void* cast(const std::string& a_class) const {
0669     if(void* p = cmp_cast<Profile>(this,a_class)) return p;
0670     return 0;
0671   }
0672 public:
0673   virtual const std::string& store_cls() const {return m_cls;}
0674   virtual bool visit(iobj_const_visitor& a_v) const {
0675     if(!a_v.begin(*this,m_cls,Profile::s_visit)) return false;
0676 
0677     int version = 1;
0678     if(!a_v.visit("fVersion",version)) return false;
0679 
0680     BaseHistogram<PROF> bh(m_hist);
0681     if(!bh.visit(a_v)) return false;
0682 
0683     if(!visitProfile(m_hist,a_v)) return false;
0684 
0685     if(!a_v.end(*this)) return false;
0686     return true;
0687   }
0688 protected:
0689   static bool s_visit(const istorable& a_o,iobj_const_visitor& a_v){
0690     const Profile* local = safe_cast<istorable,Profile>(a_o);
0691     if(!local) return false;
0692     return local->Profile::visit(a_v); //IMPORTANT : have Profile::
0693   }
0694 public:
0695   Profile(const PROF& a_hist,const std::string& a_cls)
0696   :m_hist(a_hist),m_cls(a_cls){}
0697   virtual ~Profile(){}
0698 public:
0699   Profile(const Profile& a_from)
0700   :istorable(a_from)
0701   ,m_hist(a_from.m_hist)
0702   ,m_cls(a_from.m_cls)
0703   {}
0704   Profile& operator=(const Profile& a_from){
0705     m_cls = a_from.m_cls;
0706     return *this;
0707   }
0708 protected:
0709   const PROF& m_hist;
0710   std::string m_cls;
0711 };
0712 
0713 inline bool readProfile(pd_data& aData,iobj_visitor& a_visitor){
0714   if(!a_visitor.visit(aData.m_title)) return false;
0715 
0716  {int dim;
0717   if(!a_visitor.visit(dim)) return false;
0718   aData.m_dimension = dim;}
0719 
0720  {int nbin;
0721   if(!a_visitor.visit(nbin)) return false;
0722   aData.m_bin_number = nbin;}
0723 
0724  {std::vector<int> vec;
0725   if(!a_visitor.visit(vec)) return false;
0726   convert<int,unsigned int>(vec,aData.m_bin_entries);}
0727 
0728   if(!a_visitor.visit(aData.m_bin_Sw)) return false;
0729   if(!a_visitor.visit(aData.m_bin_Sw2)) return false;
0730   if(!a_visitor.visit(aData.m_bin_Sxw)) return false;
0731   if(!a_visitor.visit(aData.m_bin_Sx2w)) return false;
0732   aData.m_axes.clear();
0733   for(unsigned int iaxis=0;iaxis<aData.m_dimension;iaxis++) {
0734     histo::axis<double,unsigned int> baxis;
0735     if(!Axis_read(a_visitor,baxis)) return false;
0736     aData.m_axes.push_back(baxis);
0737   }
0738  {int dummy;
0739   if(!a_visitor.visit(dummy)) return false;} //m_mode
0740   if(!a_visitor.visit(aData.m_is_profile)) return false;
0741   if(!a_visitor.visit(aData.m_bin_Svw)) return false;
0742   if(!a_visitor.visit(aData.m_bin_Sv2w)) return false;
0743   if(!a_visitor.visit(aData.m_cut_v)) return false;
0744   if(!a_visitor.visit(aData.m_min_v)) return false;
0745   if(!a_visitor.visit(aData.m_max_v)) return false;
0746 
0747   // Not written :
0748   //aData.fDoubles
0749   //aData.fInts
0750   //aData.m_coords.resize(aData.m_dimension,0);
0751   //aData.m_ints.resize(aData.m_dimension,0);
0752 
0753   return true;
0754 }
0755 
0756 inline bool visit(iobj_const_visitor& a_v,const histo::p1d& a_histo) {
0757   Profile<histo::p1d> h(a_histo,s_p1d());
0758   return h.visit(a_v);
0759 }
0760 
0761 inline bool read(iobj_visitor& a_visitor,histo::p1d& a_histo){
0762   //if(!a_visitor.begin(*this)) return false;
0763 
0764   int version;
0765   if(!a_visitor.visit(version)) return false;
0766 
0767   if(version!=1) {
0768     //this may come from an unexpected byteswap.
0769     a_visitor.out() << "tools::osc::read :"
0770                     << " unexpected version " << version
0771                     << std::endl;
0772     return false;
0773   }
0774 
0775 
0776   if(!BaseHistogram_read(a_visitor)) return false;
0777 
0778   pd_data hdata;
0779   if(!readProfile(hdata,a_visitor)) return false;
0780   hdata.update_fast_getters();
0781   a_histo.copy_from_data(hdata);
0782 
0783   //fAxis.copy(fHistogram.get_axis(0));
0784 
0785   //if(!a_visitor.end(*this)) return false;
0786 
0787   return true;
0788 }
0789 
0790 inline bool visit(iobj_const_visitor& a_v,const histo::p2d& a_histo) {
0791   Profile<histo::p2d> h(a_histo,s_p2d());
0792   return h.visit(a_v);
0793 }
0794 
0795 inline bool read(iobj_visitor& a_visitor,histo::p2d& a_histo){
0796   //if(!a_visitor.begin(*this)) return false;
0797 
0798   int version;
0799   if(!a_visitor.visit(version)) return false;
0800 
0801   if(version!=1) {
0802     //this may come from an unexpected byteswap.
0803     a_visitor.out() << "tools::osc::read :"
0804                     << " unexpected version " << version
0805                     << std::endl;
0806     return false;
0807   }
0808 
0809 
0810   if(!BaseHistogram_read(a_visitor)) return false;
0811 
0812   pd_data hdata;
0813   if(!readProfile(hdata,a_visitor)) return false;
0814   hdata.update_fast_getters();
0815   a_histo.copy_from_data(hdata);
0816 
0817   //fAxisX.copy(a_histo.get_axis(0));
0818   //fAxisY.copy(a_histo.get_axis(1));
0819 
0820   //if(!a_visitor.end(*this)) return false;
0821 
0822   return true;
0823 }
0824 
0825 template <class HIST>
0826 class Histogram_cp : public Histogram<HIST> {
0827   typedef Histogram<HIST> parent;
0828 public:
0829   Histogram_cp(const HIST& a_h,const std::string& a_cls)
0830   :parent(m_cp,a_cls) //give ref of m_cp to Histogram.
0831   ,m_cp(a_h)   //do a local copy.
0832   //WARNING : the upper is ok as long as Histogram constructor does nothing
0833   //          else than keeping the ref to m_cp. Else it would do
0834   //          something on an empty histo (and not on a copy of the
0835   //          passed a_data).
0836   {}
0837   virtual ~Histogram_cp(){}
0838 public:
0839   Histogram_cp(const Histogram_cp& a_from)
0840   :istorable(a_from)
0841   ,parent(m_cp,a_from.m_cls)
0842   ,m_cp(a_from.m_cp)
0843   {}
0844   Histogram_cp& operator=(const Histogram_cp& a_from){
0845     parent::operator=(a_from);
0846     m_cp = a_from.m_cp;
0847     return *this;
0848   }
0849 protected:
0850   HIST m_cp;
0851 };
0852 
0853 template <class PROF>
0854 class Profile_cp : public Profile<PROF> {
0855   typedef Profile<PROF> parent;
0856 public:
0857   Profile_cp(const PROF& a_p,const std::string& a_cls)
0858   :parent(m_cp,a_cls) //give ref of m_cp to Profile.
0859   ,m_cp(a_p)   //do a local copy.
0860   //WARNING : the upper is ok as long as Profile constructor does nothing
0861   //          else than keeping the ref to m_cp. Else it would do
0862   //          something on an empty histo (and not on a copy of the
0863   //          passed a_data).
0864   {}
0865   virtual ~Profile_cp(){}
0866 public:
0867   Profile_cp(const Profile_cp& a_from)
0868   :istorable(a_from)
0869   ,parent(m_cp,a_from.m_cls)
0870   ,m_cp(a_from.m_cp)
0871   {}
0872   Profile_cp& operator=(const Profile_cp& a_from){
0873     parent::operator=(a_from);
0874     m_cp = a_from.m_cp;
0875     return *this;
0876   }
0877 protected:
0878   PROF m_cp;
0879 };
0880 
0881 }}
0882 
0883 #endif