From 4367a0404cc20bea9f600895eebed43d10f2d2d0 Mon Sep 17 00:00:00 2001 From: Omar Zapata <Omar.Zapata@cern.ch> Date: Thu, 28 Jul 2016 09:23:11 +0200 Subject: [PATCH] TMVA: fixed dynamic value in class Event --- test/stressTMVA.cxx | 2 +- tmva/tmva/inc/TMVA/Event.h | 4 +-- tmva/tmva/src/DataSetFactory.cxx | 8 +++--- tmva/tmva/src/Event.cxx | 44 ++++++++++++++++---------------- tmva/tmva/src/VariableInfo.cxx | 2 +- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/test/stressTMVA.cxx b/test/stressTMVA.cxx index 5f2d8bda8b3..262b11c6052 100644 --- a/test/stressTMVA.cxx +++ b/test/stressTMVA.cxx @@ -1821,7 +1821,7 @@ void utVariableInfo::_testConstructor2() test_(_varinfoC2->GetExpression() == ""); // test_(_varinfoC2->GetInternalName() == ); // test_(_varinfoC2->GetLabel() - test_(_varinfoC2->GetTitle() == ""); + test_(_varinfoC2->GetTitle() == TString("")); test_(_varinfoC2->GetUnit() == ""); test_(_varinfoC2->GetVarType() == '\0'); diff --git a/tmva/tmva/inc/TMVA/Event.h b/tmva/tmva/inc/TMVA/Event.h index 67e829942d9..544e1ee376b 100644 --- a/tmva/tmva/inc/TMVA/Event.h +++ b/tmva/tmva/inc/TMVA/Event.h @@ -75,7 +75,7 @@ namespace TMVA { UInt_t theClass = 0, Double_t weight = 1.0, Double_t boostweight = 1.0 ); explicit Event( const std::vector<Float_t>&, UInt_t theClass, Double_t weight = 1.0, Double_t boostweight = 1.0 ); - explicit Event( const std::vector<Float_t>*&, UInt_t nvar ); + explicit Event( const std::vector<Float_t*>*&, UInt_t nvar ); ~Event(); @@ -137,7 +137,7 @@ namespace TMVA { mutable std::vector<Float_t> fValues; // the event values ; mutable, to be able to copy the dynamic values in there mutable std::vector<Float_t> fValuesRearranged; // the event values ; mutable, to be able to copy the dynamic values in there - mutable std::vector<Float_t> fValuesDynamic; // the event values + mutable std::vector<Float_t*> *fValuesDynamic; //! the event values std::vector<Float_t> fTargets; // target values for regression mutable std::vector<Float_t> fSpectators; // "visisting" variables not used in MVAs ; mutable, to be able to copy the dynamic values in there mutable std::vector<UInt_t> fVariableArrangement; // needed for MethodCategories, where we can train on other than the main variables diff --git a/tmva/tmva/src/DataSetFactory.cxx b/tmva/tmva/src/DataSetFactory.cxx index 001f96aa262..4cf04834ee4 100644 --- a/tmva/tmva/src/DataSetFactory.cxx +++ b/tmva/tmva/src/DataSetFactory.cxx @@ -167,7 +167,7 @@ TMVA::DataSet* TMVA::DataSetFactory::BuildDynamicDataSet( TMVA::DataSetInfo& dsi dsi.GetClassInfo( "data" )->SetNumber(0); } - std::vector<Float_t>* evdyn = new std::vector<Float_t>(0); + std::vector<Float_t*>* evdyn = new std::vector<Float_t*>(0); std::vector<VariableInfo>& varinfos = dsi.GetVariableInfos(); @@ -179,14 +179,14 @@ TMVA::DataSet* TMVA::DataSetFactory::BuildDynamicDataSet( TMVA::DataSetInfo& dsi Float_t* external=(Float_t*)(*it).GetExternalLink(); if (external==0) Log() << kDEBUG << Form("Dataset[%s] : ",dsi.GetName()) << "The link to the external variable is NULL while I am trying to build a dynamic data set. In this case fTmpEvent from MethodBase HAS TO BE USED in the method to get useful values in variables." << Endl; - else evdyn->push_back (*external); + else evdyn->push_back (external); } std::vector<VariableInfo>& spectatorinfos = dsi.GetSpectatorInfos(); it = spectatorinfos.begin(); - for (;it!=spectatorinfos.end();it++) evdyn->push_back( *(Float_t*)(*it).GetExternalLink() ); + for (;it!=spectatorinfos.end();it++) evdyn->push_back( (Float_t*)(*it).GetExternalLink() ); - TMVA::Event * ev = new Event((const std::vector<Float_t>*&)evdyn, varinfos.size()); + TMVA::Event * ev = new Event((const std::vector<Float_t*>*&)evdyn, varinfos.size()); std::vector<Event*>* newEventVector = new std::vector<Event*>; newEventVector->push_back(ev); diff --git a/tmva/tmva/src/Event.cxx b/tmva/tmva/src/Event.cxx index 1237eba075d..cfb06077427 100644 --- a/tmva/tmva/src/Event.cxx +++ b/tmva/tmva/src/Event.cxx @@ -125,7 +125,7 @@ TMVA::Event::Event( const std::vector<Float_t>& ev, //////////////////////////////////////////////////////////////////////////////// /// constructor for single events -TMVA::Event::Event( const std::vector<Float_t>*& evdyn, UInt_t nvar ) +TMVA::Event::Event( const std::vector<Float_t*>*& evdyn, UInt_t nvar ) : fValues(nvar), fValuesDynamic(0), fTargets(0), @@ -137,7 +137,7 @@ TMVA::Event::Event( const std::vector<Float_t>*& evdyn, UInt_t nvar ) fDynamic(true), fDoNotBoost(kFALSE) { - fValuesDynamic = (std::vector<Float_t>) *evdyn; + fValuesDynamic = (std::vector<Float_t*>*) evdyn; } //////////////////////////////////////////////////////////////////////////////// @@ -160,22 +160,22 @@ TMVA::Event::Event( const Event& event ) fValues.clear(); UInt_t nvar = event.GetNVariables(); UInt_t idx=0; - std::vector<Float_t>::iterator itDyn=event.fValuesDynamic.begin(), itDynEnd=event.fValuesDynamic.end(); + std::vector<Float_t*>::iterator itDyn=event.fValuesDynamic->begin(), itDynEnd=event.fValuesDynamic->end(); for (; itDyn!=itDynEnd && idx<nvar; ++itDyn){ - Float_t value=(*itDyn); + Float_t value=*(*itDyn); fValues.push_back( value ); ++idx; } fSpectators.clear(); for (; itDyn!=itDynEnd; ++itDyn){ - Float_t value=(*itDyn); + Float_t value=*(*itDyn); fSpectators.push_back( value ); ++idx; } fDynamic=kFALSE; - fValuesDynamic.clear(); - } + fValuesDynamic=NULL; +} } //////////////////////////////////////////////////////////////////////////////// @@ -209,22 +209,22 @@ void TMVA::Event::CopyVarValues( const Event& other ) UInt_t nvar = other.GetNVariables(); fValues.clear(); UInt_t idx=0; - std::vector<Float_t>::iterator itDyn=other.fValuesDynamic.begin(), itDynEnd=other.fValuesDynamic.end(); + std::vector<Float_t*>::iterator itDyn=other.fValuesDynamic->begin(), itDynEnd=other.fValuesDynamic->end(); for (; itDyn!=itDynEnd && idx<nvar; ++itDyn){ - Float_t value=(*itDyn); + Float_t value=*(*itDyn); fValues.push_back( value ); ++idx; } fSpectators.clear(); for (; itDyn!=itDynEnd; ++itDyn){ - Float_t value=(*itDyn); + Float_t value=*(*itDyn); fSpectators.push_back( value ); ++idx; } } fDynamic = kFALSE; - fValuesDynamic.clear(); - + fValuesDynamic = NULL; + fClass = other.fClass; fWeight = other.fWeight; fBoostWeight = other.fBoostWeight; @@ -237,14 +237,14 @@ Float_t TMVA::Event::GetValue( UInt_t ivar ) const { Float_t retval; if (fVariableArrangement.size()==0) { - retval = fDynamic ? ( ((fValuesDynamic).at(ivar)) ) : fValues.at(ivar); + retval = fDynamic ? ( *((fValuesDynamic)->at(ivar)) ) : fValues.at(ivar); } else { UInt_t mapIdx = fVariableArrangement[ivar]; // std::cout<< fDynamic ; if (fDynamic){ // std::cout<< " " << (*fValuesDynamic).size() << " " << fValues.size() << std::endl; - retval = ((fValuesDynamic).at(mapIdx)); + retval = *((fValuesDynamic)->at(mapIdx)); } else{ //retval = fValues.at(ivar); @@ -260,7 +260,7 @@ Float_t TMVA::Event::GetValue( UInt_t ivar ) const Float_t TMVA::Event::GetSpectator( UInt_t ivar) const { - if (fDynamic) return (fValuesDynamic.at(GetNVariables()+ivar)); + if (fDynamic) return *(fValuesDynamic->at(GetNVariables()+ivar)); else return fSpectators.at(ivar); } @@ -273,9 +273,9 @@ const std::vector<Float_t>& TMVA::Event::GetValues() const if (fDynamic) { fValues.clear(); - for (std::vector<Float_t>::const_iterator it = fValuesDynamic.begin(), itEnd=fValuesDynamic.end()-GetNSpectators(); + for (std::vector<Float_t*>::const_iterator it = fValuesDynamic->begin(), itEnd=fValuesDynamic->end()-GetNSpectators(); it != itEnd; ++it) { - Float_t val = (*it); + Float_t val = *(*it); fValues.push_back( val ); } } @@ -285,7 +285,7 @@ const std::vector<Float_t>& TMVA::Event::GetValues() const fValues.clear(); for (UInt_t i=0; i< fVariableArrangement.size(); i++){ mapIdx = fVariableArrangement[i]; - fValues.push_back(((fValuesDynamic).at(mapIdx))); + fValues.push_back(*((fValuesDynamic)->at(mapIdx))); } } else { // hmm now you have a problem, as you do not want to mess with the original event variables @@ -339,10 +339,10 @@ UInt_t TMVA::Event::GetNSpectators() const void TMVA::Event::SetVal( UInt_t ivar, Float_t val ) { - if ((fDynamic ?( fValuesDynamic.size() ) : fValues.size())<=ivar) - (fDynamic ?( fValuesDynamic.resize(ivar+1) ) : fValues.resize(ivar+1)); - - (fDynamic ?( fValuesDynamic[ivar] ) : fValues[ivar])=val; + if ((fDynamic ?( (*fValuesDynamic).size() ) : fValues.size())<=ivar) + (fDynamic ?( (*fValuesDynamic).resize(ivar+1) ) : fValues.resize(ivar+1)); + + (fDynamic ?( *(*fValuesDynamic)[ivar] ) : fValues[ivar])=val; } //////////////////////////////////////////////////////////////////////////////// diff --git a/tmva/tmva/src/VariableInfo.cxx b/tmva/tmva/src/VariableInfo.cxx index 5b05fb15805..f480f63cb3c 100644 --- a/tmva/tmva/src/VariableInfo.cxx +++ b/tmva/tmva/src/VariableInfo.cxx @@ -51,7 +51,7 @@ TMVA::VariableInfo::VariableInfo( const TString& expression, const TString& titl fXmeanNorm ( 0 ), fXrmsNorm ( 0 ), fNormalized ( normalized ), - fExternalData( (char*)external ), + fExternalData( external ), fVarCounter ( varCounter ) { if ( TMath::Abs(max - min) <= FLT_MIN ) { -- GitLab