g4tools  5.4.0
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tools::rroot::ntuple Class Reference
Inheritance diagram for tools::rroot::ntuple:
Inheritance graph
[legend]
Collaboration diagram for tools::rroot::ntuple:
Collaboration graph
[legend]

Classes

class  column
 
class  column_element
 
class  column_element_ref
 
class  column_ref
 
class  column_string
 
class  column_string_ref
 
class  column_vector_string
 
class  column_vector_string_ref
 
class  std_vector_column_ref
 

Public Member Functions

virtual const std::string & s_cls () const
 
virtual void start ()
 
virtual bool next ()
 
virtual read::icolfind_icol (const std::string &a_name)
 
virtual const std::vector< read::icol * > & columns () const
 
virtual const std::string & title () const
 
virtual bool number_of_entries (uint64 &a_value) const
 
 ntuple (tree &a_tree)
 
virtual ~ntuple ()
 
bool initialize (std::ostream &a_out, const ntuple_binding &a_bd=ntuple_binding(), bool a_enforce_double=false)
 
bool get_row () const
 
- Public Member Functions inherited from tools::read::intuple
virtual ~intuple ()
 
virtual void stop ()
 
size_t number_of_columns () const
 
void column_names (std::vector< std::string > &a_names) const
 
icolfind_icol_case_insensitive (const std::string &a_name)
 
template<class T >
icolumn< T > * find_column (const std::string &a_name)
 
template<class T >
bool find_column (const std::string &a_name, icolumn< T > *&a_col, bool a_case_sensitive=true)
 
template<class T >
bool column_is_of_type (const std::string &a_name, bool &a_is, bool a_case_sensitive=true)
 
template<class T >
bool column_min (unsigned int a_col, T &a_value)
 
template<class T >
bool column_max (unsigned int a_col, T &a_value)
 

Static Public Member Functions

static const std::string & s_class ()
 
- Static Public Member Functions inherited from tools::read::intuple
static const std::string & s_class ()
 

Protected Member Functions

 ntuple (const ntuple &a_from)
 
ntupleoperator= (const ntuple &)
 

Protected Attributes

treem_tree
 
std::vector< read::icol * > m_cols
 
int64 m_index
 

Detailed Description

Definition at line 28 of file ntuple.

Constructor & Destructor Documentation

◆ ntuple() [1/2]

tools::rroot::ntuple::ntuple ( tree a_tree)
inline

Definition at line 488 of file ntuple.

488  :m_tree(a_tree),m_index(-1){
489 #ifdef TOOLS_MEM
490  mem::increment(s_class().c_str());
491 #endif
492  }

◆ ~ntuple()

virtual tools::rroot::ntuple::~ntuple ( )
inlinevirtual

Definition at line 493 of file ntuple.

493  {
494  safe_clear<read::icol>(m_cols);
495 #ifdef TOOLS_MEM
496  mem::decrement(s_class().c_str());
497 #endif
498  }

◆ ntuple() [2/2]

tools::rroot::ntuple::ntuple ( const ntuple a_from)
inlineprotected

Definition at line 500 of file ntuple.

501  :parent(a_from),m_tree(a_from.m_tree){
502 #ifdef TOOLS_MEM
503  mem::increment(s_class().c_str());
504 #endif
505  }

Member Function Documentation

◆ columns()

virtual const std::vector<read::icol*>& tools::rroot::ntuple::columns ( ) const
inlinevirtual

Implements tools::read::intuple.

Definition at line 46 of file ntuple.

46 {return m_cols;}

◆ find_icol()

virtual read::icol* tools::rroot::ntuple::find_icol ( const std::string &  a_name)
inlinevirtual

Implements tools::read::intuple.

Definition at line 43 of file ntuple.

43  {
44  return find_named<read::icol>(m_cols,a_name);
45  }

◆ get_row()

bool tools::rroot::ntuple::get_row ( ) const
inline

Definition at line 720 of file ntuple.

720  {
721  bool status = true;
722  tools_vforcit(read::icol*,m_cols,it) {
723  if(!(*it)->fetch_entry()) {
724  m_tree.out() << "tools::rroot::ntuple::get_row : fetch_entry() failed for leaf " << (*it)->name() << std::endl;
725  status = false;
726  }
727  }
728  return status;
729  }

◆ initialize()

bool tools::rroot::ntuple::initialize ( std::ostream &  a_out,
const ntuple_binding a_bd = ntuple_binding(),
bool  a_enforce_double = false 
)
inline

Definition at line 508 of file ntuple.

