Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/g4tools/include/tools/wroot/ntuple

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_wroot_ntuple
  5 #define tools_wroot_ntuple
  6 
  7 // An ntuple class to write at the CERN-ROOT format.
  8 // It inherits wroot::tree and each column is mapped
  9 // on a (wroot::branch,wroot::leaf). Each add_row() does a tree::fill().
 10 
 11 #include "tree"
 12 #include "icol"
 13 
 14 #include "../vfind"
 15 #include "../vmanip"
 16 #include "../ntuple_booking"
 17 #include "../sout"
 18 #include "../scast"
 19 #include "../forit"
 20 
 21 // for mpi :
 22 #include "mpi_create_basket"
 23 
 24 #ifdef TOOLS_MEM
 25 #include "../mem"
 26 #endif
 27 
 28 namespace tools {
 29 namespace wroot {
 30 
 31 class ntuple : public tree {
 32 public:
 33 //typedef wroot::icol icol; //for backward compatibility.
 34 public:
 35 
 36 #include "columns.icc"
 37 
 38 public:
 39   ntuple(idir& a_dir,const std::string& a_name,const std::string& a_title,bool a_row_wise = false)
 40   :tree(a_dir,a_name,a_title),m_row_wise(a_row_wise),m_row_wise_branch(0)
 41   {
 42     if(m_row_wise) m_row_wise_branch = create_branch("row_wise_branch");
 43   }
 44 
 45   ntuple(idir& a_dir,const ntuple_booking& a_bkg,bool a_row_wise = false)
 46   :tree(a_dir,a_bkg.name(),a_bkg.title()),m_row_wise(a_row_wise),m_row_wise_branch(0)
 47   {
 48     if(m_row_wise) m_row_wise_branch = create_branch("row_wise_branch");
 49 
 50     const std::vector<column_booking>& cols = a_bkg.columns();
 51     tools_vforcit(column_booking,cols,it){
 52 
 53 #define TOOLS_WROOT_NTUPLE_CREATE_COL(a__type) \
 54       if((*it).cls_id()==_cid(a__type())) {\
 55         a__type* user = (a__type*)(*it).user_obj();\
 56         if(user) {\
 57           if(!create_column_ref<a__type>((*it).name(),*user)) {\
 58       m_out << "tools::wroot::ntuple : create_column_ref(" << (*it).name() << ") failed." << std::endl;\
 59       safe_clear<icol>(m_cols);\
 60             safe_clear<branch>(m_branches);\
 61       return;\
 62     }\
 63         } else {\
 64           if(!create_column<a__type>((*it).name())) {\
 65       m_out << "tools::wroot::ntuple : create_column(" << (*it).name() << ") failed." << std::endl;\
 66       safe_clear<icol>(m_cols);\
 67             safe_clear<branch>(m_branches);\
 68       return;\
 69     }\
 70         }\
 71       }
 72 
 73 #define TOOLS_WROOT_NTUPLE_CREATE_VEC_COL(a__type) \
 74       if((*it).cls_id()==_cid_std_vector<a__type>()) {\
 75         std::vector<a__type>* vec = (std::vector<a__type>*)(*it).user_obj();\
 76         if(vec) {\
 77           if(!create_column_vector_ref<a__type>((*it).name(),*vec)) {\
 78             m_out << "tools::wroot::ntuple : create_column_vector_ref(" << (*it).name() << ") failed." << std::endl;\
 79       safe_clear<icol>(m_cols);\
 80             safe_clear<branch>(m_branches);\
 81       return;\
 82     }\
 83         } else {\
 84           if(!create_column_vector<a__type>((*it).name())) {\
 85             m_out << "tools::wroot::ntuple : create_column_vector(" << (*it).name() << ") failed." << std::endl;\
 86       safe_clear<icol>(m_cols);\
 87             safe_clear<branch>(m_branches);\
 88       return;\
 89     }\
 90         }\
 91       }
 92 
 93       //below types are in sync with rroot/ntuple.
 94 
 95            TOOLS_WROOT_NTUPLE_CREATE_COL(char)
 96       else TOOLS_WROOT_NTUPLE_CREATE_COL(short)
 97       else TOOLS_WROOT_NTUPLE_CREATE_COL(int)
 98       else TOOLS_WROOT_NTUPLE_CREATE_COL(float)
 99       else TOOLS_WROOT_NTUPLE_CREATE_COL(double)
100 
101       else if((*it).cls_id()==_cid(std::string())) {
102         std::string* user = (std::string*)(*it).user_obj();
103         if(user) {
104           if(!create_column_string_ref((*it).name(),*user)) {
105       m_out << "tools::wroot::ntuple : create_column_string_ref(" << (*it).name() << ") failed." << std::endl;
106       safe_clear<icol>(m_cols);
107             safe_clear<branch>(m_branches);
108       return;
109     }
110         } else {
111           if(!create_column_string((*it).name())) {
112       m_out << "tools::wroot::ntuple : create_column_string(" << (*it).name() << ") failed." << std::endl;
113       safe_clear<icol>(m_cols);
114             safe_clear<branch>(m_branches);
115       return;
116     }
117         }
118       }
119 
120       else TOOLS_WROOT_NTUPLE_CREATE_VEC_COL(char)
121       else TOOLS_WROOT_NTUPLE_CREATE_VEC_COL(short)
122       else TOOLS_WROOT_NTUPLE_CREATE_VEC_COL(int)
123       else TOOLS_WROOT_NTUPLE_CREATE_VEC_COL(float)
124       else TOOLS_WROOT_NTUPLE_CREATE_VEC_COL(double)
125 
126       else if((*it).cls_id()==_cid_std_vector<std::string>()) {\
127         std::vector<std::string>* user = (std::vector<std::string>*)(*it).user_obj();
128         char sep = '\n';
129         if(user) {
130           if(!create_column_vector_string_ref((*it).name(),*user,sep)) {
131       m_out << "tools::wroot::ntuple : create_column_vector_string_ref(" << (*it).name() << ") failed." << std::endl;
132       safe_clear<icol>(m_cols);
133             safe_clear<branch>(m_branches);
134       return;
135     }
136         } else {
137           if(!create_column_vector_string((*it).name(),std::vector<std::string>(),sep)) {
138       m_out << "tools::wroot::ntuple : create_column_vector_string(" << (*it).name() << ") failed." << std::endl;
139       safe_clear<icol>(m_cols);
140             safe_clear<branch>(m_branches);
141       return;
142     }
143         }
144       }
145 
146       // no leaf_store_class() defined for the other types.
147 
148       else {
149         m_out << "tools::wroot::ntuple :"
150               << " for column " << sout((*it).name())
151               << ", type with cid " << (*it).cls_id() << " not yet handled."
152               << std::endl;
153         //throw
154         safe_clear<icol>(m_cols);
155         safe_clear<branch>(m_branches);
156         return;
157       }
158     }
159 #undef TOOLS_WROOT_NTUPLE_CREATE_VEC_COL
160 #undef TOOLS_WROOT_NTUPLE_CREATE_COL
161 
162   }
163 
164   virtual ~ntuple() {
165     safe_clear<icol>(m_cols);
166   }
167 protected:
168   ntuple(const ntuple& a_from):iobject(a_from),itree(a_from),tree(a_from),m_row_wise(a_from.m_row_wise){}
169   ntuple& operator=(const ntuple&){return *this;}
170 public:
171   const std::vector<icol*>& columns() const {return m_cols;}
172   std::vector<icol*>& columns() {return m_cols;}
173 
174   template <class T>
175   column_ref<T>* create_column_ref(const std::string& a_name,const T& a_ref) {
176     if(find_named<icol>(m_cols,a_name)) return 0;
177     branch* _branch = m_row_wise?m_row_wise_branch:create_branch(a_name);
178     if(!_branch) return 0;
179     column_ref<T>* col = new column_ref<T>(*_branch,a_name,a_ref);
180     if(!col) return 0;
181     m_cols.push_back(col);
182     return col;
183   }
184 
185   template <class T>
186   column<T>* create_column(const std::string& a_name,const T& a_def = T()) {
187     if(find_named<icol>(m_cols,a_name)) return 0;
188     branch* _branch = m_row_wise?m_row_wise_branch:create_branch(a_name);
189     if(!_branch) return 0;
190     column<T>* col = new column<T>(*_branch,a_name,a_def);
191     if(!col) return 0;
192     m_cols.push_back(col);
193     return col;
194   }
195 
196   column_string_ref* create_column_string_ref(const std::string& a_name,const std::string& a_ref) {
197     if(find_named<icol>(m_cols,a_name)) return 0;
198     branch* _branch = m_row_wise?m_row_wise_branch:create_branch(a_name);
199     if(!_branch) return 0;
200     column_string_ref* col = new column_string_ref(*_branch,a_name,a_ref);
201     if(!col) return 0;
202     m_cols.push_back(col);
203     return col;
204   }
205 
206   column_string* create_column_string(const std::string& a_name,const std::string& a_def = std::string()) {
207     if(find_named<icol>(m_cols,a_name)) return 0;
208     branch* _branch = m_row_wise?m_row_wise_branch:create_branch(a_name);
209     if(!_branch) return 0;
210     column_string* col = new column_string(*_branch,a_name,a_def);
211     if(!col) return 0;
212     m_cols.push_back(col);
213     return col;
214   }
215 
216   column_vector_string_ref* create_column_vector_string_ref(const std::string& a_name,
217                                                             const std::vector<std::string>& a_ref,char a_sep) {
218     if(find_named<icol>(m_cols,a_name)) return 0;
219     branch* _branch = m_row_wise?m_row_wise_branch:create_branch(a_name);
220     if(!_branch) return 0;
221     column_vector_string_ref* col = new column_vector_string_ref(*_branch,a_name,a_ref,a_sep);
222     if(!col) return 0;
223     m_cols.push_back(col);
224     return col;
225   }
226 
227   column_vector_string* create_column_vector_string(const std::string& a_name,
228                                                     const std::vector<std::string>& a_def,char a_sep) {
229     if(find_named<icol>(m_cols,a_name)) return 0;
230     branch* _branch = m_row_wise?m_row_wise_branch:create_branch(a_name);
231     if(!_branch) return 0;
232     column_vector_string* col = new column_vector_string(*_branch,a_name,a_def,a_sep);
233     if(!col) return 0;
234     m_cols.push_back(col);
235     return col;
236   }
237 
238   template <class T>
239   std_vector_column_ref<T>* create_column_vector_ref(const std::string& a_name,const std::vector<T>& a_ref) {
240     if(find_named<icol>(m_cols,a_name)) return 0;
241     branch* _branch = m_row_wise?m_row_wise_branch:create_std_vector_be_ref<T>(a_name,a_ref);
242     if(!_branch) return 0;
243     std_vector_column_ref<T>* col = new std_vector_column_ref<T>(*_branch,a_name,a_ref);
244     if(!col) return 0;
245     m_cols.push_back(col);
246     return col;
247   }
248 
249   template <class T>
250   std_vector_column<T>* create_column_vector(const std::string& a_name,const std::vector<T>& a_def = std::vector<T>()) {
251     if(find_named<icol>(m_cols,a_name)) return 0;
252     if(m_row_wise) {
253       branch* _branch = m_row_wise_branch;
254       std_vector_column<T>* col = new std_vector_column<T>(*_branch,a_name,a_def);
255       if(!col) return 0;
256       m_cols.push_back(col);
257       return col;
258     } else {
259       std_vector_be_pointer<T>* _branch = create_std_vector_be_pointer<T>(a_name,0);
260       if(!_branch) return 0;
261       std_vector_column<T>* col = new std_vector_column<T>(*_branch,a_name,a_def);
262       if(!col) return 0;
263       _branch->set_pointer(&(col->variable()));
264       m_cols.push_back(col);
265       return col;
266     }
267   }
268 
269   template <class T>
270   column_ref<T>* find_column_ref(const std::string& a_name) {
271     icol* col = find_named<icol>(m_cols,a_name);
272     if(!col) return 0;
273     return id_cast<icol, column_ref<T> >(*col);
274   }
275 
276   template <class T>
277   column<T>* find_column(const std::string& a_name) {
278     icol* col = find_named<icol>(m_cols,a_name);
279     if(!col) return 0;
280     return id_cast<icol, column<T> >(*col);
281   }
282 
283   column_string_ref* find_column_string_ref(const std::string& a_name) {
284     icol* col = find_named<icol>(m_cols,a_name);
285     if(!col) return 0;
286     return id_cast<icol, column_string_ref >(*col);
287   }
288 
289   column_string* find_column_string(const std::string& a_name) {
290     icol* col = find_named<icol>(m_cols,a_name);
291     if(!col) return 0;
292     return id_cast<icol, column_string >(*col);
293   }
294 
295   template <class T>
296   std_vector_column_ref<T>* find_column_vector_ref(const std::string& a_name) {
297     icol* col = find_named<icol>(m_cols,a_name);
298     if(!col) return 0;
299     return id_cast<icol, std_vector_column_ref<T> >(*col);
300   }
301 
302   template <class T>
303   std_vector_column<T>* find_column_vector(const std::string& a_name) {
304     icol* col = find_named<icol>(m_cols,a_name);
305     if(!col) return 0;
306     return id_cast<icol, std_vector_column<T> >(*col);
307   }
308 
309   column_vector_string_ref* find_column_vector_string_ref(const std::string& a_name) {
310     icol* col = find_named<icol>(m_cols,a_name);
311     if(!col) return 0;
312     return id_cast<icol, column_vector_string_ref >(*col);
313   }
314 
315   column_vector_string* find_column_vector_string(const std::string& a_name) {
316     icol* col = find_named<icol>(m_cols,a_name);
317     if(!col) return 0;
318     return id_cast<icol, column_vector_string >(*col);
319   }
320 
321   void print_columns(std::ostream& a_out) {
322     a_out << "for ntuple named " << sout(m_name) << ", number of columns " << m_cols.size() << " :" << std::endl;
323     tools_vforit(icol*,m_cols,it) {
324       a_out << " " << (*it)->name() << std::endl;
325     }
326   }
327 
328   bool add_row() {
329     if(m_cols.empty()) return false;
330     tools_vforit(icol*,m_cols,it) (*it)->add();
331     uint32 n;
332     bool status = tree::fill(n);
333     tools_vforit(icol*,m_cols,it) (*it)->set_def();
334     return status;
335   }
336 
337   void set_basket_size(uint32 a_size) {
338     if(m_row_wise) {
339       if(m_row_wise_branch) m_row_wise_branch->set_basket_size(a_size);
340     } else {
341       tools_vforit(icol*,m_cols,it) (*it)->set_basket_size(a_size);
342     }
343   }
344 
345   ///////////////////////////////////////////////////////////////////////////
346   /// for parallelization : /////////////////////////////////////////////////
347   ///////////////////////////////////////////////////////////////////////////
348   branch* get_row_wise_branch() const {return m_row_wise_branch;}
349   void get_branches(std::vector<branch*>& a_vec) const {
350     a_vec.clear();
351     tools_vforcit(icol*,m_cols,it) a_vec.push_back(&((*it)->get_branch()));
352   }
353 
354   bool merge_number_of_entries() {
355     m_entries = 0; //it should be zero!
356     m_tot_bytes = 0;
357     m_zip_bytes = 0;
358     bool status = true;
359     tools_vforit(icol*,m_cols,it) {
360       if(it==m_cols.begin()) {
361         m_entries = (*it)->get_branch().entries();
362       } else if(m_entries!=(*it)->get_branch().entries()) {
363         m_out << "tools::wroot::ntuple::merge_number_of_entries :"
364               << " branches do not have same number of entries."
365               << std::endl;
366         status = false;
367       }
368       m_tot_bytes += (*it)->get_branch().tot_bytes();
369       m_zip_bytes += (*it)->get_branch().zip_bytes();
370     }
371     return status;
372   }
373 
374   bool mpi_add_basket(impi& a_impi) {
375     uint32 icol; //not used if row_wise.
376     if(!a_impi.unpack(icol)) {
377       m_out << "tools::wroot::ntuple::mpi_add_basket : unpack(icol) failed."<< std::endl;
378       return false;
379     }
380 
381     if(m_row_wise) {
382       if(!m_row_wise_branch) return false;
383 
384       basket* basket = mpi_create_basket(m_out,a_impi,
385                                          m_dir.file().byte_swap(),m_dir.seek_directory(),
386                                          m_row_wise_branch->basket_size());
387       if(!basket) {
388         m_out << "tools::wroot::ntuple::mpi_add_basket : mpi_create_basket() failed."<< std::endl;
389         return false;
390       }
391 
392       uint32 add_bytes,nout;
393       if(!m_row_wise_branch->add_basket(m_dir.file(),*basket,add_bytes,nout)) {
394         m_out << "tools::wroot::ntuple::mpi_add_basket : row wise : branch.add_basket() failed."<< std::endl;
395         delete basket;
396         return false;
397       }
398 
399       delete basket;
400       m_row_wise_branch->set_tot_bytes(m_row_wise_branch->tot_bytes()+add_bytes);
401       m_row_wise_branch->set_zip_bytes(m_row_wise_branch->zip_bytes()+nout);
402 
403     } else {
404       if(icol>=m_cols.size()) {
405         m_out << "tools::wroot::ntuple::mpi_add_basket : column index "  << icol << " >= " << m_cols.size() << std::endl;
406         return false;
407       }
408 
409       branch& _branch = m_cols[icol]->get_branch();
410 
411       basket* basket = mpi_create_basket(m_out,a_impi,
412                                          m_dir.file().byte_swap(),m_dir.seek_directory(),
413                                          _branch.basket_size());
414       if(!basket) {
415         m_out << "tools::wroot::ntuple::mpi_add_basket : mpi_create_basket() failed."<< std::endl;
416         return false;
417       }
418 
419       uint32 add_bytes,nout;
420       if(!_branch.add_basket(m_dir.file(),*basket,add_bytes,nout)) {
421         m_out << "tools::wroot::ntuple::mpi_add_basket : column wise : branch.add_basket() failed."<< std::endl;
422         delete basket;
423         return false;
424       }
425 
426       delete basket;
427       _branch.set_tot_bytes(_branch.tot_bytes()+add_bytes);
428       _branch.set_zip_bytes(_branch.zip_bytes()+nout);
429     }
430     return true;
431   }
432 
433   bool mpi_add_baskets(impi& a_impi) { //column_wise && row_mode only.
434     uint32 _icol = 0;
435     tools_vforcit(icol*,m_cols,it) {
436       uint32 icol;
437       if(!a_impi.unpack(icol)) {
438         m_out << "tools::wroot::ntuple::mpi_add_baskets : unpack(icol) failed."<< std::endl;
439         return false;
440       }
441       if(icol!=_icol) {
442         m_out << "tools::wroot::ntuple::mpi_add_basket : received column index "  << icol << ", whilst " << _icol << " expected." << std::endl;
443         return false;
444       }
445       branch& _branch = m_cols[icol]->get_branch();
446       basket* basket = mpi_create_basket(m_out,a_impi,
447                                          m_dir.file().byte_swap(),m_dir.seek_directory(),
448                                          _branch.basket_size());
449       if(!basket) {
450         m_out << "tools::wroot::ntuple::mpi_add_basket : mpi_create_basket() failed."<< std::endl;
451         return false;
452       }
453 
454       uint32 add_bytes,nout;
455       if(!_branch.add_basket(m_dir.file(),*basket,add_bytes,nout)) {
456         m_out << "tools::wroot::ntuple::mpi_add_basket : column wise : branch.add_basket() failed."<< std::endl;
457         delete basket;
458         return false;
459       }
460 
461       delete basket;
462       _branch.set_tot_bytes(_branch.tot_bytes()+add_bytes);
463       _branch.set_zip_bytes(_branch.zip_bytes()+nout);
464 
465       _icol++;
466     }
467     return true;
468   }
469 
470   bool mpi_end_fill(impi& a_impi) {
471 
472 #define TOOLS_WROOT_NTUPLE_SET_LEAF_LENGTH_MAX(a__type) \
473           {leaf_ref<a__type>* _mleaf_ = _mleaf?id_cast<base_leaf, leaf_ref<a__type> >(*_mleaf):0;\
474             if(_mleaf_) {\
475               uint32 _len;\
476               if(!a_impi.unpack(_len)) return false;\
477               a__type _mx;\
478               if(!a_impi.unpack(_mx)) return false;\
479               _mleaf_->set_length(mx(_len,_mleaf_->length()));\
480               _mleaf_->set_max(mx(_mx,_mleaf_->get_max()));\
481               set_done = true;\
482             }}
483 
484 #define TOOLS_WROOT_NTUPLE_SET_LEAF_STD_VECTOR_LENGTH_MAX(a__type) \
485           {leaf_std_vector_ref<a__type>* _mleaf_ = _mleaf?id_cast<base_leaf, leaf_std_vector_ref<a__type> >(*_mleaf):0;\
486             if(_mleaf_) {\
487               uint32 _len;\
488               if(!a_impi.unpack(_len)) return false;\
489               a__type _mx;\
490               if(!a_impi.unpack(_mx)) return false;\
491               _mleaf_->set_length(mx(_len,_mleaf_->length()));\
492               _mleaf_->set_max(mx(_mx,_mleaf_->get_max()));\
493               set_done = true;\
494             }}
495 
496 #define TOOLS_WROOT_NTUPLE_SET_LEAF_STRING_LENGTH_MAX \
497            {leaf_string_ref* _mleaf_ = _mleaf?id_cast<base_leaf,leaf_string_ref>(*_mleaf):0;\
498             if(_mleaf_) {\
499               uint32 _len;\
500               if(!a_impi.unpack(_len)) return false;\
501               int _mx;\
502               if(!a_impi.unpack(_mx)) return false;\
503               _mleaf_->set_length(mx(_len,_mleaf_->length()));\
504               _mleaf_->set_max(mx(_mx,_mleaf_->get_max()));\
505               set_done = true;\
506             }}
507 
508     if(m_row_wise) {
509       if(!m_row_wise_branch) return false;
510 
511       tools_vforcit(base_leaf*,m_row_wise_branch->leaves(),mit) {
512         base_leaf* _mleaf = *mit;
513 
514         bool set_done = false;
515 
516         TOOLS_WROOT_NTUPLE_SET_LEAF_LENGTH_MAX(char)
517         TOOLS_WROOT_NTUPLE_SET_LEAF_LENGTH_MAX(short)
518         TOOLS_WROOT_NTUPLE_SET_LEAF_LENGTH_MAX(int)
519         TOOLS_WROOT_NTUPLE_SET_LEAF_LENGTH_MAX(float)
520         TOOLS_WROOT_NTUPLE_SET_LEAF_LENGTH_MAX(double)
521 
522         TOOLS_WROOT_NTUPLE_SET_LEAF_STD_VECTOR_LENGTH_MAX(char)
523         TOOLS_WROOT_NTUPLE_SET_LEAF_STD_VECTOR_LENGTH_MAX(short)
524         TOOLS_WROOT_NTUPLE_SET_LEAF_STD_VECTOR_LENGTH_MAX(int)
525         TOOLS_WROOT_NTUPLE_SET_LEAF_STD_VECTOR_LENGTH_MAX(float)
526         TOOLS_WROOT_NTUPLE_SET_LEAF_STD_VECTOR_LENGTH_MAX(double)
527 
528         TOOLS_WROOT_NTUPLE_SET_LEAF_STRING_LENGTH_MAX
529 
530         if(!set_done) {
531           m_out << "tools::wroot::ntuple::mpi_end_fill :"
532                 << " leaf " << _mleaf->name() << " with cid " << _mleaf->id_cls() << " not treated." << std::endl;
533           return false;
534         }
535       }
536 
537     } else { // column wise :
538       tools_vforcit(wroot::icol*,m_cols,it) {
539         base_leaf* _mleaf = (*it)->get_leaf();
540 
541         bool set_done = false;
542         TOOLS_WROOT_NTUPLE_SET_LEAF_STRING_LENGTH_MAX
543 
544         if(!set_done) {
545           uint32 _len;
546           if(!a_impi.unpack(_len)) return false;
547           int _mx;
548           if(!a_impi.unpack(_mx)) return false;
549         }
550       }
551     }
552 
553 #undef TOOLS_WROOT_NTUPLE_SET_LEAF_LENGTH_MAX
554 #undef TOOLS_WROOT_NTUPLE_SET_LEAF_STD_VECTOR_LENGTH_MAX
555 #undef TOOLS_WROOT_NTUPLE_SET_LEAF_STRING_LENGTH_MAX
556 
557     return true;
558   }
559 
560 protected:
561   std::vector<icol*> m_cols;
562   bool m_row_wise;
563   branch* m_row_wise_branch; //used if row_wise.
564 };
565 
566 }}
567 
568 #endif