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)
 
std::bitset< S >::reference msb ()
 
bool msb () const
 
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)
 
std::bitset< S >::reference operator[] (int pos)
 
bool operator[] (int pos) const
 
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 (const std::bitset< S > &bs, bool Signed=false)
 
 TTBV (const std::string &str, bool Signed=false)
 
 TTBV (double value, double base, int size, bool Signed=false)
 
 TTBV (int value, int size, bool Signed=false)
 
 TTBV (unsigned long long int value, int size)
 
bool twos () const
 
int val () const
 
int val (bool Signed) const
 
double val (double base) const
 
int val (int start, int end=0, bool Signed=false) 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.

29 : twos_(false), size_(S), bs_(std::bitset<S>(0)) {}

Referenced by val().

◆ TTBV() [2/7]

TTBV::TTBV ( const double  d)
inline

Definition at line 32 of file TTBV.h.

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  }

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

◆ 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)) {}

◆ 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())) {}

◆ 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) {}

◆ 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)) {}

◆ 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)) {}

Member Function Documentation

◆ abs()

TTBV& TTBV::abs ( )
inline

Definition at line 182 of file TTBV.h.

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  }

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

◆ all()

bool TTBV::all ( ) const
inline

Definition at line 72 of file TTBV.h.

72 { return bs_.all(); }

References bs_.

◆ any()

bool TTBV::any ( ) const
inline

Definition at line 73 of file TTBV.h.

73 { return bs_.any(); }

References bs_.

◆ bs()

std::bitset<S> TTBV::bs ( ) const
inline

Definition at line 61 of file TTBV.h.

61 { return bs_; }

References bs_.

◆ count() [1/2]

int TTBV::count ( void  ) const
inline

Definition at line 75 of file TTBV.h.

75 { return bs_.count(); }

References bs_.

◆ count() [2/2]

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

Definition at line 229 of file TTBV.h.

229  {
230  int c(0);
231  for (int i = begin; i < end; i++)
232  if (bs_[i] == b)
233  c++;
234  return c;
235  }

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

◆ flip() [1/2]

TTBV& TTBV::flip ( )
inline

Definition at line 161 of file TTBV.h.

161  {
162  for (int n = 0; n < size_; n++)
163  bs_.flip(n);
164  return *this;
165  }

References bs_, dqmiodumpmetadata::n, and size_.

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

◆ flip() [2/2]

TTBV& TTBV::flip ( int  pos)
inline

Definition at line 176 of file TTBV.h.

176  {
177  bs_.flip(pos);
178  return *this;
179  }

References bs_.

◆ iMax()

unsigned long long int TTBV::iMax ( ) const
inlineprivate

Definition at line 263 of file TTBV.h.

263  {
264  static const std::array<unsigned long long int, S> lut = powersOfTwo();
265  return lut[size_];
266  }

References powersOfTwo(), and size_.

Referenced by val().

◆ msb() [1/2]

std::bitset<S>::reference TTBV::msb ( )
inline

Definition at line 69 of file TTBV.h.

69 { return bs_[size_ - 1]; }

References bs_, and size_.

◆ msb() [2/2]

bool TTBV::msb ( ) const
inline

Definition at line 68 of file TTBV.h.

68 { return bs_[size_ - 1]; }

References bs_, and size_.

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

◆ none()

bool TTBV::none ( ) const
inline

Definition at line 74 of file TTBV.h.

74 { return bs_.none(); }

References bs_.

◆ operator!=()

bool TTBV::operator!= ( const TTBV rhs) const
inline

Definition at line 79 of file TTBV.h.

79 { return bs_ != rhs.bs_; }

References bs_.

◆ operator&=()

TTBV& TTBV::operator&= ( const TTBV rhs)
inline

Definition at line 82 of file TTBV.h.

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  }

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

◆ 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  }

◆ operator++()

TTBV& TTBV::operator++ ( )
inline

Definition at line 145 of file TTBV.h.

145  {
146  bs_ = std::bitset<S>(bs_.to_ullong() + 1);
147  this->resize(size_);
148  return *this;
149  }

References bs_, and resize().

Referenced by abs().

◆ operator+=()

TTBV& TTBV::operator+= ( const TTBV rhs)
inline

Definition at line 133 of file TTBV.h.

133  {
134  bs_ <<= rhs.size();
135  bs_ |= rhs.bs_;
136  size_ += rhs.size();
137  return *this;
138  }

References bs_, size(), and size_.

◆ 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  }

◆ operator<<=()

TTBV& TTBV::operator<<= ( int  pos)
inline

Definition at line 117 of file TTBV.h.

117  {
118  bs_ <<= S - size_ + pos;
119  bs_ >>= S - size_ + pos;
120  size_ -= pos;
121  return *this;
122  }

References bs_, and size_.

Referenced by resize().

◆ operator==()

bool TTBV::operator== ( const TTBV rhs) const
inline

Definition at line 78 of file TTBV.h.

78 { return bs_ == rhs.bs_; }

References bs_.

◆ 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  }

◆ operator>>=()

TTBV& TTBV::operator>>= ( int  pos)
inline

Definition at line 112 of file TTBV.h.

112  {
113  bs_ >>= pos;
114  size_ -= pos;
115  return *this;
116  }

References bs_, and size_.

◆ operator[]() [1/2]

std::bitset<S>::reference TTBV::operator[] ( int  pos)
inline

Definition at line 65 of file TTBV.h.

65 { return bs_[pos]; }

References bs_.

◆ operator[]() [2/2]

bool TTBV::operator[] ( int  pos) const
inline

Definition at line 64 of file TTBV.h.

64 { return bs_[pos]; }

References bs_.

◆ operator^=()

TTBV& TTBV::operator^= ( const TTBV rhs)
inline

