CMS 3D CMS Logo

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

pat::strbitset Class Reference

#include <strbitset.h>

List of all members.

Classes

class  index_type

Public Types

typedef std::vector< bool > bit_vector
typedef unsigned int size_t
typedef std::map< std::string,
size_t
str_index_map

Public Member Functions

size_t any () const
 returns true if any are set
const bit_vectorbits () const
 give access to the ordered bits
void clear ()
 clear the bitset and map
size_t count () const
 returns number of bits set
strbitsetflip (index_type const &i)
strbitsetflip ()
 flip method of all bits
strbitsetflip (std::string s)
 flip method of one bit
size_t none () const
 returns true if none are set
 operator bool () const
 ! cast to bool
bool operator! () const
 ! Logical negation of bool()
bool operator!= (const strbitset &r) const
 inequality operator
bool operator!= (bool b) const
 inequality operator to bool
strbitsetoperator&= (const strbitset &r)
 bitwise and
bool operator== (bool b) const
 equality operator to bool
bool operator== (const strbitset &r) const
 equality operator
bit_vector::const_reference operator[] (index_type const &i) const
bit_vector::reference operator[] (const std::string s)
 access method non-const
bit_vector::reference operator[] (index_type const &i)
bit_vector::const_reference operator[] (const std::string s) const
 access method const
strbitsetoperator^= (const strbitset &r)
 bitwise xor
strbitsetoperator|= (const strbitset &r)
 bitwise or
strbitset operator~ ()
 logical negation
void print (std::ostream &out) const
 print method
void push_back (std::string s)
strbitsetset (bool val=true)
 set method of all bits
strbitsetset (index_type const &i, bool val=true)
strbitsetset (std::string s, bool val=true)
 set method of one bit
 strbitset ()
 constructor: just clears the bitset and map
const std::vector< std::string > strings () const
 give access to the ordered strings
bool test (std::string s) const
 test
bool test (index_type const &i) const

Private Member Functions

size_t index (std::string s) const
std::string const & index (size_t i) const

Private Attributes

bit_vector bits_
 the actual bits, indexed by the index in "map_"
str_index_map map_
 map that holds the string-->index map

Static Private Attributes

static const std::string dummy_ = std::string("")

Friends

class index_type
strbitset operator& (const strbitset &l, const strbitset &r)
strbitset operator^ (const strbitset &l, const strbitset &r)
strbitset operator| (const strbitset &l, const strbitset &r)

Detailed Description

Definition at line 24 of file strbitset.h.


Member Typedef Documentation

typedef std::vector<bool> pat::strbitset::bit_vector

Definition at line 67 of file strbitset.h.

typedef unsigned int pat::strbitset::size_t

Definition at line 65 of file strbitset.h.

typedef std::map<std::string, size_t> pat::strbitset::str_index_map

Definition at line 66 of file strbitset.h.


Constructor & Destructor Documentation

pat::strbitset::strbitset ( ) [inline]

constructor: just clears the bitset and map

Definition at line 70 of file strbitset.h.

References clear().

             {
    clear();
  }

Member Function Documentation

size_t pat::strbitset::any ( ) const [inline]

returns true if any are set

Definition at line 316 of file strbitset.h.

References bits_, and i.

Referenced by none().

                     {
    for ( bit_vector::const_iterator ibegin = bits_.begin(),
            iend = bits_.end(), i = ibegin;
          i != iend; ++i ) {
      if ( *i ) return true;
    }
    return true;
  }
const bit_vector& pat::strbitset::bits ( ) const [inline]

give access to the ordered bits

Definition at line 340 of file strbitset.h.

References bits_.

                                 {
    return bits_;
  }
void pat::strbitset::clear ( void  ) [inline]

clear the bitset and map

Definition at line 75 of file strbitset.h.

References bits_, and map_.

Referenced by Selector< pat::Electron >::Selector(), and strbitset().

               {
    map_.clear();
    bits_.clear();
  }
size_t pat::strbitset::count ( void  ) const [inline]

returns number of bits set

Definition at line 303 of file strbitset.h.

