* *
**********************************************************************************/
#include <string>
#include "TMVA/Node.h"
#include "Riostream.h"
#include <stdexcept>
#include "TMVA/Event.h"
ClassImp(TMVA::Node)
TMVA::Node::~Node( void )
{
if (this->GetEventOwnership()) delete fEvent;
}
Bool_t TMVA::Node::GoesRight(const TMVA::Event * e) const {
if (e->GetData(fSelector) > fEvent->GetData(fSelector)) return true;
else return false;
}
Bool_t TMVA::Node::GoesLeft(const TMVA::Event * e) const
{
if (e->GetData(fSelector) <= fEvent->GetData(fSelector)) return true;
else return false;
}
Bool_t TMVA::Node::EqualsMe(const TMVA::Event * e) const
{
Bool_t result = true;
for (Int_t i=0; i<fEvent->GetEventSize(); i++) {
result &= (e->GetData(i) == fEvent->GetData(i));
}
return result;
}
Int_t TMVA::Node::CountMeAndAllDaughters( void ) const
{
Int_t n=1;
if(this->GetLeft() != NULL)
n+= this->GetLeft()->CountMeAndAllDaughters();
if(this->GetRight() != NULL)
n+= this->GetRight()->CountMeAndAllDaughters();
return n;
}
void TMVA::Node::Print(ostream& os) const
{
os << "node.Data: " << endl << this->GetData() <<endl;
os << "Selector: " << this->GetSelector() <<endl;
os << " address: "<< this
<< " Parent: " << this->GetParent()
<< " Left: " << this->GetLeft()
<< " Right: " << this->GetRight()
<< endl;
}
void TMVA::Node::PrintRec(ostream& os, const Int_t Depth, const std::string pos ) const
{
os << Depth << " " << pos << " node.Data: " << endl << this->GetData()
<< endl;
os << Depth << " " << pos << " Selector: " << this->GetSelector() <<endl;
if(this->GetLeft() != NULL)this->GetLeft()->PrintRec(os,Depth+1,"Left") ;
if(this->GetRight() != NULL)this->GetRight()->PrintRec(os,Depth+1,"Right");
}
TMVA::NodeID TMVA::Node::ReadRec(ifstream& is, TMVA::NodeID nodeID, TMVA::Node* Parent )
{
std::string tmp;
Int_t itmp;
std::string pos;
TMVA::NodeID nextNodeID;
if (Parent==NULL) {
is >> itmp >> pos >> tmp;
nodeID.SetDepth(itmp);
nodeID.SetPos(pos);
}
else is >> tmp;
TMVA::Event* e=new TMVA::Event();
this->SetEventOwnership(kTRUE);
e->Read(is);
this->SetData(e);
is >> itmp >> pos >> tmp >> tmp;
this->SetSelector(atoi(tmp.c_str()));
is >> itmp >> pos;
nextNodeID.SetDepth(itmp);
nextNodeID.SetPos(pos);
if (nextNodeID.GetDepth() == nodeID.GetDepth()+1){
if (nextNodeID.GetPos()=="Left") {
this->SetLeft(new TMVA::Node());
this->GetLeft()->SetParent(this);
nextNodeID = this->GetLeft()->ReadRec(is,nextNodeID,this);
}
}
if (nextNodeID.GetDepth() == nodeID.GetDepth()+1){
if (nextNodeID.GetPos()=="Right") {
this->SetRight(new TMVA::Node());
this->GetRight()->SetParent(this);
nextNodeID = this->GetRight()->ReadRec(is,nextNodeID,this);
}
}
return nextNodeID;
}
ostream& TMVA::operator<<(ostream& os, const TMVA::Node& node)
{
node.Print(os);
return os;
}
ostream& TMVA::operator<<(ostream& os, const TMVA::Node* node)
{
if (node!=NULL) node->Print(os);
return os;
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.