CMS 3D CMS Logo

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

Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within margin) sized two's complement string. More...

#include <TTBV.h>

Public Member Functions

TTBVabs ()
 
bool all () const
 
bool any () const
 
std::bitset< Sbs () const
 
int count () const
 
int count (int begin, int end, bool b=true) const
 
TTBVflip ()
 
TTBVflip (int pos)
 
bool msb () const
 
std::bitset< S >::reference msb ()
 
bool none () const
 
bool operator!= (const TTBV &rhs) const
 
TTBVoperator&= (const TTBV &rhs)
 
TTBV operator+ (const TTBV &rhs) const
 
TTBVoperator++ ()
 
TTBVoperator+= (const TTBV &rhs)
 
TTBV operator<< (int pos) const
 
TTBVoperator<<= (int pos)
 
bool operator== (const TTBV &rhs) const
 
TTBV operator>> (int pos) const
 
TTBVoperator>>= (int pos)
 
bool operator[] (int pos) const
 
std::bitset< S >::reference operator[] (int pos)
 
TTBVoperator^= (const TTBV &rhs)
 
TTBVoperator|= (const TTBV &rhs)
 
TTBV operator~ () const
 
int plEncode (bool b=true) const
 
int pmEncode (bool b=true) const
 
TTBVreset ()
 
TTBVreset (int pos)
 
TTBVresize (int size)
 
TTBVset ()
 
TTBVset (int pos)
 
int size () const
 
std::string str () const
 
std::string str (int start, int end=0) const
 
 TTBV ()
 
 TTBV (const double d)
 
 TTBV (unsigned long long int value, int size)
 
 TTBV (int value, int size, bool Signed=false)
 
 TTBV (double value, double base, int size, bool Signed=false)
 
 TTBV (const std::string &str, bool Signed=false)
 
 TTBV (const std::bitset< S > &bs, bool Signed=false)
 
bool twos () const
 
int val () const
 
int val (bool Signed) const
 
int val (int start, int end=0, bool Signed=false) const
 
double val (double base) const
 

Static Public Attributes

static constexpr int S = 64
 

Private Member Functions

unsigned long long int iMax () const
 
constexpr std::array< unsigned
long long int, S
powersOfTwo () const
 

Private Attributes

std::bitset< Sbs_
 
int size_
 
bool twos_
 

Detailed Description

Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within margin) sized two's complement string.

Author
Thomas Schuh
Date
2020, Jan

Definition at line 18 of file TTBV.h.

Constructor & Destructor Documentation

TTBV::TTBV ( )
inline

Definition at line 29 of file TTBV.h.

Referenced by val().

29 : twos_(false), size_(S), bs_(std::bitset<S>(0)) {}
std::bitset< S > bs_
Definition: TTBV.h:25
bool twos_
Definition: TTBV.h:23
int size_
Definition: TTBV.h:24
TTBV::TTBV ( const double  d)
inline

Definition at line 32 of file TTBV.h.

References bs_, c, and ztail::d.

32  : twos_(false), size_(S) {
33  int index(0);
34  const char* c = reinterpret_cast<const char*>(&d);
35  for (int iByte = 0; iByte < (int)sizeof(d); iByte++) {
36  const std::bitset<std::numeric_limits<unsigned char>::digits> byte(*(c + iByte));
37  for (int bit = 0; bit < std::numeric_limits<unsigned char>::digits; bit++)
38  bs_[index++] = byte[bit];
39  }
40  }
const edm::EventSetup & c
std::bitset< S > bs_
Definition: TTBV.h:25
bool twos_
Definition: TTBV.h:23
tuple d
Definition: ztail.py:151
int size_
Definition: TTBV.h:24
TTBV::TTBV ( unsigned long long int  value,
int  size 
)
inline

Definition at line 43 of file TTBV.h.

43 : twos_(false), size_(size), bs_(std::bitset<S>(value)) {}
std::bitset< S > bs_
Definition: TTBV.h:25
int size() const
Definition: TTBV.h:60
bool twos_
Definition: TTBV.h:23
int size_
Definition: TTBV.h:24
TTBV::TTBV ( int  value,
int  size,
bool  Signed = false 
)
inline

Definition at line 46 of file TTBV.h.

