CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 23 of file strbitset.h.

Member Typedef Documentation

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

Definition at line 61 of file strbitset.h.

typedef unsigned int pat::strbitset::size_t

Definition at line 59 of file strbitset.h.

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

Definition at line 60 of file strbitset.h.

Constructor & Destructor Documentation

pat::strbitset::strbitset ( )
inline

constructor: just clears the bitset and map

Definition at line 64 of file strbitset.h.

References clear().

64 { clear(); }
void clear()
clear the bitset and map
Definition: strbitset.h:67

Member Function Documentation

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

returns true if any are set

Definition at line 275 of file strbitset.h.

References bits_, and mps_fire::i.

Referenced by none().

275  {
276  for (bit_vector::const_iterator ibegin = bits_.begin(), iend = bits_.end(), i = ibegin; i != iend; ++i) {
277  if (*i)
278  return true;
279  }
280  return true;
281  }
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:332
const bit_vector& pat::strbitset::bits ( ) const
inline

give access to the ordered bits

Definition at line 292 of file strbitset.h.

References bits_.

292 { return bits_; }
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:332
void pat::strbitset::clear ( void  )
inline

clear the bitset and map

Definition at line 67 of file strbitset.h.

References bits_, and map_.

Referenced by Selector< edm::Ptr< reco::Photon > >::Selector(), and strbitset().

67  {
68  map_.clear();
69  bits_.clear();
70  }
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:332
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:331
size_t pat::strbitset::count ( void  ) const
inline

returns number of bits set

Definition at line 265 of file strbitset.h.

References bits_, mps_fire::i, and runTheMatrix::ret.

265  {
266  size_t ret = 0;
267  for (bit_vector::const_iterator ibegin = bits_.begin(), iend = bits_.end(), i = ibegin; i != iend; ++i) {
268  if (*i)
269  ++ret;
270  }
271  return ret;
272  }
tuple ret
prodAgent to be discontinued
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:332
strbitset& pat::strbitset::flip ( )
inline

flip method of all bits

Definition at line 134 of file strbitset.h.

References bits_, and mps_fire::i.

134  {
135  for (bit_vector::iterator ibegin = bits_.begin(), iend = bits_.end(), i = ibegin; i != iend; ++i) {
136  *i = !(*i);
137  }
138  return *this;
139  }
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:332
strbitset& pat::strbitset::flip ( std::string  s)
inline

flip method of one bit

Definition at line 153 of file strbitset.h.

References alignCSCRings::s.

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

Definition at line 158 of file strbitset.h.

References mps_fire::i.

158  {
159  (*this)[i] = !((*this)[i]);
160  return *this;
161  }
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 311 of file strbitset.h.

References gather_cfg::cout, validate-o2o-wbm::f, and map_.

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

311  {
312  str_index_map::const_iterator f = map_.find(s);
313  if (f == map_.end()) {
314  std::cout << "Cannot find " << s << ", returning size()" << std::endl;
315  return map_.size();
316  } else {
317  return f->second;
318  }
319  }
tuple cout
Definition: gather_cfg.py:144
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:331
std::string const& pat::strbitset::index ( size_t  i) const
inlineprivate

Definition at line 321 of file strbitset.h.

References gather_cfg::cout, dummy_, validate-o2o-wbm::f, and map_.

Referenced by BeautifulSoup.PageElement::_invert().

321  {
322  for (str_index_map::const_iterator f = map_.begin(), fEnd = map_.end(); f != fEnd; ++f) {
323  if (f->second == i)
324  return f->first;
325  }
326  std::cout << "Cannot find " << i << ", returning dummy" << std::endl;
327  return dummy_;
328  }
static const std::string dummy_
Definition: strbitset.h:330
tuple cout
Definition: gather_cfg.py:144
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:331
size_t pat::strbitset::none ( ) const
inline

returns true if none are set

Definition at line 284 of file strbitset.h.

References any().

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

! cast to bool

Definition at line 73 of file strbitset.h.

References b, and bits_.

73  {
74  bool b = true;
75  for (bit_vector::const_iterator bitsBegin = bits_.begin(), bitsEnd = bits_.end(), ibit = bitsBegin;
76  ibit != bitsEnd;
77  ++ibit) {
78  if (*ibit == false)
79  b = false;
80  }
81  return b;
82  }
double b
Definition: hdecay.h:118
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:332
bool pat::strbitset::operator! ( ) const
inline

! Logical negation of bool()

Definition at line 85 of file strbitset.h.

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

inequality operator

Definition at line 259 of file strbitset.h.

References operator==().

