10#include <tracking/trackFindingCDC/numerics/WithWeight.h>
22 namespace TrackFindingCDC {
24 template <
class T,
class AItem>
50 return std::accumulate(
begin(),
52 static_cast<Weight
>(0.0),
54 return accumulatedWeight + weightedItem.
getWeight();
59 template <
class APredicate>
71 void insert(
const AItem& item, Weight weight = 1.0)
79 template <
class AMeasure>
82 for (AItem item : items.m_items) {
83 const Weight weight = measure(item);
84 if (not std::isnan(weight)) {
91 typename std::vector<WithWeight<AItem>>::iterator
begin()
97 typename std::vector<WithWeight<AItem>>::const_iterator
begin()
const
103 typename std::vector<WithWeight<AItem>>::iterator
end()
109 typename std::vector<WithWeight<AItem>>::const_iterator
end()
const
117 return std::distance(
begin(),
end());
126 Super& super = *
this;
127 clearIfApplicable(super);
A mixin class to attach a weight to an object.
Weight getWeight() const
Getter for the weight.
A mixin class to attach a set of weighted items to a class.
size_t size() const
Getter for the number of items.
Weight getWeight() const
Cumulated weight of the contained items.
std::vector< WithWeight< AItem > > m_items
Memory for the weighted items.
void eraseIf(const APredicate &predicate)
Erase items from this node that satisfy the predicate.
T Super
Type of the base class.
WithWeightedItems(const T &t)
Also forward the copy constructor form the base class object.
std::vector< WithWeight< AItem > >::iterator begin()
Begin iterator of the contained items.
std::vector< WithWeight< AItem > >::const_iterator end() const
End iterator of the contained items.
std::vector< WithWeight< AItem > >::iterator end()
End iterator of the contained items.
void insert(const This &items, AMeasure &measure)
Add the items from another item range assigning a weight from the predicate.
void clear()
Clear the contained items.
std::vector< WithWeight< AItem > >::iterator m_itEnd
Memory for the end of the items that are not erased.
std::vector< WithWeight< AItem > >::const_iterator begin() const
Begin iterator of the contained items.
void insert(const AItem &item, Weight weight=1.0)
Add an item with weight.
Abstract base class for different kinds of events.