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 ]

Diff markup

Differences between /externals/g4tools/include/tools/wroot/ntuple (Version 11.3.0) and /externals/g4tools/include/tools/wroot/ntuple (Version 11.1.2)


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