CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends
pat::strbitset Class Reference

#include <strbitset.h>

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

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().

70  {
71  clear();
72  }
void clear()
clear the bitset and map
Definition: strbitset.h:75

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().

316  {
317  for ( bit_vector::const_iterator ibegin = bits_.begin(),
318  iend = bits_.end(), i = ibegin;
319  i != iend; ++i ) {
320  if ( *i ) return true;
321  }
322  return true;
323  }
int i
Definition: DBlmapReader.cc:9
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:391
const bit_vector& pat::strbitset::bits ( ) const
inline

give access to the ordered bits

Definition at line 340 of file strbitset.h.

References bits_.

340  {
341  return bits_;
342  }
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:391
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< edm::Ptr< reco::Photon > >::Selector(), and strbitset().

75  {
76  map_.clear();
77  bits_.clear();
78  }
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:391
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:390
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 runTheMatrix::ret.

303  {
304  size_t ret = 0;
305  for ( bit_vector::const_iterator ibegin = bits_.begin(),
306  iend = bits_.end(), i = ibegin;
307  i != iend; ++i ) {
308  if ( *i ) ++ret;
309  }
310  return ret;
311  }
int i
Definition: DBlmapReader.cc:9
tuple ret
prodAgent to be discontinued
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:391
strbitset& pat::strbitset::flip ( )
inline

flip method of all bits

Definition at line 154 of file strbitset.h.

References bits_, and i.

154  {
155  for ( bit_vector::iterator ibegin = bits_.begin(),
156  iend = bits_.end(), i = ibegin;
157  i != iend; ++i ) {
158  *i = ! (*i);
159  }
160  return *this;
161  }
int i
Definition: DBlmapReader.cc:9
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:391
strbitset& pat::strbitset::flip ( std::string  s)
inline

flip method of one bit

Definition at line 176 of file strbitset.h.

References alignCSCRings::s.

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

Definition at line 181 of file strbitset.h.

References i.

181  {
182  (*this)[i] = !( (*this)[i] );
183  return *this;
184  }
int i
Definition: DBlmapReader.cc:9
size_t pat::strbitset::index ( std::string  s) const
inlineprivate

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 BeautifulSoup.PageElement::_invert(), pat::strbitset::index_type::index_type(), operator[](), and pat::strbitset::index_type::str().

368  {
369  str_index_map::const_iterator f = map_.find(s);
370  if ( f == map_.end() ) {
371  std::cout << "Cannot find " << s << ", returning size()" << std::endl;
372  return map_.size();
373  } else {
374  return f->second;
375  }
376  }
double f[11][100]
tuple cout
Definition: gather_cfg.py:145
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:390
std::string const& pat::strbitset::index ( size_t  i) const
inlineprivate

Definition at line 378 of file strbitset.h.

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

Referenced by BeautifulSoup.PageElement::_invert().

378  {
379  for ( str_index_map::const_iterator f = map_.begin(),
380  fEnd = map_.end();
381  f != fEnd; ++f ) {
382  if ( f->second == i ) return f->first;
383  }
384  std::cout << "Cannot find " << i << ", returning dummy" << std::endl;
385  return dummy_;
386 
387  }
int i
Definition: DBlmapReader.cc:9
double f[11][100]
static const std::string dummy_
Definition: strbitset.h:389
tuple cout
Definition: gather_cfg.py:145
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:390
size_t pat::strbitset::none ( ) const
inline

returns true if none are set

Definition at line 326 of file strbitset.h.

References any().

326  {
327  return !any();
328  }
size_t any() const
returns true if any are set
Definition: strbitset.h:316
pat::strbitset::operator bool ( ) const
inline

! cast to bool

Definition at line 81 of file strbitset.h.

References b, and bits_.

81  {
82  bool b = true;
83  for ( bit_vector::const_iterator bitsBegin = bits_.begin(),
84  bitsEnd = bits_.end(), ibit = bitsBegin;
85  ibit != bitsEnd; ++ibit ) {
86  if ( *ibit == false ) b = false;
87  }
88  return b;
89  }
double b
Definition: hdecay.h:120
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:391
bool pat::strbitset::operator! ( ) const
inline

! Logical negation of bool()

Definition at line 92 of file strbitset.h.

92  {
93  return ! ( operator bool() );
94  }
bool pat::strbitset::operator!= ( const strbitset r) const
inline

inequality operator

Definition at line 293 of file strbitset.h.

References operator==().