References bits_, i, and run_regression::ret.

                       {
    size_t ret = 0;
    for ( bit_vector::const_iterator ibegin = bits_.begin(),
            iend = bits_.end(), i = ibegin;
          i != iend; ++i ) {
      if ( *i ) ++ret;
    }    
    return ret;
  }
strbitset& pat::strbitset::flip ( ) [inline]

flip method of all bits

Definition at line 154 of file strbitset.h.

References bits_, and i.

                     {
    for ( bit_vector::iterator ibegin = bits_.begin(),
            iend = bits_.end(), i = ibegin;
          i != iend; ++i ) {
      *i = ! (*i);
    }
    return *this;
  }
strbitset& pat::strbitset::flip ( std::string  s) [inline]

flip method of one bit

Definition at line 176 of file strbitset.h.

References alignCSCRings::s.

                                 {
    (*this)[s] = !( (*this)[s] );
    return *this;
  }
strbitset& pat::strbitset::flip ( index_type const &  i) [inline]

Definition at line 181 of file strbitset.h.

References i.

                                           {
    (*this)[i] = !( (*this)[i] );
    return *this;
  }
std::string const& pat::strbitset::index ( size_t  i) const [inline, private]

Definition at line 378 of file strbitset.h.

References gather_cfg::cout, dummy_, f, and map_.

                                            {
    for ( str_index_map::const_iterator f = map_.begin(),
            fEnd = map_.end();
          f != fEnd; ++f ) {
      if ( f->second == i ) return f->first;
    }
    std::cout << "Cannot find " << i << ", returning dummy" << std::endl;
    return dummy_;

  }
size_t pat::strbitset::index ( std::string  s) const [inline, private]

workhorse: this gets the index of "bits" that is pointed to by the string "s"

Definition at line 368 of file strbitset.h.

References gather_cfg::cout, f, and map_.

Referenced by pat::strbitset::index_type::index_type(), operator[](), and pat::strbitset::index_type::str().

                                   {
    str_index_map::const_iterator f = map_.find(s);
    if ( f == map_.end() ) {
      std::cout << "Cannot find " << s << ", returning size()" << std::endl;
      return map_.size();
    } else {
      return f->second;
    }
  }
size_t pat::strbitset::none ( ) const [inline]

returns true if none are set

Definition at line 326 of file strbitset.h.

References any().

                       {
    return !any();
  }
pat::strbitset::operator bool ( ) const [inline]

! cast to bool

Definition at line 81 of file strbitset.h.

References b, and bits_.

Referenced by operator!().

                        {
    bool b = true;
    for ( bit_vector::const_iterator bitsBegin = bits_.begin(),
            bitsEnd = bits_.end(), ibit = bitsBegin;
          ibit != bitsEnd; ++ibit ) {
      if ( *ibit == false ) b = false;
    }
    return b;
  }
bool pat::strbitset::operator! ( ) const [inline]

! Logical negation of bool()

Definition at line 92 of file strbitset.h.

References operator bool().

                         {
    return ! ( operator bool() );
  }
bool pat::strbitset::operator!= ( const strbitset r) const [inline]

inequality operator

Definition at line 293 of file strbitset.h.

References operator==().

Referenced by operator!=().

                                              {
    return ! (operator==(r));
  }
bool pat::strbitset::operator!= ( bool  b) const [inline]

inequality operator to bool

Definition at line 298 of file strbitset.h.

References operator!=().

                                  {
    return ! ( operator!=(b));
  }
strbitset& pat::strbitset::operator&= ( const strbitset r) [inline]

bitwise and

Definition at line 198 of file strbitset.h.

References gather_cfg::cout, i, j, combine::key, and map_.

                                               {
    if ( map_.size() != r.map_.size() ) { 
      std::cout << "strbitset operator&= : bitsets not the same size" << std::endl;
    } else {
      str_index_map::iterator ibegin = map_.begin(), iend = map_.end(), i = ibegin;
      for ( ; i != iend; ++i ) {
        std::string key = i->first;
        str_index_map::const_iterator j = r.map_.find( key );
        if ( j == r.map_.end() ) {
          std::cout << "strbitset operator&= : cannot find key " << key << std::endl;
        } else {
          (*this)[key] = (*this)[key] && r[key];
        }
      }
    }
    return *this;
  }
