Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/g4tools/include/tools/rroot/THistogram

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 ]

  1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.
  3 
  4 #ifndef tools_rroot_THistogram
  5 #define tools_rroot_THistogram
  6 
  7 // to read some files produced with BatchLab (opaw/examples/osc/analysis.root).
  8 
  9 #include "../histo/profile_data"
 10 
 11 #include "named"
 12 #include "../vmanip"
 13 
 14 namespace tools {
 15 namespace rroot {
 16 
 17 //typedef histo::histo_data<double,unsigned int,double> hd_data;
 18 typedef histo::profile_data<double,unsigned int,unsigned int,double,double> pd_data_t;
 19 typedef histo::axis<double,unsigned int> axis_t;
 20 typedef std::map<std::string,std::string> annotations_t;
 21 
 22 inline bool Axis_read_v0_v3(buffer& a_buffer,axis_t& a_axis) {
 23   int idummy;
 24   double ddummy;
 25   if(!a_buffer.read(a_axis.m_minimum_value)) return false;
 26   if(!a_buffer.read(a_axis.m_maximum_value)) return false;
 27   if(!a_buffer.read(a_axis.m_offset)) return false;
 28   if(!a_buffer.read(a_axis.m_number_of_bins)) return false;
 29   if(!a_buffer.read(idummy)) return false; //fOverFlow
 30   if(!a_buffer.read(idummy)) return false; //fUnderFlow
 31   if(!a_buffer.read(a_axis.m_bin_width)) return false;
 32   if(!a_buffer.read(ddummy)) return false; //fSxw
 33   if(!a_buffer.read(ddummy)) return false; //fSx2w
 34   a_axis.m_fixed = true;
 35   a_axis.m_edges.clear();
 36   return true;
 37 }
 38 
 39 inline bool Axis_read_v4_v6(buffer& a_buffer,axis_t& a_axis) {
 40   int idummy;
 41   double ddummy;
 42   if(!a_buffer.read(a_axis.m_offset)) return false;
 43   if(!a_buffer.read(idummy)) return false; //fOverFlow
 44   if(!a_buffer.read(idummy)) return false; //fUnderFlow
 45   if(!a_buffer.read(ddummy)) return false; //fSxw
 46   if(!a_buffer.read(ddummy)) return false; //fSx2w
 47   if(!a_buffer.read(a_axis.m_number_of_bins)) return false;
 48   if(!a_buffer.read(a_axis.m_minimum_value)) return false;
 49   if(!a_buffer.read(a_axis.m_maximum_value)) return false;
 50   if(!a_buffer.read(a_axis.m_fixed)) return false;
 51   if(!a_buffer.read(a_axis.m_bin_width)) return false;
 52   int edgen;
 53   if(!a_buffer.read(edgen)) return false;
 54   for(int count=0;count<edgen;count++) {
 55     double value;
 56     if(!a_buffer.read(value)) return false;
 57     a_axis.m_edges.push_back(value);
 58   }
 59   return true;
 60 }
 61 
 62 inline bool Axis_read_v7(buffer& a_buffer,axis_t& a_axis) {
 63   if(!a_buffer.read(a_axis.m_offset)) return false;
 64   if(!a_buffer.read(a_axis.m_number_of_bins)) return false;
 65   if(!a_buffer.read(a_axis.m_minimum_value)) return false;
 66   if(!a_buffer.read(a_axis.m_maximum_value)) return false;
 67   if(!a_buffer.read(a_axis.m_fixed)) return false;
 68   if(!a_buffer.read(a_axis.m_bin_width)) return false;
 69   int edgen;
 70   if(!a_buffer.read(edgen)) return false;
 71   for(int count=0;count<edgen;count++) {
 72     double value;
 73     if(!a_buffer.read(value)) return false;
 74     a_axis.m_edges.push_back(value);
 75   }
 76   return true;
 77 }
 78 
 79 inline unsigned int new_bin_number(const std::vector< axis_t >& aAxes) {
 80   unsigned int number = 1;
 81   for(unsigned int iaxis=0;iaxis<aAxes.size();iaxis++)
 82     number *= (aAxes[iaxis].bins()+2);
 83   return number;
 84 }
 85 
 86 template <class T>
 87 inline void add_outflow(const std::vector< axis_t >& aAxes,std::vector<T>& aVector) {
 88   // aAxes[].m_offset contains the offset without outflow.
 89   std::size_t dim = aAxes.size();
 90   // new size and offsets :
 91   std::vector<int> aoff(dim);
 92 
 93   int newn = 1;
 94  {for(unsigned iaxis=0;iaxis<dim;iaxis++) newn *= (aAxes[iaxis].bins()+2);}
 95 
 96   aoff[0] = 1;
 97  {for(unsigned iaxis=1;iaxis<dim;iaxis++) {
 98     aoff[iaxis] = aoff[iaxis-1] * (aAxes[iaxis-1].bins()+2);
 99   }}
100   // copy :
101   std::vector<T> tmp = aVector;
102   int oldn = (int)tmp.size();
103   aVector.resize(newn,0);
104   // Copy :
105   std::vector<int> is(dim);
106   int offset;
107   for(int index=0;index<oldn;index++) {
108     // Get new offset of index :
109     offset = index;
110    {for(int iaxis=(int)dim-1;iaxis>=0;iaxis--) {
111       is[iaxis] = offset/aAxes[iaxis].m_offset;
112       offset -= is[iaxis] * aAxes[iaxis].m_offset;
113     }}
114     // new offset :
115     offset = 0;
116    {for(std::size_t iaxis=0;iaxis<dim;iaxis++) offset += is[iaxis] * aoff[iaxis];}
117     aVector[offset] = tmp[index];
118   }
119 }
120 
121 inline void add_outflow(std::vector< axis_t >& aAxes) {
122   // Restore new offsets :
123   aAxes[0].m_offset = 1;
124   for(unsigned int iaxis=1;iaxis<aAxes.size();iaxis++)
125     aAxes[iaxis].m_offset = aAxes[iaxis-1].m_offset * (aAxes[iaxis-1].bins()+2);
126 }
127 
128 inline bool read_v0(buffer& a_buffer,pd_data_t& a_data) {
129   int idummy;
130   double ddummy;
131   std::string sdummy;
132   if(!a_buffer.read(sdummy)) return false;
133   if(!a_buffer.read(a_data.m_title)) return false;
134 
135  {int dim;
136   if(!a_buffer.read(dim)) return false;
137   a_data.m_dimension = dim;}
138 
139  {int nbin;
140   if(!a_buffer.read(nbin)) return false;
141   a_data.m_bin_number = nbin;}
142 
143   if(!a_buffer.read(idummy)) return false; //fEntries
144   if(!a_buffer.read(idummy)) return false; //fOutFlow
145   if(!a_buffer.read(ddummy)) return false; //fSw
146 
147   std::vector<int> vec;
148   if(!a_buffer.read_array<int>(vec)) return false;
149   convert<int,unsigned int>(vec,a_data.m_bin_entries);
150 
151   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
152   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
153   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
154   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
155   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
156   if(a_data.m_dimension>0) {
157     a_data.m_axes.resize(a_data.m_dimension);
158     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
159       if(!Axis_read_v0_v3(a_buffer,a_data.m_axes[iaxis])) return false;
160     }
161   }
162   axis_t axisOfValues;
163   if(!Axis_read_v0_v3(a_buffer,axisOfValues)) return false;
164  {int dummy;
165   if(!a_buffer.read(dummy)) return false;} //m_mode
166 
167   // Add outflow :
168   a_data.m_bin_number = new_bin_number(a_data.m_axes);
169   add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries);
170   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw);
171   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2);
172   add_outflow(a_data.m_axes);
173 
174   // Not here in v0 :
175   std::vector<double> empty;
176   empty.resize(a_data.m_dimension,0);
177   a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty);
178   a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty);
179   a_data.m_is_profile = false;
180   a_data.m_bin_Svw.clear();
181   a_data.m_bin_Sv2w.clear();
182 
183   return true;
184 }
185 
186 inline bool read_v1(buffer& a_buffer,pd_data_t& a_data) {
187   int idummy;
188   double ddummy;
189   if(!a_buffer.read(a_data.m_title)) return false;
190 
191  {int dim;
192   if(!a_buffer.read(dim)) return false;
193   a_data.m_dimension = dim;}
194 
195  {int nbin;
196   if(!a_buffer.read(nbin)) return false;
197   a_data.m_bin_number = nbin;}
198 
199   if(!a_buffer.read(idummy)) return false; //fEntries
200   if(!a_buffer.read(idummy)) return false; //fOutFlow
201   if(!a_buffer.read(ddummy)) return false; //fSw
202 
203   std::vector<int> vec;
204   if(!a_buffer.read_array<int>(vec)) return false;
205   convert<int,unsigned int>(vec,a_data.m_bin_entries);
206 
207   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
208   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
209   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
210   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
211   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
212   if(a_data.m_dimension>0) {
213     a_data.m_axes.resize(a_data.m_dimension);
214     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
215       if(!Axis_read_v0_v3(a_buffer,a_data.m_axes[iaxis])) return false;
216     }
217   }
218   axis_t axisOfValues;
219   if(!Axis_read_v0_v3(a_buffer,axisOfValues)) return false;
220  {int dummy;
221   if(!a_buffer.read(dummy)) return false;} //m_mode
222 
223   // Add outflow :
224   a_data.m_bin_number = new_bin_number(a_data.m_axes);
225   add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries);
226   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw);
227   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2);
228   add_outflow(a_data.m_axes);
229 
230   // Not here in v1 :
231   std::vector<double> empty;
232   empty.resize(a_data.m_dimension,0);
233   a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty);
234   a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty);
235   a_data.m_is_profile = false;
236   a_data.m_bin_Svw.clear();
237   a_data.m_bin_Sv2w.clear();
238 
239   return true;
240 }
241 
242 inline bool read_v2(buffer& a_buffer,pd_data_t& a_data) {
243   int idummy;
244   double ddummy;
245   std::string sdummy;
246   if(!a_buffer.read(a_data.m_title)) return false;
247   if(!a_buffer.read(sdummy)) return false;
248 
249  {int dim;
250   if(!a_buffer.read(dim)) return false;
251   a_data.m_dimension = dim;}
252 
253  {int nbin;
254   if(!a_buffer.read(nbin)) return false;
255   a_data.m_bin_number = nbin;}
256 
257   if(!a_buffer.read(idummy)) return false; //fEntries
258   if(!a_buffer.read(idummy)) return false; //fOutFlow
259   if(!a_buffer.read(ddummy)) return false; //fSw
260 
261   std::vector<int> vec;
262   if(!a_buffer.read_array<int>(vec)) return false;
263   convert<int,unsigned int>(vec,a_data.m_bin_entries);
264 
265   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
266   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
267   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
268   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
269   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
270   if(a_data.m_dimension>0) {
271     a_data.m_axes.resize(a_data.m_dimension);
272     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
273       if(!Axis_read_v0_v3(a_buffer,a_data.m_axes[iaxis])) return false;
274     }
275   }
276   axis_t axisOfValues;
277   if(!Axis_read_v0_v3(a_buffer,axisOfValues)) return false;
278  {int dummy;
279   if(!a_buffer.read(dummy)) return false;} //m_mode
280 
281   // Add outflow :
282   a_data.m_bin_number = new_bin_number(a_data.m_axes);
283   add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries);
284   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw);
285   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2);
286   add_outflow(a_data.m_axes);
287 
288   // Not here in v2 :
289   std::vector<double> empty;
290   empty.resize(a_data.m_dimension,0);
291   a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty);
292   a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty);
293   a_data.m_is_profile = false;
294   a_data.m_bin_Svw.clear();
295   a_data.m_bin_Sv2w.clear();
296 
297   return true;
298 }
299 
300 inline bool read_v3(buffer& a_buffer,pd_data_t& a_data) {
301   int idummy;
302   double ddummy;
303 
304   int l;
305   if(!a_buffer.read(l)) return false;
306   char* str = new char[l+1];
307   for (int i = 0; i < l; i++) {
308     if(!a_buffer.read(str[i])) { delete [] str;return false;}
309   }
310   str[l] = '\0';
311   a_data.m_title = str;
312   delete [] str;
313 
314  {int dim;
315   if(!a_buffer.read(dim)) return false;
316   a_data.m_dimension = dim;}
317 
318  {int nbin;
319   if(!a_buffer.read(nbin)) return false;
320   a_data.m_bin_number = nbin;}
321 
322   if(!a_buffer.read(idummy)) return false; //fEntries
323   if(!a_buffer.read(idummy)) return false; //fOutFlow
324   if(!a_buffer.read(ddummy)) return false; //fSw
325 
326   std::vector<int> vec;
327   if(!a_buffer.read_array<int>(vec)) return false;
328   convert<int,unsigned int>(vec,a_data.m_bin_entries);
329 
330   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
331   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
332   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
333   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
334   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
335   if(a_data.m_dimension>0) {
336     a_data.m_axes.resize(a_data.m_dimension);
337     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
338       if(!Axis_read_v0_v3(a_buffer,a_data.m_axes[iaxis])) return false;
339     }
340   }
341   axis_t axisOfValues;
342   if(!Axis_read_v0_v3(a_buffer,axisOfValues)) return false;
343  {int dummy;
344   if(!a_buffer.read(dummy)) return false;} //m_mode
345 
346   // Add outflow :
347   a_data.m_bin_number = new_bin_number(a_data.m_axes);
348   add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries);
349   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw);
350   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2);
351   add_outflow(a_data.m_axes);
352 
353   // Not here in v3 :
354   std::vector<double> empty;
355   empty.resize(a_data.m_dimension,0);
356   a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty);
357   a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty);
358   a_data.m_is_profile = false;
359   a_data.m_bin_Svw.clear();
360   a_data.m_bin_Sv2w.clear();
361 
362   return true;
363 }
364 
365 inline bool read_v4(buffer& a_buffer,pd_data_t& a_data) {
366   int idummy;
367   double ddummy;
368 
369   int l;
370   if(!a_buffer.read(l)) return false;
371   char* str = new char[l+1];
372   for (int i = 0; i < l; i++) {
373     if(!a_buffer.read(str[i])) { delete [] str;return false;}
374   }
375   str[l] = '\0';
376   a_data.m_title = str;
377   delete [] str;
378 
379  {int dim;
380   if(!a_buffer.read(dim)) return false;
381   a_data.m_dimension = dim;}
382 
383  {int nbin;
384   if(!a_buffer.read(nbin)) return false;
385   a_data.m_bin_number = nbin;}
386 
387   if(!a_buffer.read(idummy)) return false; //fEntries
388   if(!a_buffer.read(idummy)) return false; //fOutFlow
389   if(!a_buffer.read(ddummy)) return false; //fSw
390 
391   std::vector<int> vec;
392   if(!a_buffer.read_array<int>(vec)) return false;
393   convert<int,unsigned int>(vec,a_data.m_bin_entries);
394 
395   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
396   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
397   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
398   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
399   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
400   if(a_data.m_dimension>0) {
401     a_data.m_axes.resize(a_data.m_dimension);
402     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
403       if(!Axis_read_v4_v6(a_buffer,a_data.m_axes[iaxis])) return false;
404     }
405   }
406  {int dummy;
407   if(!a_buffer.read(dummy)) return false;} //m_mode
408 
409   // Add outflow :
410   a_data.m_bin_number = new_bin_number(a_data.m_axes);
411   add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries);
412   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw);
413   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2);
414   add_outflow(a_data.m_axes);
415 
416   // Not here in v4 :
417   std::vector<double> empty;
418   empty.resize(a_data.m_dimension,0);
419   a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty);
420   a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty);
421   a_data.m_is_profile = false;
422   a_data.m_bin_Svw.clear();
423   a_data.m_bin_Sv2w.clear();
424 
425   return true;
426 }
427 
428 inline bool read_v5(buffer& a_buffer,pd_data_t& a_data) {
429   int idummy;
430   double ddummy;
431   if(!a_buffer.read(a_data.m_title)) return false;
432 
433  {int dim;
434   if(!a_buffer.read(dim)) return false;
435   a_data.m_dimension = dim;}
436 
437  {int nbin;
438   if(!a_buffer.read(nbin)) return false;
439   a_data.m_bin_number = nbin;}
440 
441   if(!a_buffer.read(idummy)) return false; //fEntries
442   if(!a_buffer.read(idummy)) return false; //fOutFlow
443   if(!a_buffer.read(ddummy)) return false; //fSw
444 
445   std::vector<int> vec;
446   if(!a_buffer.read_array<int>(vec)) return false;
447   convert<int,unsigned int>(vec,a_data.m_bin_entries);
448 
449   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
450   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
451   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
452   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
453   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
454   if(a_data.m_dimension>0) {
455     a_data.m_axes.resize(a_data.m_dimension);
456     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
457       if(!Axis_read_v4_v6(a_buffer,a_data.m_axes[iaxis])) return false;
458     }
459   }
460  {int dummy;
461   if(!a_buffer.read(dummy)) return false;} //m_mode
462 
463   // Add outflow :
464   a_data.m_bin_number = new_bin_number(a_data.m_axes);
465   add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries);
466   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw);
467   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2);
468   add_outflow(a_data.m_axes);
469 
470   // Not here in v5 :
471   std::vector<double> empty;
472   empty.resize(a_data.m_dimension,0);
473   a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty);
474   a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty);
475   a_data.m_is_profile = false;
476   a_data.m_bin_Svw.clear();
477   a_data.m_bin_Sv2w.clear();
478 
479   return true;
480 }
481 
482 inline bool read_v6(buffer& a_buffer,pd_data_t& a_data) {
483   int idummy;
484   double ddummy;
485   if(!a_buffer.read(a_data.m_title)) return false;
486 
487  {int dim;
488   if(!a_buffer.read(dim)) return false;
489   a_data.m_dimension = dim;}
490 
491  {int nbin;
492   if(!a_buffer.read(nbin)) return false;
493   a_data.m_bin_number = nbin;}
494 
495   if(!a_buffer.read(idummy)) return false; //fEntries
496   if(!a_buffer.read(idummy)) return false; //fOutFlow
497   if(!a_buffer.read(ddummy)) return false; //fSw
498 
499   std::vector<int> vec;
500   if(!a_buffer.read_array<int>(vec)) return false;
501   convert<int,unsigned int>(vec,a_data.m_bin_entries);
502 
503   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
504   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
505   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
506   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
507   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
508   if(a_data.m_dimension>0) {
509     a_data.m_axes.resize(a_data.m_dimension);
510     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
511       if(!Axis_read_v4_v6(a_buffer,a_data.m_axes[iaxis])) return false;
512     }
513   }
514  {int dummy;
515   if(!a_buffer.read(dummy)) return false;} //m_mode
516 
517   // Profile :
518   if(!a_buffer.read(a_data.m_is_profile)) return false;
519   if(a_data.m_is_profile) {
520     if(!a_buffer.read_array<double>(a_data.m_bin_Svw)) return false;
521     if(a_data.m_bin_Svw.size()!=a_data.m_bin_number) return false;
522     if(!a_buffer.read(a_data.m_cut_v)) return false;
523     if(!a_buffer.read(a_data.m_min_v)) return false;
524     if(!a_buffer.read(a_data.m_max_v)) return false;
525   }
526 
527   // Add outflow :
528   a_data.m_bin_number = new_bin_number(a_data.m_axes);
529   add_outflow<unsigned int>(a_data.m_axes,a_data.m_bin_entries);
530   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw);
531   add_outflow<double>(a_data.m_axes,a_data.m_bin_Sw2);
532   add_outflow<double>(a_data.m_axes,a_data.m_bin_Svw);
533   add_outflow(a_data.m_axes);
534 
535   // Not here in v6 :
536   std::vector<double> empty;
537   empty.resize(a_data.m_dimension,0);
538   a_data.m_bin_Sxw.resize(a_data.m_bin_number,empty); //Forget to write in v6 !
539   a_data.m_bin_Sx2w.resize(a_data.m_bin_number,empty);
540   if(a_data.m_is_profile) {
541     a_data.m_bin_Sv2w.resize(a_data.m_bin_number,0);
542   }
543 
544   return true;
545 }
546 
547 inline bool read_v7(buffer& a_buffer,pd_data_t& a_data) {
548   if(!a_buffer.read(a_data.m_title)) return false;
549 
550  {int dim;
551   if(!a_buffer.read(dim)) return false;
552   a_data.m_dimension = dim;}
553 
554  {int nbin;
555   if(!a_buffer.read(nbin)) return false;
556   a_data.m_bin_number = nbin;}
557 
558   std::vector<int> vec;
559   if(!a_buffer.read_array<int>(vec)) return false;
560   convert<int,unsigned int>(vec,a_data.m_bin_entries);
561 
562   if(a_data.m_bin_entries.size()!=a_data.m_bin_number) return false;
563   if(!a_buffer.read_array<double>(a_data.m_bin_Sw)) return false;
564   if(a_data.m_bin_Sw.size()!=a_data.m_bin_number) return false;
565   if(!a_buffer.read_array<double>(a_data.m_bin_Sw2)) return false;
566   if(a_data.m_bin_Sw2.size()!=a_data.m_bin_number) return false;
567   if(!a_buffer.read_array2<double>(a_data.m_bin_Sxw)) return false;
568   if(a_data.m_bin_Sxw.size()!=a_data.m_bin_number) return false;
569   if(!a_buffer.read_array2<double>(a_data.m_bin_Sx2w)) return false;
570   if(a_data.m_bin_Sx2w.size()!=a_data.m_bin_number) return false;
571   if(a_data.m_dimension>0) {
572     a_data.m_axes.resize(a_data.m_dimension);
573     for(unsigned int iaxis=0;iaxis<a_data.m_dimension;iaxis++) {
574       if(!Axis_read_v7(a_buffer,a_data.m_axes[iaxis])) return false;
575     }
576   }
577  {int dummy;
578   if(!a_buffer.read(dummy)) return false;} //m_mode
579   // Profile :
580   if(!a_buffer.read(a_data.m_is_profile)) return false;
581   if(a_data.m_is_profile) {
582     if(!a_buffer.read_array<double>(a_data.m_bin_Svw)) return false;
583     if(a_data.m_bin_Svw.size()!=a_data.m_bin_number) return false;
584     if(!a_buffer.read_array<double>(a_data.m_bin_Sv2w)) return false;
585     if(a_data.m_bin_Sv2w.size()!=a_data.m_bin_number) return false;
586     if(!a_buffer.read(a_data.m_cut_v)) return false;
587     if(!a_buffer.read(a_data.m_min_v)) return false;
588     if(!a_buffer.read(a_data.m_max_v)) return false;
589   }
590 
591   return true;
592 }
593 
594 inline bool read_annotations(buffer& a_buffer,annotations_t& a_annotations) {
595   a_annotations.clear(); //reset() does not remove sticky items.
596   int number;
597   if(!a_buffer.read(number)) return false;
598   for(int index=0;index<number;index++) {
599     std::string key;
600     if(!a_buffer.read(key)) return false;
601     std::string value;
602     if(!a_buffer.read(value)) return false;
603     bool sticky;
604     if(!a_buffer.read(sticky)) return false;
605     //if(!a_annotations.addItem(key,value,sticky)) return false; //FIXME : handle sticky ?
606     a_annotations[key] = value;
607   }
608   return true;
609 }
610 
611 inline bool read_THistogram(buffer& a_buffer,pd_data_t& a_data,annotations_t& a_annotations) {
612 
613   short v;
614   if(!a_buffer.read_version(v)) return false;
615 
616  {std::string name,title;
617   if(!Named_stream(a_buffer,name,title)) return false;}
618 
619   if(v==0) {
620     if(!read_v0(a_buffer,a_data)) return false;
621   } else if(v==1) {
622     if(!read_v1(a_buffer,a_data)) return false;
623   } else if(v==2) {
624     if(!read_v2(a_buffer,a_data)) return false;
625   } else if(v==3) {
626     if(!read_v3(a_buffer,a_data)) return false;
627   } else if(v==4) {
628     if(!read_v4(a_buffer,a_data)) return false;
629   } else if(v==5) {
630     if(!read_v5(a_buffer,a_data)) return false;
631   } else if(v==6) {
632     if(!read_v6(a_buffer,a_data)) return false;
633   } else if(v==7) {
634     if(!read_v7(a_buffer,a_data)) return false;
635   } else if(v==8) {
636     if(!read_annotations(a_buffer,a_annotations)) return false;
637     if(!read_v7(a_buffer,a_data)) return false;
638   } else {
639     return false;
640   }
641 
642   //data.m_coords.resize(data.m_dimension,0);
643   //data.m_ints.resize(data.m_dimension,0);
644 
645   a_data.update_fast_getters();
646 
647   return true;
648 }
649 
650 inline const std::string& THistogram_cls(){
651   static const std::string s_v("THistogram");
652   return s_v;
653 }
654 
655 }}
656 
657 #include "key"
658 
659 namespace tools {
660 namespace rroot {
661 
662 inline bool read_key_THistogram(ifile& a_file,key& a_key,pd_data_t& a_data,annotations_t& a_annotations,bool a_warn = true) {
663   std::ostream& out = a_key.out();
664   if(a_key.object_class()!=THistogram_cls()) {
665     if(a_warn) out << "tools::rroot::read_key_THisogram : key not a THistogram." << std::endl;
666     return 0;
667   }
668   unsigned int sz;
669   char* buf = a_key.get_object_buffer(a_file,sz); //we don't have ownership of buf.
670   if(!buf) {
671     out << "tools::rroot::read_key_THisogram : can't get data buffer of " << a_key.object_name() << "." << std::endl;
672     return 0;
673   }
674   buffer b(out,a_file.byte_swap(),sz,buf,a_key.key_length(),false);
675   return read_THistogram(b,a_data,a_annotations);
676 }
677 
678 }}
679 
680 #include "../histo/h1d"
681 #include "../histo/h2d"
682 #include "../histo/p1d"
683 #include "../histo/p2d"
684 
685 namespace tools {
686 namespace rroot {
687 
688 inline histo::h1d* THistogram_to_h1d(const pd_data_t& a_data) {
689   unsigned int dim = a_data.m_dimension;
690   bool is_profile = a_data.m_is_profile;
691   if(dim!=1) return 0;
692   if(is_profile) return 0;
693   histo::h1d* histo = new histo::h1d("",10,0,1);
694   histo->copy_from_data(a_data);
695   return histo;
696 }
697 
698 inline histo::h2d* THistogram_to_h2d(const pd_data_t& a_data) {
699   unsigned int dim = a_data.m_dimension;
700   bool is_profile = a_data.m_is_profile;
701   if(dim!=2) return 0;
702   if(is_profile) return 0;
703   histo::h2d* histo = new histo::h2d("",10,0,1,10,0,1);
704   histo->copy_from_data(a_data);
705   return histo;
706 }
707 
708 inline histo::p1d* THistogram_to_p1d(const pd_data_t& a_data) {
709   unsigned int dim = a_data.m_dimension;
710   bool is_profile = a_data.m_is_profile;
711   if(dim!=1) return 0;
712   if(!is_profile) return 0;
713   histo::p1d* histo = new histo::p1d("",10,0,1);
714   histo->copy_from_data(a_data);
715   return histo;
716 }
717 
718 inline histo::p2d* THistogram_to_p2d(const pd_data_t& a_data) {
719   unsigned int dim = a_data.m_dimension;
720   bool is_profile = a_data.m_is_profile;
721   if(dim!=2) return 0;
722   if(!is_profile) return 0;
723   histo::p2d* histo = new histo::p2d("",10,0,1,10,0,1);
724   histo->copy_from_data(a_data);
725   return histo;
726 }
727 
728 }}
729 
730 #endif