4 #ifndef tools_wroot_ntuple
5 #define tools_wroot_ntuple
16 #include "../ntuple_booking"
39 ntuple(
idir& a_dir,
const std::string& a_name,
const std::string& a_title,
bool a_row_wise =
false)
50 const std::vector<column_booking>& cols = a_bkg.
columns();
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();\
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);\
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);\
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();\
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);\
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);\
101 else if((*it).cls_id()==
_cid(std::string())) {
102 std::string* user = (std::string*)(*it).user_obj();
105 m_out <<
"tools::wroot::ntuple : create_column_string_ref(" << (*it).name() <<
") failed." << std::endl;
112 m_out <<
"tools::wroot::ntuple : create_column_string(" << (*it).name() <<
") failed." << std::endl;
126 else if((*it).cls_id()==_cid_std_vector<std::string>()) {\
127 std::vector<std::string>* user = (std::vector<std::string>*)(*it).user_obj();
131 m_out <<
"tools::wroot::ntuple : create_column_vector_string_ref(" << (*it).name() <<
") failed." << std::endl;
138 m_out <<
"tools::wroot::ntuple : create_column_vector_string(" << (*it).name() <<
") failed." << std::endl;
149 m_out <<
"tools::wroot::ntuple :"
150 <<
" for column " <<
sout((*it).name())
151 <<
", type with cid " << (*it).cls_id() <<
" not yet handled."
159 #undef TOOLS_WROOT_NTUPLE_CREATE_VEC_COL
160 #undef TOOLS_WROOT_NTUPLE_CREATE_COL
176 if(find_named<icol>(
m_cols,a_name))
return 0;
178 if(!_branch)
return 0;
179 column_ref<T>* col =
new column_ref<T>(*_branch,a_name,a_ref);
187 if(find_named<icol>(
m_cols,a_name))
return 0;
189 if(!_branch)
return 0;
190 column<T>* col =
new column<T>(*_branch,a_name,a_def);
197 if(find_named<icol>(
m_cols,a_name))
return 0;
199 if(!_branch)
return 0;
200 column_string_ref* col =
new column_string_ref(*_branch,a_name,a_ref);
207 if(find_named<icol>(
m_cols,a_name))
return 0;
209 if(!_branch)
return 0;
210 column_string* col =
new column_string(*_branch,a_name,a_def);
217 const std::vector<std::string>& a_ref,
char a_sep) {
218 if(find_named<icol>(
m_cols,a_name))
return 0;
220 if(!_branch)
return 0;
221 column_vector_string_ref* col =
new column_vector_string_ref(*_branch,a_name,a_ref,a_sep);
228 const std::vector<std::string>& a_def,
char a_sep) {
229 if(find_named<icol>(
m_cols,a_name))
return 0;
231 if(!_branch)
return 0;
232 column_vector_string* col =
new column_vector_string(*_branch,a_name,a_def,a_sep);
240 if(find_named<icol>(
m_cols,a_name))
return 0;
242 if(!_branch)
return 0;
243 std_vector_column_ref<T>* col =
new std_vector_column_ref<T>(*_branch,a_name,a_ref);
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;
254 std_vector_column<T>* col =
new std_vector_column<T>(*_branch,a_name,a_def);
260 if(!_branch)
return 0;
261 std_vector_column<T>* col =
new std_vector_column<T>(*_branch,a_name,a_def);
273 return id_cast<icol, column_ref<T> >(*col);
280 return id_cast<icol, column<T> >(*col);
286 return id_cast<icol, column_string_ref >(*col);
292 return id_cast<icol, column_string >(*col);
299 return id_cast<icol, std_vector_column_ref<T> >(*col);
306 return id_cast<icol, std_vector_column<T> >(*col);
312 return id_cast<icol, column_vector_string_ref >(*col);
318 return id_cast<icol, column_vector_string >(*col);
322 a_out <<
"for ntuple named " <<
sout(
m_name) <<
", number of columns " <<
m_cols.size() <<
" :" << std::endl;
324 a_out <<
" " << (*it)->name() << std::endl;
329 if(
m_cols.empty())
return false;
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."
377 m_out <<
"tools::wroot::ntuple::mpi_add_basket : unpack(icol) failed."<< std::endl;
388 m_out <<
"tools::wroot::ntuple::mpi_add_basket : mpi_create_basket() failed."<< std::endl;
394 m_out <<
"tools::wroot::ntuple::mpi_add_basket : row wise : branch.add_basket() failed."<< std::endl;
405 m_out <<
"tools::wroot::ntuple::mpi_add_basket : column index " <<
icol <<
" >= " <<
m_cols.size() << std::endl;
415 m_out <<
"tools::wroot::ntuple::mpi_add_basket : mpi_create_basket() failed."<< std::endl;
421 m_out <<
"tools::wroot::ntuple::mpi_add_basket : column wise : branch.add_basket() failed."<< std::endl;
438 m_out <<
"tools::wroot::ntuple::mpi_add_baskets : unpack(icol) failed."<< std::endl;
442 m_out <<
"tools::wroot::ntuple::mpi_add_basket : received column index " <<
icol <<
", whilst " << _icol <<
" expected." << std::endl;
450 m_out <<
"tools::wroot::ntuple::mpi_add_basket : mpi_create_basket() failed."<< std::endl;
456 m_out <<
"tools::wroot::ntuple::mpi_add_basket : column wise : branch.add_basket() failed."<< std::endl;
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;\
476 if(!a_impi.unpack(_len)) return false;\
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()));\
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;\
488 if(!a_impi.unpack(_len)) return false;\
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()));\
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;\
500 if(!a_impi.unpack(_len)) return false;\
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()));\
514 bool set_done =
false;
531 m_out <<
"tools::wroot::ntuple::mpi_end_fill :"
532 <<
" leaf " << _mleaf->
name() <<
" with cid " << _mleaf->
id_cls() <<
" not treated." << std::endl;
541 bool set_done =
false;
546 if(!a_impi.
unpack(_len))
return false;
548 if(!a_impi.
unpack(_mx))
return false;
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