Referenced by operator!=().

293  {
294  return ! (operator==(r));
295  }
bool operator==(const strbitset &r) const
equality operator
Definition: strbitset.h:262
bool pat::strbitset::operator!= ( bool  b) const
inline

inequality operator to bool

Definition at line 298 of file strbitset.h.

References operator!=().

298  {
299  return ! ( operator!=(b));
300  }
bool operator!=(const strbitset &r) const
inequality operator
Definition: strbitset.h:293
double b
Definition: hdecay.h:120
strbitset& pat::strbitset::operator&= ( const strbitset r)
inline

bitwise and

Definition at line 198 of file strbitset.h.

References gather_cfg::cout, i, j, relval_steps::key, map_, and AlCaHLTBitMon_QueryRunRegistry::string.

198  {
199  if ( map_.size() != r.map_.size() ) {
200  std::cout << "strbitset operator&= : bitsets not the same size" << std::endl;
201  } else {
202  str_index_map::iterator ibegin = map_.begin(), iend = map_.end(), i = ibegin;
203  for ( ; i != iend; ++i ) {
204  std::string key = i->first;
205  str_index_map::const_iterator j = r.map_.find( key );
206  if ( j == r.map_.end() ) {
207  std::cout << "strbitset operator&= : cannot find key " << key << std::endl;
208  } else {
209  (*this)[key] = (*this)[key] && r[key];
210  }
211  }
212  }
213  return *this;
214  }
int i
Definition: DBlmapReader.cc:9
int j
Definition: DBlmapReader.cc:9
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
tuple cout
Definition: gather_cfg.py:145
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:390
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, relval_steps::key, map_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by operator!=().

262  {
263  if ( map_.size() != r.map_.size() ) {
264  std::cout << "strbitset operator&= : bitsets not the same size" << std::endl;
265  } else {
266  str_index_map::const_iterator ibegin = map_.begin(), iend = map_.end(), i = ibegin;
267  for ( ; i != iend; ++i ) {
268  std::string key = i->first;
269  str_index_map::const_iterator j = r.map_.find( key );
270  if ( j == r.map_.end() ) {
271  std::cout << "strbitset operator&= : cannot find key " << key << std::endl;
272  } else {
273  if ( (*this)[key] != r[key] ) return false;
274  }
275  }
276  }
277  return true;
278  }
int i
Definition: DBlmapReader.cc:9
int j
Definition: DBlmapReader.cc:9
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
tuple cout
Definition: gather_cfg.py:145
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:390
bool pat::strbitset::operator== ( bool  b) const
inline

equality operator to bool

Definition at line 281 of file strbitset.h.

References b, bits_, and mps_fire::result.

281  {
282  bool result = true;
283  for ( bit_vector::const_iterator iBegin = bits_.begin(),
284  iEnd = bits_.end(), ibit = iBegin;
285  ibit != iEnd; ++ibit ) {
286  result &= ( *ibit == b );
287  }
288  return result;
289  }
tuple result
Definition: mps_fire.py:83
double b
Definition: hdecay.h:120
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:391
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().

123  {
124  size_t index = this->index(s);
125  return bits_.operator[](index);
126  }
size_t index(std::string s) const
Definition: strbitset.h:368
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:391
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_.

128  {
129  return bits_.operator[](i.i_);
130  }
int i
Definition: DBlmapReader.cc:9
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:391
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().

133  {
134  size_t index = this->index(s);
135  return bits_.operator[](index);
136  }
size_t index(std::string s) const
Definition: strbitset.h:368
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:391
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_.

138  {
139  return bits_.operator[](i.i_);
140  }
int i
Definition: DBlmapReader.cc:9
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:391
strbitset& pat::strbitset::operator^= ( const strbitset r)
inline

bitwise xor

Definition at line 239 of file strbitset.h.

References gather_cfg::cout, i, j, relval_steps::key, map_, and AlCaHLTBitMon_QueryRunRegistry::string.

239  {
240  if ( map_.size() != r.map_.size() ) {
241  std::cout << "strbitset operator&= : bitsets not the same size" << std::endl;
242  } else {
243  str_index_map::iterator ibegin = map_.begin(), iend = map_.end(), i = ibegin;
244  for ( ; i != iend; ++i ) {
245  std::string key = i->first;
246  str_index_map::const_iterator j = r.map_.find( key );
247  if ( j == r.map_.end() ) {
248  std::cout << "strbitset operator&= : cannot find key " << key << std::endl;
249  } else {
250  (*this)[key] = ( (*this)[key] || r[key]) && ! ((*this)[key] && r[key]);
251  }
252  }
253  }
254  return *this;
255  }
int i
Definition: DBlmapReader.cc:9
int j
Definition: DBlmapReader.cc:9
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
tuple cout
Definition: gather_cfg.py:145
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:390
strbitset& pat::strbitset::operator|= ( const strbitset r)
inline