259 { return !(operator==(r)); }
bool operator==(const strbitset &r) const
equality operator
Definition: strbitset.h:230
bool pat::strbitset::operator!= ( bool  b) const
inline

inequality operator to bool

Definition at line 262 of file strbitset.h.

References operator==().

262 { return !(operator==(b)); }
bool operator==(const strbitset &r) const
equality operator
Definition: strbitset.h:230
double b
Definition: hdecay.h:118
strbitset& pat::strbitset::operator&= ( const strbitset r)
inline

bitwise and

Definition at line 173 of file strbitset.h.

References gather_cfg::cout, mps_fire::i, dqmiolumiharvest::j, submitPVResolutionJobs::key, map_, and AlCaHLTBitMon_QueryRunRegistry::string.

173  {
174  if (map_.size() != r.map_.size()) {
175  std::cout << "strbitset operator&= : bitsets not the same size" << std::endl;
176  } else {
177  str_index_map::iterator ibegin = map_.begin(), iend = map_.end(), i = ibegin;
178  for (; i != iend; ++i) {
179  std::string key = i->first;
180  str_index_map::const_iterator j = r.map_.find(key);
181  if (j == r.map_.end()) {
182  std::cout << "strbitset operator&= : cannot find key " << key << std::endl;
183  } else {
184  (*this)[key] = (*this)[key] && r[key];
185  }
186  }
187  }
188  return *this;
189  }
tuple key
prepare the HTCondor submission files and eventually submit them
tuple cout
Definition: gather_cfg.py:144
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:331
bool pat::strbitset::operator== ( const strbitset r) const
inline

equality operator

Definition at line 230 of file strbitset.h.

References gather_cfg::cout, mps_fire::i, dqmiolumiharvest::j, submitPVResolutionJobs::key, map_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by operator!=().

230  {
231  if (map_.size() != r.map_.size()) {
232  std::cout << "strbitset operator&= : bitsets not the same size" << std::endl;
233  } else {
234  str_index_map::const_iterator ibegin = map_.begin(), iend = map_.end(), i = ibegin;
235  for (; i != iend; ++i) {
236  std::string key = i->first;
237  str_index_map::const_iterator j = r.map_.find(key);
238  if (j == r.map_.end()) {
239  std::cout << "strbitset operator&= : cannot find key " << key << std::endl;
240  } else {
241  if ((*this)[key] != r[key])
242  return false;
243  }
244  }
245  }
246  return true;
247  }
tuple key
prepare the HTCondor submission files and eventually submit them
tuple cout
Definition: gather_cfg.py:144
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:331
bool pat::strbitset::operator== ( bool  b) const
inline

equality operator to bool

Definition at line 250 of file strbitset.h.

References b, bits_, and mps_fire::result.

250  {
251  bool result = true;
252  for (bit_vector::const_iterator iBegin = bits_.begin(), iEnd = bits_.end(), ibit = iBegin; ibit != iEnd; ++ibit) {
253  result &= (*ibit == b);
254  }
255  return result;
256  }
tuple result
Definition: mps_fire.py:311
double b
Definition: hdecay.h:118
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:332
bit_vector::const_reference pat::strbitset::operator[] ( const std::string  s) const
inline

access method const

Definition at line 110 of file strbitset.h.

References bits_, and index().

110  {
111  size_t index = this->index(s);
112  return bits_.operator[](index);
113  }
size_t index(std::string s) const
Definition: strbitset.h:311
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:332
bit_vector::const_reference pat::strbitset::operator[] ( index_type const &  i) const
inline

Definition at line 115 of file strbitset.h.

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

115 { return bits_.operator[](i.i_); }
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:332
bit_vector::reference pat::strbitset::operator[] ( const std::string  s)
inline

access method non-const

Definition at line 118 of file strbitset.h.

References bits_, and index().

118  {
119  size_t index = this->index(s);
120  return bits_.operator[](index);
121  }
size_t index(std::string s) const
Definition: strbitset.h:311
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:332
bit_vector::reference pat::strbitset::operator[] ( index_type const &  i)
inline

Definition at line 123 of file strbitset.h.

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

123 { return bits_.operator[](i.i_); }
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:332
strbitset& pat::strbitset::operator^= ( const strbitset r)
inline

bitwise xor

Definition at line 211 of file strbitset.h.

References gather_cfg::cout, mps_fire::i, dqmiolumiharvest::j, submitPVResolutionJobs::key, map_, and AlCaHLTBitMon_QueryRunRegistry::string.