bool pat::strbitset::operator== ( bool  b) const [inline]

equality operator to bool

Definition at line 281 of file strbitset.h.

References b, bits_, and query::result.

                                  {
    bool result = true;
    for ( bit_vector::const_iterator iBegin = bits_.begin(),
            iEnd = bits_.end(), ibit = iBegin;
          ibit != iEnd; ++ibit ) {
      result &= ( *ibit == b );
    }
    return result;
  }
bool pat::strbitset::operator== ( const strbitset r) const [inline]

equality operator

Definition at line 262 of file strbitset.h.

References gather_cfg::cout, i, j, combine::key, and map_.

Referenced by operator!=().

                                              {
    if ( map_.size() != r.map_.size() ) { 
      std::cout << "strbitset operator&= : bitsets not the same size" << std::endl;
    } else {
      str_index_map::const_iterator ibegin = map_.begin(), iend = map_.end(), i = ibegin;
      for ( ; i != iend; ++i ) {
        std::string key = i->first;
        str_index_map::const_iterator j = r.map_.find( key );
        if ( j == r.map_.end() ) {
          std::cout << "strbitset operator&= : cannot find key " << key << std::endl;
        } else {
          if ( (*this)[key] != r[key] ) return false;
        }
      }
    }
    return true;
  }
bit_vector::reference pat::strbitset::operator[] ( const std::string  s) [inline]

access method non-const

Definition at line 133 of file strbitset.h.

References bits_, and index().

                                                      {
    size_t index = this->index(s);
    return bits_.operator[](index);
  }
bit_vector::reference pat::strbitset::operator[] ( index_type const &  i) [inline]

Definition at line 138 of file strbitset.h.

References bits_, and pat::strbitset::index_type::i_.

                                                          {
    return bits_.operator[](i.i_);
  }
bit_vector::const_reference pat::strbitset::operator[] ( const std::string  s) const [inline]

access method const

Definition at line 123 of file strbitset.h.

References bits_, and index().

                                                                  {
    size_t index = this->index(s);
    return bits_.operator[](index);
  }
bit_vector::const_reference pat::strbitset::operator[] ( index_type const &  i) const [inline]

Definition at line 128 of file strbitset.h.

References bits_, and pat::strbitset::index_type::i_.

                                                                     {
    return bits_.operator[](i.i_);
  }
strbitset& pat::strbitset::operator^= ( const strbitset r) [inline]

bitwise xor

Definition at line 239 of file strbitset.h.

References gather_cfg::cout, i, j, combine::key, and map_.

                                               {
    if ( map_.size() != r.map_.size() ) { 
      std::cout << "strbitset operator&= : bitsets not the same size" << std::endl;
    } else {
      str_index_map::iterator ibegin = map_.begin(), iend = map_.end(), i = ibegin;
      for ( ; i != iend; ++i ) {
        std::string key = i->first;
        str_index_map::const_iterator j = r.map_.find( key );
        if ( j == r.map_.end() ) {
          std::cout << "strbitset operator&= : cannot find key " << key << std::endl;
        } else {
          (*this)[key] = ( (*this)[key] || r[key]) && ! ((*this)[key] && r[key]);
        }
      }
    }
    return *this;
  }
strbitset& pat::strbitset::operator|= ( const strbitset r) [inline]

bitwise or

Definition at line 218 of file strbitset.h.

References gather_cfg::cout, i, j, combine::key, and map_.

                                               {
    if ( map_.size() != r.map_.size() ) { 
      std::cout << "strbitset operator&= : bitsets not the same size" << std::endl;
    } else {
      str_index_map::iterator ibegin = map_.begin(), iend = map_.end(), i = ibegin;
      for ( ; i != iend; ++i ) {
        std::string key = i->first;
        str_index_map::const_iterator j = r.map_.find( key );
        if ( j == r.map_.end() ) {
          std::cout << "strbitset operator&= : cannot find key " << key << std::endl;
        } else {
          (*this)[key] = (*this)[key] || r[key];
        }
      }
    }
    return *this;
  }
