ROOT  6.06/09
Reference Guide
Node.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Kai Voss
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Classes: Node *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Node for the BinarySearch or Decision Trees *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
16  * Kai Voss <Kai.Voss@cern.ch> - U. of Victoria, Canada *
17  * *
18  * Copyright (c) 2005: *
19  * CERN, Switzerland *
20  * U. of Victoria, Canada *
21  * MPI-K Heidelberg, Germany *
22  * *
23  * Redistribution and use in source and binary forms, with or without *
24  * modification, are permitted according to the terms listed in LICENSE *
25  * (http://tmva.sourceforge.net/LICENSE) *
26  **********************************************************************************/
27 
28 #ifndef ROOT_TMVA_Node
29 #define ROOT_TMVA_Node
30 
31 //////////////////////////////////////////////////////////////////////////
32 // //
33 // Node //
34 // //
35 // Node base class for the BinarySearch or Decision Trees Nodes //
36 // //
37 //////////////////////////////////////////////////////////////////////////
38 
39 #include <iosfwd>
40 #ifndef ROOT_Rtypes
41 #include "Rtypes.h"
42 #endif
43 
44 #ifndef ROOT_TMVA_Version
45 #include "TMVA/Version.h"
46 #endif
47 
48 namespace TMVA {
49 
50  class Node;
51  class Event;
52  class BinaryTree;
53 
54  std::ostream& operator<<( std::ostream& os, const Node& node );
55  std::ostream& operator<<( std::ostream& os, const Node* node );
56 
57  // a class used to identify a Node; (needed for recursive reading from text file)
58  // (currently it is NOT UNIQUE... but could eventually made it
59  // a node in the tree structure
60  class Node {
61 
62  // output operator for a node
63  friend std::ostream& operator << (std::ostream& os, const Node& node);
64  // output operator with a pointer to the node (which still prints the node itself)
65  friend std::ostream& operator << (std::ostream& os, const Node* node);
66 
67  public:
68 
69  // constructor of a node
70  Node();
71 
72  // constructor of a daughter node as a daughter of 'p'
73  Node( Node* p, char pos );
74 
75  // copy constructor
76  Node( const Node &n );
77 
78  // destructor
79  virtual ~Node();
80 
81  virtual Node* CreateNode() const = 0;
82 
83  // test event if i{ decends the tree at this node to the right
84  virtual Bool_t GoesRight( const Event& ) const = 0;
85  // test event if it decends the tree at this node to the left
86 
87  virtual Bool_t GoesLeft ( const Event& ) const = 0;
88  // test event if it is equal to the event that "makes the node" (just for the "search tree"
89 
90  // return pointer to the left/right daughter or parent node
91  inline virtual Node* GetLeft () const { return fLeft; }
92  inline virtual Node* GetRight () const { return fRight; }
93  inline virtual Node* GetParent() const { return fParent; }
94 
95  // set pointer to the left/right daughter or parent node
96  inline virtual void SetLeft (Node* l) { fLeft = l;}
97  inline virtual void SetRight (Node* r) { fRight = r;}
98  inline virtual void SetParent(Node* p) { fParent = p;}
99 
100  //recursively go through the part of the tree below this node and count all daughters
102 
103  // printout of the node
104  virtual void Print( std::ostream& os ) const = 0;
105 
106  // recursive printout of the node and it daughters
107  virtual void PrintRec ( std::ostream& os ) const = 0;
108 
109  void* AddXMLTo(void* parent) const;
110  void ReadXML(void* node, UInt_t tmva_Version_Code = TMVA_VERSION_CODE );
111  virtual void AddAttributesToNode(void* node) const = 0;
112  virtual void AddContentToNode(std::stringstream& s) const = 0;
113 
114  // Set depth, layer of the where the node is within the tree, seen from the top (root)
115  void SetDepth(UInt_t d){fDepth=d;}
116 
117  // Return depth, layer of the where the node is within the tree, seen from the top (root)
118  UInt_t GetDepth() const {return fDepth;}
119 
120  // set node position, i.e, the node is a left (l) or right (r) daugther
121  void SetPos(char s) {fPos=s;}
122 
123  // Return the node position, i.e, the node is a left (l) or right (r) daugther
124  char GetPos() const {return fPos;}
125 
126  // Return the pointer to the Parent tree to which the Node belongs
127  virtual TMVA::BinaryTree* GetParentTree() const {return fParentTree;}
128 
129  // set the pointer to the Parent Tree to which the Node belongs
130  virtual void SetParentTree(TMVA::BinaryTree* t) {fParentTree = t;}
131 
132  int GetCount();
133 
134  virtual Bool_t ReadDataRecord( std::istream&, UInt_t tmva_Version_Code = TMVA_VERSION_CODE ) = 0;
135  virtual void ReadAttributes(void* node, UInt_t tmva_Version_Code = TMVA_VERSION_CODE ) = 0;
136  virtual void ReadContent(std::stringstream& s) =0;
137 
138  protected:
139 
140  Node* fParent; // the previous (parent) node
141  Node* fLeft; // pointers to the two "daughter" nodes
142  Node* fRight; // pointers to the two "daughter" nodes
143 
144  char fPos; // position, i.e. it is a left (l) or right (r) daughter
145  UInt_t fDepth; // depth of the node within the tree (seen from root node)
146 
147  BinaryTree* fParentTree; // pointer to the parent tree to which the Node belongs
148  private:
149 
150  static Int_t fgCount; // counter of all nodes present.. for debug.. to spot memory leaks...
151 
152  public:
153  ClassDef(Node,0) // Node for the BinarySearch or Decision Trees
154  };
155 
156 } // namespace TMVA
157 
158 #endif
159 
Node * fRight
Definition: Node.h:142
virtual void PrintRec(std::ostream &os) const =0
void * AddXMLTo(void *parent) const
add attributes to XML
Definition: Node.cxx:149
int GetCount()
retuns the global number of instantiated nodes
Definition: Node.cxx:108
#define TMVA_VERSION_CODE
Definition: Version.h:47
Node * fLeft
Definition: Node.h:141
virtual TMVA::BinaryTree * GetParentTree() const
Definition: Node.h:127
virtual void ReadAttributes(void *node, UInt_t tmva_Version_Code=TMVA_VERSION_CODE)=0
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void SetRight(Node *r)
Definition: Node.h:97
virtual ~Node()
node destructor
Definition: Node.cxx:100
virtual void SetParentTree(TMVA::BinaryTree *t)
Definition: Node.h:130
UInt_t fDepth
Definition: Node.h:145
virtual void AddAttributesToNode(void *node) const =0
virtual Bool_t ReadDataRecord(std::istream &, UInt_t tmva_Version_Code=TMVA_VERSION_CODE)=0
void SetDepth(UInt_t d)
Definition: Node.h:115
UInt_t GetDepth() const
Definition: Node.h:118
virtual Bool_t GoesLeft(const Event &) const =0
virtual void SetLeft(Node *l)
Definition: Node.h:96
#define ClassDef(name, id)
Definition: Rtypes.h:254
Node * fParent
Definition: Node.h:140
void ReadXML(void *node, UInt_t tmva_Version_Code=TMVA_VERSION_CODE)
read attributes from XML
Definition: Node.cxx:165
ROOT::R::TRInterface & r
Definition: Object.C:4
virtual void AddContentToNode(std::stringstream &s) const =0
virtual void Print(std::ostream &os) const =0
unsigned int UInt_t
Definition: RtypesCore.h:42
TLine * l
Definition: textangle.C:4
std::ostream & operator<<(std::ostream &os, const BinaryTree &tree)
print the tree recursinvely using the << operator
Definition: BinaryTree.cxx:155
virtual void SetParent(Node *p)
Definition: Node.h:98
friend std::ostream & operator<<(std::ostream &os, const Node &node)
char fPos
Definition: Node.h:144
char GetPos() const
Definition: Node.h:124
virtual Node * GetParent() const
Definition: Node.h:93
virtual Node * GetRight() const
Definition: Node.h:92
static Int_t fgCount
Definition: Node.h:150
BinaryTree * fParentTree
Definition: Node.h:147
Abstract ClassifierFactory template that handles arbitrary types.
virtual Bool_t GoesRight(const Event &) const =0
Int_t CountMeAndAllDaughters() const
recursively go through the part of the tree below this node and count all daughters ...
Definition: Node.cxx:116
virtual Node * CreateNode() const =0
const Int_t n
Definition: legend1.C:16
virtual void ReadContent(std::stringstream &s)=0
void SetPos(char s)
Definition: Node.h:121
virtual Node * GetLeft() const
Definition: Node.h:91