9 #ifndef ThePEG_VSelector_H 10 #define ThePEG_VSelector_H 13 #include "ThePEG/Config/ThePEG.h" 20 template <
typename T,
typename WeightType =
double>
54 typedef typename WeightVector::const_iterator
WIterator;
60 typedef typename ObjectVector::iterator
iterator;
94 WeightType
insert(WeightType d,
const T & t) {
95 WeightType newSum =
theSum + d;
96 if ( newSum <=
theSum )
return d;
108 WeightType
reweight(WeightType,
const T &);
116 WeightType
erase(
const T &);
122 void replace(
const T & told,
const T & tnew) {
124 if ( *it == told ) *it = tnew;
138 T &
select(
double rnd,
double * remainder = 0) throw(range_error) {
164 const T &
select(
double rnd,
double * remainder = 0)
const throw(range_error) {
191 template <
typename RNDGEN>
192 T &
select(RNDGEN & rnd)
throw(range_error) {
194 T & t =
select(rnd(), &rem);
211 template <
typename RNDGEN>
212 const T &
select(RNDGEN & rnd)
const throw(range_error) {
214 const T & t =
select(rnd(), &rem);
271 template <
typename OStream>
272 void output(OStream &)
const;
277 template <
typename IStream>
278 void input(IStream &);
285 size_type
iselect(
double rnd,
double * remainder)
const throw(range_error);
314 template <
typename OStream,
typename T,
typename WeightType>
324 template <
typename IStream,
typename T,
typename WeightType>
334 #include "VSelector.tcc" const_iterator end() const
Access to the end() iterator in the underlying vector of objects.
const T & select(double rnd, double *remainder=0) const
Selct an object randomly.
vector< WeightType > WeightVector
A vector of weights.
void output(OStream &) const
Output to a stream.
void swap(VSelector &s)
Swap the underlying representation with the argument.
const_iterator begin() const
Access to the begin() iterator of the underlying vector of objects.
WeightVector::const_iterator WIterator
The weight vector iterator type.
vector< T > ObjectVector
A vector ob objects.
bool empty() const
Returns true if the VSelector is empty.
WeightType theSum
The sum of all weights.
VSelector is a templated class for storing objects associated with probabilities in a way such that...
This is the main namespace within which all identifiers in ThePEG are declared.
const T & operator[](double rnd) const
Selct an object randomly.
const T & select(RNDGEN &rnd) const
Selct an object randomly.
T & select(RNDGEN &rnd)
Selct an object randomly.
void clear()
Erases all objects.
WeightType erase(const T &)
Erase an object, previously inserted.
T & select(double rnd, double *remainder=0)
Select an object randomly.
size_type size() const
Returns the number of objects in the selector.
ObjectVector::const_iterator const_iterator
The object vector const iterator type.
WeightVector theWeights
The vector of weights for the objects in the selector.
ObjectVector::size_type size_type
Size type of the underlying vector.
vector< T > & operator>>(vector< T > &tv, U &u)
Overload the right shift operator for vector to pop objects from a vector.
WeightType sum() const
Return the sum of probabilities of the objects inserted.
void replace(const T &told, const T &tnew)
Replace all occurencies of told with tnew without changing the probability for the entry...
ObjectVector theObjects
The vector of objects in the selector.
vector< T > & operator<<(vector< T > &tv, const U &u)
Overload the left shift operator for vector to push_back objects to a vector.
ObjectVector::iterator iterator
The object vector iterator type.
WeightType reweight(WeightType, const T &)
Reweight an object previously inserted giving it a new weight.
VSelector(size_type reserved=0)
Default constructor.
WeightVector theSums
The vector of accumulated weights for the objects in the selector.
void reserve(size_type reserved)
Allocate space for a number of objects in the underlying vectors.
size_type iselect(double rnd, double *remainder) const
Internal selection engine.
void input(IStream &)
Input from a stream.
T & operator[](double rnd)
Selct an object randomly.
WeightType insert(WeightType d, const T &t)
Insert an object given a probability for this object.