Node.h

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: Node.h 37986 2011-02-04 21:42:15Z pcanal $    
00002 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Kai Voss 
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Classes: Node                                                                  *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *      Node for the BinarySearch or Decision Trees                               *
00012  *                                                                                *
00013  * Authors (alphabetical):                                                        *
00014  *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
00015  *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
00016  *      Kai Voss        <Kai.Voss@cern.ch>       - U. of Victoria, Canada         *
00017  *                                                                                *
00018  * Copyright (c) 2005:                                                            *
00019  *      CERN, Switzerland                                                         * 
00020  *      U. of Victoria, Canada                                                    * 
00021  *      MPI-K Heidelberg, Germany                                                 * 
00022  *                                                                                *
00023  * Redistribution and use in source and binary forms, with or without             *
00024  * modification, are permitted according to the terms listed in LICENSE           *
00025  * (http://tmva.sourceforge.net/LICENSE)                                          *
00026  **********************************************************************************/
00027 
00028 #ifndef ROOT_TMVA_Node
00029 #define ROOT_TMVA_Node
00030 
00031 //////////////////////////////////////////////////////////////////////////
00032 //                                                                      //
00033 // Node                                                                 //
00034 //                                                                      //
00035 // Node base class for the BinarySearch or Decision Trees Nodes         //
00036 //                                                                      //
00037 //////////////////////////////////////////////////////////////////////////
00038 
00039 #include <iosfwd>
00040 #ifndef ROOT_Rtypes
00041 #include "Rtypes.h"
00042 #endif
00043 
00044 #ifndef ROOT_TMVA_Version
00045 #include "TMVA/Version.h"
00046 #endif
00047 
00048 namespace TMVA {
00049 
00050    class Node;
00051    class Event;
00052    class BinaryTree;
00053 
00054    std::ostream& operator<<( std::ostream& os, const Node& node );
00055    std::ostream& operator<<( std::ostream& os, const Node* node );
00056 
00057    // a class used to identify a Node; (needed for recursive reading from text file)
00058    // (currently it is NOT UNIQUE... but could eventually made it
00059    // a node in the tree structure
00060    class Node {
00061 
00062       // output operator for a node
00063       friend std::ostream& operator << (std::ostream& os, const Node& node);
00064       // output operator with a pointer to the node (which still prints the node itself)
00065       friend std::ostream& operator << (std::ostream& os, const Node* node);
00066     
00067    public:
00068 
00069       // constructor of a node 
00070       Node();
00071       
00072       // constructor of a daughter node as a daughter of 'p'
00073       Node( Node* p, char pos );
00074 
00075       // copy constructor
00076       Node( const Node &n );
00077 
00078       // destructor
00079       virtual ~Node();
00080 
00081       virtual Node* CreateNode() const = 0;
00082 
00083       // test event if i{ decends the tree at this node to the right  
00084       virtual Bool_t GoesRight( const Event& ) const = 0;
00085       // test event if it decends the tree at this node to the left 
00086 
00087       virtual Bool_t GoesLeft ( const Event& ) const = 0;
00088       // test event if it is equal to the event that "makes the node" (just for the "search tree"  
00089 
00090       // return pointer to the left/right daughter or parent node
00091       inline virtual Node* GetLeft  () const { return fLeft;   }
00092       inline virtual Node* GetRight () const { return fRight;  }
00093       inline virtual Node* GetParent() const { return fParent; }
00094     
00095       // set pointer to the left/right daughter or parent node
00096       inline virtual void SetLeft  (Node* l) { fLeft   = l;} 
00097       inline virtual void SetRight (Node* r) { fRight  = r;} 
00098       inline virtual void SetParent(Node* p) { fParent = p;} 
00099     
00100       //recursively go through the part of the tree below this node and count all daughters
00101       Int_t  CountMeAndAllDaughters() const;
00102     
00103       // printout of the node
00104       virtual void Print( std::ostream& os ) const = 0;
00105 
00106       // recursive printout of the node and it daughters 
00107       virtual void PrintRec ( std::ostream& os ) const = 0;
00108 
00109       void* AddXMLTo(void* parent) const;
00110       void  ReadXML(void* node, UInt_t tmva_Version_Code = TMVA_VERSION_CODE );
00111       virtual void AddAttributesToNode(void* node) const = 0;
00112       virtual void AddContentToNode(std::stringstream& s) const = 0;
00113 
00114       // Set depth, layer of the where the node is within the tree, seen from the top (root)
00115       void SetDepth(UInt_t d){fDepth=d;}
00116       
00117       // Return depth, layer of the where the node is within the tree, seen from the top (root)
00118       UInt_t GetDepth() const {return fDepth;}
00119       
00120       // set node position, i.e, the node is a left (l) or right (r) daugther
00121       void SetPos(char s) {fPos=s;}
00122       
00123       // Return the node position, i.e, the node is a left (l) or right (r) daugther
00124       char GetPos() const {return fPos;}
00125 
00126       // Return the pointer to the Parent tree to which the Node belongs 
00127       virtual TMVA::BinaryTree* GetParentTree() const {return fParentTree;}
00128 
00129       // set the pointer to the Parent Tree to which the Node belongs 
00130       virtual void SetParentTree(TMVA::BinaryTree* t) {fParentTree = t;} 
00131 
00132       int GetCount();
00133 
00134       virtual Bool_t ReadDataRecord( std::istream&, UInt_t tmva_Version_Code = TMVA_VERSION_CODE ) = 0;
00135       virtual void ReadAttributes(void* node, UInt_t tmva_Version_Code = TMVA_VERSION_CODE  ) = 0;
00136       virtual void ReadContent(std::stringstream& s) =0;
00137 
00138    protected: 
00139 
00140       Node*   fParent;              // the previous (parent) node
00141       Node*   fLeft;                // pointers to the two "daughter" nodes
00142       Node*   fRight;               // pointers to the two "daughter" nodes
00143 
00144       char    fPos;                 // position, i.e. it is a left (l) or right (r) daughter 
00145       UInt_t  fDepth;               // depth of the node within the tree (seen from root node)
00146 
00147       BinaryTree*  fParentTree;     // pointer to the parent tree to which the Node belongs 
00148    private: 
00149 
00150       static Int_t fgCount;         // counter of all nodes present.. for debug.. to spot memory leaks...
00151 
00152    public:
00153       ClassDef(Node,0) // Node for the BinarySearch or Decision Trees
00154    };
00155 
00156 } // namespace TMVA
00157 
00158 #endif
00159 

Generated on Tue Jul 5 14:27:32 2011 for ROOT_528-00b_version by  doxygen 1.5.1