50 ClassImp(TMVA::BinaryTree);
 
   55 TMVA::BinaryTree::BinaryTree( 
void )
 
   65 TMVA::BinaryTree::~BinaryTree( 
void )
 
   67    this->DeleteNode( fRoot );
 
   74 void TMVA::BinaryTree::DeleteNode( TMVA::Node* node )
 
   77       this->DeleteNode(node->GetLeft());  
 
   78       this->DeleteNode(node->GetRight()); 
 
   87 TMVA::Node* TMVA::BinaryTree::GetLeftDaughter( Node *n)
 
   89    return (Node*) n->GetLeft();
 
   95 TMVA::Node* TMVA::BinaryTree::GetRightDaughter( Node *n)
 
   97    return (Node*) n->GetRight();
 
  103 UInt_t TMVA::BinaryTree::CountNodes(TMVA::Node *n)
 
  106       n = (Node*)this->GetRoot();
 
  107       if (n == NULL) 
return 0 ;
 
  112    if (this->GetLeftDaughter(n) != NULL){
 
  113       countNodes += this->CountNodes( this->GetLeftDaughter(n) );
 
  115    if (this->GetRightDaughter(n) != NULL) {
 
  116       countNodes += this->CountNodes( this->GetRightDaughter(n) );
 
  119    return fNNodes = countNodes;
 
  125 void TMVA::BinaryTree::Print(std::ostream & os)
 const 
  127    this->GetRoot()->PrintRec(os);
 
  128    os << 
"-1" << std::endl;
 
  134 void* TMVA::BinaryTree::AddXMLTo(
void* parent)
 const {
 
  135    void* bdt = gTools().AddChild(parent, 
"BinaryTree");
 
  136    gTools().AddAttr( bdt, 
"type" , ClassName() );
 
  137    this->GetRoot()->AddXMLTo(bdt);
 
  144 void TMVA::BinaryTree::ReadXML(
void* node, UInt_t tmva_Version_Code ) {
 
  145    this->DeleteNode( fRoot );
 
  148    void* trnode = gTools().GetChild(node);
 
  149    fRoot->ReadXML(trnode, tmva_Version_Code);
 
  151    this->SetTotalTreeDepth();
 
  158 std::ostream& TMVA::operator<< (std::ostream& os, 
const TMVA::BinaryTree& tree)
 
  169 void TMVA::BinaryTree::Read(std::istream & istr, UInt_t tmva_Version_Code )
 
  171    Node * currentNode = GetRoot();
 
  175       currentNode=CreateNode();
 
  176       SetRoot(currentNode);
 
  180       if ( ! currentNode->ReadDataRecord(istr, tmva_Version_Code) ) {
 
  182          this->SetTotalTreeDepth();
 
  187       while( parent!=0 && parent->GetDepth() != currentNode->GetDepth()-1) parent=parent->GetParent();
 
  190          currentNode->SetParent(parent);
 
  191          if (currentNode->GetPos()==
'l') parent->SetLeft(currentNode);
 
  192          if (currentNode->GetPos()==
'r') parent->SetRight(currentNode);
 
  195       parent = currentNode; 
 
  197       currentNode = CreateNode(); 
 
  204 std::istream& TMVA::operator>> (std::istream& istr, TMVA::BinaryTree& tree)
 
  213 void TMVA::BinaryTree::SetTotalTreeDepth( Node *n)
 
  216       n = (Node*) this->GetRoot();
 
  218          Log() << kFATAL << 
"SetTotalTreeDepth: started with undefined ROOT node" <<Endl;
 
  222    if (this->GetLeftDaughter(n) != NULL){
 
  223       this->SetTotalTreeDepth( this->GetLeftDaughter(n) );
 
  225    if (this->GetRightDaughter(n) != NULL) {
 
  226       this->SetTotalTreeDepth( this->GetRightDaughter(n) );
 
  228    if (n->GetDepth() > this->GetTotalTreeDepth()) this->SetTotalTreeDepth(n->GetDepth());
 
  235 TMVA::MsgLogger& TMVA::BinaryTree::Log()
 const {
 
  236    TTHREAD_TLS_DECL_ARG(MsgLogger,logger,
"BinaryTree");