Definition at line 98 of file TTBV.h.

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  }

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

◆ operator|=()

TTBV& TTBV::operator|= ( const TTBV rhs)
inline

Definition at line 90 of file TTBV.h.

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  }

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

◆ operator~()

TTBV TTBV::operator~ ( ) const
inline

Definition at line 106 of file TTBV.h.

106  {
107  TTBV bv(*this);
108  return bv.flip();
109  }

References flip().

◆ plEncode()

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

Definition at line 238 of file TTBV.h.

238  {
239  for (int e = 0; e < size_; e++)
240  if (bs_[e] == b)
241  return e;
242  return size_;
243  }

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

◆ pmEncode()

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

Definition at line 246 of file TTBV.h.

246  {
247  for (int e = size_ - 1; e > -1; e--)
248  if (bs_[e] == b)
249  return e;
250  return size_;
251  }

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

◆ powersOfTwo()

constexpr std::array<unsigned long long int, S> TTBV::powersOfTwo ( ) const
inlineconstexprprivate

Definition at line 255 of file TTBV.h.

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  }

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

Referenced by iMax().

◆ reset() [1/2]

TTBV& TTBV::reset ( void  )
inline

Definition at line 152 of file TTBV.h.

152  {
153  bs_.reset();
154  return *this;
155  }

References bs_.

◆ reset() [2/2]

TTBV& TTBV::reset ( int  pos)
inline

Definition at line 168 of file TTBV.h.

168  {
169  bs_.reset(pos);
170  return *this;
171  }

References bs_.

◆ resize()

TTBV& TTBV::resize ( int  size)
inline

Definition at line 195 of file TTBV.h.

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  }

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

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

◆ set() [1/2]

TTBV& TTBV::set ( )
inline

Definition at line 156 of file TTBV.h.

156  {
157  for (int n = 0; n < size_; n++)
158  bs_.set(n);
159  return *this;
160  }

References bs_, dqmiodumpmetadata::n, and size_.

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

◆ set() [2/2]

TTBV& TTBV::set ( int  pos)
inline

Definition at line 172 of file TTBV.h.

172  {
173  bs_.set(pos);
174  return *this;
175  }

References bs_.

◆ size()

int TTBV::size ( void  ) const
inline

◆ str() [1/2]

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

Definition at line 211 of file TTBV.h.

211 { return bs_.to_string().substr(S - size_, S); }

References size_.

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

◆ str() [2/2]

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

Definition at line 214 of file TTBV.h.

214 { return this->str().substr(size_ - start, size_ - end); }

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

Referenced by str().

◆ twos()

bool TTBV::twos ( ) const
inline

Definition at line 59 of file TTBV.h.

59 { return twos_; }

References twos_.

◆ val() [1/4]

int TTBV::val ( ) const
inline

Definition at line 217 of file TTBV.h.

217 { return (twos_ && this->msb()) ? (int)bs_.to_ullong() - iMax() : bs_.to_ullong(); }

References bs_, iMax(), createfilelist::int, msb(), and twos_.

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

◆ val() [2/4]

int TTBV::val ( bool  Signed) const
inline

Definition at line 220 of file TTBV.h.

220 { return (Signed && this->msb()) ? (int)bs_.to_ullong() - iMax() : bs_.to_ullong(); }

References bs_, iMax(), createfilelist::int, and msb().

◆ val() [3/4]

double TTBV::val ( double  base) const
inline

Definition at line 226 of file TTBV.h.

226 { return (this->val() + .5) * base; }

References newFWLiteAna::base, and val().

Referenced by val().

◆ val() [4/4]

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

Definition at line 223 of file TTBV.h.

223 { return TTBV(this->str(start, end), Signed).val(); }

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

Member Data Documentation

◆ bs_

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

◆ S

constexpr int TTBV::S = 64
staticconstexpr

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

mps_fire.i
i
Definition: mps_fire.py:428
start
Definition: start.py:1
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
TTBV::bs
std::bitset< S > bs() const
Definition: TTBV.h:61
TTBV::val
int val() const
Definition: TTBV.h:217
TTBV::S
static constexpr int S
Definition: TTBV.h:20
pos
Definition: PixelAliasList.h:18
TTBV::powersOfTwo
constexpr std::array< unsigned long long int, S > powersOfTwo() const
Definition: TTBV.h:255
TTBV::size_
int size_
Definition: TTBV.h:24
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
mps_fire.end
end
Definition: mps_fire.py:242
TTBV::operator++
TTBV & operator++()
Definition: TTBV.h:145
b
double b
Definition: hdecay.h:118
TTBV::iMax
unsigned long long int iMax() const
Definition: TTBV.h:263
TTBV::bs_
std::bitset< S > bs_
Definition: TTBV.h:25
TTBV::operator<<=
TTBV & operator<<=(int pos)
Definition: TTBV.h:117
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
createfilelist.int
int
Definition: createfilelist.py:10
value
Definition: value.py:1
TTBV
Bit vector used by Track Trigger emulators. Mainly used to convert integers into arbitrary (within ma...
Definition: TTBV.h:18
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
TTBV::TTBV
TTBV()
Definition: TTBV.h:29
TTBV::flip
TTBV & flip()
Definition: TTBV.h:161
TTBV::msb
bool msb() const
Definition: TTBV.h:68
S
Definition: CSCDBL1TPParametersExtended.h:16
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
TTBV::resize
TTBV & resize(int size)
Definition: TTBV.h:195
TTBV::str
std::string str() const
Definition: TTBV.h:211
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
ztail.d
d
Definition: ztail.py:151
TTBV::size
int size() const
Definition: TTBV.h:60
newFWLiteAna.base
base
Definition: newFWLiteAna.py:92
TTBV::twos_
bool twos_
Definition: TTBV.h:23
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37