CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1GctUnsignedInt.h
Go to the documentation of this file.
1 #ifndef L1GCTUNSIGNEDINT_H
2 #define L1GCTUNSIGNEDINT_H
3 
4 #include <ostream>
5 
26 template <int nBits>
28 public:
32  L1GctUnsignedInt(unsigned value);
35 
37  template <int mBits>
39 
41  void reset() {
42  m_value = static_cast<unsigned>(0);
43  m_overFlow = false;
44  }
45 
47  void setValue(unsigned value);
48 
50  void setOverFlow(bool oflow) { m_overFlow = oflow; }
51 
53  unsigned value() const { return m_value; }
54 
56  bool overFlow() const { return m_overFlow; }
57 
59  int size() const { return m_nBits; }
60 
62  L1GctUnsignedInt operator+(const L1GctUnsignedInt& rhs) const;
63 
65  L1GctUnsignedInt& operator=(int value);
66 
67 protected:
68  // number of bits
69  int m_nBits;
70 
71  // value
72  unsigned m_value;
73 
74  // overflow
75  bool m_overFlow;
76 
77  static const int MAX_NBITS = 24;
78 };
79 
80 template <int nBits>
81 std::ostream& operator<<(std::ostream& s, const L1GctUnsignedInt<nBits>& data);
82 
83 template <int nBits>
85  m_nBits = nBits > 0 && nBits < MAX_NBITS ? nBits : 16;
86  this->reset();
87 }
88 
89 template <int nBits>
91  m_nBits = nBits > 0 && nBits < MAX_NBITS ? nBits : 16;
92  m_overFlow = false;
93  this->setValue(value);
94 }
95 
96 template <int nBits>
98 
99 // copy contructor to move data between
100 // representations with different numbers of bits
101 template <int nBits>
102 template <int mBits>
104  m_nBits = nBits > 0 && nBits < MAX_NBITS ? nBits : 16;
105  this->setValue(rhs.value());
106  this->setOverFlow(this->overFlow() || rhs.overFlow());
107 }
108 
109 // set value, checking for overflow
110 template <int nBits>
112  // check for overflow
113  if (value >= (static_cast<unsigned>(1 << m_nBits))) {
114  m_overFlow = true;
115  }
116 
117  // set value with bitmask
118  m_value = value & ((1 << m_nBits) - 1);
119 }
120 
121 // add two unsigneds
122 template <int nBits>
124  // temporary variable for storing the result (need to set its size)
126 
127  unsigned sum;
128  bool ofl;
129 
130  // do the addition here
131  sum = this->value() + rhs.value();
132  ofl = this->overFlow() || rhs.overFlow();
133 
134  //fill the temporary argument
135  temp.setValue(sum);
136  temp.setOverFlow(temp.overFlow() || ofl);
137 
138  // return the temporary
139  return temp;
140 }
141 
142 // overload assignment by int
143 template <int nBits>
145  this->setValue(value);
146  return *this;
147 }
148 
149 // overload ostream<<
150 template <int nBits>
151 std::ostream& operator<<(std::ostream& s, const L1GctUnsignedInt<nBits>& data) {
152  s << "L1GctUnsignedInt value : " << data.value();
153  if (data.overFlow()) {
154  s << " Overflow set! ";
155  }
156 
157  return s;
158 }
159 
160 #endif
void setOverFlow(bool oflow)
set the overflow bit
Definition of unsigned integer types with overflow.
bool setValue(Container &, const reco::JetBaseRef &, const JetExtendedData &)
associate jet with value. Returns false and associate nothing if jet is already associated ...
unsigned value() const
access value as unsigned
static const int MAX_NBITS
~L1GctUnsignedInt()
Destructor.
L1GctUnsignedInt()
Construct an unsigned integer with initial value zero.
int size() const
return number of bits
void reset()
reset value and overflow to zero
L1GctUnsignedInt operator+(const L1GctUnsignedInt &rhs) const
add two numbers
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
void setValue(unsigned value)
Set value from unsigned.
L1GctUnsignedInt & operator=(int value)
overload = operator
bool overFlow() const
access overflow
void reset(double vett[256])
Definition: TPedValues.cc:11