CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Types | Private Attributes
reco::tau::Combinatoric< T > Class Template Reference

#include <CombinatoricGenerator.h>

Classes

class  IndexInSet
 
class  ValueAccessor
 

Public Types

typedef boost::filter_iterator< IndexInSet, index_iterComboIter
 
typedef boost::transform_iterator< ValueAccessor, ComboIterValueIter
 

Public Member Functions

 Combinatoric (const value_iter &begin, const indices_collection &indices, const indices_collection &combo, bool done)
 
const indices_setcombo () const
 Return the set of selected indices. More...
 
ValueIter combo_begin () const
 The first element in the selected subset. More...
 
ValueIter combo_end () const
 One past the last element in the selected subset. More...
 
bool done () const
 
Combinatoric< Tnext () const
 Build the next cominatoric subset after the current one. More...
 
bool operator== (const Combinatoric< T > &rhs) const
 Comparison to another combination. More...
 
ValueIter remainder_begin () const
 One past the last element in the non-selected subset. More...
 
ValueIter remainder_end () const
 The first element in the non-selected subset. More...
 

Private Types

typedef indices_collection::const_iterator index_iter
 
typedef size_t index_type
 
typedef std::vector< index_typeindices_collection
 
typedef std::set< index_typeindices_set
 
typedef T::const_iterator value_iter
 
typedef T::value_type value_type
 

Private Attributes

value_iter begin_
 
indices_collection combo_
 
indices_set comboSet_
 
bool done_
 
IndexInSet inChoice_
 
indices_collection indices_
 
IndexInSet notInChoice_
 
ValueAccessor valueAccessor_
 

Detailed Description

template<typename T>
class reco::tau::Combinatoric< T >

Definition at line 50 of file CombinatoricGenerator.h.

Member Typedef Documentation

template<typename T>
typedef boost::filter_iterator<IndexInSet, index_iter> reco::tau::Combinatoric< T >::ComboIter

Definition at line 110 of file CombinatoricGenerator.h.

template<typename T>
typedef indices_collection::const_iterator reco::tau::Combinatoric< T >::index_iter
private

Definition at line 69 of file CombinatoricGenerator.h.

template<typename T>
typedef size_t reco::tau::Combinatoric< T >::index_type
private

Definition at line 67 of file CombinatoricGenerator.h.

template<typename T>
typedef std::vector<index_type> reco::tau::Combinatoric< T >::indices_collection
private

Definition at line 68 of file CombinatoricGenerator.h.

template<typename T>
typedef std::set<index_type> reco::tau::Combinatoric< T >::indices_set
private

Definition at line 70 of file CombinatoricGenerator.h.

template<typename T>
typedef T::const_iterator reco::tau::Combinatoric< T >::value_iter
private

Definition at line 65 of file CombinatoricGenerator.h.

template<typename T>
typedef T::value_type reco::tau::Combinatoric< T >::value_type
private

Definition at line 66 of file CombinatoricGenerator.h.

template<typename T>
typedef boost::transform_iterator<ValueAccessor, ComboIter> reco::tau::Combinatoric< T >::ValueIter

Definition at line 111 of file CombinatoricGenerator.h.

Constructor & Destructor Documentation

template<typename T>
reco::tau::Combinatoric< T >::Combinatoric ( const value_iter begin,
const indices_collection indices,
const indices_collection combo,
bool  done 
)
inline

Definition at line 101 of file CombinatoricGenerator.h.

102  :
103  begin_(begin), combo_(combo.begin(), combo.end()),
104  comboSet_(combo.begin(), combo.end()),
105  indices_(indices),
106  done_(done),
108  notInChoice_(comboSet_, true) {}
const indices_set & combo() const
Return the set of selected indices.
#define begin
Definition: vmac.h:32

Member Function Documentation

template<typename T>
const indices_set& reco::tau::Combinatoric< T >::combo ( ) const
inline

Return the set of selected indices.

Definition at line 188 of file CombinatoricGenerator.h.

References reco::tau::Combinatoric< T >::comboSet_.

Referenced by reco::tau::Combinatoric< T >::operator==().

188 { return comboSet_; }
template<typename T>
ValueIter reco::tau::Combinatoric< T >::combo_begin ( ) const
inline

The first element in the selected subset.

Definition at line 114 of file CombinatoricGenerator.h.

References reco::tau::Combinatoric< T >::inChoice_, reco::tau::Combinatoric< T >::indices_, and reco::tau::Combinatoric< T >::valueAccessor_.

114 { return ValueIter(ComboIter(inChoice_, indices_.begin(), indices_.end()), valueAccessor_); }
boost::filter_iterator< IndexInSet, index_iter > ComboIter
boost::transform_iterator< ValueAccessor, ComboIter > ValueIter
template<typename T>
ValueIter reco::tau::Combinatoric< T >::combo_end ( ) const
inline

One past the last element in the selected subset.

Definition at line 116 of file CombinatoricGenerator.h.

References reco::tau::Combinatoric< T >::inChoice_, reco::tau::Combinatoric< T >::indices_, and reco::tau::Combinatoric< T >::valueAccessor_.

116 { return ValueIter(ComboIter(inChoice_, indices_.end(), indices_.end()), valueAccessor_); }
boost::filter_iterator< IndexInSet, index_iter > ComboIter
boost::transform_iterator< ValueAccessor, ComboIter > ValueIter
template<typename T>
bool reco::tau::Combinatoric< T >::done ( ) const
inline
template<typename T>
Combinatoric<T> reco::tau::Combinatoric< T >::next ( void  ) const
inline

Build the next cominatoric subset after the current one.

