Skip to content

Commit

Permalink
fixup! [RF] Improve hash-assisted find in RooAbsCollection.
Browse files Browse the repository at this point in the history
  • Loading branch information
hageboeck committed Dec 10, 2021
1 parent 3bb0821 commit 6597cde
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 7 additions & 1 deletion roofit/roofitcore/inc/RooAbsCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ ROOT::RRangeCast<T, true, Range_t> dynamic_range_cast(Range_t &&coll)

class RooCmdArg;

namespace RooFit {
namespace Detail {
struct HashAssistedFind;
}
}

class RooAbsCollection : public TObject, public RooPrintable {
public:
using Storage_t = std::vector<RooAbsArg*>;
Expand Down Expand Up @@ -381,7 +387,7 @@ class RooAbsCollection : public TObject, public RooPrintable {
private:
std::unique_ptr<LegacyIterator_t> makeLegacyIterator (bool forward = true) const;

struct HashAssistedFind;
using HashAssistedFind = RooFit::Detail::HashAssistedFind;
mutable std::unique_ptr<HashAssistedFind> _hashAssistedFind; //!
std::size_t _sizeThresholdForMapSearch; //!

Expand Down
10 changes: 7 additions & 3 deletions roofit/roofitcore/src/RooAbsCollection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ char* operator+( streampos&, char* );

ClassImp(RooAbsCollection);

namespace RooFit {
namespace Detail {

/**
* Helper for hash-map-assisted finding of elements by name.
* Create this helper if finding of elements by name is needed.
Expand All @@ -71,7 +74,7 @@ ClassImp(RooAbsCollection);
* gets renamed, this counter will be increased, and the name to
* object map becomes invalid. In this case, it has to be recreated.
*/
struct RooAbsCollection::HashAssistedFind {
struct HashAssistedFind {

/// Inititalise empty hash map for fast finding by name.
template<typename It_t>
Expand Down Expand Up @@ -114,7 +117,8 @@ struct RooAbsCollection::HashAssistedFind {
std::size_t rooNameRegCounterWhereMapWasValid = 0;
};


}
}


////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1561,8 +1565,8 @@ void RooAbsCollection::insert(RooAbsArg* item) {
////////////////////////////////////////////////////////////////////////////////
/// \param[in] flag Switch hash map on or off.
void RooAbsCollection::useHashMapForFind(bool flag) const {
if (flag && !_hashAssistedFind) _hashAssistedFind = std::make_unique<HashAssistedFind>(_list.begin(), _list.end());
if (!flag) _hashAssistedFind = nullptr;
else _hashAssistedFind = std::make_unique<HashAssistedFind>(_list.begin(), _list.end());
}


Expand Down

0 comments on commit 6597cde

Please sign in to comment.