00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <stdexcept>
00042 #include <iosfwd>
00043 #include <iostream>
00044
00045 #include "TMVA/Node.h"
00046 #include "TMVA/Tools.h"
00047
00048 ClassImp(TMVA::Node)
00049
00050 Int_t TMVA::Node::fgCount = 0;
00051
00052 TMVA::Node::Node()
00053 : fParent( NULL ),
00054 fLeft ( NULL),
00055 fRight ( NULL ),
00056 fPos ( 'u' ),
00057 fDepth ( 0 ),
00058 fParentTree( NULL )
00059 {
00060
00061 fgCount++;
00062 }
00063
00064
00065 TMVA::Node::Node( Node* p, char pos )
00066 : fParent ( p ),
00067 fLeft ( NULL ),
00068 fRight( NULL ),
00069 fPos ( pos ),
00070 fDepth( p->GetDepth() + 1),
00071 fParentTree(p->GetParentTree())
00072 {
00073
00074
00075 fgCount++;
00076 if (fPos == 'l' ) p->SetLeft(this);
00077 else if (fPos == 'r' ) p->SetRight(this);
00078 }
00079
00080
00081 TMVA::Node::Node ( const Node &n )
00082 : fParent( NULL ),
00083 fLeft ( NULL),
00084 fRight ( NULL ),
00085 fPos ( n.fPos ),
00086 fDepth ( n.fDepth ),
00087 fParentTree( NULL )
00088 {
00089
00090
00091
00092 fgCount++;
00093 }
00094
00095
00096 TMVA::Node::~Node()
00097 {
00098
00099 fgCount--;
00100 }
00101
00102
00103 int TMVA::Node::GetCount()
00104 {
00105
00106 return fgCount;
00107 }
00108
00109
00110 Int_t TMVA::Node::CountMeAndAllDaughters() const
00111 {
00112
00113 Int_t n=1;
00114 if (this->GetLeft() != NULL)
00115 n+= this->GetLeft()->CountMeAndAllDaughters();
00116 if (this->GetRight() != NULL)
00117 n+= this->GetRight()->CountMeAndAllDaughters();
00118
00119 return n;
00120 }
00121
00122
00123
00124 ostream& TMVA::operator<<( ostream& os, const TMVA::Node& node )
00125 {
00126
00127 node.Print(os);
00128 return os;
00129 }
00130
00131
00132 ostream& TMVA::operator<<( ostream& os, const TMVA::Node* node )
00133 {
00134
00135 if (node!=NULL) node->Print(os);
00136 return os;
00137 }
00138
00139
00140 void* TMVA::Node::AddXMLTo( void* parent ) const
00141 {
00142
00143 std::stringstream s("");
00144 AddContentToNode(s);
00145 void* node = gTools().AddChild(parent, "Node", s.str().c_str());
00146 gTools().AddAttr( node, "pos", fPos );
00147 gTools().AddAttr( node, "depth", fDepth );
00148 this->AddAttributesToNode(node);
00149 if (this->GetLeft()) this->GetLeft()->AddXMLTo(node);
00150 if (this->GetRight()) this->GetRight()->AddXMLTo(node);
00151 return node;
00152 }
00153
00154
00155 void TMVA::Node::ReadXML( void* node, UInt_t tmva_Version_Code )
00156 {
00157
00158 ReadAttributes(node, tmva_Version_Code);
00159 const char* content = gTools().GetContent(node);
00160 if (content) {
00161 std::stringstream s(content);
00162 ReadContent(s);
00163 }
00164 gTools().ReadAttr( node, "pos", fPos );
00165 gTools().ReadAttr( node, "depth", fDepth );
00166
00167 void* ch = gTools().GetChild(node);
00168 while (ch) {
00169 Node* n = CreateNode();
00170 n->ReadXML(ch, tmva_Version_Code);
00171 if (n->GetPos()=='l') { this->SetLeft(n); }
00172 else if(n->GetPos()=='r') { this->SetRight(n); }
00173 else {
00174 std::cout << "neither left nor right" << std::endl;
00175 }
00176 ch = gTools().GetNextChild(ch);
00177 }
00178 }