strbitset pat::strbitset::operator~ ( ) [inline]

logical negation

Definition at line 187 of file strbitset.h.

References bits_, i, and run_regression::ret.

                        {
    strbitset ret(*this);
    for ( bit_vector::iterator ibegin = ret.bits_.begin(),
            iend = ret.bits_.end(), i = ibegin;
          i != iend; ++i ) {
      *i = !(*i);
    }
    return ret;
  }
void pat::strbitset::print ( std::ostream &  out) const [inline]

print method

Definition at line 111 of file strbitset.h.

References bits_, and map_.

                                     {
    for( str_index_map::const_iterator mbegin = map_.begin(),
           mend = map_.end(),
           mit = mbegin;
         mit != mend; ++mit ) {
      char buff[100];
      sprintf(buff, "%10s = %6d", mit->first.c_str(), bits_.at(mit->second));
      out << buff << std::endl;
    }
  }
void pat::strbitset::push_back ( std::string  s) [inline]

adds an item that is indexed by the string. this can then be sorted, cut, whatever, and the index mapping is kept

Definition at line 99 of file strbitset.h.

References bits_, gather_cfg::cout, map_, and alignCSCRings::s.

Referenced by Selector< pat::Electron >::push_back().

                                {
    if ( map_.find(s) == map_.end() ) {
      map_[s] = bits_.size();
      bits_.resize( bits_.size() + 1 );
      *(bits_.rbegin()) = false;
    } else {
      std::cout << "Duplicate entry " << s << ", not added to registry" << std::endl;
    }
  }
strbitset& pat::strbitset::set ( bool  val = true) [inline]
strbitset& pat::strbitset::set ( std::string  s,
bool  val = true 
) [inline]

set method of one bit

Definition at line 164 of file strbitset.h.

References alignCSCRings::s.

                                                 {
    (*this)[s] = val;
    return *this;
  }
strbitset& pat::strbitset::set ( index_type const &  i,
bool  val = true 
) [inline]

Definition at line 169 of file strbitset.h.

References i.

                                                          {
    (*this)[i] = val;
    return *this;
  }
const std::vector<std::string> pat::strbitset::strings ( ) const [inline]

give access to the ordered strings

Definition at line 346 of file strbitset.h.

References bits_, end, and map_.

                                             {
    std::vector<std::string> strings;
    strings.resize(bits_.size());
    for (str_index_map::const_iterator it = map_.begin(), 
         end = map_.end(); it != end; ++it){
      strings[it->second] = it->first;
    }
    return strings;
  }
bool pat::strbitset::test ( index_type const &  i) const [inline]

Definition at line 335 of file strbitset.h.

References i.

                                       {
    return (*this)[i] == true;
  }
bool pat::strbitset::test ( std::string  s) const [inline]

test

Definition at line 331 of file strbitset.h.

References alignCSCRings::s.

Referenced by main().

                               {
    return (*this)[s] == true;
  }

Friends And Related Function Documentation

friend class index_type [friend]

Definition at line 62 of file strbitset.h.

strbitset operator& ( const strbitset l,
const strbitset r 
) [friend]
strbitset operator^ ( const strbitset l,
const strbitset r 
) [friend]
strbitset operator| ( const strbitset l,
const strbitset r 
) [friend]

Member Data Documentation

the actual bits, indexed by the index in "map_"

Definition at line 391 of file strbitset.h.

Referenced by any(), bits(), clear(), count(), flip(), operator bool(), operator==(), operator[](), operator~(), print(), push_back(), set(), and strings().

const std::string strbitset::dummy_ = std::string("") [static, private]

Definition at line 389 of file strbitset.h.

Referenced by index().

map that holds the string-->index map

Definition at line 390 of file strbitset.h.

Referenced by clear(), index(), operator&=(), operator==(), operator^=(), operator|=(), print(), push_back(), and strings().