CMS 3D CMS Logo

FPGAWord.cc
Go to the documentation of this file.
2 
4 
5 using namespace std;
6 using namespace trklet;
7 
8 FPGAWord::FPGAWord() {}
9 
10 FPGAWord::FPGAWord(int value, int nbits, bool positive, int line, const char* file) {
11  set(value, nbits, positive, line, file);
12 }
13 
14 void FPGAWord::set(int value, int nbits, bool positive, int line, const char* file) {
15  value_ = value;
16  nbits_ = nbits;
17  positive_ = positive;
18  if (positive) {
19  if (value < 0) {
20  edm::LogProblem("Tracklet") << "FPGAWord got negative value:" << value << " (" << file << ":" << line << ")";
21  }
22  assert(value >= 0);
23  }
24  if (nbits >= 22) {
25  edm::LogPrint("Tracklet") << "FPGAWord got too many bits:" << nbits << " (" << file << ":" << line << ")";
26  }
27  assert(nbits < 22);
28  if (nbits <= 0) {
29  edm::LogPrint("Tracklet") << "FPGAWord got too few bits:" << nbits << " (" << file << ":" << line << ")";
30  }
31  assert(nbits > 0);
32  if (positive) {
33  if (value >= (1 << nbits)) {
34  if (file != nullptr) {
35  edm::LogProblem("Tracklet") << "value too large:" << value << " " << (1 << nbits) << " (" << file << ":" << line
36  << ")";
37  }
38  }
39  assert(value < (1 << nbits));
40  } else {
41  if (value > (1 << (nbits - 1))) {
42  edm::LogProblem("Tracklet") << "value too large:" << value << " " << (1 << (nbits - 1)) << " (" << file << ":"
43  << line << ")";
44  }
45  assert(value <= (1 << (nbits - 1)));
46  if (value < -(1 << (nbits - 1))) {
47  edm::LogProblem("Tracklet") << "value too negative:" << value << " " << -(1 << (nbits - 1)) << " (" << file << ":"
48  << line << ")";
49  }
50  assert(value >= -(1 << (nbits - 1)));
51  }
52 }
53 
55  const int nbit = nbits_;
56 
57  if (!(nbit > 0 && nbit < 22))
58  edm::LogVerbatim("Tracklet") << "nbit: " << nbit;
59  if (nbit == -1)
60  return "?";
61  if (nbit == 0)
62  return "~";
63 
64  int valtmp = value_;
65  string str = "";
66  for (int i = 0; i < nbit; i++) {
67  str = ((valtmp & 1) ? "1" : "0") + str;
68  valtmp >>= 1;
69  }
70 
71  return str;
72 }
73 
74 unsigned int FPGAWord::bits(unsigned int lsb, unsigned int nbit) const {
75  assert(lsb + nbit <= (unsigned int)nbits());
76  return (value_ >> lsb) & ((1 << nbit) - 1);
77 }
78 
79 bool FPGAWord::atExtreme() const {
80  if (positive_) {
81  return (value_ == 0) || (value_ == (1 << nbits_) - 1);
82  }
83  return ((value_ == (-(1 << (nbits_ - 1)))) || (value_ == ((1 << (nbits_ - 1)) - 1)));
84 }
85 
86 bool FPGAWord::operator==(const FPGAWord& other) const {
87  return (value_ == other.value_) && (nbits_ == other.nbits_) && (positive_ == other.positive_);
88 }
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
edm::LogPrint
Log< level::Warning, true > LogPrint
Definition: MessageLogger.h:130
cms::cuda::assert
assert(be >=bs)
hgcalVFEProducer_cfi.lsb
lsb
Definition: hgcalVFEProducer_cfi.py:80
FPGAWord.h
edm::LogProblem
Log< level::Error, true > LogProblem
Definition: MessageLogger.h:131
str
#define str(s)
Definition: TestProcessor.cc:52
trackingPlots.other
other
Definition: trackingPlots.py:1460
trklet::FPGAWord
Definition: FPGAWord.h:9
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
operator==
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
Definition: QGLikelihoodObject.h:49
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
value
Definition: value.py:1
trklet
Definition: AllProjectionsMemory.h:9
std
Definition: JetResolutionObject.h:76
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
relativeConstraints.value
value
Definition: relativeConstraints.py:53
mps_splice.line
line
Definition: mps_splice.py:76