211  {
212  if (map_.size() != r.map_.size()) {
213  std::cout << "strbitset operator&= : bitsets not the same size" << std::endl;
214  } else {
215  str_index_map::iterator ibegin = map_.begin(), iend = map_.end(), i = ibegin;
216  for (; i != iend; ++i) {
217  std::string key = i->first;
218  str_index_map::const_iterator j = r.map_.find(key);
219  if (j == r.map_.end()) {
220  std::cout << "strbitset operator&= : cannot find key " << key << std::endl;
221  } else {
222  (*this)[key] = ((*this)[key] || r[key]) && !((*this)[key] && r[key]);
223  }
224  }
225  }
226  return *this;
227  }
tuple key
prepare the HTCondor submission files and eventually submit them
tuple cout
Definition: gather_cfg.py:144
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:331
strbitset& pat::strbitset::operator|= ( const strbitset r)
inline

bitwise or

Definition at line 192 of file strbitset.h.

References gather_cfg::cout, mps_fire::i, dqmiolumiharvest::j, submitPVResolutionJobs::key, map_, and AlCaHLTBitMon_QueryRunRegistry::string.

192  {
193  if (map_.size() != r.map_.size()) {
194  std::cout << "strbitset operator&= : bitsets not the same size" << std::endl;
195  } else {
196  str_index_map::iterator ibegin = map_.begin(), iend = map_.end(), i = ibegin;
197  for (; i != iend; ++i) {
198  std::string key = i->first;
199  str_index_map::const_iterator j = r.map_.find(key);
200  if (j == r.map_.end()) {
201  std::cout << "strbitset operator&= : cannot find key " << key << std::endl;
202  } else {
203  (*this)[key] = (*this)[key] || r[key];
204  }
205  }
206  }
207  return *this;
208  }
tuple key
prepare the HTCondor submission files and eventually submit them
tuple cout
Definition: gather_cfg.py:144
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:331
strbitset pat::strbitset::operator~ ( )
inline

logical negation

Definition at line 164 of file strbitset.h.

References bits_, mps_fire::i, and runTheMatrix::ret.

164  {
165  strbitset ret(*this);
166  for (bit_vector::iterator ibegin = ret.bits_.begin(), iend = ret.bits_.end(), i = ibegin; i != iend; ++i) {
167  *i = !(*i);
168  }
169  return ret;
170  }
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 101 of file strbitset.h.

References bits_, and map_.

101  {
102  for (str_index_map::const_iterator mbegin = map_.begin(), mend = map_.end(), mit = mbegin; mit != mend; ++mit) {
103  char buff[100];
104  sprintf(buff, "%10s = %6i", mit->first.c_str(), (int)(bits_.at(mit->second)));
105  out << buff << std::endl;
106  }
107  }
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:332
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:331
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 90 of file strbitset.h.

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

Referenced by Selector< edm::Ptr< reco::Photon > >::push_back().

90  {
91  if (map_.find(s) == map_.end()) {
92  map_[s] = bits_.size();
93  bits_.resize(bits_.size() + 1);
94  *(bits_.rbegin()) = false;
95  } else {
96  std::cout << "Duplicate entry " << s << ", not added to registry" << std::endl;
97  }
98  }
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:332
tuple cout
Definition: gather_cfg.py:144
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:331
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 142 of file strbitset.h.

References alignCSCRings::s, and hgcalPerformanceValidation::val.

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

Definition at line 147 of file strbitset.h.

References mps_fire::i, and hgcalPerformanceValidation::val.

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

give access to the ordered strings

Definition at line 295 of file strbitset.h.

References bits_, dataset::end, and map_.

295  {
296  std::vector<std::string> strings;
297  strings.resize(bits_.size());
298  for (str_index_map::const_iterator it = map_.begin(), end = map_.end(); it != end; ++it) {
299  strings[it->second] = it->first;
300  }
301  return strings;
302  }
bit_vector bits_
the actual bits, indexed by the index in &quot;map_&quot;
Definition: strbitset.h:332
const std::vector< std::string > strings() const
give access to the ordered strings
Definition: strbitset.h:295
string end
Definition: dataset.py:937
str_index_map map_
map that holds the string–&gt;index map
Definition: strbitset.h:331
bool pat::strbitset::test ( std::string  s) const
inline

test

Definition at line 287 of file strbitset.h.

References alignCSCRings::s.

Referenced by main().

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

Definition at line 289 of file strbitset.h.

References mps_fire::i.

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

Friends And Related Function Documentation

friend class index_type
friend

Definition at line 56 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 332 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 330 of file strbitset.h.

Referenced by index().

str_index_map pat::strbitset::map_
private

map that holds the string–>index map

Definition at line 331 of file strbitset.h.

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