diff --git a/tmva/tmva/src/MethodBase.cxx b/tmva/tmva/src/MethodBase.cxx index 32ca641140c54..608194a490557 100644 --- a/tmva/tmva/src/MethodBase.cxx +++ b/tmva/tmva/src/MethodBase.cxx @@ -1458,13 +1458,10 @@ void TMVA::MethodBase::WriteStateToXML( void* parent ) const void TMVA::MethodBase::ReadStateFromStream( TFile& rf ) { - Bool_t addDirStatus = TH1::AddDirectoryStatus(); - TH1::AddDirectory( 0 ); // this avoids the binding of the hists in PDF to the current ROOT file + TDirectory::TContext dirCtx{nullptr}; // Don't register histograms to current directory fMVAPdfS = (TMVA::PDF*)rf.Get( "MVA_PDF_Signal" ); fMVAPdfB = (TMVA::PDF*)rf.Get( "MVA_PDF_Background" ); - TH1::AddDirectory( addDirStatus ); - ReadWeightsFromStream( rf ); SetTestvarName(); diff --git a/tmva/tmva/src/MethodLikelihood.cxx b/tmva/tmva/src/MethodLikelihood.cxx index 5c715c9571c86..f7033a6eb7e13 100644 --- a/tmva/tmva/src/MethodLikelihood.cxx +++ b/tmva/tmva/src/MethodLikelihood.cxx @@ -668,8 +668,7 @@ void TMVA::MethodLikelihood::WriteWeightsToStream( TFile& ) const void TMVA::MethodLikelihood::ReadWeightsFromXML(void* wghtnode) { TString pname = "PDF_"; - Bool_t addDirStatus = TH1::AddDirectoryStatus(); - TH1::AddDirectory(0); // this avoids the binding of the hists in TMVA::PDF to the current ROOT file + TDirectory::TContext dirCtx{nullptr}; // Don't register histograms to current directory UInt_t nvars=0; gTools().ReadAttr(wghtnode, "NVariables",nvars); void* descnode = gTools().GetChild(wghtnode); @@ -688,7 +687,6 @@ void TMVA::MethodLikelihood::ReadWeightsFromXML(void* wghtnode) (*(*fPDFBgd)[ivar]).ReadXML(pdfnode); descnode = gTools().GetNextChild(descnode); } - TH1::AddDirectory(addDirStatus); } //////////////////////////////////////////////////////////////////////////////// @@ -698,8 +696,7 @@ void TMVA::MethodLikelihood::ReadWeightsFromXML(void* wghtnode) void TMVA::MethodLikelihood::ReadWeightsFromStream( std::istream & istr ) { TString pname = "PDF_"; - Bool_t addDirStatus = TH1::AddDirectoryStatus(); - TH1::AddDirectory(0); // this avoids the binding of the hists in TMVA::PDF to the current ROOT file + TDirectory::TContext dirCtx{nullptr}; // Don't register histograms to current directory for (UInt_t ivar=0; ivar> *(*fPDFSig)[ivar]; istr >> *(*fPDFBgd)[ivar]; } - TH1::AddDirectory(addDirStatus); } //////////////////////////////////////////////////////////////////////////////// @@ -720,13 +716,11 @@ void TMVA::MethodLikelihood::ReadWeightsFromStream( std::istream & istr ) void TMVA::MethodLikelihood::ReadWeightsFromStream( TFile& rf ) { TString pname = "PDF_"; - Bool_t addDirStatus = TH1::AddDirectoryStatus(); - TH1::AddDirectory(0); // this avoids the binding of the hists in TMVA::PDF to the current ROOT file + TDirectory::TContext dirCtx{nullptr}; // Don't register histograms to current directory for (UInt_t ivar=0; ivar