CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Private Types | Private Attributes

reco::tau::Combinatoric< T > Class Template Reference

#include <CombinatoricGenerator.h>

List of all members.

Classes

class  IndexInSet
class  ValueAccessor

Public Types

typedef boost::filter_iterator
< IndexInSet, index_iter
ComboIter
typedef
boost::transform_iterator
< ValueAccessor, ComboIter
ValueIter

Public Member Functions

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

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,
indices_collection  combo,
bool  done 
) [inline]

Definition at line 101 of file CombinatoricGenerator.h.

                                            :
      begin_(begin), combo_(combo.begin(), combo.end()),
      comboSet_(combo.begin(), combo.end()), 
      indices_(indices),
      done_(done),
      valueAccessor_(begin), inChoice_(comboSet_, false),
      notInChoice_(comboSet_, true) {}

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 187 of file CombinatoricGenerator.h.

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

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

{ return comboSet_; }
template<typename T>
ValueIter reco::tau::Combinatoric< T >::combo_begin ( ) const [inline]
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_.

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 >::combo_, reco::tau::Combinatoric< T >::done(), reco::tau::Combinatoric< T >::indices_, and pos.

    {
      //std::cout << "building next: " << std::endl;
      //std::cout << "current " << std::endl;
      //std::copy(combo_.begin(), combo_.end(), std::ostream_iterator<int>(std::cout, " "));
      //std::cout << std::endl;

      indices_collection newCombo(combo_);

      // Find the first value that can be updated (starting from the back
      // max value for index is (nElements-1) - (distance from end)
      // Examples:
      //    189 -> 289 (will be updated to 234)
      //    179 -> 189 
      //    123 -> 124
      size_t distanceFromEnd = 0;
      size_t nElements = indices_.size();
      indices_collection::reverse_iterator pos = newCombo.rbegin();
      for(; pos != newCombo.rend(); ++pos, ++distanceFromEnd) 
      {
        // Check if we can update this element to the next value (without overflow)
        // If so, increment it it, then quit
        if( *pos < (nElements - 1 - distanceFromEnd) )
        {
          (*pos)++;
          break;
        } else {
          // Set to 'unset value' - we need to update it!
          (*pos) = nElements;
        }
      }

      //std::cout << "after update " << std::endl;
      //std::copy(newCombo.begin(), newCombo.end(), std::ostream_iterator<int>(std::cout, " "));
      //std::cout << std::endl;

      // Everything after pos needs to be updated.  i.e. 159 -> 167
      index_type next_pos_value = (*pos)+1;
      // forward_pos points to the element *after* pos
      indices_collection::iterator forward_pos = pos.base();
      // Only do the updates if we have not reached all the way to the beginning!
      // this indicates we are at the end of the iteration.  We return a combo
      // with all values at nElements to flag that we are at the end
      bool done = true;
      if (forward_pos != newCombo.begin()) {
        done = false;
        for (; forward_pos != newCombo.end(); ++forward_pos, ++next_pos_value) {
          *forward_pos = next_pos_value;
        }
      }

      //std::cout << "final " << std::endl;
      //std::copy(newCombo.begin(), newCombo.end(), std::ostream_iterator<int>(std::cout, " "));
      //std::cout << std::endl;

      //return std::auto_ptr<Combinatoric<T> >(new Combinatoric<T>(begin_, indices_, newCombo));
      return Combinatoric<T>(begin_, indices_, newCombo, done);
    }
template<typename T>
bool reco::tau::Combinatoric< T >::operator== ( const Combinatoric< T > &  rhs) const [inline]

Comparison to another combination.

Definition at line 190 of file CombinatoricGenerator.h.

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

    {
      return (this->combo() == rhs.combo() && this->done() == rhs.done());
    }
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_.

template<typename T>
ValueIter reco::tau::Combinatoric< T >::remainder_end ( ) const [inline]

Member Data Documentation

template<typename T>
value_iter reco::tau::Combinatoric< T >::begin_ [private]

Definition at line 198 of file CombinatoricGenerator.h.

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

template<typename T>
indices_collection reco::tau::Combinatoric< T >::combo_ [private]

Definition at line 199 of file CombinatoricGenerator.h.

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

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

Definition at line 200 of file CombinatoricGenerator.h.

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

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

Definition at line 202 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]