Belle II Software  release-08-01-10
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 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 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 27 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 34 of file BestMatchContainer.h.

Member Function Documentation

◆ add()

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

Add a new item with an estimator value.

Parameters
itemitem
estestimator
estComparisonThe default estimator will favor items with smaller estimates

Definition at line 44 of file BestMatchContainer.h.

46  {return newEst < currentBest;}
47  )
48  {
49  if (!hasMatch()) {
50  // not best match yet, take this one !
51  setBestMatch(item, est);
52  return true;
53  }
54 
55  if (estComparison(m_bestEstimator, est)) {
56  setBestMatch(item, est);
57  return true;
58  }
59 
60  // best match was not updated
61  return false;
62  }
TEstimator m_bestEstimator
Stores the estimator value of the best match.
void setBestMatch(TItem item, TEstimator est)
Set a new item as the best match.

◆ 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 76 of file BestMatchContainer.h.

◆ hasMatch()

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

Definition at line 67 of file BestMatchContainer.h.


The documentation for this class was generated from the following file: