CMS 3D CMS Logo

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_tstr_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 (index_type const &i)
 
strbitsetflip (std::string s)
 flip method of one bit More...
 
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!= (bool b) const
 inequality operator to bool More...
 
bool operator!= (const strbitset &r) const
 inequality operator More...
 
strbitsetoperator&= (const strbitset &r)
 bitwise and More...
 
bool operator== (bool b) const
 equality operator to bool More...
 
bool operator== (const strbitset &r) const
 equality operator More...
 
bit_vector::reference operator[] (const std::string s)
 access method non-const More...
 
bit_vector::const_reference operator[] (const std::string s) const
 access method const More...
 
bit_vector::reference operator[] (index_type const &i)
 
bit_vector::const_reference operator[] (index_type const &i) const
 
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 (index_type const &i, bool val=true)
 
strbitsetset (std::string s, bool val=true)
 set method of one bit More...
 
 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 (index_type const &i) const
 
bool test (std::string s) const
 test More...
 

Private Member Functions

std::string const & index (size_t i) const
 
size_t index (std::string s) 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

◆ bit_vector

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

Definition at line 61 of file strbitset.h.

◆ size_t

typedef unsigned int pat::strbitset::size_t

Definition at line 59 of file strbitset.h.

◆ str_index_map

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

Definition at line 60 of file strbitset.h.

Constructor & Destructor Documentation

◆ strbitset()

pat::strbitset::strbitset ( )
inline

constructor: just clears the bitset and map

Definition at line 64 of file strbitset.h.

64 { clear(); }

References clear().

Member Function Documentation

◆ any()

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

returns true if any are set

Definition at line 275 of file strbitset.h.

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  }

References bits_, and mps_fire::i.

Referenced by none().

◆ bits()

const bit_vector& pat::strbitset::bits ( ) const
inline

give access to the ordered bits

Definition at line 292 of file strbitset.h.

292 { return bits_; }

References bits_.

◆ clear()

void pat::strbitset::clear ( void  )
inline

clear the bitset and map

Definition at line 67 of file strbitset.h.

67  {
68  map_.clear();
69  bits_.clear();
70  }

References bits_, and map_.

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

◆ count()

size_t pat::strbitset::count ( void  ) const
inline

returns number of bits set

Definition at line 265 of file strbitset.h.

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  }

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

◆ flip() [1/3]

strbitset& pat::strbitset::flip ( )
inline

flip method of all bits

Definition at line 134 of file strbitset.h.

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  }

References bits_, and mps_fire::i.

◆ flip() [2/3]

strbitset& pat::strbitset::flip ( index_type const &  i)
inline

Definition at line 158 of file strbitset.h.

158  {
159  (*this)[i] = !((*this)[i]);
160  return *this;
161  }

References mps_fire::i.

◆ flip() [3/3]

strbitset& pat::strbitset::flip ( std::string  s)
inline

flip method of one bit

Definition at line 153 of file strbitset.h.

153  {
154  (*this)[s] = !((*this)[s]);
155  return *this;
156  }

References alignCSCRings::s.

◆ index() [1/2]

std::string const& pat::strbitset::index ( size_t  i) const
inlineprivate

Definition at line 321 of file strbitset.h.

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  }

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

Referenced by BeautifulSoup.PageElement::insert().

◆ index() [2/2]

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.

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  }

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

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

◆ none()

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

returns true if none are set

Definition at line 284 of file strbitset.h.

284 { return !any(); }

References any().

◆ operator bool()

pat::strbitset::operator bool ( ) const
inline

! cast to bool

Definition at line 73 of file strbitset.h.

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  }

References b, and bits_.

◆ operator!()

bool pat::strbitset::operator! ( ) const
inline

! Logical negation of bool()

Definition at line 85 of file strbitset.h.

85 { return !(operator bool()); }

References electrons_cff::bool.

◆ operator!=() [1/2]