47  : twos_(Signed), size_(size), bs_(std::bitset<S>((!Signed || value >= 0) ? value : value + iMax())) {}
unsigned long long int iMax() const
Definition: TTBV.h:263
std::bitset< S > bs_
Definition: TTBV.h:25
int size() const
Definition: TTBV.h:60
bool twos_
Definition: TTBV.h:23
int size_
Definition: TTBV.h:24
TTBV::TTBV ( double  value,
double  base,
int  size,
bool  Signed = false 
)
inline

Definition at line 50 of file TTBV.h.

50 : TTBV((int)std::floor(value / base), size, Signed) {}
tuple base
Main Program
Definition: newFWLiteAna.py:92
int size() const
Definition: TTBV.h:60
TTBV()
Definition: TTBV.h:29
TTBV::TTBV ( const std::string &  str,
bool  Signed = false 
)
inline

Definition at line 53 of file TTBV.h.

53 : twos_(Signed), size_(str.size()), bs_(std::bitset<S>(str)) {}
std::string str() const
Definition: TTBV.h:211
std::bitset< S > bs_
Definition: TTBV.h:25
bool twos_
Definition: TTBV.h:23
int size_
Definition: TTBV.h:24
TTBV::TTBV ( const std::bitset< S > &  bs,
bool  Signed = false 
)
inline

Definition at line 56 of file TTBV.h.

56 : twos_(Signed), size_(S), bs_(std::bitset<S>(bs)) {}
std::bitset< S > bs() const
Definition: TTBV.h:61
std::bitset< S > bs_
Definition: TTBV.h:25
bool twos_
Definition: TTBV.h:23
int size_
Definition: TTBV.h:24

Member Function Documentation

TTBV& TTBV::abs ( )
inline

Definition at line 182 of file TTBV.h.

References flip(), msb(), operator++(), size_, and twos_.

182  {
183  if (twos_) {
184  twos_ = false;
185  if (this->msb()) {
186  this->flip();
187  this->operator++();
188  }
189  size_--;
190  }
191  return *this;
192  }
TTBV & operator++()
Definition: TTBV.h:145
TTBV & flip()
Definition: TTBV.h:161
bool msb() const
Definition: TTBV.h:68
bool twos_
Definition: TTBV.h:23
int size_
Definition: TTBV.h:24
bool TTBV::all ( ) const
inline

Definition at line 72 of file TTBV.h.

References bs_.

72 { return bs_.all(); }
std::bitset< S > bs_
Definition: TTBV.h:25
bool TTBV::any ( ) const
inline

Definition at line 73 of file TTBV.h.

References bs_.

73 { return bs_.any(); }
std::bitset< S > bs_
Definition: TTBV.h:25
std::bitset<S> TTBV::bs ( ) const
inline

Definition at line 61 of file TTBV.h.

References bs_.

61 { return bs_; }
std::bitset< S > bs_
Definition: TTBV.h:25
int TTBV::count ( void  ) const
inline

Definition at line 75 of file TTBV.h.

References bs_.

75 { return bs_.count(); }
std::bitset< S > bs_
Definition: TTBV.h:25
int TTBV::count ( int  begin,
int  end,
bool  b = true 
) const
inline

Definition at line 229 of file TTBV.h.

References b, bs_, c, dataset::end, and mps_fire::i.

229  {
230  int c(0);
231  for (int i = begin; i < end; i++)
232  if (bs_[i] == b)
233  c++;
234  return c;
235  }
const edm::EventSetup & c
std::bitset< S > bs_
Definition: TTBV.h:25
double b
Definition: hdecay.h:118
string end
Definition: dataset.py:937
TTBV& TTBV::flip ( )
inline

Definition at line 161 of file TTBV.h.

References bs_, dqmiodumpmetadata::n, and size_.

Referenced by abs(), and operator~().

161  {
162  for (int n = 0; n < size_; n++)
163  bs_.flip(n);
164  return *this;
165  }
std::bitset< S > bs_
Definition: TTBV.h:25
int size_
Definition: TTBV.h:24
TTBV& TTBV::flip ( int  pos)
inline

Definition at line 176 of file TTBV.h.

References bs_.

176  {
177  bs_.flip(pos);
178  return *this;
179  }
std::bitset< S > bs_
Definition: TTBV.h:25
unsigned long long int TTBV::iMax ( ) const
inlineprivate

Definition at line 263 of file TTBV.h.

References powersOfTwo(), and size_.

Referenced by val().

