Belle II Software  release-05-02-19
BestMatchContainer< TItem, TEstimator > Class Template Reference

Multiple entries can be added, but only the one will be kept, which has the best quality estimator. More...

#include <BestMatchContainer.h>

Public Types

typedef std::function< bool(TEstimator, TEstimator)> EstimatorComparison
 Lambda typedef for the function comparing estimators. More...
 

Public Member Functions

bool add (TItem const &item, TEstimator est, EstimatorComparison estComparison=[](TEstimator currentBest, TEstimator newEst) {return newEst< currentBest;})
 Add a new item with an estimator value. More...
 
bool hasMatch () const
 
TItem const & getBestMatch () const
 

Private Member Functions

void setBestMatch (TItem const &item, TEstimator est)
 Set a new item as the best match.
 

Private Attributes

std::optional< TItem > m_bestMatch
 Stores the best matched item.
 
TEstimator m_bestEstimator = TEstimator()
 Stores the estimator value of the best match.
 

Detailed Description

template<class TItem, class TEstimator>
class Belle2::BestMatchContainer< TItem, TEstimator >

Multiple entries can be added, but only the one will be kept, which has the best quality estimator.

This class can be used in cases where the best-match candidate is searched

Definition at line 35 of file BestMatchContainer.h.

Member Typedef Documentation

◆ EstimatorComparison

typedef std::function< bool(TEstimator, TEstimator)> EstimatorComparison

Lambda typedef for the function comparing estimators.

Returns true if the second parameter is a better estimation than the first one.

Definition at line 42 of file BestMatchContainer.h.

Member Function Documentation

◆ add()

bool add ( TItem const &  item,
TEstimator  est,
EstimatorComparison  estComparison = [](TEstimator currentBest, TEstimator newEst) {return newEst < currentBest;} 
)
inline

Add a new item with an estimator value.

Parameters
estComparisonThe default estimator will favor items with smaller estimates

Definition at line 50 of file BestMatchContainer.h.

53  {
54  setBestMatch(item, est);
55  return true;
56  }
57 
58  // best match was not updated
59  return false;
60  }
61 
65  bool hasMatch() const
66  {
67  return static_cast<bool>(m_bestMatch);
68  }

◆ getBestMatch()

TItem const& getBestMatch ( ) const
inline
Returns
Returns a reference to the candidate with the best match according to the estimator value.

Definition at line 82 of file BestMatchContainer.h.

◆ hasMatch()

bool hasMatch ( ) const
inline
Returns
Returns true if at least one candidate has been matched.

Definition at line 73 of file BestMatchContainer.h.


The documentation for this class was generated from the following file:
Belle2::BestMatchContainer::hasMatch
bool hasMatch() const
Definition: BestMatchContainer.h:73
Belle2::BestMatchContainer::m_bestMatch
std::optional< TItem > m_bestMatch
Stores the best matched item.
Definition: BestMatchContainer.h:99
Belle2::BestMatchContainer::setBestMatch
void setBestMatch(TItem const &item, TEstimator est)
Set a new item as the best match.
Definition: BestMatchContainer.h:92