From 7db3834e8d1d1982474f3c4ecbf6227a99999418 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Fri, 31 Jan 2025 17:11:32 +0100 Subject: [PATCH] [RF] Refactor RooAICRegistry and its usage Modernize RooAICRegistry, the helper that operator p.d.f.s use to cache analytical integration codes and their associated RooArgSets, and clean up its usage across RooFitCore. Storage and ownership: - Replace the four parallel `std::vector` members and the hand-written copy/destroy bookkeeping with a single `std::array>, 4>`. The manual destructor and `copyImpl()` helper are gone; lifetime is now handled by the smart pointers. - `store()` no longer takes ownership of the RooArgSets passed to it; it only snapshots them. Callers are updated accordingly: they either keep their `unique_ptr`s (RooAbsAnaConvPdf) or pass stack objects instead of heap allocations (RooAbsCachedPdf), removing several `new`/`release()`/`delete` dances. API: - Replace the four `retrieve()` out-parameter overloads with a single method returning a small `Output` struct (the code list plus the four set pointers), so call sites no longer declare and thread raw pointers by reference. - Drop the `ClassDef`/dictionary and the corresponding LinkDef entry: all data members were transient, so the registry was never persisted and does not need I/O support. Cleanups in the consumers: - Remove the unused `_codeReg` registry members (and the now-redundant RooAICRegistry.h includes) from RooHistFunc, RooHistPdf and RooAddModel. - In RooProdPdf, `_genCode` only ever stored code lists without any RooArgSets, so demote it from a RooAICRegistry to a plain `std::vector>` and look codes up directly. --- roofit/roofitcore/inc/LinkDef.h | 1 - roofit/roofitcore/inc/RooAICRegistry.h | 63 +++--- roofit/roofitcore/inc/RooAddModel.h | 3 - roofit/roofitcore/inc/RooHistFunc.h | 2 - roofit/roofitcore/inc/RooHistPdf.h | 2 - roofit/roofitcore/inc/RooProdPdf.h | 3 +- roofit/roofitcore/inc/RooRealSumFunc.h | 1 - roofit/roofitcore/inc/RooRealSumPdf.h | 1 - roofit/roofitcore/inc/RooSimultaneous.h | 1 - roofit/roofitcore/src/RooAICRegistry.cxx | 234 +++++---------------- roofit/roofitcore/src/RooAbsAnaConvPdf.cxx | 18 +- roofit/roofitcore/src/RooAbsCachedPdf.cxx | 24 +-- roofit/roofitcore/src/RooAddModel.cxx | 2 - roofit/roofitcore/src/RooAddPdf.cxx | 8 +- roofit/roofitcore/src/RooHistFunc.cxx | 3 - roofit/roofitcore/src/RooHistPdf.cxx | 3 - roofit/roofitcore/src/RooProdPdf.cxx | 17 +- 17 files changed, 125 insertions(+), 261 deletions(-) diff --git a/roofit/roofitcore/inc/LinkDef.h b/roofit/roofitcore/inc/LinkDef.h index 2dfbf74869e15..63b0da9460b57 100644 --- a/roofit/roofitcore/inc/LinkDef.h +++ b/roofit/roofitcore/inc/LinkDef.h @@ -64,7 +64,6 @@ #pragma link C++ class RooAddGenContext+ ; #pragma link C++ class RooAddition+ ; #pragma link C++ class RooAddModel+ ; -#pragma link C++ class RooAICRegistry+ ; #pragma link C++ class RooArgList+ ; #pragma link C++ class RooArgProxy+ ; #pragma link C++ class RooArgSet+ ; diff --git a/roofit/roofitcore/inc/RooAICRegistry.h b/roofit/roofitcore/inc/RooAICRegistry.h index 4575bf33ad49b..57d4c16dca391 100644 --- a/roofit/roofitcore/inc/RooAICRegistry.h +++ b/roofit/roofitcore/inc/RooAICRegistry.h @@ -16,44 +16,47 @@ #ifndef ROO_AIC_REGISTRY #define ROO_AIC_REGISTRY +#include +#include #include -#include "Rtypes.h" class RooArgSet; -typedef RooArgSet* pRooArgSet ; - +/// Registry for analytical integration codes. class RooAICRegistry { public: - RooAICRegistry(UInt_t size = 10) ; - RooAICRegistry(const RooAICRegistry &other); - RooAICRegistry &operator=(const RooAICRegistry &other); - RooAICRegistry(RooAICRegistry &&other) = default; - RooAICRegistry &operator=(RooAICRegistry &&other) = default; - virtual ~RooAICRegistry() ; - - Int_t store(const std::vector& codeList, RooArgSet* set1 = nullptr, RooArgSet* set2 = nullptr, - RooArgSet* set3 = nullptr, RooArgSet* set4 = nullptr) ; - const std::vector& retrieve(Int_t masterCode) const ; - const std::vector& retrieve(Int_t masterCode, pRooArgSet& set1) const ; - const std::vector& retrieve(Int_t masterCode, pRooArgSet& set1, pRooArgSet& set2) const ; - const std::vector& retrieve(Int_t masterCode, pRooArgSet& set1, - pRooArgSet& set2, pRooArgSet& set3, pRooArgSet& set4) const ; - size_t size() const; - -private: - void copyImpl(const RooAICRegistry &other); + RooAICRegistry(std::size_t size = 10); + RooAICRegistry(const RooAICRegistry &other); + RooAICRegistry &operator=(const RooAICRegistry &other); + RooAICRegistry(RooAICRegistry &&other) = default; + RooAICRegistry &operator=(RooAICRegistry &&other) = default; + + int store(const std::vector &codeList, RooArgSet *set1 = nullptr, RooArgSet *set2 = nullptr, + RooArgSet *set3 = nullptr, RooArgSet *set4 = nullptr); + + struct Output { + std::vector const &codes; + std::array sets; + }; + + /// Retrieve the array of integer codes associated with the given master code, + /// together with the (up to four) RooArgSets associated with this master code. + Output retrieve(int masterCode) + { + Output out{.codes = _clArr[masterCode], .sets = {}}; + for (std::size_t iArr = 0; iArr < 4; ++iArr) { + out.sets[iArr] = _asArr[iArr][masterCode].get(); + } + return out; + } + + /// Number of stored code lists. + std::size_t size() const { return _clArr.size(); } protected: - - std::vector > _clArr; /// _asArr1; /// _asArr2; /// _asArr3; /// _asArr4; ///> _clArr; ///>, 4> _asArr; /// @@ -115,7 +114,6 @@ class RooHistFunc : public RooAbsReal { RooSetProxy _depList; ///< List of observables mapped onto histogram observables RooDataHist* _dataHist = nullptr; ///< Unowned pointer to underlying histogram std::unique_ptr _ownedDataHist; /// @@ -111,7 +110,6 @@ class RooHistPdf : public RooAbsPdf { RooSetProxy _pdfObsList; ///< List of observables mapped onto histogram observables RooDataHist* _dataHist = nullptr; ///< Unowned pointer to underlying histogram std::unique_ptr _ownedDataHist; ///> _genCode; /// diff --git a/roofit/roofitcore/inc/RooRealSumPdf.h b/roofit/roofitcore/inc/RooRealSumPdf.h index f59f0cd6472b2..740c4aa6176f0 100644 --- a/roofit/roofitcore/inc/RooRealSumPdf.h +++ b/roofit/roofitcore/inc/RooRealSumPdf.h @@ -18,7 +18,6 @@ #include "RooAbsPdf.h" #include "RooListProxy.h" -#include "RooAICRegistry.h" #include "RooObjCacheManager.h" class RooRealSumPdf : public RooAbsPdf { diff --git a/roofit/roofitcore/inc/RooSimultaneous.h b/roofit/roofitcore/inc/RooSimultaneous.h index e9ce1e295800a..f4c51531fa627 100644 --- a/roofit/roofitcore/inc/RooSimultaneous.h +++ b/roofit/roofitcore/inc/RooSimultaneous.h @@ -16,7 +16,6 @@ #ifndef ROO_SIMULTANEOUS #define ROO_SIMULTANEOUS -#include #include #include #include diff --git a/roofit/roofitcore/src/RooAICRegistry.cxx b/roofit/roofitcore/src/RooAICRegistry.cxx index 8dbe0d4d294dd..8c05bce9565ec 100644 --- a/roofit/roofitcore/src/RooAICRegistry.cxx +++ b/roofit/roofitcore/src/RooAICRegistry.cxx @@ -24,116 +24,50 @@ classes that keeps track of analytical integration codes and associated normalization and integration sets. **/ -#include "RooAICRegistry.h" -#include "RooMsgService.h" -#include "RooArgSet.h" - -#include "Riostream.h" - +#include +#include namespace { -RooArgSet * makeSnapshot(RooArgSet const* set) { - if(!set) { - return nullptr; - } - auto out = new RooArgSet; - set->snapshot(*out, false); - return out; -} - -} - -//////////////////////////////////////////////////////////////////////////////// - -RooAICRegistry::RooAICRegistry(UInt_t size) - : _clArr(0), _asArr1(0), _asArr2(0), _asArr3(0), _asArr4(0) -{ - _clArr.reserve(size); - _asArr1.reserve(size); - _asArr2.reserve(size); - _asArr3.reserve(size); - _asArr4.reserve(size); -} - -//////////////////////////////////////////////////////////////////////////////// -/// Copy constructor - -RooAICRegistry::RooAICRegistry(const RooAICRegistry &other) +template +std::unique_ptr makeSnapshot(RooArgSetPointer_t const &set) { - copyImpl(other); + if (!set) + return nullptr; + auto out = std::make_unique(); + set->snapshot(*out, false); + return out; } -//////////////////////////////////////////////////////////////////////////////// -/// Copy assignment +} // namespace -RooAICRegistry &RooAICRegistry::operator=(const RooAICRegistry &other) +RooAICRegistry::RooAICRegistry(std::size_t size) { - // Delete code list array, if allocated - for (unsigned int i = 0; i < _clArr.size(); ++i) { - if (_asArr1[i]) { - delete _asArr1[i]; - _asArr1[i] = nullptr; - } - if (_asArr2[i]) { - delete _asArr2[i]; - _asArr2[i] = nullptr; - } - if (_asArr3[i]) { - delete _asArr3[i]; - _asArr3[i] = nullptr; - } - if (_asArr4[i]) { - delete _asArr4[i]; - _asArr4[i] = nullptr; - } + _clArr.reserve(size); + for (auto &a : _asArr) { + a.reserve(size); } - copyImpl(other); - return *this; } -//////////////////////////////////////////////////////////////////////////////// -/// Destructor - -RooAICRegistry::~RooAICRegistry() -{ - // Delete code list array, if allocated - for (unsigned int i = 0; i < _clArr.size(); ++i) { - if (_asArr1[i]) delete _asArr1[i]; - if (_asArr2[i]) delete _asArr2[i]; - if (_asArr3[i]) delete _asArr3[i]; - if (_asArr4[i]) delete _asArr4[i]; - } -} - - -void RooAICRegistry::copyImpl(const RooAICRegistry &other) +RooAICRegistry::RooAICRegistry(const RooAICRegistry &other) : _clArr(other._clArr) { - _clArr = other._clArr; - // Copy code-list array if other PDF has one - UInt_t size = other._clArr.size(); - if (size) { - _asArr1.resize(size, nullptr); - _asArr2.resize(size, nullptr); - _asArr3.resize(size, nullptr); - _asArr4.resize(size, nullptr); - for (UInt_t i = 0; i < size; ++i) { - _asArr1[i] = makeSnapshot(other._asArr1[i]); - _asArr2[i] = makeSnapshot(other._asArr2[i]); - _asArr3[i] = makeSnapshot(other._asArr3[i]); - _asArr4[i] = makeSnapshot(other._asArr4[i]); + for (std::size_t iArr = 0; iArr < _asArr.size(); ++iArr) { + _asArr[iArr].resize(_clArr.size()); + for (std::size_t i = 0; i < _clArr.size(); ++i) { + _asArr[iArr][i] = makeSnapshot(other._asArr[iArr][i]); } } } - //////////////////////////////////////////////////////////////////////////////// -/// Get size of _clArr vector +/// Copy assignment. -size_t RooAICRegistry::size() const +RooAICRegistry &RooAICRegistry::operator=(const RooAICRegistry &other) { - return _clArr.size(); + RooAICRegistry tmp(other); + *this = std::move(tmp); + return *this; } //////////////////////////////////////////////////////////////////////////////// @@ -146,98 +80,40 @@ size_t RooAICRegistry::size() const /// previously stored in the registry no objects are stored and the /// unique code of the existing entry is returned. -Int_t RooAICRegistry::store(const std::vector& codeList, RooArgSet* set1, - RooArgSet* set2, RooArgSet* set3, RooArgSet* set4) +int RooAICRegistry::store(const std::vector &codeList, RooArgSet *set1, RooArgSet *set2, RooArgSet *set3, + RooArgSet *set4) { - // Loop over code-list array - for (UInt_t i = 0; i < _clArr.size(); ++i) { - // Existing slot, compare with current list, if matched return index - bool match(true) ; - - // Check that array contents is identical - match &= _clArr[i] == codeList; - - // Check that supplied configuration of lists is identical - if (_asArr1[i] && !set1) match=false ; - if (!_asArr1[i] && set1) match=false ; - if (_asArr2[i] && !set2) match=false ; - if (!_asArr2[i] && set2) match=false ; - if (_asArr3[i] && !set3) match=false ; - if (!_asArr3[i] && set3) match=false ; - if (_asArr4[i] && !set4) match=false ; - if (!_asArr4[i] && set4) match=false ; - - // Check that contents of arrays is identical - if (_asArr1[i] && set1 && !set1->equals(*_asArr1[i])) match=false ; - if (_asArr2[i] && set2 && !set2->equals(*_asArr2[i])) match=false ; - if (_asArr3[i] && set3 && !set3->equals(*_asArr3[i])) match=false ; - if (_asArr4[i] && set4 && !set4->equals(*_asArr4[i])) match=false ; - - if (match) { - if (set1) delete set1 ; - if (set2) delete set2 ; - if (set3) delete set3 ; - if (set4) delete set4 ; - return i ; - } - } - - // Store code list and return index - _clArr.push_back(codeList); - _asArr1.emplace_back(makeSnapshot(set1)); - _asArr2.emplace_back(makeSnapshot(set2)); - _asArr3.emplace_back(makeSnapshot(set3)); - _asArr4.emplace_back(makeSnapshot(set4)); - - if (set1) delete set1 ; - if (set2) delete set2 ; - if (set3) delete set3 ; - if (set4) delete set4 ; - return _clArr.size() - 1; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Retrieve the array of integer codes associated with the given master code - -const std::vector& RooAICRegistry::retrieve(Int_t masterCode) const -{ - return _clArr[masterCode] ; -} - -//////////////////////////////////////////////////////////////////////////////// -/// Retrieve the array of integer codes associated with the given master code -/// and set the passed set1 pointer to the first RooArgSet associated with this master code - -const std::vector& RooAICRegistry::retrieve(Int_t masterCode, pRooArgSet& set1) const -{ - set1 = _asArr1[masterCode] ; - return _clArr[masterCode] ; -} + // Taking the ownership of the input sets + std::array sets{set1, set2, set3, set4}; + + // Loop over code-list array + for (std::size_t i = 0; i < _clArr.size(); ++i) { + // Existing slot, compare with current list, if matched return index. + // First., check that array contents is identical. + bool match = _clArr[i] == codeList; + + // Check that supplied configuration of lists is identical + for (std::size_t iArr = 0; iArr < 4; ++iArr) { + if ((_asArr[iArr][i] && !sets[iArr]) || (!_asArr[iArr][i] && sets[iArr])) + match = false; + } -//////////////////////////////////////////////////////////////////////////////// -/// Retrieve the array of integer codes associated with the given master code -/// and set the passed set1,set2 pointers to the first and second RooArgSets associated with this -/// master code respectively + // Check that contents of arrays is identical + for (std::size_t iArr = 0; iArr < 4; ++iArr) { + if (_asArr[iArr][i] && sets[iArr] && !sets[iArr]->equals(*_asArr[iArr][i])) + match = false; + } -const std::vector& RooAICRegistry::retrieve -(Int_t masterCode, pRooArgSet& set1, pRooArgSet& set2) const -{ - set1 = _asArr1[masterCode] ; - set2 = _asArr2[masterCode] ; - return _clArr[masterCode] ; -} + if (match) { + return i; + } + } -//////////////////////////////////////////////////////////////////////////////// -/// Retrieve the array of integer codes associated with the given master code -/// and set the passed set1-4 pointers to the four RooArgSets associated with this -/// master code respectively + // Store code list and return index + _clArr.push_back(codeList); + for (std::size_t iArr = 0; iArr < 4; ++iArr) { + _asArr[iArr].emplace_back(makeSnapshot(sets[iArr])); + } -const std::vector& RooAICRegistry::retrieve -(Int_t masterCode, pRooArgSet& set1, pRooArgSet& set2, pRooArgSet& set3, pRooArgSet& set4) const -{ - set1 = _asArr1[masterCode] ; - set2 = _asArr2[masterCode] ; - set3 = _asArr3[masterCode] ; - set4 = _asArr4[masterCode] ; - return _clArr[masterCode] ; + return _clArr.size() - 1; } diff --git a/roofit/roofitcore/src/RooAbsAnaConvPdf.cxx b/roofit/roofitcore/src/RooAbsAnaConvPdf.cxx index 0844a77eb5ee0..d73c0f0edbf94 100644 --- a/roofit/roofitcore/src/RooAbsAnaConvPdf.cxx +++ b/roofit/roofitcore/src/RooAbsAnaConvPdf.cxx @@ -506,10 +506,10 @@ Int_t RooAbsAnaConvPdf::getAnalyticalIntegralWN(RooArgSet& allVars, // takes ownership of all sets masterCode = _codeReg.store(tmp, - intCoefSet.release(), - intConvSet.release(), - normCoefSet.release(), - normConvSet.release()) + 1; + intCoefSet.get(), + intConvSet.get(), + normCoefSet.get(), + normConvSet.get()) + 1; analVars.add(allDeps) ; @@ -556,11 +556,11 @@ double RooAbsAnaConvPdf::analyticalIntegralWN(Int_t code, const RooArgSet *normS return getVal(normSet); // Unpack master code - RooArgSet *intCoefSet; - RooArgSet *intConvSet; - RooArgSet *normCoefSet; - RooArgSet *normConvSet; - _codeReg.retrieve(code - 1, intCoefSet, intConvSet, normCoefSet, normConvSet); + auto retrieved = _codeReg.retrieve(code - 1); + RooArgSet *intCoefSet = retrieved.sets[0]; + RooArgSet *intConvSet = retrieved.sets[1]; + RooArgSet *normCoefSet = retrieved.sets[2]; + RooArgSet *normConvSet = retrieved.sets[3]; Int_t index(0); diff --git a/roofit/roofitcore/src/RooAbsCachedPdf.cxx b/roofit/roofitcore/src/RooAbsCachedPdf.cxx index 6610faaad99f3..13859e2b267d2 100644 --- a/roofit/roofitcore/src/RooAbsCachedPdf.cxx +++ b/roofit/roofitcore/src/RooAbsCachedPdf.cxx @@ -326,18 +326,18 @@ int RooAbsCachedPdf::getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& anal return 0 ; } - RooArgSet* all = new RooArgSet ; - RooArgSet* ana = new RooArgSet ; - RooArgSet* nrm = new RooArgSet ; - all->addClone(allVars) ; - ana->addClone(analVars) ; + RooArgSet all; + RooArgSet ana; + RooArgSet nrm; + all.addClone(allVars) ; + ana.addClone(analVars) ; if (normSet) { - nrm->addClone(*normSet) ; + nrm.addClone(*normSet) ; } std::vector codeList(2); codeList[0] = code ; codeList[1] = cache->pdf()->haveUnitNorm() ? 1 : 0 ; - int masterCode = _anaReg.store(codeList,all,ana,nrm)+1 ; // takes ownership of all sets + int masterCode = _anaReg.store(codeList,&all,&ana,&nrm)+1 ; // Mark all observables as internally integrated @@ -368,11 +368,11 @@ double RooAbsCachedPdf::analyticalIntegralWN(int code, const RooArgSet* normSet, return 0.; } - RooArgSet *allVars(nullptr); - RooArgSet *anaVars(nullptr); - RooArgSet *normSet2(nullptr); - RooArgSet *dummy(nullptr); - const std::vector codeList = _anaReg.retrieve(code-1,allVars,anaVars,normSet2,dummy) ; + auto retrieved = _anaReg.retrieve(code-1); + std::vector const &codeList = retrieved.codes; + RooArgSet *allVars = retrieved.sets[0]; + RooArgSet *anaVars = retrieved.sets[1]; + RooArgSet *normSet2 = retrieved.sets[2]; // Mirror getAnalyticalIntegralWN's lookup key. If the caller passed a null // normSet to getAnalyticalIntegralWN, the stored normSet2 is non-null but diff --git a/roofit/roofitcore/src/RooAddModel.cxx b/roofit/roofitcore/src/RooAddModel.cxx index ba7b3c181c9c3..e575e36fd200c 100644 --- a/roofit/roofitcore/src/RooAddModel.cxx +++ b/roofit/roofitcore/src/RooAddModel.cxx @@ -82,7 +82,6 @@ RooAddModel::RooAddModel(const char *name, const char *title, const RooArgList& _refCoefNorm("!refCoefNorm","Reference coefficient normalization set",this,false,false), _projCacheMgr(this,10), _intCacheMgr(this,10), - _codeReg(10), _pdfList("!pdfs","List of PDFs",this), _coefList("!coefficients","List of coefficients",this) { @@ -160,7 +159,6 @@ RooAddModel::RooAddModel(const RooAddModel &other, const char *name) _refCoefRangeName((TNamed *)other._refCoefRangeName), _projCacheMgr(other._projCacheMgr, this), _intCacheMgr(other._intCacheMgr, this), - _codeReg(other._codeReg), _pdfList("!pdfs", this, other._pdfList), _coefList("!coefficients", this, other._coefList), _haveLastCoef(other._haveLastCoef), diff --git a/roofit/roofitcore/src/RooAddPdf.cxx b/roofit/roofitcore/src/RooAddPdf.cxx index 87858e7e56b36..e45115d14cfb9 100644 --- a/roofit/roofitcore/src/RooAddPdf.cxx +++ b/roofit/roofitcore/src/RooAddPdf.cxx @@ -683,8 +683,7 @@ Int_t RooAddPdf::getAnalyticalIntegralWN(RooArgSet& allVars, RooArgSet& analVars analVars.add(allAnalVars) ; // Store set of variables analytically integrated - RooArgSet* intSet = new RooArgSet(allAnalVars) ; - Int_t masterCode = _codeReg.store(subCode,intSet)+1 ; + Int_t masterCode = _codeReg.store(subCode,&allAnalVars)+1 ; return masterCode ; } @@ -702,8 +701,9 @@ double RooAddPdf::analyticalIntegralWN(Int_t code, const RooArgSet* normSet, con } // Retrieve analytical integration subCodes and set of observabels integrated over - RooArgSet* intSet = nullptr; - const std::vector& subCode = _codeReg.retrieve(code-1,intSet) ; + auto retrieved = _codeReg.retrieve(code-1); + std::vector const &subCode = retrieved.codes; + RooArgSet *intSet = retrieved.sets[0]; if (subCode.empty()) { std::stringstream errorMsg; errorMsg << "RooAddPdf::analyticalIntegral(" << GetName() << "): ERROR unrecognized integration code, " << code; diff --git a/roofit/roofitcore/src/RooHistFunc.cxx b/roofit/roofitcore/src/RooHistFunc.cxx index 6d8f0c5a2bb8e..ab1d372238e3d 100644 --- a/roofit/roofitcore/src/RooHistFunc.cxx +++ b/roofit/roofitcore/src/RooHistFunc.cxx @@ -53,7 +53,6 @@ RooHistFunc::RooHistFunc(const char *name, const char *title, const RooArgSet& v RooAbsReal(name,title), _depList("depList","List of dependents",this), _dataHist(const_cast(&dhist)), - _codeReg(10), _intOrder(intOrder) { _histObsList.addClone(vars) ; @@ -91,7 +90,6 @@ RooHistFunc::RooHistFunc(const char *name, const char *title, const RooArgList& RooAbsReal(name,title), _depList("depList","List of dependents",this), _dataHist(const_cast(&dhist)), - _codeReg(10), _intOrder(intOrder) { _histObsList.addClone(histObs) ; @@ -137,7 +135,6 @@ RooHistFunc::RooHistFunc(const RooHistFunc& other, const char* name) : RooAbsReal(other,name), _depList("depList",this,other._depList), _dataHist(other._dataHist), - _codeReg(other._codeReg), _intOrder(other._intOrder), _cdfBoundaries(other._cdfBoundaries), _totVolume(other._totVolume), diff --git a/roofit/roofitcore/src/RooHistPdf.cxx b/roofit/roofitcore/src/RooHistPdf.cxx index 94c2164a5e791..7ac8eff0ea9ae 100644 --- a/roofit/roofitcore/src/RooHistPdf.cxx +++ b/roofit/roofitcore/src/RooHistPdf.cxx @@ -55,7 +55,6 @@ RooHistPdf::RooHistPdf(const char *name, const char *title, const RooArgSet& var RooAbsPdf(name,title), _pdfObsList("pdfObs","List of p.d.f. observables",this), _dataHist(const_cast(&dhist)), - _codeReg(10), _intOrder(intOrder) { _histObsList.addClone(vars) ; @@ -104,7 +103,6 @@ RooHistPdf::RooHistPdf(const char *name, const char *title, const RooArgList& pd RooAbsPdf(name,title), _pdfObsList("pdfObs","List of p.d.f. observables",this), _dataHist(const_cast(&dhist)), - _codeReg(10), _intOrder(intOrder) { _histObsList.addClone(histObs) ; @@ -164,7 +162,6 @@ RooHistPdf::RooHistPdf(const RooHistPdf& other, const char* name) : RooAbsPdf(other,name), _pdfObsList("pdfObs",this,other._pdfObsList), _dataHist(other._dataHist), - _codeReg(other._codeReg), _intOrder(other._intOrder), _cdfBoundaries(other._cdfBoundaries), _totVolume(other._totVolume), diff --git a/roofit/roofitcore/src/RooProdPdf.cxx b/roofit/roofitcore/src/RooProdPdf.cxx index 2538a4c7bf88a..395eaa44bc9cb 100644 --- a/roofit/roofitcore/src/RooProdPdf.cxx +++ b/roofit/roofitcore/src/RooProdPdf.cxx @@ -1504,11 +1504,16 @@ Int_t RooProdPdf::getGenerator(const RooArgSet& directVars, RooArgSet &generateV if (!generateVars.empty()) { - Int_t masterCode = _genCode.store(code) ; - return masterCode+1 ; - } else { - return 0 ; + auto found = std::find(_genCode.begin(), _genCode.end(), code); + // If a generator for the codes was already cached, return the index to the + // corresponding caching index plus one. + if (found != _genCode.end()) { + return std::distance(_genCode.begin(), found) + 1; + } + _genCode.emplace_back(std::move(code)); + return _genCode.size(); } + return 0; } @@ -1521,7 +1526,7 @@ void RooProdPdf::initGenerator(Int_t code) { if (!_useDefaultGen) return ; - const std::vector& codeList = _genCode.retrieve(code-1) ; + const std::vector& codeList = _genCode[code-1]; Int_t i(0) ; for (auto* pdf : static_range_cast(_pdfList)) { if (codeList[i]!=0) { @@ -1542,7 +1547,7 @@ void RooProdPdf::generateEvent(Int_t code) { if (!_useDefaultGen) return ; - const std::vector& codeList = _genCode.retrieve(code-1) ; + const std::vector& codeList = _genCode[code-1]; Int_t i(0) ; for (auto* pdf : static_range_cast(_pdfList)) { if (codeList[i]!=0) {