From 64d561af2462a9528952e50c6f5c701f7905e545 Mon Sep 17 00:00:00 2001 From: Omar Zapata <Omar.Zapata@cern.ch> Date: Sun, 19 Jun 2016 20:32:32 +0200 Subject: [PATCH] TMVA: working to remove static variables from TMVA::Factory the global file is not static now. --- tmva/tmva/inc/TMVA/Factory.h | 4 ++-- tmva/tmva/inc/TMVA/MethodBase.h | 12 ++++++++++-- tmva/tmva/src/Factory.cxx | 5 ++++- tmva/tmva/src/MethodBase.cxx | 18 ++++++++++-------- tmva/tmva/src/MethodBoost.cxx | 2 +- tmva/tmva/src/RuleFit.cxx | 2 +- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/tmva/tmva/inc/TMVA/Factory.h b/tmva/tmva/inc/TMVA/Factory.h index f0388ba9dbc..af6e17afd5f 100644 --- a/tmva/tmva/inc/TMVA/Factory.h +++ b/tmva/tmva/inc/TMVA/Factory.h @@ -150,7 +150,7 @@ namespace TMVA { // classifiers are printed void PrintHelpMessage(const TString& datasetname , const TString& methodTitle = "" ) const; - static TDirectory* RootBaseDir() { return (TDirectory*)fgTargetFile; } + TDirectory* RootBaseDir() { return (TDirectory*)fgTargetFile; } static Bool_t IsSilentFile(); @@ -191,7 +191,7 @@ namespace TMVA { // data members - static TFile* fgTargetFile; //! ROOT output file + TFile* fgTargetFile; //! ROOT output file std::vector<TMVA::VariableTransformBase*> fDefaultTrfs; //! list of transformations on default DataSet diff --git a/tmva/tmva/inc/TMVA/MethodBase.h b/tmva/tmva/inc/TMVA/MethodBase.h index ce1c2c1cb2d..03517e29cce 100644 --- a/tmva/tmva/inc/TMVA/MethodBase.h +++ b/tmva/tmva/inc/TMVA/MethodBase.h @@ -72,6 +72,9 @@ #include<TMVA/Results.h> #endif +#ifndef ROOT_TFile +#include<TFile.h> +#endif class TGraph; class TTree; @@ -336,10 +339,13 @@ namespace TMVA { // pointers to ROOT directories TDirectory* BaseDir() const; TDirectory* MethodBaseDir() const; + TFile* GetFile() const {return fFile;} + void SetMethodDir ( TDirectory* methodDir ) { fBaseDir = fMethodBaseDir = methodDir; } void SetBaseDir( TDirectory* methodDir ){ fBaseDir = methodDir; } void SetMethodBaseDir( TDirectory* methodDir ){ fMethodBaseDir = methodDir; } - + void SetFile(TFile* file){fFile=file;} + // the TMVA version can be obtained and checked using // if (GetTrainingTMVAVersionCode()>TMVA_VERSION(3,7,2)) {...} // or @@ -539,11 +545,13 @@ namespace TMVA { UInt_t fROOTTrainingVersion; // ROOT version used for training Bool_t fConstructedFromWeightFile; // is it obtained from weight file? - // Directory structure: fMethodBaseDir/fBaseDir + // Directory structure: dataloader/fMethodBaseDir/fBaseDir // where the first directory name is defined by the method type // and the second is user supplied (the title given in Factory::BookMethod()) TDirectory* fBaseDir; // base directory for the instance, needed to know where to jump back from localDir mutable TDirectory* fMethodBaseDir; // base directory for the method + //this will be the next way to save results + TFile *fFile; TString fParentDir; // method parent name, like booster name diff --git a/tmva/tmva/src/Factory.cxx b/tmva/tmva/src/Factory.cxx index 893747d4b54..a9d6c7b97cf 100644 --- a/tmva/tmva/src/Factory.cxx +++ b/tmva/tmva/src/Factory.cxx @@ -96,7 +96,6 @@ const Int_t MinNoTrainingEvents = 10; //const Int_t MinNoTestEvents = 1; -TFile* TMVA::Factory::fgTargetFile = 0; ClassImp(TMVA::Factory) @@ -319,6 +318,7 @@ TMVA::MethodBase* TMVA::Factory::BookMethod( TMVA::DataLoader *loader, TString t Log() << kFATAL << "Method with type kBoost cannot be casted to MethodCategory. /Factory" << Endl; // DSMTEST methBoost->SetBoostedMethodName( theMethodName ); // DSMTEST divided into two lines methBoost->fDataSetManager = loader->fDataSetManager; // DSMTEST + methBoost->SetFile(fgTargetFile); } MethodBase *method = dynamic_cast<MethodBase*>(im); @@ -330,6 +330,7 @@ TMVA::MethodBase* TMVA::Factory::BookMethod( TMVA::DataLoader *loader, TString t if (!methCat) // DSMTEST Log() << kFATAL << "Method with type kCategory cannot be casted to MethodCategory. /Factory" << Endl; // DSMTEST methCat->fDataSetManager = loader->fDataSetManager; // DSMTEST + methCat->SetFile(fgTargetFile); } // DSMTEST @@ -355,6 +356,7 @@ TMVA::MethodBase* TMVA::Factory::BookMethod( TMVA::DataLoader *loader, TString t method->SetupMethod(); method->ParseOptions(); method->ProcessSetup(); + method->SetFile(fgTargetFile); // check-for-unused-options is performed; may be overridden by derived classes method->CheckSetup(); @@ -1017,6 +1019,7 @@ void TMVA::Factory::EvaluateAllMethods( void ) Event::SetIsTraining(kFALSE); MethodBase* theMethod = dynamic_cast<MethodBase*>(*itrMethod); if(theMethod==0) continue; + theMethod->SetFile(fgTargetFile); if (theMethod->GetMethodType() != Types::kCuts) methodsNoCuts.push_back( *itrMethod ); if (theMethod->DoRegression()) { diff --git a/tmva/tmva/src/MethodBase.cxx b/tmva/tmva/src/MethodBase.cxx index 254423b3b5d..1ddbb93f085 100644 --- a/tmva/tmva/src/MethodBase.cxx +++ b/tmva/tmva/src/MethodBase.cxx @@ -167,6 +167,7 @@ TMVA::MethodBase::MethodBase( const TString& jobName, fConstructedFromWeightFile ( kFALSE ), fBaseDir ( 0 ), fMethodBaseDir ( 0 ), + fFile ( 0 ), fWeightFile ( "" ), fEffS ( 0 ), fDefaultPDF ( 0 ), @@ -229,6 +230,7 @@ TMVA::MethodBase::MethodBase( Types::EMVA methodType, fConstructedFromWeightFile ( kTRUE ), fBaseDir ( 0 ), fMethodBaseDir ( 0 ), + fFile ( 0 ), fWeightFile ( weightFile ), fEffS ( 0 ), fDefaultPDF ( 0 ), @@ -1860,14 +1862,14 @@ TDirectory* TMVA::MethodBase::BaseDir() const /// returns the ROOT directory where all instances of the /// corresponding MVA method are stored -TDirectory* TMVA::MethodBase::MethodBaseDir() const -{ - if (fMethodBaseDir != 0) return fMethodBaseDir; - - Log()<<kDEBUG<<Form("Dataset[%s] : ",DataInfo().GetName())<<" Base Directory for " << GetMethodTypeName() << " not set yet --> check if already there.." <<Endl; - - - TDirectory *fFactoryBaseDir=Factory::RootBaseDir(); + TDirectory* TMVA::MethodBase::MethodBaseDir() const + { + if (fMethodBaseDir != 0) return fMethodBaseDir; + + Log()<<kDEBUG<<Form("Dataset[%s] : ",DataInfo().GetName())<<" Base Directory for " << GetMethodTypeName() << " not set yet --> check if already there.." <<Endl; + + + TDirectory *fFactoryBaseDir=GetFile(); fMethodBaseDir = fFactoryBaseDir->GetDirectory(DataInfo().GetName()); if(!fMethodBaseDir) //creating dataset directory diff --git a/tmva/tmva/src/MethodBoost.cxx b/tmva/tmva/src/MethodBoost.cxx index de09e028044..229b9b20e6b 100644 --- a/tmva/tmva/src/MethodBoost.cxx +++ b/tmva/tmva/src/MethodBoost.cxx @@ -418,7 +418,7 @@ void TMVA::MethodBoost::Train() // creating the directory of the classifier if (fMonitorBoostedMethod) { - methodDir=MethodBaseDir()->GetDirectory(dirName=Form("%s_B%04i",fBoostedMethodName.Data(),fCurrentMethodIdx)); + methodDir=GetFile()->GetDirectory(dirName=Form("%s_B%04i",fBoostedMethodName.Data(),fCurrentMethodIdx)); if (methodDir==0) { methodDir=BaseDir()->mkdir(dirName,dirTitle=Form("Directory Boosted %s #%04i", fBoostedMethodName.Data(),fCurrentMethodIdx)); } diff --git a/tmva/tmva/src/RuleFit.cxx b/tmva/tmva/src/RuleFit.cxx index c16f5e11f08..cbc3750d32d 100644 --- a/tmva/tmva/src/RuleFit.cxx +++ b/tmva/tmva/src/RuleFit.cxx @@ -778,7 +778,7 @@ void TMVA::RuleFit::MakeVisHists() const TString corrDirName = "CorrelationPlots"; - TDirectory* rootDir = Factory::RootBaseDir(); + TDirectory* rootDir = fMethodBase->GetFile(); TDirectory* varDir = 0; TDirectory* corrDir = 0; -- GitLab