bitwise or

Definition at line 218 of file strbitset.h.

References gather_cfg::cout, i, j, relval_steps::key, map_, and AlCaHLTBitMon_QueryRunRegistry::string.

218  {
219  if ( map_.size() != r.map_.size() ) {
220  std::cout << "strbitset operator&= : bitsets not the same size" << std::endl;
221  } else {
222  str_index_map::iterator ibegin = map_.begin(), iend = map_.end(), i = ibegin;
223  for ( ; i != iend; ++i ) {
224  std::string key = i->first;
225  str_index_map::const_iterator j = r.map_.find( key );
226  if ( j == r.map_.end() ) {
227  std::cout << "strbitset operator&= : cannot find key " << key << std::endl;
228  } else {
229  (*this)[key] = (*this)[key] || r[key];
230  }
231  }
232  }
233  return *this;
234  }
int i
Definition: DBlmapReader.cc:9
int j
Definition: DBlmapReader.cc:9
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
tuple cout
Definition: gather_cfg.py:145
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:390
strbitset pat::strbitset::operator~ ( )
inline

logical negation

Definition at line 187 of file strbitset.h.

References bits_, i, and runTheMatrix::ret.

187  {
188  strbitset ret(*this);
189  for ( bit_vector::iterator ibegin = ret.bits_.begin(),
190  iend = ret.bits_.end(), i = ibegin;
191  i != iend; ++i ) {
192  *i = !(*i);
193  }
194  return ret;
195  }
int i
Definition: DBlmapReader.cc:9
tuple ret
prodAgent to be discontinued
Implements a string-indexed bit_vector.
void pat::strbitset::print ( std::ostream &  out) const
inline

print method

Definition at line 111 of file strbitset.h.

References bits_, and map_.

111  {
112  for( str_index_map::const_iterator mbegin = map_.begin(),
113  mend = map_.end(),
114  mit = mbegin;
115  mit != mend; ++mit ) {
116  char buff[100];
117  sprintf(buff, "%10s = %6d", mit->first.c_str(), bits_.at(mit->second));
118  out << buff << std::endl;
119  }
120  }
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:391
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:390
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< edm::Ptr< reco::Photon > >::push_back().

99  {
100  if ( map_.find(s) == map_.end() ) {
101  map_[s] = bits_.size();
102  bits_.resize( bits_.size() + 1 );
103  *(bits_.rbegin()) = false;
104  } else {
105  std::cout << "Duplicate entry " << s << ", not added to registry" << std::endl;
106  }
107  }
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:391
tuple cout
Definition: gather_cfg.py:145
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:390
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.

Referenced by betterConfigParser.BetterConfigParser::getGeneral().

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

Definition at line 169 of file strbitset.h.

References i.

Referenced by betterConfigParser.BetterConfigParser::getGeneral().

169  {
170  (*this)[i] = val;
171  return *this;
172  }
int i
Definition: DBlmapReader.cc:9
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_.

346  {
347  std::vector<std::string> strings;
348  strings.resize(bits_.size());
349  for (str_index_map::const_iterator it = map_.begin(),
350  end = map_.end(); it != end; ++it){
351  strings[it->second] = it->first;
352  }
353  return strings;
354  }
#define end
Definition: vmac.h:37
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:391
const std::vector< std::string > strings() const
give access to the ordered strings
Definition: strbitset.h:346
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:390
bool pat::strbitset::test ( std::string  s) const
inline

test

Definition at line 331 of file strbitset.h.

References alignCSCRings::s.

Referenced by main().

331  {
332  return (*this)[s] == true;
333  }
bool pat::strbitset::test ( index_type const &  i) const
inline

Definition at line 335 of file strbitset.h.

References i.

335  {
336  return (*this)[i] == true;
337  }
int i
Definition: DBlmapReader.cc:9

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

bit_vector pat::strbitset::bits_
private

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("")
staticprivate

Definition at line 389 of file strbitset.h.

Referenced by index().

str_index_map pat::strbitset::map_
private

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().