Go to the documentation of this file.
4 #ifndef tools_rroot_ntuple
5 #define tools_rroot_ntuple
18 #include "../ntuple_binding"
19 #include "../get_lines"
32 static const std::string s_v(
"tools::rroot::ntuple");
44 return find_named<read::icol>(
m_cols,a_name);
46 virtual const std::vector<read::icol*>&
columns()
const {
return m_cols;}
51 template <
class T,
class LEAF>
58 if(
void* p = cmp_cast<column_ref>(
this,a_class))
return p;
63 virtual const std::string&
name()
const {
return m_leaf.name();}
91 if(&a_from==
this)
return *
this;
100 typename LEAF::value_t _tmp;
101 if(!
m_leaf.value(0,_tmp))
return false;
114 template <
class T,
class LEAF>
121 if(
void* p = cmp_cast<column>(
this,a_class))
return p;
134 ,
read::icolumn<T>(a_from)
139 if(&a_from==
this)
return *
this;
153 static const std::string s_v;
154 return _cid(s_v)+10000;
158 if(
void* p = cmp_cast<column_string_ref>(
this,a_class))
return p;
184 if(&a_from==
this)
return *
this;
198 if(!_cs) {
m_ref.clear();
return false;}
214 static const std::string s_v;
219 if(
void* p = cmp_cast<column_string>(
this,a_class))
return p;
236 if(&a_from==
this)
return *
this;
249 static cid id_class() {
return _cid_std_vector<std::string>()+10000;}
252 if(
void* p = cmp_cast<column_vector_string_ref>(
this,a_class))
return p;
261 std::vector<std::string>& a_ref,
char a_sep)
275 if(&a_from==
this)
return *
this;
303 if(
void* p = cmp_cast<column_vector_string>(
this,a_class))
return p;
320 if(&a_from==
this)
return *
this;
338 if(
void* p = cmp_cast<std_vector_column_ref>(
this,a_class))
return p;
343 virtual const std::string&
name()
const {
return m_leaf.name();}
348 if(
m_ref.empty()) {a_v = T();
return false;}
372 if(&a_from==
this)
return *
this;
391 template <
class RT,
class T>
398 if(
void* p = cmp_cast<column_element_ref>(
this,a_class))
return p;
430 if(&a_from==
this)
return *
this;
438 if(!obj) {
m_ref = T();
return false;}
439 RT* v = id_cast<iro,RT>(*obj);
440 if(!v) {
m_ref = T();
return false;}
452 template <
class RT,
class T>
459 if(
void* p = cmp_cast<column_element>(
this,a_class))
return p;
472 ,
read::icolumn<T>(a_from)
477 if(&a_from==
this)
return *
this;
490 mem::increment(
s_class().c_str());
494 safe_clear<read::icol>(
m_cols);
496 mem::decrement(
s_class().c_str());
503 mem::increment(
s_class().c_str());
509 safe_clear<read::icol>(
m_cols);
511 std::vector<base_leaf*> leaves;
515 if(find_named<read::icol>(
m_cols,bl->
name())) {
516 a_out <<
"tools::rroot::ntuple::initialize :"
517 <<
" column with name " <<
sout(bl->
name())
518 <<
" already exists."
520 safe_clear<read::icol>(
m_cols);
525 a_out <<
"tools::rroot::ntuple::initialize :"
526 <<
" can't find branch of leaf " <<
sout(bl->
name()) <<
"."
528 safe_clear<read::icol>(
m_cols);
537 #define TOOLS_RROOT_NTUPLE_CREATE_COL(a__type) \
538 if(leaf<a__type>* lf_##a__type = safe_cast<base_leaf, leaf<a__type> >(*bl) ){\
539 cid user_cid;void* user_obj;\
540 a_bd.find_user_obj(bl->name(),user_cid,user_obj);\
541 typedef leaf<a__type> leaf_t;\
543 if(a_enforce_double) {\
544 column<double,leaf_t>* col = new column<double,leaf_t>(m_tree.file(),*_branch,*lf_##a__type,m_index);\
545 m_cols.push_back(col);\
547 column<a__type,leaf_t>* col = new column<a__type,leaf_t>(m_tree.file(),*_branch,*lf_##a__type,m_index);\
548 m_cols.push_back(col);\
551 const base_leaf* lfc = bl->leaf_count();\
554 if(user_cid!=_cid_std_vector<a__type>()) {\
555 a_out << "tools::rroot::ntuple::initialize :"\
556 << " for leaf with name " << sout(bl->name())\
557 << ", user variable type is not a std::vector of " << #a__type << "."\
559 safe_clear<read::icol>(m_cols);\
562 std::vector<a__type>* user_var = (std::vector<a__type>*)user_obj;\
563 std_vector_column_ref<a__type>* col = new std_vector_column_ref<a__type>\
564 (m_tree.file(),*_branch,*lf_##a__type,m_index,*user_var);\
565 m_cols.push_back(col);\
568 if(user_cid!=_cid(a__type())) {\
569 a_out << "tools::rroot::ntuple::initialize :"\
570 << " for leaf with name " << sout(bl->name())\
571 << ", user variable type is not a " << #a__type << "."\
573 safe_clear<read::icol>(m_cols);\
576 a__type* user_var = (a__type*)user_obj;\
577 column_ref<a__type,leaf_t>* col =\
578 new column_ref<a__type,leaf_t>(m_tree.file(),*_branch,*lf_##a__type,m_index,*user_var);\
579 m_cols.push_back(col);\
592 else if(
leaf_string* ls = safe_cast<base_leaf, leaf_string >(*bl) ){
594 cid user_cid;
void* user_obj;
595 if(!a_bd.find_user_obj(bl->
name(),user_cid,user_obj)) {
598 }
else if(user_cid==_cid_std_vector<std::string>()) {
599 std::vector<std::string>* user_var = (std::vector<std::string>*)user_obj;
607 }
else if(user_cid==
_cid(std::string())) {
608 std::string* user_var = (std::string*)user_obj;
617 a_out <<
"tools::rroot::ntuple::initialize :"
618 <<
" for leaf with name " <<
sout(ls->name())
619 <<
", user variable type is not a std::string or a std::vector<std::string>."
620 <<
". It's class id is " << user_cid <<
"."
622 safe_clear<read::icol>(
m_cols);
626 }
else if(
leaf_element* le = safe_cast<base_leaf,leaf_element>(*bl) ){
630 a_out <<
"tools::rroot::ntuple::initialize : branch is not a branch_element." << std::endl;
631 safe_clear<read::icol>(
m_cols);
635 #define TOOLS_RROOT_NTUPLE_CREATE_VEC_COL(a__name,a__type) \
636 if(be->class_name()==a__name) {\
638 typedef a__type el_t;\
639 std::vector<el_t>* user_var = a_bd.find_vector_variable<el_t>(bl->name());\
641 typedef column_element_ref< stl_vector<el_t> , std::vector<el_t> > ce_t;\
642 ce_t* col = new ce_t(m_tree.file(),*be,*le,m_index,*user_var);\
643 m_cols.push_back(col);\
645 typedef column_element< stl_vector<el_t> , std::vector<el_t> > ce_t;\
646 ce_t* col = new ce_t(m_tree.file(),*be,*le,m_index);\
647 m_cols.push_back(col);\
673 a_out <<
"tools::rroot::ntuple::initialize :"
674 <<
" WARNING : leaf element"
675 <<
" with name " <<
sout(bl->
name())
677 <<
" br_elem class name " << be->
class_name() <<
"."
683 a_out <<
"tools::rroot::ntuple::initialize :"
684 <<
" WARNING : column type not yet handled for leaf"
685 <<
" with name " <<
sout(bl->
name())
686 <<
" and title " <<
sout(bl->
title()) <<
"."
687 <<
" s_cls() is " <<
sout(bl->
s_cls()) <<
"."
694 #undef TOOLS_RROOT_NTUPLE_CREATE_VEC_COL
695 #undef TOOLS_RROOT_NTUPLE_CREATE_COL
697 size_t num =
m_cols.size();
699 a_out <<
"tools::rroot::ntuple::initialize :"
706 if(!find_named<read::icol>(
m_cols,(*it).name())) {
707 a_out <<
"tools::rroot::ntuple::initialize :"
708 <<
" warning : for column binding with name " <<
sout((*it).name()) <<
", no ntuple column found."
723 if(!(*it)->fetch_entry()) {
724 m_tree.
out() <<
"tools::rroot::ntuple::get_row : fetch_entry() failed for leaf " << (*it)->name() << std::endl;
754 static const std::string s_v(
"tools::rroot::fac_tree_ntuple");
#define TOOLS_RROOT_NTUPLE_CREATE_VEC_COL(a__name, a__type)
#define TOOLS_RROOT_NTUPLE_CREATE_COL(a__type)
#define tools_vforcit(a__T, a__v, a__it)