263  {
264  static const std::array<unsigned long long int, S> lut = powersOfTwo();
265  return lut[size_];
266  }
constexpr std::array< unsigned long long int, S > powersOfTwo() const
Definition: TTBV.h:255
int size_
Definition: TTBV.h:24
bool TTBV::msb ( ) const
inline

Definition at line 68 of file TTBV.h.

References bs_, and size_.

Referenced by abs(), resize(), and val().

68 { return bs_[size_ - 1]; }
std::bitset< S > bs_
Definition: TTBV.h:25
int size_
Definition: TTBV.h:24
std::bitset<S>::reference TTBV::msb ( )
inline

Definition at line 69 of file TTBV.h.

References bs_, and size_.

69 { return bs_[size_ - 1]; }
std::bitset< S > bs_
Definition: TTBV.h:25
int size_
Definition: TTBV.h:24
bool TTBV::none ( ) const
inline

Definition at line 74 of file TTBV.h.

References bs_.

74 { return bs_.none(); }
std::bitset< S > bs_
Definition: TTBV.h:25
bool TTBV::operator!= ( const TTBV rhs) const
inline

Definition at line 79 of file TTBV.h.

References bs_.

79 { return bs_ != rhs.bs_; }
std::bitset< S > bs_
Definition: TTBV.h:25
TTBV& TTBV::operator&= ( const TTBV rhs)
inline

Definition at line 82 of file TTBV.h.

References bs_, visualization-live-secondInstance_cfg::m, SiStripPI::max, resize(), size(), and size_.

82  {
83  const int m(std::max(size_, rhs.size()));
84  this->resize(m);
85  TTBV bv(rhs);
86  bv.resize(m);
87  bs_ &= bv.bs_;
88  return *this;
89  }
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:18
std::bitset< S > bs_
Definition: TTBV.h:25
TTBV & resize(int size)
Definition: TTBV.h:195
int size() const
Definition: TTBV.h:60
int size_
Definition: TTBV.h:24
TTBV TTBV::operator+ ( const TTBV rhs) const
inline

Definition at line 139 of file TTBV.h.

139  {
140  TTBV lhs(*this);
141  return lhs += rhs;
142  }
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:18
TTBV& TTBV::operator++ ( )
inline

Definition at line 145 of file TTBV.h.

References bs_, resize(), and size_.

Referenced by abs().

145  {
146  bs_ = std::bitset<S>(bs_.to_ullong() + 1);
147  this->resize(size_);
148  return *this;
149  }
std::bitset< S > bs_
Definition: TTBV.h:25
TTBV & resize(int size)
Definition: TTBV.h:195
int size_
Definition: TTBV.h:24
TTBV& TTBV::operator+= ( const TTBV rhs)
inline

Definition at line 133 of file TTBV.h.

References bs_, size(), and size_.

133  {
134  bs_ <<= rhs.size();
135  bs_ |= rhs.bs_;
136  size_ += rhs.size();
137  return *this;
138  }
std::bitset< S > bs_
Definition: TTBV.h:25
int size() const
Definition: TTBV.h:60
int size_
Definition: TTBV.h:24
TTBV TTBV::operator<< ( int  pos) const
inline

Definition at line 123 of file TTBV.h.

123  {
124  TTBV bv(*this);
125  return bv >>= pos;
126  }
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:18
TTBV& TTBV::operator<<= ( int  pos)
inline

Definition at line 117 of file TTBV.h.

References bs_, and size_.

Referenced by resize().

117  {
118  bs_ <<= S - size_ + pos;
119  bs_ >>= S - size_ + pos;
120  size_ -= pos;
121  return *this;
122  }
std::bitset< S > bs_
Definition: TTBV.h:25
int size_
Definition: TTBV.h:24
bool TTBV::operator== ( const TTBV rhs) const
inline

Definition at line 78 of file TTBV.h.

References bs_.

78 { return bs_ == rhs.bs_; }
std::bitset< S > bs_
Definition: TTBV.h:25
TTBV TTBV::operator>> ( int  pos) const
inline

Definition at line 127 of file TTBV.h.

127  {
128  TTBV bv(*this);
129  return bv <<= pos;
130  }
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:18
TTBV& TTBV::operator>>= ( int  pos)
inline

Definition at line 112 of file TTBV.h.

References bs_, and size_.