508  {
509  safe_clear<read::icol>(m_cols);
510 
511  std::vector<base_leaf*> leaves;
512  m_tree.find_leaves(leaves);
513  tools_vforcit(base_leaf*,leaves,it) {
514  base_leaf* bl = (*it);
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."
519  << std::endl;
520  safe_clear<read::icol>(m_cols);
521  return false;
522  }
523  branch* _branch = m_tree.find_leaf_branch(*bl);
524  if(!_branch) {
525  a_out << "tools::rroot::ntuple::initialize :"
526  << " can't find branch of leaf " << sout(bl->name()) << "."
527  << std::endl;
528  safe_clear<read::icol>(m_cols);
529  return false;
530  }
531 
532  //a_out << "tools::rroot::ntuple::initialize :"
533  // << " branch " << _branch->name()
534  // << ", entries " << _branch->entry_number() << "."
535  // << std::endl;
536 
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;\
542  if(!user_obj) {\
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);\
546  } else {\
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);\
549  }\
550  } else {\
551  const base_leaf* lfc = bl->leaf_count();\
552  if(lfc) {\
553  /*::printf("debug : ntuple : create col leaf count : %s\n",bl->name().c_str());*/\
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 << "."\
558  << std::endl;\
559  safe_clear<read::icol>(m_cols);\
560  return false;\
561  }\
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);\
566  } else {\
567  /*::printf("debug : ntuple : create col : %s\n",bl->name().c_str());*/\
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 << "."\
572  << std::endl;\
573  safe_clear<read::icol>(m_cols);\
574  return false;\
575  }\
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);\
580  }\
581  }\
582  }
583 
584  //below types are in sync with wroot/ntuple.
585 
590  else TOOLS_RROOT_NTUPLE_CREATE_COL(double)
591 
592  else if(leaf_string* ls = safe_cast<base_leaf, leaf_string >(*bl) ){
593  char sep = '\n';
594  cid user_cid;void* user_obj;
595  if(!a_bd.find_user_obj(bl->name(),user_cid,user_obj)) {
596  column_vector_string* col = new column_vector_string(m_tree.file(),*_branch,*ls,m_index,sep);
597  m_cols.push_back(col);
598  } else if(user_cid==_cid_std_vector<std::string>()) {
599  std::vector<std::string>* user_var = (std::vector<std::string>*)user_obj;
600  if(user_var) {
601  column_vector_string_ref* col = new column_vector_string_ref(m_tree.file(),*_branch,*ls,m_index,*user_var,sep);
602  m_cols.push_back(col);
603  } else {
604  column_vector_string* col = new column_vector_string(m_tree.file(),*_branch,*ls,m_index,sep);
605  m_cols.push_back(col);
606  }
607  } else if(user_cid==_cid(std::string())) {
608  std::string* user_var = (std::string*)user_obj;
609  if(user_var) {
610  column_string_ref* col = new column_string_ref(m_tree.file(),*_branch,*ls,m_index,*user_var);
611  m_cols.push_back(col);
612  } else {
613  column_string* col = new column_string(m_tree.file(),*_branch,*ls,m_index);
614  m_cols.push_back(col);
615  }
616  } else {
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 << "."
621  << std::endl;
622  safe_clear<read::icol>(m_cols);
623  return false;
624  }
625 
626  } else if(leaf_element* le = safe_cast<base_leaf,leaf_element>(*bl) ){
627 
628  branch_element* be = safe_cast<branch,branch_element>(*_branch);
629  if(!be) {
630  a_out << "tools::rroot::ntuple::initialize : branch is not a branch_element." << std::endl;
631  safe_clear<read::icol>(m_cols);
632  return false;
633  }
634 
635 #define TOOLS_RROOT_NTUPLE_CREATE_VEC_COL(a__name,a__type) \
636  if(be->class_name()==a__name) {\
637  /*::printf("debug : ntuple : create vec col : %s\n",bl->name().c_str());*/\
638  typedef a__type el_t;\
639  std::vector<el_t>* user_var = a_bd.find_vector_variable<el_t>(bl->name());\
640  if(user_var) {\
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);\
644  } else {\
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);\
648  }\
649  }
650 
651  TOOLS_RROOT_NTUPLE_CREATE_VEC_COL("vector<char>",char)
652  else TOOLS_RROOT_NTUPLE_CREATE_VEC_COL("vector<short>",short)
653  //else TOOLS_RROOT_NTUPLE_CREATE_VEC_COL("vector<unsigned short>",unsigned short)
654  //else TOOLS_RROOT_NTUPLE_CREATE_VEC_COL("vector<unsigned int>",unsigned int)
655  else TOOLS_RROOT_NTUPLE_CREATE_VEC_COL("vector<int>",int)
656  else TOOLS_RROOT_NTUPLE_CREATE_VEC_COL("vector<float>",float)
657  else TOOLS_RROOT_NTUPLE_CREATE_VEC_COL("vector<double>",double)
658 
659  //else TOOLS_RROOT_NTUPLE_CREATE_VEC_COL("vector<string>",std::string)
660  //else TOOLS_RROOT_NTUPLE_CREATE_VEC_COL("vector<unsigned long>",uint64) //beurk
661 
662  // WARNING : take care of the space in "> >".
663  /* VisualC++ : the below does not compile.
664  else TOOLS_RROOT_NTUPLE_CREATE_VEC_COL("vector<vector<unsigned short> >",std::vector<unsigned short>)
665  else TOOLS_RROOT_NTUPLE_CREATE_VEC_COL("vector<vector<short> >",std::vector<short>)
666  else TOOLS_RROOT_NTUPLE_CREATE_VEC_COL("vector<vector<unsigned int> >",std::vector<unsigned int>)
667  else TOOLS_RROOT_NTUPLE_CREATE_VEC_COL("vector<vector<int> >",std::vector<short>)
668  else TOOLS_RROOT_NTUPLE_CREATE_VEC_COL("vector<vector<float> >",std::vector<float>)
669  else TOOLS_RROOT_NTUPLE_CREATE_VEC_COL("vector<vector<double> >",std::vector<double>)
670  */
671 
672  else {
673  a_out << "tools::rroot::ntuple::initialize :"
674  << " WARNING : leaf element"
675  << " with name " << sout(bl->name())
676  << ",title " << sout(bl->title())
677  << " br_elem class name " << be->class_name() << "."
678  << " entries " << be->entry_number() << "."
679  << std::endl;
680  }
681 
682  } else {
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()) << "."
688  << " Not fatal."
689  << std::endl;
690  }
691 
692  }
693 
694 #undef TOOLS_RROOT_NTUPLE_CREATE_VEC_COL
695 #undef TOOLS_RROOT_NTUPLE_CREATE_COL
696 
697  size_t num = m_cols.size();
698  if(!num) {
699  a_out << "tools::rroot::ntuple::initialize :"
700  << " zero columns."
701  << std::endl;
702  return false;
703  }
704 
705  {tools_vforcit(column_binding,a_bd.columns(),it) {
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."
709  << std::endl;
710  }
711  }}
712 
713  //a_out << "tools::rroot::ntuple::initialize :"
714  // << " number of columns " << num << "."
715  // << std::endl;
716 
717  return true;
718  }