bool pat::strbitset::operator!= ( bool  b) const
inline

inequality operator to bool

Definition at line 262 of file strbitset.h.

262 { return !(operator==(b)); }

References b, and operator==().

◆ operator!=() [2/2]

bool pat::strbitset::operator!= ( const strbitset r) const
inline

inequality operator

Definition at line 259 of file strbitset.h.

259 { return !(operator==(r)); }

References operator==(), and alignCSCRings::r.

◆ operator&=()

strbitset& pat::strbitset::operator&= ( const strbitset r)
inline

bitwise and

Definition at line 173 of file strbitset.h.

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  }

References gather_cfg::cout, mps_fire::i, dqmiolumiharvest::j, crabWrapper::key, map_, alignCSCRings::r, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ operator==() [1/2]

bool pat::strbitset::operator== ( bool  b) const
inline

equality operator to bool

Definition at line 250 of file strbitset.h.

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  }

References b, bits_, and mps_fire::result.

◆ operator==() [2/2]

bool pat::strbitset::operator== ( const strbitset r) const
inline

equality operator

Definition at line 230 of file strbitset.h.

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  }

References gather_cfg::cout, mps_fire::i, dqmiolumiharvest::j, crabWrapper::key, map_, alignCSCRings::r, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by operator!=().

◆ operator[]() [1/4]

bit_vector::reference pat::strbitset::operator[] ( const std::string  s)
inline

access method non-const

Definition at line 118 of file strbitset.h.

118  {
119  size_t index = this->index(s);
120  return bits_.operator[](index);
121  }

References bits_, and index().

◆ operator[]() [2/4]

bit_vector::const_reference pat::strbitset::operator[] ( const std::string  s) const
inline

access method const

Definition at line 110 of file strbitset.h.

110  {
111  size_t index = this->index(s);
112  return bits_.operator[](index);
113  }

References bits_, and index().

◆ operator[]() [3/4]

bit_vector::reference pat::strbitset::operator[] ( index_type const &  i)
inline

Definition at line 123 of file strbitset.h.

123 { return bits_.operator[](i.i_); }

References bits_, and mps_fire::i.

◆ operator[]() [4/4]

bit_vector::const_reference pat::strbitset::operator[] ( index_type const &  i) const
inline

Definition at line 115 of file strbitset.h.

115 { return bits_.operator[](i.i_); }

References bits_, and mps_fire::i.

◆ operator^=()

strbitset& pat::strbitset::operator^= ( const strbitset r)
inline

bitwise xor

Definition at line 211 of file strbitset.h.

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  }

References gather_cfg::cout, mps_fire::i, dqmiolumiharvest::j, crabWrapper::key, map_, alignCSCRings::r, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ operator|=()

strbitset& pat::strbitset::operator|= ( const strbitset r)
inline

bitwise or

Definition at line 192 of file strbitset.h.

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  }

References gather_cfg::cout, mps_fire::i, dqmiolumiharvest::j, crabWrapper::key, map_, alignCSCRings::r, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ operator~()

strbitset pat::strbitset::operator~ ( )
inline

logical negation

Definition at line 164 of file strbitset.h.

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  }

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

◆ print()

void pat::strbitset::print ( std::ostream &  out) const
inline

print method

Definition at line 101 of file strbitset.h.

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  }

References bits_, createfilelist::int, map_, and MillePedeFileConverter_cfg::out.

◆ push_back()

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.

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  }

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

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

◆ set() [1/3]

strbitset& pat::strbitset::set ( bool  val = true)
inline

set method of all bits

Definition at line 126 of file strbitset.h.

126  {
127  for (bit_vector::iterator ibegin = bits_.begin(), iend = bits_.end(), i = ibegin; i != iend; ++i) {
128  *i = val;
129  }
130  return *this;
131  }

References bits_, mps_fire::i, and heppy_batch::val.

