9 #ifndef ThePEG_Selector_H 10 #define ThePEG_Selector_H 13 #include "ThePEG/Config/ThePEG.h" 45 template <
typename T,
typename WeightType =
double>
51 typedef map<WeightType, T, less<WeightType> >
MapType;
84 WeightType
insert(WeightType d,
const T & t) {
85 typedef typename MapType::value_type value_type;
86 WeightType newSum =
theSum + d;
87 if ( newSum <=
theSum )
return d;
109 WeightType
erase(
const T &);
115 void replace(
const T & oldObject,
const T & newObject) {
116 for ( iterator it =
theMap.begin(); it !=
theMap.end(); ++it )
117 if ( it->second == oldObject ) it->second = newObject;
131 T &
select(
double rnd,
double * remainder = 0)
throw(range_error);
153 const T &
select(
double rnd,
double * remainder = 0)
const throw(range_error);
176 template <
typename RNDGEN>
177 T &
select(RNDGEN & rnd)
throw(range_error) {
179 T & t =
select(rnd(), &rem);
196 template <
typename RNDGEN>
197 const T &
select(RNDGEN & rnd)
const throw(range_error) {
199 const T & t =
select(rnd(), &rem);
244 template <
typename OStream>
245 void output(OStream &)
const;
250 template <
typename IStream>
251 void input(IStream &);
270 template <
typename OStream,
typename T,
typename WeightType>
271 OStream & operator<<(OStream & os, const Selector<T,WeightType> & s)
280 template <
typename IStream,
typename T,
typename WeightType>
290 #ifndef ThePEG_TEMPLATES_IN_CC_FILE 291 #include "Selector.tcc" void clear()
Erases all objects.
MapType::size_type size_type
Size type of the underlying map.
size_type size() const
Returns the number of objects in the selector.
void replace(const T &oldObject, const T &newObject)
Replace all occurencies of oldObject with newObject without changing the probability for the entry...
WeightType theSum
The sum of all probabilities assicialted with inserted objects.
void swap(Selector &s)
Swap the underlying representation with the argument.
WeightType erase(const T &)
Erase an object, previously inserted.
void input(IStream &)
Input from a stream.
T & select(RNDGEN &rnd)
Selct an object randomly.
T & select(double rnd, double *remainder=0)
Select an object randomly.
This is the main namespace within which all identifiers in ThePEG are declared.
Selector()
Default constructor.
WeightType sum() const
Return the sum of probabilities of the objects inserted.
bool empty() const
Returns true if the Selector is empty.
vector< T > & operator>>(vector< T > &tv, U &u)
Overload the right shift operator for vector to pop objects from a vector.
MapType theMap
The underlying map relating sums of probabilities to inserted objects.
map< WeightType, T, less< WeightType > > MapType
Map doubles to objects.
const_iterator begin() const
Access to the begin() iterator of the underlying map.
MapType::const_iterator const_iterator
Iterator corresponding to the underlying map.
Selector is a templated class for storing objects associated with probabilities in a way such that...
WeightType reweight(WeightType d, const T &t)
Reweight an object previously inserted giving it a new weight.
const_iterator end() const
Access to the end() iterator in the underlying map.
T & operator[](double rnd)
Selct an object randomly.
const T & select(RNDGEN &rnd) const
Selct an object randomly.
WeightType insert(WeightType d, const T &t)
Insert an object given a probability for this object.
void output(OStream &) const
Output to a stream.
const T & operator[](double rnd) const
Selct an object randomly.
MapType::iterator iterator
Iterator corresponding to the underlying map.