10#include <tracking/trackingUtilities/numerics/WithWeight.h>
22 namespace TrackFindingCDC {
24 template <
class T,
class AItem>
54 template <
class APredicate>
67 static_cast<TrackingUtilities::Weight
>(0.0),
69 return accumulatedWeight + weightedItem.
getWeight();
75 void insert(
const AItem& item, TrackingUtilities::Weight weight = 1.0)
78 m_items.emplace_back(item, weight);
84 template <
class AMeasure>
87 for (AItem item : items.m_items) {
88 const TrackingUtilities::Weight weight = measure(item);
89 if (not std::isnan(weight)) {
96 typename std::vector<TrackingUtilities::WithWeight<AItem>>::iterator
begin()
102 typename std::vector<TrackingUtilities::WithWeight<AItem>>::const_iterator
begin()
const
108 typename std::vector<TrackingUtilities::WithWeight<AItem>>::iterator
end()
114 typename std::vector<TrackingUtilities::WithWeight<AItem>>::const_iterator
end()
const
122 return std::distance(
begin(),
end());
132 Super& super = *
this;
133 TrackingUtilities::clearIfApplicable(super);
138 std::vector<TrackingUtilities::WithWeight<AItem>>
m_items;
141 typename std::vector<TrackingUtilities::WithWeight<AItem>>::iterator
m_itEnd{
m_items.end()};
WithWeightedItems< T, AItem > This
Type of this class.
std::vector< TrackingUtilities::WithWeight< AItem > >::const_iterator end() const
End iterator of the contained items.
size_t size() const
Getter for the number of items.
std::vector< TrackingUtilities::WithWeight< AItem > > m_items
Memory for the weighted items.
TrackingUtilities::Weight getWeight() const
Cumulated weight of the contained items.
void insert(const AItem &item, TrackingUtilities::Weight weight=1.0)
Add an item with weight.
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< TrackingUtilities::WithWeight< AItem > >::const_iterator begin() const
Begin iterator of the contained items.
std::vector< TrackingUtilities::WithWeight< AItem > >::iterator end()
End iterator of the contained items.
TrackingUtilities::Weight m_weightSum
Cumulated weight of the contained items, kept up to date on insertion and removal.
std::vector< TrackingUtilities::WithWeight< AItem > >::iterator begin()
Begin 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< TrackingUtilities::WithWeight< AItem > >::iterator m_itEnd
Memory for the end of the items that are not erased.
A mixin class to attach a weight to an object.
Weight getWeight() const
Getter for the weight.
Abstract base class for different kinds of events.