Referenced by Selector< edm::Ptr< reco::Photon > >::operator()(), JetIDStudiesSelector::operator()(), VersionedSelector< edm::Ptr< reco::Photon > >::operator()(), JetIDSelectionFunctor::operator()(), and PFJetIDSelectionFunctor::operator()().

◆ set() [2/3]

strbitset& pat::strbitset::set ( index_type const &  i,
bool  val = true 
)
inline

Definition at line 147 of file strbitset.h.

147  {
148  (*this)[i] = val;
149  return *this;
150  }

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

◆ set() [3/3]

strbitset& pat::strbitset::set ( std::string  s,
bool  val = true 
)
inline

set method of one bit

Definition at line 142 of file strbitset.h.

142  {
143  (*this)[s] = val;
144  return *this;
145  }

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

◆ strings()

const std::vector<std::string> pat::strbitset::strings ( ) const
inline

give access to the ordered strings

Definition at line 295 of file strbitset.h.

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  }

References bits_, mps_fire::end, and map_.

◆ test() [1/2]

bool pat::strbitset::test ( index_type const &  i) const
inline

Definition at line 289 of file strbitset.h.

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

References mps_fire::i.

◆ test() [2/2]

bool pat::strbitset::test ( std::string  s) const
inline

test

Definition at line 287 of file strbitset.h.

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

References alignCSCRings::s.

Referenced by main().

Friends And Related Function Documentation

◆ index_type

friend class index_type
friend

Definition at line 56 of file strbitset.h.

◆ operator&

strbitset operator& ( const strbitset l,
const strbitset r 
)
friend

Definition at line 7 of file strbitset.cc.

7  {
8  strbitset ret = r;
9  ret &= l;
10  return ret;
11  }

◆ operator^

strbitset operator^ ( const strbitset l,
const strbitset r 
)
friend

Definition at line 19 of file strbitset.cc.

19  {
20  strbitset ret = r;
21  ret ^= l;
22  return ret;
23  }

◆ operator|

strbitset operator| ( const strbitset l,
const strbitset r 
)
friend

Definition at line 13 of file strbitset.cc.

13  {
14  strbitset ret = r;
15  ret |= l;
16  return ret;
17  }

Member Data Documentation

◆ bits_

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[](), print(), push_back(), set(), and strings().

◆ dummy_

const std::string strbitset::dummy_ = std::string("")
staticprivate

Definition at line 330 of file strbitset.h.

Referenced by index().

◆ map_

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

runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:543
pat::strbitset::any
size_t any() const
returns true if any are set
Definition: strbitset.h:275
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pat::strbitset::clear
void clear()
clear the bitset and map
Definition: strbitset.h:67
pat::strbitset::dummy_
static const std::string dummy_
Definition: strbitset.h:330
pat::strbitset::operator==
bool operator==(const strbitset &r) const
equality operator
Definition: strbitset.h:230
pat::strbitset::bits_
bit_vector bits_
the actual bits, indexed by the index in "map_"
Definition: strbitset.h:332
alignCSCRings.s
s
Definition: alignCSCRings.py:92
pat::strbitset::map_
str_index_map map_
map that holds the string-->index map
Definition: strbitset.h:331
mps_fire.end
end
Definition: mps_fire.py:242
b
double b
Definition: hdecay.h:118
createfilelist.int
int
Definition: createfilelist.py:10
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
alignCSCRings.r
r
Definition: alignCSCRings.py:93
pat::strbitset::strings
const std::vector< std::string > strings() const
give access to the ordered strings
Definition: strbitset.h:295
heppy_batch.val
val
Definition: heppy_batch.py:351
pat::strbitset::index
size_t index(std::string s) const
Definition: strbitset.h:311
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
strbitset
Implements a string-indexed bit_vector.
mps_fire.result
result
Definition: mps_fire.py:311
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
crabWrapper.key
key
Definition: crabWrapper.py:19