CMS 3D CMS Logo

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
 
TTBVoperator &= (const TTBV &rhs)
 
bool operator!= (const TTBV &rhs) const
 
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, SpowersOfTwo () 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() [1/7]

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() [2/7]

TTBV::TTBV ( const double  d)
inline

Definition at line 32 of file TTBV.h.

References bs_, c, ztail::d, and createfilelist::int.

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  }
std::bitset< S > bs_
Definition: TTBV.h:25
bool twos_
Definition: TTBV.h:23
d
Definition: ztail.py:151
int size_
Definition: TTBV.h:24

◆ TTBV() [3/7]

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
bool twos_
Definition: TTBV.h:23
int size() const
Definition: TTBV.h:60
Definition: value.py:1
int size_
Definition: TTBV.h:24

◆ TTBV() [4/7]

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
bool twos_
Definition: TTBV.h:23
int size() const
Definition: TTBV.h:60
Definition: value.py:1
int size_
Definition: TTBV.h:24

◆ TTBV() [5/7]

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) {}
base
Main Program
Definition: newFWLiteAna.py:92
TTBV()
Definition: TTBV.h:29
int size() const
Definition: TTBV.h:60
Definition: value.py:1

◆ TTBV() [6/7]

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::bitset< S > bs_
Definition: TTBV.h:25
bool twos_
Definition: TTBV.h:23
std::string str() const
Definition: TTBV.h:211
int size_
Definition: TTBV.h:24

◆ TTBV() [7/7]

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_
Definition: TTBV.h:25
bool twos_
Definition: TTBV.h:23
std::bitset< S > bs() const
Definition: TTBV.h:61
int size_
Definition: TTBV.h:24

Member Function Documentation

◆ abs()

TTBV& TTBV::abs ( )
inline

Definition at line 182 of file TTBV.h.

References flip(), msb(), operator++(), 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
bool msb() const
Definition: TTBV.h:68
TTBV & flip()
Definition: TTBV.h:161
bool twos_
Definition: TTBV.h:23
int size_
Definition: TTBV.h:24

◆ all()

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

◆ any()

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

◆ bs()

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

◆ count() [1/2]

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

◆ count() [2/2]

int TTBV::count ( int  begin,
int  end,
bool  b = true 
) const
inline

Definition at line 229 of file TTBV.h.

References b, bs_, c, mps_fire::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  }
std::bitset< S > bs_
Definition: TTBV.h:25
double b
Definition: hdecay.h:118

◆ flip() [1/2]

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

◆ flip() [2/2]

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

◆ iMax()

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

◆ msb() [1/2]

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

◆ msb() [2/2]

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

◆ none()

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

◆ operator &=()

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

◆ operator!=()

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

◆ operator+()

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

◆ operator++()

TTBV& TTBV::operator++ ( )
inline

Definition at line 145 of file TTBV.h.

References bs_, and resize().

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

◆ operator+=()

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

◆ operator<<()

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

◆ operator<<=()

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

◆ operator==()

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

◆ operator>>()

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

◆ operator>>=()

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

◆ operator[]() [1/2]

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

◆ operator[]() [2/2]

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

◆ operator^=()

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

◆ operator|=()

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

◆ operator~()

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

◆ plEncode()

int TTBV::plEncode ( bool  b = true) const
inline

Definition at line 238 of file TTBV.h.

References b, bs_, MillePedeFileConverter_cfg::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

◆ pmEncode()

int TTBV::pmEncode ( bool  b = true) const
inline

Definition at line 246 of file TTBV.h.

References b, bs_, MillePedeFileConverter_cfg::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

◆ powersOfTwo()

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

◆ reset() [1/2]

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

◆ reset() [2/2]

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

◆ resize()

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  }
bool msb() const
Definition: TTBV.h:68
std::bitset< S > bs_
Definition: TTBV.h:25
bool twos_
Definition: TTBV.h:23
int size() const
Definition: TTBV.h:60
int size_
Definition: TTBV.h:24
TTBV & operator<<=(int pos)
Definition: TTBV.h:117

◆ set() [1/2]

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

◆ set() [2/2]

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

◆ size()

int TTBV::size ( void  ) const
inline

◆ str() [1/2]

std::string TTBV::str ( ) const
inline

Definition at line 211 of file TTBV.h.

References 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

◆ str() [2/2]

std::string TTBV::str ( int  start,
int  end = 0 
) const
inline

Definition at line 214 of file TTBV.h.

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

Referenced by str().

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

◆ twos()

bool TTBV::twos ( ) const
inline

Definition at line 59 of file TTBV.h.

References twos_.

59 { return twos_; }
bool twos_
Definition: TTBV.h:23

◆ val() [1/4]

int TTBV::val ( ) const
inline

Definition at line 217 of file TTBV.h.

References bs_, iMax(), createfilelist::int, 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
bool msb() const
Definition: TTBV.h:68
std::bitset< S > bs_
Definition: TTBV.h:25
bool twos_
Definition: TTBV.h:23

◆ val() [2/4]

int TTBV::val ( bool  Signed) const
inline

Definition at line 220 of file TTBV.h.

References bs_, iMax(), createfilelist::int, 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
bool msb() const
Definition: TTBV.h:68
std::bitset< S > bs_
Definition: TTBV.h:25

◆ val() [3/4]

int TTBV::val ( int  start,
int  end = 0,
bool  Signed = false 
) const
inline

Definition at line 223 of file TTBV.h.

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

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

◆ val() [4/4]

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; }
base
Main Program
Definition: newFWLiteAna.py:92
int val() const
Definition: TTBV.h:217

Member Data Documentation

◆ bs_

std::bitset<S> TTBV::bs_
private

◆ S

constexpr int TTBV::S = 64
static

Definition at line 20 of file TTBV.h.

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

◆ size_

int TTBV::size_
private

◆ twos_

bool TTBV::twos_
private

Definition at line 23 of file TTBV.h.

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