◆ next()

virtual bool tools::rroot::ntuple::next ( )
inlinevirtual

Implements tools::read::intuple.

Definition at line 38 of file ntuple.

38  {
39  m_index++;
40  if((uint64)m_index>=m_tree.entries()) return false;
41  return true;
42  }

◆ number_of_entries()

virtual bool tools::rroot::ntuple::number_of_entries ( uint64 a_value) const
inlinevirtual

Implements tools::read::intuple.

Definition at line 48 of file ntuple.

48 {a_value = m_tree.entries();return true;}

◆ operator=()

ntuple& tools::rroot::ntuple::operator= ( const ntuple )
inlineprotected

Definition at line 506 of file ntuple.

506 {return *this;}

◆ s_class()

static const std::string& tools::rroot::ntuple::s_class ( )
inlinestatic

Definition at line 31 of file ntuple.

31  {
32  static const std::string s_v("tools::rroot::ntuple");
33  return s_v;
34  }

◆ s_cls()

virtual const std::string& tools::rroot::ntuple::s_cls ( ) const
inlinevirtual

Reimplemented in tools::rroot::fac_tree_ntuple.

Definition at line 35 of file ntuple.

35 {return s_class();}

◆ start()

virtual void tools::rroot::ntuple::start ( )
inlinevirtual

Implements tools::read::intuple.

Definition at line 37 of file ntuple.

37 {m_index = -1;}

◆ title()

virtual const std::string& tools::rroot::ntuple::title ( ) const
inlinevirtual

Implements tools::read::intuple.

Definition at line 47 of file ntuple.

47 {return m_tree.title();}

Member Data Documentation

◆ m_cols

std::vector<read::icol*> tools::rroot::ntuple::m_cols
protected

Definition at line 732 of file ntuple.

◆ m_index

int64 tools::rroot::ntuple::m_index
protected

Definition at line 733 of file ntuple.

◆ m_tree

tree& tools::rroot::ntuple::m_tree
protected

Definition at line 731 of file ntuple.


The documentation for this class was generated from the following file:
tools::rroot::tree::entries
uint64 entries() const
Definition: tree:128
tools::uint64
unsigned long long uint64
Definition: typedefs:72
tools::_cid
cid _cid(byte)
Definition: cids:14
tools::rroot::ntuple::s_class
static const std::string & s_class()
Definition: ntuple:31
tools::rroot::tree::title
virtual const std::string & title() const
Definition: tree:29
tools::rroot::ntuple::m_cols
std::vector< read::icol * > m_cols
Definition: ntuple:732
TOOLS_RROOT_NTUPLE_CREATE_VEC_COL
#define TOOLS_RROOT_NTUPLE_CREATE_VEC_COL(a__name, a__type)
tools::rroot::ntuple::m_tree
tree & m_tree
Definition: ntuple:731
tools::rroot::tree::find_leaf_branch
branch * find_leaf_branch(const base_leaf &a_leaf) const
Definition: tree:118
tools::rroot::tree::find_leaves
void find_leaves(std::vector< base_leaf * > &a_leaves) const
Definition: tree:108
tools::rroot::tree::out
std::ostream & out() const
Definition: tree:63
tools::rroot::ntuple::m_index
int64 m_index
Definition: ntuple:733
tools::rroot::tree::file
ifile & file()
Definition: tree:65
TOOLS_RROOT_NTUPLE_CREATE_COL
#define TOOLS_RROOT_NTUPLE_CREATE_COL(a__type)
tools::sep
const std::string & sep()
Definition: sep:11
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::cid
unsigned short cid
Definition: cid:9