Definition at line 124 of file CombinatoricGenerator.h.

References reco::tau::Combinatoric< T >::begin_, reco::tau::Combinatoric< T >::IndexInSet::combo_, reco::tau::Combinatoric< T >::done(), and reco::tau::Combinatoric< T >::indices_.

125  {
126  //std::cout << "building next: " << std::endl;
127  //std::cout << "current " << std::endl;
128  //std::copy(combo_.begin(), combo_.end(), std::ostream_iterator<int>(std::cout, " "));
129  //std::cout << std::endl;
130 
131  indices_collection newCombo(combo_);
132 
133  // Find the first value that can be updated (starting from the back
134  // max value for index is (nElements-1) - (distance from end)
135  // Examples:
136  // 189 -> 289 (will be updated to 234)
137  // 179 -> 189
138  // 123 -> 124
139  size_t distanceFromEnd = 0;
140  size_t nElements = indices_.size();
141  indices_collection::reverse_iterator pos = newCombo.rbegin();
142  for(; pos != newCombo.rend(); ++pos, ++distanceFromEnd)
143  {
144  // Check if we can update this element to the next value (without overflow)
145  // If so, increment it it, then quit
146  if( *pos < (nElements - 1 - distanceFromEnd) )
147  {
148  (*pos)++;
149  break;
150  } else {
151  // Set to 'unset value' - we need to update it!
152  (*pos) = nElements;
153  }
154  }
155 
156  //std::cout << "after update " << std::endl;
157  //std::copy(newCombo.begin(), newCombo.end(), std::ostream_iterator<int>(std::cout, " "));
158  //std::cout << std::endl;
159 
160  // forward_pos points to the element *after* pos
161  indices_collection::iterator forward_pos = pos.base();
162  // Only do the updates if we have not reached all the way to the beginning!
163  // this indicates we are at the end of the iteration. We return a combo
164  // with all values at nElements to flag that we are at the end
165  bool done = true;
166  if (forward_pos != newCombo.begin()) {
167  // Everything after pos needs to be updated. i.e. 159 -> 167
168  index_type next_pos_value = (*pos)+1;
169  //std::cout << "next pos: " << next_pos_value << std::endl;
170  done = false;
171  for (; forward_pos != newCombo.end(); ++forward_pos, ++next_pos_value) {
172  *forward_pos = next_pos_value;
173  }
174  }
175 
176  //std::cout << "final " << std::endl;
177  //std::copy(newCombo.begin(), newCombo.end(), std::ostream_iterator<int>(std::cout, " "));
178  //std::cout << std::endl;
179 
180  //return std::unique_ptr<Combinatoric<T> >(new Combinatoric<T>(begin_, indices_, newCombo));
181  return Combinatoric<T>(begin_, indices_, newCombo, done);
182  }
std::vector< index_type > indices_collection
template<typename T>
bool reco::tau::Combinatoric< T >::operator== ( const Combinatoric< T > &  rhs) const
inline

Comparison to another combination.

Definition at line 191 of file CombinatoricGenerator.h.

References reco::tau::Combinatoric< T >::combo(), and reco::tau::Combinatoric< T >::done().

192  {
193  return (this->combo() == rhs.combo() && this->done() == rhs.done());
194  }
const indices_set & combo() const
Return the set of selected indices.
template<typename T>
ValueIter reco::tau::Combinatoric< T >::remainder_begin ( ) const
inline

One past the last element in the non-selected subset.

Definition at line 121 of file CombinatoricGenerator.h.

References reco::tau::Combinatoric< T >::indices_, reco::tau::Combinatoric< T >::notInChoice_, and reco::tau::Combinatoric< T >::valueAccessor_.

121 { return ValueIter(ComboIter(notInChoice_, indices_.begin(), indices_.end()), valueAccessor_); }
boost::filter_iterator< IndexInSet, index_iter > ComboIter
boost::transform_iterator< ValueAccessor, ComboIter > ValueIter
template<typename T>
ValueIter reco::tau::Combinatoric< T >::remainder_end ( ) const
inline

The first element in the non-selected subset.

Definition at line 119 of file CombinatoricGenerator.h.

References reco::tau::Combinatoric< T >::indices_, reco::tau::Combinatoric< T >::notInChoice_, and reco::tau::Combinatoric< T >::valueAccessor_.

119 { return ValueIter(ComboIter(notInChoice_, indices_.end(), indices_.end()), valueAccessor_); }
boost::filter_iterator< IndexInSet, index_iter > ComboIter
boost::transform_iterator< ValueAccessor, ComboIter > ValueIter

Member Data Documentation

template<typename T>
value_iter reco::tau::Combinatoric< T >::begin_
private
template<typename T>
indices_collection reco::tau::Combinatoric< T >::combo_
private

Definition at line 200 of file CombinatoricGenerator.h.

template<typename T>
indices_set reco::tau::Combinatoric< T >::comboSet_
private

Definition at line 201 of file CombinatoricGenerator.h.

Referenced by reco::tau::Combinatoric< T >::combo().

template<typename T>
bool reco::tau::Combinatoric< T >::done_
private

Definition at line 203 of file CombinatoricGenerator.h.

Referenced by reco::tau::Combinatoric< T >::done().

template<typename T>
IndexInSet reco::tau::Combinatoric< T >::inChoice_
private
template<typename T>
indices_collection reco::tau::Combinatoric< T >::indices_
private
template<typename T>
IndexInSet reco::tau::Combinatoric< T >::notInChoice_
private
template<typename T>
ValueAccessor reco::tau::Combinatoric< T >::valueAccessor_
private