CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1GctUnsignedInt.h
Go to the documentation of this file.
1 #ifndef L1GCTUNSIGNEDINT_H
2 #define L1GCTUNSIGNEDINT_H
3 
4 #include <boost/cstdint.hpp>
5 #include <ostream>
6 
28 template <int nBits>
30 
31  public:
32 
36  L1GctUnsignedInt(unsigned value);
39 
41  template <int mBits> L1GctUnsignedInt(const L1GctUnsignedInt<mBits>& rhs);
42 
44  void reset() { m_value = static_cast<unsigned>(0); m_overFlow = false; }
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 
69  // number of bits
70  int m_nBits;
71 
72  // value
73  unsigned m_value;
74 
75  // overflow
76  bool m_overFlow;
77 
78  static const int MAX_NBITS = 24;
79 
80 };
81 
82 template <int nBits>
83 std::ostream& operator<<(std::ostream& s, const L1GctUnsignedInt<nBits>& data);
84 
85 template <int nBits>
87 
88  m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
89  this->reset();
90 }
91 
92 template <int nBits>
94 
95  m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
96  m_overFlow = false;
97  this->setValue(value);
98 }
99 
100 template <int nBits>
102 {
103 
104 }
105 
106 // copy contructor to move data between
107 // representations with different numbers of bits
108 template <int nBits>
109 template <int mBits>
111  m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
112  this->setValue( rhs.value() );
113  this->setOverFlow( this->overFlow() || rhs.overFlow() );
114 }
115 
116 // set value, checking for overflow
117 template <int nBits>
119 {
120  // check for overflow
121  if (value >= (static_cast<unsigned>(1<<m_nBits)) ) {
122  m_overFlow = true;
123  }
124 
125  // set value with bitmask
126  m_value = value & ((1<<m_nBits) - 1);
127 
128 }
129 
130 // add two unsigneds
131 template <int nBits>
134 
135  // temporary variable for storing the result (need to set its size)
137 
138  unsigned sum;
139  bool ofl;
140 
141  // do the addition here
142  sum = this->value() + rhs.value();
143  ofl = this->overFlow() || rhs.overFlow();
144 
145  //fill the temporary argument
146  temp.setValue(sum);
147  temp.setOverFlow(temp.overFlow() || ofl);
148 
149  // return the temporary
150  return temp;
151 
152 }
153 
154 // overload assignment by int
155 template <int nBits>
157 
158  this->setValue(value);
159  return *this;
160 
161 }
162 
163 
164 // overload ostream<<
165 template <int nBits>
166 std::ostream& operator<<(std::ostream& s, const L1GctUnsignedInt<nBits>& data) {
167 
168  s << "L1GctUnsignedInt value : " << data.value();
169  if (data.overFlow()) { s << " Overflow set! "; }
170 
171  return s;
172 
173 }
174 
175 
176 #endif
177 
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:82
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