112  {
113  bs_ >>= pos;
114  size_ -= pos;
115  return *this;
116  }
std::bitset< S > bs_
Definition: TTBV.h:25
int size_
Definition: TTBV.h:24
bool TTBV::operator[] ( int  pos) const
inline

Definition at line 64 of file TTBV.h.

References bs_.

64 { return bs_[pos]; }
std::bitset< S > bs_
Definition: TTBV.h:25
std::bitset<S>::reference TTBV::operator[] ( int  pos)
inline

Definition at line 65 of file TTBV.h.

References bs_.

65 { return bs_[pos]; }
std::bitset< S > bs_
Definition: TTBV.h:25
TTBV& TTBV::operator^= ( const TTBV rhs)
inline

Definition at line 98 of file TTBV.h.

References bs_, visualization-live-secondInstance_cfg::m, SiStripPI::max, resize(), size(), and size_.

98  {
99  const int m(std::max(size_, rhs.size()));
100  this->resize(m);
101  TTBV bv(rhs);
102  bv.resize(m);
103  bs_ ^= bv.bs_;
104  return *this;
105  }
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:18
std::bitset< S > bs_
Definition: TTBV.h:25
TTBV & resize(int size)
Definition: TTBV.h:195
int size() const
Definition: TTBV.h:60
int size_
Definition: TTBV.h:24
TTBV& TTBV::operator|= ( const TTBV rhs)
inline

Definition at line 90 of file TTBV.h.

References bs_, visualization-live-secondInstance_cfg::m, SiStripPI::max, resize(), size(), and size_.

90  {
91  const int m(std::max(size_, rhs.size()));
92  this->resize(m);
93  TTBV bv(rhs);
94  bv.resize(m);
95  bs_ |= bv.bs_;
96  return *this;
97  }
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:18
std::bitset< S > bs_
Definition: TTBV.h:25
TTBV & resize(int size)
Definition: TTBV.h:195
int size() const
Definition: TTBV.h:60
int size_
Definition: TTBV.h:24
TTBV TTBV::operator~ ( ) const
inline

Definition at line 106 of file TTBV.h.

References flip().

106  {
107  TTBV bv(*this);
108  return bv.flip();
109  }
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:18
int TTBV::plEncode ( bool  b = true) const
inline

Definition at line 238 of file TTBV.h.

References b, bs_, alignCSCRings::e, and size_.

238  {
239  for (int e = 0; e < size_; e++)
240  if (bs_[e] == b)
241  return e;
242  return size_;
243  }
std::bitset< S > bs_
Definition: TTBV.h:25
double b
Definition: hdecay.h:118
int size_
Definition: TTBV.h:24
int TTBV::pmEncode ( bool  b = true) const
inline

Definition at line 246 of file TTBV.h.

References b, bs_, alignCSCRings::e, and size_.

246  {
247  for (int e = size_ - 1; e > -1; e--)
248  if (bs_[e] == b)
249  return e;
250  return size_;
251  }
std::bitset< S > bs_
Definition: TTBV.h:25
double b
Definition: hdecay.h:118
int size_
Definition: TTBV.h:24
constexpr std::array<unsigned long long int, S> TTBV::powersOfTwo ( ) const
inlineprivate

Definition at line 255 of file TTBV.h.

References mps_fire::i, funct::pow(), and S.

Referenced by iMax().

255  {
256  std::array<unsigned long long int, S> lut = {};
257  for (int i = 0; i < S; i++)
258  lut[i] = std::pow(2, i);
259  return lut;
260  }
static constexpr int S
Definition: TTBV.h:20
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
TTBV& TTBV::reset ( void  )
inline

Definition at line 152 of file TTBV.h.

References bs_.

152  {
153  bs_.reset();
154  return *this;
155  }
std::bitset< S > bs_
Definition: TTBV.h:25
TTBV& TTBV::reset ( int  pos)
inline

Definition at line 168 of file TTBV.h.

References bs_.

168  {
169  bs_.reset(pos);
170  return *this;
171  }
std::bitset< S > bs_
Definition: TTBV.h:25
TTBV& TTBV::resize ( int  size)
inline

Definition at line 195 of file TTBV.h.

References bs_, msb(), dqmiodumpmetadata::n, operator<<=(), size(), size_, and twos_.

Referenced by operator&=(), operator++(), operator^=(), and operator|=().

