Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/rroot/THistogram 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_rroot_THistogram
0005 #define tools_rroot_THistogram
0006 
0007 // to read some files produced with BatchLab (opaw/examples/osc/analysis.root).
0008 
0009 #include "../histo/profile_data"
0010 
0011 #include "named"
0012 #include "../vmanip"
0013 
0014 namespace tools {
0015 namespace rroot {
0016 
0017 //typedef histo::histo_data<double,unsigned int,double> hd_data;
0018 typedef histo::profile_data<double,unsigned int,unsigned int,double,double> pd_data_t;
0019 typedef histo::axis<double,unsigned int> axis_t;
0020 typedef std::map<std::string,std::string> annotations_t;
0021 
0022 inline bool Axis_read_v0_v3(buffer& a_buffer,axis_t& a_axis) {
0023   int idummy;
0024   double ddummy;
0025   if(!a_buffer.read(a_axis.m_minimum_value)) return false;
0026   if(!a_buffer.read(a_axis.m_maximum_value)) return false;
0027   if(!a_buffer.read(a_axis.m_offset)) return false;
0028   if(!a_buffer.read(a_axis.m_number_of_bins)) return false;
0029   if(!a_buffer.read(idummy)) return false; //fOverFlow
0030   if(!a_buffer.read(idummy)) return false; //fUnderFlow
0031   if(!a_buffer.read(a_axis.m_bin_width)) return false;
0032   if(!a_buffer.read(ddummy)) return false; //fSxw
0033   if(!a_buffer.read(ddummy)) return false; //fSx2w
0034   a_axis.m_fixed = true;
0035   a_axis.m_edges.clear();
0036   return true;
0037 }
0038 
0039 inline bool Axis_read_v4_v6(buffer& a_buffer,axis_t& a_axis) {
0040   int idummy;
0041   double ddummy;
0042   if(!a_buffer.read(a_axis.m_offset)) return false;
0043   if(!a_buffer.read(idummy)) return false; //fOverFlow
0044   if(!a_buffer.read(idummy)) return false; //fUnderFlow
0045   if(!a_buffer.read(ddummy)) return false; //fSxw
0046   if(!a_buffer.read(ddummy)) return false; //fSx2w
0047   if(!a_buffer.read(a_axis.m_number_of_bins)) return false;
0048   if(!a_buffer.read(a_axis.m_minimum_value)) return false;
0049   if(!a_buffer.read(a_axis.m_maximum_value)) return false;
0050   if(!a_buffer.read(a_axis.m_fixed)) return false;
0051   if(!a_buffer.read(a_axis.m_bin_width)) return false;
0052   int edgen;
0053   if(!a_buffer.read(edgen)) return false;
0054   for(int count=0;count<edgen;count++) {
0055     double value;
0056     if(!a_buffer.read(value)) return false;
0057     a_axis.m_edges.push_back(value);
0058   }
0059   return true;
0060 }
0061 
0062 inline bool Axis_read_v7(buffer& a_buffer,axis_t& a_axis) {
0063   if(!a_buffer.read(a_axis.m_offset)) return false;
0064   if(!a_buffer.read(a_axis.m_number_of_bins)) return false;
0065   if(!a_buffer.read(a_axis.m_minimum_value)) return false;
0066   if(!a_buffer.read(a_axis.m_maximum_value)) return false;
0067   if(!a_buffer.read(a_axis.m_fixed)) return false;
0068   if(!a_buffer.read(a_axis.m_bin_width)) return false;
0069   int edgen;
0070   if(!a_buffer.read(edgen)) return false;
0071   for(int count=0;count<edgen;count++) {
0072     double value;
0073     if(!a_buffer.read(value)) return false;
0074     a_axis.m_edges.push_back(value);
0075   }
0076   return true;
0077 }
0078 
0079 inline unsigned int new_bin_number(const std::vector< axis_t >& aAxes) {
0080   unsigned int number = 1;
0081   for(unsigned int iaxis=0;iaxis<aAxes.size();iaxis++)
0082     number *= (aAxes[iaxis].bins()+2);
0083   return number;
0084 }
0085 
0086 template <class T>
0087 inline void add_outflow(const std::vector< axis_t >& aAxes,std::vector<T>& aVector) {
0088   // aAxes[].m_offset contains the offset without outflow.
0089   std::size_t dim = aAxes.size();
0090   // new size and offsets :
0091   std::vector<int> aoff(dim);
0092 
0093   int newn = 1;
0094  {for(unsigned iaxis=0;iaxis<dim;iaxis++) newn *= (aAxes[iaxis].bins()+2);}
0095 
0096   aoff[0] = 1;
0097  {for(unsigned iaxis=1;iaxis<dim;iaxis++) {
0098     aoff[iaxis] = aoff[iaxis-1] * (aAxes[iaxis-1].bins()+2);
0099   }}
0100   // copy :
0101   std::vector<T> tmp = aVector;
0102   int oldn = (int)tmp.size();
0103   aVector.resize(newn,0);
0104   // Copy :
0105   std::vector<int> is(dim);
0106   int offset;
0107   for(int index=0;index<oldn;index++) {
0108     // Get new offset of index :
0109     offset = index;
0110    {for(int iaxis=(int)dim-1;iaxis>=0;iaxis--) {
0111       is[iaxis] = offset/aAxes[iaxis].m_offset;
0112       offset -= is[iaxis] * aAxes[iaxis].m_offset;
0113     }}
0114     // new offset :
0115     offset = 0;
0116    {for(std::size_t iaxis=0;iaxis<dim;iaxis++) offset += is[iaxis] * aoff[iaxis];}
0117     aVector[offset] = tmp[index];
0118   }
0119 }
0120 
0121 inline void add_outflow(std::vector< axis_t >& aAxes) {
0122   // Restore new offsets :
0123   aAxes[0].m_offset = 1;
0124   for(unsigned int iaxis=1;iaxis<aAxes.size();iaxis++)
0125     aAxes[iaxis].m_offset = aAxes[iaxis-1].m_offset * (aAxes[iaxis-1].bins()+2);
0126 }
0127 
0128 inline bool read_v0(buffer& a_buffer,pd_data_t& a_data) {
0129   int idummy;
0130   double ddummy;
0131   std::string sdummy;
0132   if(!a_buffer.read(sdummy)) return false;
0133   if(!a_buffer.read(a_data.m_title)) return false;
0134 
0135  {int dim;
0136   if(!a_buffer.read(dim)) return false;
0137   a_data.m_dimension = dim;}
0138 
0139  {int nbin;
0140   if(!a_buffer.read(nbin)) return false;
0141   a_data.m_bin_number = nbin;}
0142 
0143   if(!a_buffer.read(idummy)) return false; //fEntries
0144   if(!a_buffer.read(idummy)) return false; //fOutFlow
0145   if(!a_buffer.read(ddummy)) return false; //fSw
0146 
0147   std::vector<int> vec;
0148   if(!a_buffer.read_array<int>(vec)) return false;
0149   convert<int,unsigned int>(vec,a_data.m_bin_entries);
0150 
0151   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
0152   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
0153   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
0154   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
0155   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
0156   if(a_data.m_dimension>0) {
0157     a_data.m_axes.resize(a_data.m_dimension);
0158     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
0159       if(!Axis_read_v0_v3(a_buffer,a_data.m_axes[iaxis])) return false;
0160     }
0161   }
0162   axis_t axisOfValues;
0163   if(!Axis_read_v0_v3(a_buffer,axisOfValues)) return false;
0164  {int dummy;
0165   if(!a_buffer.read(dummy)) return false;} //m_mode
0166 
0167   // Add outflow :
0168   a_data.m_bin_number = new_bin_number(a_data.m_axes);
0169   add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries);
0170   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw);
0171   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2);
0172   add_outflow(a_data.m_axes);
0173 
0174   // Not here in v0 :
0175   std::vector<double> empty;
0176   empty.resize(a_data.m_dimension,0);
0177   a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty);
0178   a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty);
0179   a_data.m_is_profile = false;
0180   a_data.m_bin_Svw.clear();
0181   a_data.m_bin_Sv2w.clear();
0182 
0183   return true;
0184 }
0185 
0186 inline bool read_v1(buffer& a_buffer,pd_data_t& a_data) {
0187   int idummy;
0188   double ddummy;
0189   if(!a_buffer.read(a_data.m_title)) return false;
0190 
0191  {int dim;
0192   if(!a_buffer.read(dim)) return false;
0193   a_data.m_dimension = dim;}
0194 
0195  {int nbin;
0196   if(!a_buffer.read(nbin)) return false;
0197   a_data.m_bin_number = nbin;}
0198 
0199   if(!a_buffer.read(idummy)) return false; //fEntries
0200   if(!a_buffer.read(idummy)) return false; //fOutFlow
0201   if(!a_buffer.read(ddummy)) return false; //fSw
0202 
0203   std::vector<int> vec;
0204   if(!a_buffer.read_array<int>(vec)) return false;
0205   convert<int,unsigned int>(vec,a_data.m_bin_entries);
0206 
0207   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
0208   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
0209   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
0210   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
0211   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
0212   if(a_data.m_dimension>0) {
0213     a_data.m_axes.resize(a_data.m_dimension);
0214     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
0215       if(!Axis_read_v0_v3(a_buffer,a_data.m_axes[iaxis])) return false;
0216     }
0217   }
0218   axis_t axisOfValues;
0219   if(!Axis_read_v0_v3(a_buffer,axisOfValues)) return false;
0220  {int dummy;
0221   if(!a_buffer.read(dummy)) return false;} //m_mode
0222 
0223   // Add outflow :
0224   a_data.m_bin_number = new_bin_number(a_data.m_axes);
0225   add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries);
0226   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw);
0227   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2);
0228   add_outflow(a_data.m_axes);
0229 
0230   // Not here in v1 :
0231   std::vector<double> empty;
0232   empty.resize(a_data.m_dimension,0);
0233   a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty);
0234   a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty);
0235   a_data.m_is_profile = false;
0236   a_data.m_bin_Svw.clear();
0237   a_data.m_bin_Sv2w.clear();
0238 
0239   return true;
0240 }
0241 
0242 inline bool read_v2(buffer& a_buffer,pd_data_t& a_data) {
0243   int idummy;
0244   double ddummy;
0245   std::string sdummy;
0246   if(!a_buffer.read(a_data.m_title)) return false;
0247   if(!a_buffer.read(sdummy)) return false;
0248 
0249  {int dim;
0250   if(!a_buffer.read(dim)) return false;
0251   a_data.m_dimension = dim;}
0252 
0253  {int nbin;
0254   if(!a_buffer.read(nbin)) return false;
0255   a_data.m_bin_number = nbin;}
0256 
0257   if(!a_buffer.read(idummy)) return false; //fEntries
0258   if(!a_buffer.read(idummy)) return false; //fOutFlow
0259   if(!a_buffer.read(ddummy)) return false; //fSw
0260 
0261   std::vector<int> vec;
0262   if(!a_buffer.read_array<int>(vec)) return false;
0263   convert<int,unsigned int>(vec,a_data.m_bin_entries);
0264 
0265   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
0266   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
0267   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
0268   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
0269   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
0270   if(a_data.m_dimension>0) {
0271     a_data.m_axes.resize(a_data.m_dimension);
0272     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
0273       if(!Axis_read_v0_v3(a_buffer,a_data.m_axes[iaxis])) return false;
0274     }
0275   }
0276   axis_t axisOfValues;
0277   if(!Axis_read_v0_v3(a_buffer,axisOfValues)) return false;
0278  {int dummy;
0279   if(!a_buffer.read(dummy)) return false;} //m_mode
0280 
0281   // Add outflow :
0282   a_data.m_bin_number = new_bin_number(a_data.m_axes);
0283   add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries);
0284   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw);
0285   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2);
0286   add_outflow(a_data.m_axes);
0287 
0288   // Not here in v2 :
0289   std::vector<double> empty;
0290   empty.resize(a_data.m_dimension,0);
0291   a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty);
0292   a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty);
0293   a_data.m_is_profile = false;
0294   a_data.m_bin_Svw.clear();
0295   a_data.m_bin_Sv2w.clear();
0296 
0297   return true;
0298 }
0299 
0300 inline bool read_v3(buffer& a_buffer,pd_data_t& a_data) {
0301   int idummy;
0302   double ddummy;
0303 
0304   int l;
0305   if(!a_buffer.read(l)) return false;
0306   char* str = new char[l+1];
0307   for (int i = 0; i < l; i++) {
0308     if(!a_buffer.read(str[i])) { delete [] str;return false;}
0309   }
0310   str[l] = '\0';
0311   a_data.m_title = str;
0312   delete [] str;
0313 
0314  {int dim;
0315   if(!a_buffer.read(dim)) return false;
0316   a_data.m_dimension = dim;}
0317 
0318  {int nbin;
0319   if(!a_buffer.read(nbin)) return false;
0320   a_data.m_bin_number = nbin;}
0321 
0322   if(!a_buffer.read(idummy)) return false; //fEntries
0323   if(!a_buffer.read(idummy)) return false; //fOutFlow
0324   if(!a_buffer.read(ddummy)) return false; //fSw
0325 
0326   std::vector<int> vec;
0327   if(!a_buffer.read_array<int>(vec)) return false;
0328   convert<int,unsigned int>(vec,a_data.m_bin_entries);
0329 
0330   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
0331   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
0332   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
0333   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
0334   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
0335   if(a_data.m_dimension>0) {
0336     a_data.m_axes.resize(a_data.m_dimension);
0337     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
0338       if(!Axis_read_v0_v3(a_buffer,a_data.m_axes[iaxis])) return false;
0339     }
0340   }
0341   axis_t axisOfValues;
0342   if(!Axis_read_v0_v3(a_buffer,axisOfValues)) return false;
0343  {int dummy;
0344   if(!a_buffer.read(dummy)) return false;} //m_mode
0345 
0346   // Add outflow :
0347   a_data.m_bin_number = new_bin_number(a_data.m_axes);
0348   add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries);
0349   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw);
0350   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2);
0351   add_outflow(a_data.m_axes);
0352 
0353   // Not here in v3 :
0354   std::vector<double> empty;
0355   empty.resize(a_data.m_dimension,0);
0356   a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty);
0357   a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty);
0358   a_data.m_is_profile = false;
0359   a_data.m_bin_Svw.clear();
0360   a_data.m_bin_Sv2w.clear();
0361 
0362   return true;
0363 }
0364 
0365 inline bool read_v4(buffer& a_buffer,pd_data_t& a_data) {
0366   int idummy;
0367   double ddummy;
0368 
0369   int l;
0370   if(!a_buffer.read(l)) return false;
0371   char* str = new char[l+1];
0372   for (int i = 0; i < l; i++) {
0373     if(!a_buffer.read(str[i])) { delete [] str;return false;}
0374   }
0375   str[l] = '\0';
0376   a_data.m_title = str;
0377   delete [] str;
0378 
0379  {int dim;
0380   if(!a_buffer.read(dim)) return false;
0381   a_data.m_dimension = dim;}
0382 
0383  {int nbin;
0384   if(!a_buffer.read(nbin)) return false;
0385   a_data.m_bin_number = nbin;}
0386 
0387   if(!a_buffer.read(idummy)) return false; //fEntries
0388   if(!a_buffer.read(idummy)) return false; //fOutFlow
0389   if(!a_buffer.read(ddummy)) return false; //fSw
0390 
0391   std::vector<int> vec;
0392   if(!a_buffer.read_array<int>(vec)) return false;
0393   convert<int,unsigned int>(vec,a_data.m_bin_entries);
0394 
0395   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
0396   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
0397   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
0398   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
0399   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
0400   if(a_data.m_dimension>0) {
0401     a_data.m_axes.resize(a_data.m_dimension);
0402     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
0403       if(!Axis_read_v4_v6(a_buffer,a_data.m_axes[iaxis])) return false;
0404     }
0405   }
0406  {int dummy;
0407   if(!a_buffer.read(dummy)) return false;} //m_mode
0408 
0409   // Add outflow :
0410   a_data.m_bin_number = new_bin_number(a_data.m_axes);
0411   add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries);
0412   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw);
0413   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2);
0414   add_outflow(a_data.m_axes);
0415 
0416   // Not here in v4 :
0417   std::vector<double> empty;
0418   empty.resize(a_data.m_dimension,0);
0419   a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty);
0420   a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty);
0421   a_data.m_is_profile = false;
0422   a_data.m_bin_Svw.clear();
0423   a_data.m_bin_Sv2w.clear();
0424 
0425   return true;
0426 }
0427 
0428 inline bool read_v5(buffer& a_buffer,pd_data_t& a_data) {
0429   int idummy;
0430   double ddummy;
0431   if(!a_buffer.read(a_data.m_title)) return false;
0432 
0433  {int dim;
0434   if(!a_buffer.read(dim)) return false;
0435   a_data.m_dimension = dim;}
0436 
0437  {int nbin;
0438   if(!a_buffer.read(nbin)) return false;
0439   a_data.m_bin_number = nbin;}
0440 
0441   if(!a_buffer.read(idummy)) return false; //fEntries
0442   if(!a_buffer.read(idummy)) return false; //fOutFlow
0443   if(!a_buffer.read(ddummy)) return false; //fSw
0444 
0445   std::vector<int> vec;
0446   if(!a_buffer.read_array<int>(vec)) return false;
0447   convert<int,unsigned int>(vec,a_data.m_bin_entries);
0448 
0449   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
0450   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
0451   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
0452   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
0453   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
0454   if(a_data.m_dimension>0) {
0455     a_data.m_axes.resize(a_data.m_dimension);
0456     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
0457       if(!Axis_read_v4_v6(a_buffer,a_data.m_axes[iaxis])) return false;
0458     }
0459   }
0460  {int dummy;
0461   if(!a_buffer.read(dummy)) return false;} //m_mode
0462 
0463   // Add outflow :
0464   a_data.m_bin_number = new_bin_number(a_data.m_axes);
0465   add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries);
0466   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw);
0467   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2);
0468   add_outflow(a_data.m_axes);
0469 
0470   // Not here in v5 :
0471   std::vector<double> empty;
0472   empty.resize(a_data.m_dimension,0);
0473   a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty);
0474   a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty);
0475   a_data.m_is_profile = false;
0476   a_data.m_bin_Svw.clear();
0477   a_data.m_bin_Sv2w.clear();
0478 
0479   return true;
0480 }
0481 
0482 inline bool read_v6(buffer& a_buffer,pd_data_t& a_data) {
0483   int idummy;
0484   double ddummy;
0485   if(!a_buffer.read(a_data.m_title)) return false;
0486 
0487  {int dim;
0488   if(!a_buffer.read(dim)) return false;
0489   a_data.m_dimension = dim;}
0490 
0491  {int nbin;
0492   if(!a_buffer.read(nbin)) return false;
0493   a_data.m_bin_number = nbin;}
0494 
0495   if(!a_buffer.read(idummy)) return false; //fEntries
0496   if(!a_buffer.read(idummy)) return false; //fOutFlow
0497   if(!a_buffer.read(ddummy)) return false; //fSw
0498 
0499   std::vector<int> vec;
0500   if(!a_buffer.read_array<int>(vec)) return false;
0501   convert<int,unsigned int>(vec,a_data.m_bin_entries);
0502 
0503   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
0504   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
0505   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
0506   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
0507   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
0508   if(a_data.m_dimension>0) {
0509     a_data.m_axes.resize(a_data.m_dimension);
0510     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
0511       if(!Axis_read_v4_v6(a_buffer,a_data.m_axes[iaxis])) return false;
0512     }
0513   }
0514  {int dummy;
0515   if(!a_buffer.read(dummy)) return false;} //m_mode
0516 
0517   // Profile :
0518   if(!a_buffer.read(a_data.m_is_profile)) return false;
0519   if(a_data.m_is_profile) {
0520     if(!a_buffer.read_array<double>(a_data.m_bin_Svw)) return false;
0521     if(a_data.m_bin_Svw.size()!=a_data.m_bin_number) return false;
0522     if(!a_buffer.read(a_data.m_cut_v)) return false;
0523     if(!a_buffer.read(a_data.m_min_v)) return false;
0524     if(!a_buffer.read(a_data.m_max_v)) return false;
0525   }
0526 
0527   // Add outflow :
0528   a_data.m_bin_number = new_bin_number(a_data.m_axes);
0529   add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries);
0530   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw);
0531   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2);
0532   add_outflow<double>(a_data.m_axes,a_data.m_bin_Svw);
0533   add_outflow(a_data.m_axes);
0534 
0535   // Not here in v6 :
0536   std::vector<double> empty;
0537   empty.resize(a_data.m_dimension,0);
0538   a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty); //Forget to write in v6 !
0539   a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty);
0540   if(a_data.m_is_profile) {
0541     a_data.m_bin_Sv2w.resize(a_data.m_bin_number,0);
0542   }
0543 
0544   return true;
0545 }
0546 
0547 inline bool read_v7(buffer& a_buffer,pd_data_t& a_data) {
0548   if(!a_buffer.read(a_data.m_title)) return false;
0549 
0550  {int dim;
0551   if(!a_buffer.read(dim)) return false;
0552   a_data.m_dimension = dim;}
0553 
0554  {int nbin;
0555   if(!a_buffer.read(nbin)) return false;
0556   a_data.m_bin_number = nbin;}
0557 
0558   std::vector<int> vec;
0559   if(!a_buffer.read_array<int>(vec)) return false;
0560   convert<int,unsigned int>(vec,a_data.m_bin_entries);
0561 
0562   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
0563   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
0564   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
0565   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
0566   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
0567   if(!a_buffer.read_array2<double>(a_data.m_bin_Sxw)) return false;
0568   if(a_data.m_bin_Sxw.size()!=a_data.m_bin_number) return false;
0569   if(!a_buffer.read_array2<double>(a_data.m_bin_Sx2w)) return false;
0570   if(a_data.m_bin_Sx2w.size()!=a_data.m_bin_number) return false;
0571   if(a_data.m_dimension>0) {
0572     a_data.m_axes.resize(a_data.m_dimension);
0573     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
0574       if(!Axis_read_v7(a_buffer,a_data.m_axes[iaxis])) return false;
0575     }
0576   }
0577  {int dummy;
0578   if(!a_buffer.read(dummy)) return false;} //m_mode
0579   // Profile :
0580   if(!a_buffer.read(a_data.m_is_profile)) return false;
0581   if(a_data.m_is_profile) {
0582     if(!a_buffer.read_array<double>(a_data.m_bin_Svw)) return false;
0583     if(a_data.m_bin_Svw.size()!=a_data.m_bin_number) return false;
0584     if(!a_buffer.read_array<double>(a_data.m_bin_Sv2w)) return false;
0585     if(a_data.m_bin_Sv2w.size()!=a_data.m_bin_number) return false;
0586     if(!a_buffer.read(a_data.m_cut_v)) return false;
0587     if(!a_buffer.read(a_data.m_min_v)) return false;
0588     if(!a_buffer.read(a_data.m_max_v)) return false;
0589   }
0590 
0591   return true;
0592 }
0593 
0594 inline bool read_annotations(buffer& a_buffer,annotations_t& a_annotations) {
0595   a_annotations.clear(); //reset() does not remove sticky items.
0596   int number;
0597   if(!a_buffer.read(number)) return false;
0598   for(int index=0;index<number;index++) {
0599     std::string key;
0600     if(!a_buffer.read(key)) return false;
0601     std::string value;
0602     if(!a_buffer.read(value)) return false;
0603     bool sticky;
0604     if(!a_buffer.read(sticky)) return false;
0605     //if(!a_annotations.addItem(key,value,sticky)) return false; //FIXME : handle sticky ?
0606     a_annotations[key] = value;
0607   }
0608   return true;
0609 }
0610 
0611 inline bool read_THistogram(buffer& a_buffer,pd_data_t& a_data,annotations_t& a_annotations) {
0612 
0613   short v;
0614   if(!a_buffer.read_version(v)) return false;
0615 
0616  {std::string name,title;
0617   if(!Named_stream(a_buffer,name,title)) return false;}
0618 
0619   if(v==0) {
0620     if(!read_v0(a_buffer,a_data)) return false;
0621   } else if(v==1) {
0622     if(!read_v1(a_buffer,a_data)) return false;
0623   } else if(v==2) {
0624     if(!read_v2(a_buffer,a_data)) return false;
0625   } else if(v==3) {
0626     if(!read_v3(a_buffer,a_data)) return false;
0627   } else if(v==4) {
0628     if(!read_v4(a_buffer,a_data)) return false;
0629   } else if(v==5) {
0630     if(!read_v5(a_buffer,a_data)) return false;
0631   } else if(v==6) {
0632     if(!read_v6(a_buffer,a_data)) return false;
0633   } else if(v==7) {
0634     if(!read_v7(a_buffer,a_data)) return false;
0635   } else if(v==8) {
0636     if(!read_annotations(a_buffer,a_annotations)) return false;
0637     if(!read_v7(a_buffer,a_data)) return false;
0638   } else {
0639     return false;
0640   }
0641 
0642   //data.m_coords.resize(data.m_dimension,0);
0643   //data.m_ints.resize(data.m_dimension,0);
0644 
0645   a_data.update_fast_getters();
0646 
0647   return true;
0648 }
0649 
0650 inline const std::string& THistogram_cls(){
0651   static const std::string s_v("THistogram");
0652   return s_v;
0653 }
0654 
0655 }}
0656 
0657 #include "key"
0658 
0659 namespace tools {
0660 namespace rroot {
0661 
0662 inline bool read_key_THistogram(ifile& a_file,key& a_key,pd_data_t& a_data,annotations_t& a_annotations,bool a_warn = true) {
0663   std::ostream& out = a_key.out();
0664   if(a_key.object_class()!=THistogram_cls()) {
0665     if(a_warn) out << "tools::rroot::read_key_THisogram : key not a THistogram." << std::endl;
0666     return 0;
0667   }
0668   unsigned int sz;
0669   char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf.
0670   if(!buf) {
0671     out << "tools::rroot::read_key_THisogram : can't get data buffer of " << a_key.object_name() << "." << std::endl;
0672     return 0;
0673   }
0674   buffer b(out,a_file.byte_swap(),sz,buf,a_key.key_length(),false);
0675   return read_THistogram(b,a_data,a_annotations);
0676 }
0677 
0678 }}
0679 
0680 #include "../histo/h1d"
0681 #include "../histo/h2d"
0682 #include "../histo/p1d"
0683 #include "../histo/p2d"
0684 
0685 namespace tools {
0686 namespace rroot {
0687 
0688 inline histo::h1d* THistogram_to_h1d(const pd_data_t& a_data) {
0689   unsigned int dim = a_data.m_dimension;
0690   bool is_profile = a_data.m_is_profile;
0691   if(dim!=1) return 0;
0692   if(is_profile) return 0;
0693   histo::h1d* histo = new histo::h1d("",10,0,1);
0694   histo->copy_from_data(a_data);
0695   return histo;
0696 }
0697 
0698 inline histo::h2d* THistogram_to_h2d(const pd_data_t& a_data) {
0699   unsigned int dim = a_data.m_dimension;
0700   bool is_profile = a_data.m_is_profile;
0701   if(dim!=2) return 0;
0702   if(is_profile) return 0;
0703   histo::h2d* histo = new histo::h2d("",10,0,1,10,0,1);
0704   histo->copy_from_data(a_data);
0705   return histo;
0706 }
0707 
0708 inline histo::p1d* THistogram_to_p1d(const pd_data_t& a_data) {
0709   unsigned int dim = a_data.m_dimension;
0710   bool is_profile = a_data.m_is_profile;
0711   if(dim!=1) return 0;
0712   if(!is_profile) return 0;
0713   histo::p1d* histo = new histo::p1d("",10,0,1);
0714   histo->copy_from_data(a_data);
0715   return histo;
0716 }
0717 
0718 inline histo::p2d* THistogram_to_p2d(const pd_data_t& a_data) {
0719   unsigned int dim = a_data.m_dimension;
0720   bool is_profile = a_data.m_is_profile;
0721   if(dim!=2) return 0;
0722   if(!is_profile) return 0;
0723   histo::p2d* histo = new histo::p2d("",10,0,1,10,0,1);
0724   histo->copy_from_data(a_data);
0725   return histo;
0726 }
0727 
0728 }}
0729 
0730 #endif