From ed22e9b965697323996e53d37a78d823a2cff6b8 Mon Sep 17 00:00:00 2001 From: Jonas Rembser Date: Tue, 4 Jun 2024 11:31:54 +0200 Subject: [PATCH] [RF] Avoid using transient `std::unique_ptr` Harmless change to circumvent errors like these when building RooFit standalone: ``` Error in : data member with index 0 is not found in class tuple > Error in : Cannot find data member # 0 of class tuple > for parent RooAddPdf! Error in : data member with index 1 is not found in class tuple > Error in : Cannot find data member # 1 of class tuple > for parent RooAddPdf! Error in : data member with index 0 is not found in class tuple > Error in : Cannot find data member # 0 of class tuple > for parent RooPolynomial! ``` --- roofit/roofitcore/inc/RooAbsCategory.h | 2 +- roofit/roofitcore/inc/RooAbsCollection.h | 2 +- roofit/roofitcore/inc/RooAbsReal.h | 2 +- roofit/roofitcore/src/RooAbsCategory.cxx | 10 ++++++++-- roofit/roofitcore/src/RooAbsCollection.cxx | 23 +++++++++++++++++----- roofit/roofitcore/src/RooAbsReal.cxx | 13 ++++++++++-- 6 files changed, 40 insertions(+), 12 deletions(-) diff --git a/roofit/roofitcore/inc/RooAbsCategory.h b/roofit/roofitcore/inc/RooAbsCategory.h index ca6ef01b6d92e..29f757a56b159 100644 --- a/roofit/roofitcore/inc/RooAbsCategory.h +++ b/roofit/roofitcore/inc/RooAbsCategory.h @@ -221,7 +221,7 @@ class RooAbsCategory : public RooAbsArg { static const decltype(_stateNames)::value_type& invalidCategory(); private: - std::unique_ptr _treeReadBuffer; //! A buffer for reading values from trees + TreeReadBuffer *_treeReadBuffer = nullptr; //! A buffer for reading values from trees ClassDefOverride(RooAbsCategory, 4) // Abstract discrete variable }; diff --git a/roofit/roofitcore/inc/RooAbsCollection.h b/roofit/roofitcore/inc/RooAbsCollection.h index b48f09aed1761..acd3c60b64eec 100644 --- a/roofit/roofitcore/inc/RooAbsCollection.h +++ b/roofit/roofitcore/inc/RooAbsCollection.h @@ -443,7 +443,7 @@ class RooAbsCollection : public TObject, public RooPrintable { bool replaceImpl(const RooAbsArg& var1, const RooAbsArg& var2); using HashAssistedFind = RooFit::Detail::HashAssistedFind; - mutable std::unique_ptr _hashAssistedFind; /// _specIntegratorConfig; // Numeric integrator configuration specific for this object - std::unique_ptr _treeReadBuffer; //! A buffer for reading values from trees + TreeReadBuffer *_treeReadBuffer = nullptr; //! A buffer for reading values from trees bool _selectComp = true; //! Component selection flag for RooAbsPdf::plotCompOn mutable RooFit::UniqueId::Value_t _lastNormSetId = RooFit::UniqueId::nullval; ///second(); + _treeReadBuffer = typeDetails->second().release(); } else { + if (_treeReadBuffer) { + delete _treeReadBuffer; + } _treeReadBuffer = nullptr; if (typeName == "Int_t") { diff --git a/roofit/roofitcore/src/RooAbsCollection.cxx b/roofit/roofitcore/src/RooAbsCollection.cxx index 6e476bbd93c77..fd91282f3b87c 100644 --- a/roofit/roofitcore/src/RooAbsCollection.cxx +++ b/roofit/roofitcore/src/RooAbsCollection.cxx @@ -178,6 +178,10 @@ RooAbsCollection::~RooAbsCollection() if(_ownCont){ deleteList() ; } + if (_hashAssistedFind) { + delete _hashAssistedFind; + } + _hashAssistedFind = nullptr; } @@ -189,6 +193,9 @@ RooAbsCollection::~RooAbsCollection() void RooAbsCollection::deleteList() { + if (_hashAssistedFind) { + delete _hashAssistedFind; + } _hashAssistedFind = nullptr; // Built-in delete remaining elements @@ -748,6 +755,9 @@ bool RooAbsCollection::remove(const RooAbsCollection& list, bool /*silent*/, boo void RooAbsCollection::removeAll() { + if (_hashAssistedFind) { + delete _hashAssistedFind; + } _hashAssistedFind = nullptr; if(_ownCont) { @@ -920,7 +930,7 @@ RooAbsArg * RooAbsCollection::find(const char *name) const if (_hashAssistedFind || _list.size() >= _sizeThresholdForMapSearch) { if (!_hashAssistedFind || !_hashAssistedFind->isValid()) { - _hashAssistedFind = std::make_unique(_list.begin(), _list.end()); + _hashAssistedFind = new HashAssistedFind{_list.begin(), _list.end()}; } return _hashAssistedFind->find(nptr); @@ -940,7 +950,7 @@ RooAbsArg * RooAbsCollection::find(const RooAbsArg& arg) const if (_hashAssistedFind || _list.size() >= _sizeThresholdForMapSearch) { if (!_hashAssistedFind || !_hashAssistedFind->isValid()) { - _hashAssistedFind = std::make_unique(_list.begin(), _list.end()); + _hashAssistedFind = new HashAssistedFind{_list.begin(), _list.end()}; } return _hashAssistedFind->find(nptr); @@ -1617,10 +1627,13 @@ void RooAbsCollection::useHashMapForFind(bool flag) const throw std::runtime_error(msg.str()); } #endif - if (flag && !_hashAssistedFind) - _hashAssistedFind = std::make_unique(_list.begin(), _list.end()); - if (!flag) + if (flag && !_hashAssistedFind) { + _hashAssistedFind = new HashAssistedFind{_list.begin(), _list.end()}; + } + if (!flag && _hashAssistedFind) { + delete _hashAssistedFind; _hashAssistedFind = nullptr; + } } diff --git a/roofit/roofitcore/src/RooAbsReal.cxx b/roofit/roofitcore/src/RooAbsReal.cxx index 06aefedc97575..016fb1b4ed4cc 100644 --- a/roofit/roofitcore/src/RooAbsReal.cxx +++ b/roofit/roofitcore/src/RooAbsReal.cxx @@ -219,7 +219,13 @@ RooAbsReal::RooAbsReal(const RooAbsReal& other, const char* name) : //////////////////////////////////////////////////////////////////////////////// /// Destructor -RooAbsReal::~RooAbsReal() {} +RooAbsReal::~RooAbsReal() +{ + if (_treeReadBuffer) { + delete _treeReadBuffer; + } + _treeReadBuffer = nullptr; +} //////////////////////////////////////////////////////////////////////////////// @@ -3153,8 +3159,11 @@ void RooAbsReal::attachToTree(TTree& t, Int_t bufSize) coutI(DataHandling) << "RooAbsReal::attachToTree(" << GetName() << ") TTree " << typeDetails->first << " branch " << GetName() << " will be converted to double precision." << std::endl ; setAttribute(typeDetails->second.first.c_str(), true); - _treeReadBuffer = typeDetails->second.second(); + _treeReadBuffer = typeDetails->second.second().release(); } else { + if (_treeReadBuffer) { + delete _treeReadBuffer; + } _treeReadBuffer = nullptr; if (!typeName.CompareTo("Double_t")) {