195  {
196  bool msb = this->msb();
197  if (size > size_) {
198  if (twos_)
199  for (int n = size_; n < size; n++)
200  bs_.set(n, msb);
201  size_ = size;
202  } else if (size < size_ && size > 0) {
203  this->operator<<=(size - size_);
204  if (twos_)
205  this->msb() = msb;
206  }
207  return *this;
208  }
std::bitset< S > bs_
Definition: TTBV.h:25
bool msb() const
Definition: TTBV.h:68
int size() const
Definition: TTBV.h:60
bool twos_
Definition: TTBV.h:23
int size_
Definition: TTBV.h:24
TTBV & operator<<=(int pos)
Definition: TTBV.h:117
TTBV& TTBV::set ( )
inline

Definition at line 156 of file TTBV.h.

References bs_, dqmiodumpmetadata::n, and size_.

Referenced by trackerDTC::Stub::formatTMTT().

156  {
157  for (int n = 0; n < size_; n++)
158  bs_.set(n);
159  return *this;
160  }
std::bitset< S > bs_
Definition: TTBV.h:25
int size_
Definition: TTBV.h:24
TTBV& TTBV::set ( int  pos)
inline

Definition at line 172 of file TTBV.h.

References bs_.

172  {
173  bs_.set(pos);
174  return *this;
175  }
std::bitset< S > bs_
Definition: TTBV.h:25
int TTBV::size ( void  ) const
inline
std::string TTBV::str ( ) const
inline

Definition at line 211 of file TTBV.h.

References bs_, and size_.

Referenced by trackerDTC::Stub::formatTMTT(), and val().

211 { return bs_.to_string().substr(S - size_, S); }
std::bitset< S > bs_
Definition: TTBV.h:25
int size_
Definition: TTBV.h:24
std::string TTBV::str ( int  start,
int  end = 0 
) const
inline

Definition at line 214 of file TTBV.h.

References dataset::end, size_, and str().

Referenced by str().

214 { return this->str().substr(size_ - start, size_ - end); }
std::string str() const
Definition: TTBV.h:211
int size_
Definition: TTBV.h:24
string end
Definition: dataset.py:937
bool TTBV::twos ( ) const
inline

Definition at line 59 of file TTBV.h.

References twos_.

59 { return twos_; }
bool twos_
Definition: TTBV.h:23
int TTBV::val ( ) const
inline

Definition at line 217 of file TTBV.h.

References bs_, iMax(), msb(), and twos_.

Referenced by trackerDTC::Setup::stubPos().

217 { return (twos_ && this->msb()) ? (int)bs_.to_ullong() - iMax() : bs_.to_ullong(); }
unsigned long long int iMax() const
Definition: TTBV.h:263
std::bitset< S > bs_
Definition: TTBV.h:25
bool msb() const
Definition: TTBV.h:68
bool twos_
Definition: TTBV.h:23
int TTBV::val ( bool  Signed) const
inline

Definition at line 220 of file TTBV.h.

References bs_, iMax(), and msb().

220 { return (Signed && this->msb()) ? (int)bs_.to_ullong() - iMax() : bs_.to_ullong(); }
unsigned long long int iMax() const
Definition: TTBV.h:263
std::bitset< S > bs_
Definition: TTBV.h:25
bool msb() const
Definition: TTBV.h:68
int TTBV::val ( int  start,
int  end = 0,
bool  Signed = false 
) const
inline

Definition at line 223 of file TTBV.h.

References dataset::end, str(), and TTBV().

223 { return TTBV(this->str(start, end), Signed).val(); }
std::string str() const
Definition: TTBV.h:211
TTBV()
Definition: TTBV.h:29
string end
Definition: dataset.py:937
double TTBV::val ( double  base) const
inline

Definition at line 226 of file TTBV.h.

References newFWLiteAna::base, and val().

Referenced by val().

226 { return (this->val() + .5) * base; }
tuple base
Main Program
Definition: newFWLiteAna.py:92
int val() const
Definition: TTBV.h:217

Member Data Documentation

std::bitset<S> TTBV::bs_
private
constexpr int TTBV::S = 64
static

Definition at line 20 of file TTBV.h.

Referenced by trackerDTC::Setup::calculateConstants(), and powersOfTwo().

int TTBV::size_
private
bool TTBV::twos_
private

Definition at line 23 of file TTBV.h.

Referenced by abs(), resize(), twos(), and val().