From 805d693c941e66099884214db60a81c5194920ed Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Tue, 10 Sep 2024 20:56:56 +0200 Subject: [PATCH] [RF] Modernize RooCustomizer by using RooArgList istead of TList This will also avoid possible errors in PyROOT at the end of the process, because the RooArgList doesn't complain if it's elements are empty at destruction time. --- roofit/roofitcore/inc/RooCustomizer.h | 19 ++++++++-------- roofit/roofitcore/src/RooCustomizer.cxx | 30 ++++++++++++------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/roofit/roofitcore/inc/RooCustomizer.h b/roofit/roofitcore/inc/RooCustomizer.h index 56b85f8ae9769..4aff93c8424dd 100644 --- a/roofit/roofitcore/inc/RooCustomizer.h +++ b/roofit/roofitcore/inc/RooCustomizer.h @@ -17,11 +17,12 @@ #ifndef ROO_PDF_CUSTOMIZER #define ROO_PDF_CUSTOMIZER -#include "TList.h" -#include "TNamed.h" -#include "TString.h" -#include "RooArgSet.h" -#include "RooPrintable.h" +#include +#include +#include + +#include +#include #include #include @@ -84,11 +85,11 @@ class RooCustomizer { bool _owning ; ///< If true we own all created components TString _name ; ///< Name of this object - TList _splitArgList ; ///< List of RooAbsArgs to be split - TList _splitCatList ; ///< List of categories to be used for above splits + RooArgList _splitArgList ; ///< List of RooAbsArgs to be split + RooArgList _splitCatList ; ///< List of categories to be used for above splits - TList _replaceArgList ; ///< List of RooAbsArgs to be replaced - TList _replaceSubList ; ///< List of replacement RooAbsArgs + RooArgList _replaceArgList ; ///< List of RooAbsArgs to be replaced + RooArgList _replaceSubList ; ///< List of replacement RooAbsArgs // Master nodes are not owned RooAbsArg* _masterPdf ; ///< Pointer to input p.d.f diff --git a/roofit/roofitcore/src/RooCustomizer.cxx b/roofit/roofitcore/src/RooCustomizer.cxx index ad0aef93e0648..1674ce53c09b1 100644 --- a/roofit/roofitcore/src/RooCustomizer.cxx +++ b/roofit/roofitcore/src/RooCustomizer.cxx @@ -154,8 +154,6 @@ #include "RooAbsCategory.h" #include "RooAbsArg.h" #include "RooAbsPdf.h" -#include "RooArgSet.h" -#include "RooArgList.h" #include "RooMsgService.h" #include "RooHelpers.h" @@ -305,7 +303,7 @@ void RooCustomizer::splitArgs(const RooArgSet& set, const RooAbsCategory& splitC void RooCustomizer::splitArg(const RooAbsArg& arg, const RooAbsCategory& splitCat) { - if (_splitArgList.FindObject(arg.GetName())) { + if (_splitArgList.find(arg.GetName())) { oocoutE(nullptr, InputArguments) << "RooCustomizer(" << _masterPdf->GetName() << ") ERROR: multiple splitting rules defined for " << arg.GetName() << " only using first rule" << endl ; return ; @@ -317,8 +315,8 @@ void RooCustomizer::splitArg(const RooAbsArg& arg, const RooAbsCategory& splitCa return ; } - _splitArgList.Add(const_cast(&arg)); - _splitCatList.Add(const_cast(&splitCat)); + _splitArgList.add(arg); + _splitCatList.add(splitCat); } @@ -328,14 +326,14 @@ void RooCustomizer::splitArg(const RooAbsArg& arg, const RooAbsCategory& splitCa void RooCustomizer::replaceArg(const RooAbsArg& orig, const RooAbsArg& subst) { - if (_replaceArgList.FindObject(orig.GetName())) { + if (_replaceArgList.find(orig.GetName())) { oocoutE(nullptr, InputArguments) << "RooCustomizer(" << _masterPdf->GetName() << ") ERROR: multiple replacement rules defined for " << orig.GetName() << " only using first rule" << endl ; return ; } - _replaceArgList.Add(const_cast(&orig)); - _replaceSubList.Add(const_cast(&subst)); + _replaceArgList.add(orig); + _replaceSubList.add(subst); } @@ -419,9 +417,9 @@ RooAbsArg* RooCustomizer::doBuild(const char* masterCatState, bool verbose) // cout << "loop over " << nodeList.size() << " nodes" << endl ; for (auto node : nodeList) { - RooAbsArg* theSplitArg = !_sterile?static_cast(_splitArgList.FindObject(node->GetName())):nullptr ; + RooAbsArg* theSplitArg = !_sterile?static_cast(_splitArgList.find(node->GetName())):nullptr ; if (theSplitArg) { - RooAbsCategory* splitCat = static_cast(_splitCatList.At(_splitArgList.IndexOf(theSplitArg))) ; + RooAbsCategory* splitCat = static_cast(_splitCatList.at(_splitArgList.index(theSplitArg))) ; if (verbose) { oocoutI(nullptr, ObjectHandling) << "RooCustomizer::build(" << _masterPdf->GetName() << "): tree node " << node->GetName() << " is split by category " << splitCat->GetName() << endl ; @@ -495,9 +493,9 @@ RooAbsArg* RooCustomizer::doBuild(const char* masterCatState, bool verbose) masterNodesToBeSplit.add(*node) ; } - RooAbsArg* ReplaceArg = static_cast(_replaceArgList.FindObject(node->GetName())) ; + RooAbsArg* ReplaceArg = static_cast(_replaceArgList.find(node->GetName())) ; if (ReplaceArg) { - RooAbsArg* substArg = static_cast(_replaceSubList.At(_replaceArgList.IndexOf(ReplaceArg))) ; + RooAbsArg* substArg = static_cast(_replaceSubList.at(_replaceArgList.index(ReplaceArg))) ; if (verbose) { oocoutI(nullptr, ObjectHandling) << "RooCustomizer::build(" << _masterPdf->GetName() << "): tree node " << node->GetName() << " will be replaced by " << substArg->GetName() << endl ; @@ -614,19 +612,19 @@ void RooCustomizer::printMultiline(ostream& os, Int_t /*content*/, bool /*verbos os << indent << "RooCustomizer for " << _masterPdf->GetName() << (_sterile?" (sterile)":"") << endl ; Int_t i; - Int_t nsplit = _splitArgList.GetSize(); + Int_t nsplit = _splitArgList.size(); if (nsplit>0) { os << indent << " Splitting rules:" << endl ; for (i=0 ; iGetName() << " is split by " << _splitCatList.At(i)->GetName() << endl ; + os << indent << " " << _splitArgList.at(i)->GetName() << " is split by " << _splitCatList.at(i)->GetName() << endl ; } } - Int_t nrepl = _replaceArgList.GetSize() ; + Int_t nrepl = _replaceArgList.size() ; if (nrepl>0) { os << indent << " Replacement rules:" << endl ; for (i=0 ; iGetName() << " replaces " << _replaceArgList.At(i)->GetName() << endl ; + os << indent << " " << _replaceSubList.at(i)->GetName() << " replaces " << _replaceArgList.at(i)->GetName() << endl ; } }