test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
L1GctTwosComplement< nBits > Class Template Reference

Definition of signed integer types with overflow. More...

#include <L1GctTwosComplement.h>

Public Member Functions

 L1GctTwosComplement ()
 Construct a signed integer with initial value zero. More...
 
 L1GctTwosComplement (uint32_t raw)
 Construct a signed integer from raw data, checking for overFlow. More...
 
 L1GctTwosComplement (int value)
 Construct a signed integer, checking for overflow. More...
 
template<int mBits>
 L1GctTwosComplement (const L1GctTwosComplement< mBits > &rhs)
 Copy contructor to move data between representations with different numbers of bits. More...
 
L1GctTwosComplement operator+ (const L1GctTwosComplement &rhs) const
 add two numbers of the same size More...
 
L1GctTwosComplement operator- () const
 overload unary - (negation) operator More...
 
L1GctTwosComplementoperator= (int value)
 overload = operator More...
 
bool overFlow () const
 access overflow More...
 
uint32_t raw () const
 access raw data More...
 
void reset ()
 reset value and overflow to zero More...
 
void setOverFlow (bool oflow)
 set the overflow bit More...
 
void setRaw (uint32_t raw)
 set the raw data More...
 
void setValue (int value)
 set value from signed int More...
 
int size () const
 return number of bits More...
 
int value () const
 access value as signed int More...
 
 ~L1GctTwosComplement ()
 Destructor. More...
 

Private Member Functions

void checkOverFlow (uint32_t rawValue, uint32_t &maskValue, bool &overFlow)
 

Private Attributes

uint32_t m_data
 
int m_nBits
 
bool m_overFlow
 

Static Private Attributes

static const int MAX_NBITS = 24
 
static const int MAX_VALUE = 1<<(MAX_NBITS-1)
 

Detailed Description

template<int nBits>
class L1GctTwosComplement< nBits >

Definition of signed integer types with overflow.

This file defines the template class L1GctTwosComplement. It is used to store energy values that are represented in a given number of bits in hardware. The type has a built-in overFlow that is set if the value to be represented is outside the allowed range for that number of bits. This type represents signed integers; unsigned integers are represented by L1GctUnsignedInt. Functions are defined to add two values, and to copy data into a different number of bits.

this header file contains method definitions because these are template classes see http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12

Author
Jim Brooke & Greg Heath
Date
May 2006

Definition at line 29 of file L1GctTwosComplement.h.

Constructor & Destructor Documentation

template<int nBits>
L1GctTwosComplement< nBits >::L1GctTwosComplement ( )

Construct a signed integer with initial value zero.

Definition at line 101 of file L1GctTwosComplement.h.

References reset().

101  {
102  m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
103  this->reset();
104 }
void reset()
reset value and overflow to zero
static const int MAX_NBITS
template<int nBits>
L1GctTwosComplement< nBits >::L1GctTwosComplement ( uint32_t  raw)

Construct a signed integer from raw data, checking for overFlow.

Definition at line 108 of file L1GctTwosComplement.h.

108  {
109  m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
110  m_overFlow = false;
111  this->setRaw(raw);
112 }
void setRaw(uint32_t raw)
set the raw data
uint32_t raw() const
access raw data
static const int MAX_NBITS
template<int nBits>
L1GctTwosComplement< nBits >::L1GctTwosComplement ( int  value)

Construct a signed integer, checking for overflow.

Definition at line 116 of file L1GctTwosComplement.h.

References reco::JetExtendedAssociation::setValue().

116  {
117  m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
118  m_overFlow = false;
119  this->setValue(value);
120 }
void setValue(int value)
set value from signed int
int value() const
access value as signed int
static const int MAX_NBITS
template<int nBits>
L1GctTwosComplement< nBits >::~L1GctTwosComplement ( )
inline

Destructor.

Definition at line 38 of file L1GctTwosComplement.h.

38 { }
template<int nBits>
template<int mBits>
L1GctTwosComplement< nBits >::L1GctTwosComplement ( const L1GctTwosComplement< mBits > &  rhs)

Copy contructor to move data between representations with different numbers of bits.

Definition at line 126 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::overFlow(), and L1GctTwosComplement< nBits >::raw().

126  {
127  m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
128  this->setRaw( rhs.raw() );
129  this->setOverFlow( this->overFlow() || rhs.overFlow() );
130 }
bool overFlow() const
access overflow
void setOverFlow(bool oflow)
set the overflow bit
void setRaw(uint32_t raw)
set the raw data
uint32_t raw() const
access raw data
static const int MAX_NBITS

Member Function Documentation

template<int nBits>
void L1GctTwosComplement< nBits >::checkOverFlow ( uint32_t  rawValue,
uint32_t &  maskValue,
bool &  overFlow 
)
private

Definition at line 219 of file L1GctTwosComplement.h.

References relativeConstraints::value.

219  {
220  uint32_t signBit = 1<<(m_nBits-1);
221  uint32_t signExtendBits = (static_cast<uint32_t>(MAX_VALUE)-signBit)<<1;
222  // Consider and return only MAX_NBITS least significant bits
223  uint32_t mskRawValue = rawValue & ((1<<MAX_NBITS)-1);
224  uint32_t value;
225  bool ofl;
226 
227  if ((mskRawValue&signBit)==0) {
228  value = mskRawValue & ~signExtendBits;
229  } else {
230  value = mskRawValue | signExtendBits;
231  }
232  ofl = value != mskRawValue;
233 
234  maskValue = value;
235  overFlow = ofl;
236 
237 }
bool overFlow() const
access overflow
static const int MAX_VALUE
int value() const
access value as signed int
static const int MAX_NBITS
template<int nBits>
L1GctTwosComplement< nBits > L1GctTwosComplement< nBits >::operator+ ( const L1GctTwosComplement< nBits > &  rhs) const

add two numbers of the same size

Definition at line 178 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::overFlow(), L1GctTwosComplement< nBits >::raw(), L1GctTwosComplement< nBits >::setOverFlow(), L1GctTwosComplement< nBits >::setRaw(), and groupFilesInBlocks::temp.

178  {
179 
180  // temporary variable for storing the result (need to set its size)
182  uint32_t sum;
183  bool ofl;
184 
185  // do the addition here
186  sum = this->raw() + rhs.raw();
187  ofl = this->overFlow() || rhs.overFlow();
188 
189  //fill the temporary argument
190  temp.setRaw(sum);
191  temp.setOverFlow(temp.overFlow() || ofl);
192 
193  // return the temporary
194  return temp;
195 
196 }
bool overFlow() const
access overflow
void setOverFlow(bool oflow)
set the overflow bit
void setRaw(uint32_t raw)
set the raw data
uint32_t raw() const
access raw data
Definition of signed integer types with overflow.
template<int nBits>
L1GctTwosComplement< nBits > L1GctTwosComplement< nBits >::operator- ( ) const

overload unary - (negation) operator

Definition at line 200 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::overFlow(), L1GctTwosComplement< nBits >::setOverFlow(), L1GctTwosComplement< nBits >::setValue(), groupFilesInBlocks::temp, and relativeConstraints::value.

200  {
201 
203  temp.setValue(-this->value());
204  temp.setOverFlow(temp.overFlow() || this->overFlow());
205  return temp;
206 }
bool overFlow() const
access overflow
void setOverFlow(bool oflow)
set the overflow bit
Definition of signed integer types with overflow.
void setValue(int value)
set value from signed int
int value() const
access value as signed int
template<int nBits>
L1GctTwosComplement< nBits > & L1GctTwosComplement< nBits >::operator= ( int  value)

overload = operator

Definition at line 210 of file L1GctTwosComplement.h.

References reco::JetExtendedAssociation::setValue().

210  {
211 
212  this->setValue(value);
213  return *this;
214 
215 }
void setValue(int value)
set value from signed int
int value() const
access value as signed int
template<int nBits>
bool L1GctTwosComplement< nBits >::overFlow ( ) const
inline
template<int nBits>
uint32_t L1GctTwosComplement< nBits >::raw ( ) const
inline
template<int nBits>
void L1GctTwosComplement< nBits >::reset ( void  )

reset value and overflow to zero

Definition at line 134 of file L1GctTwosComplement.h.

Referenced by L1GctWheelEnergyFpga::resetProcessor(), L1GctWheelJetFpga::resetProcessor(), L1GctJetLeafCard::resetProcessor(), and L1GctGlobalEnergyAlgos::resetProcessor().

134  {
135  m_data = static_cast<uint32_t>(0);
136  m_overFlow = false;
137 }
template<int nBits>
void L1GctTwosComplement< nBits >::setOverFlow ( bool  oflow)
inline
template<int nBits>
void L1GctTwosComplement< nBits >::setRaw ( uint32_t  raw)

set the raw data

Definition at line 141 of file L1GctTwosComplement.h.

Referenced by L1GctTwosComplement< nBits >::operator+().

141  {
143 }
uint32_t raw() const
access raw data
void checkOverFlow(uint32_t rawValue, uint32_t &maskValue, bool &overFlow)
template<int nBits>
void L1GctTwosComplement< nBits >::setValue ( int  value)

set value from signed int

Definition at line 147 of file L1GctTwosComplement.h.

References relativeConstraints::value.

Referenced by L1GctTwosComplement< nBits >::operator-(), L1GctGlobalEnergyAlgos::setInputWheelEx(), L1GctGlobalEnergyAlgos::setInputWheelEy(), L1GctGlobalEnergyAlgos::setInputWheelHx(), and L1GctGlobalEnergyAlgos::setInputWheelHy().

147  {
148  int chkValue, posValue;
149  uint32_t raw;
150 
151  // Make sure we have an integer in the range MAX_NBITS
152  chkValue = value;
153  if (chkValue<-MAX_VALUE) { chkValue = -MAX_VALUE; m_overFlow = true; }
154  if (chkValue>=MAX_VALUE) { chkValue = MAX_VALUE-1; m_overFlow = true; }
155 
156  // Transform negative values to large positive values
157  posValue = chkValue<0 ? chkValue + (1<<MAX_NBITS) : chkValue ;
158  raw = static_cast<uint32_t>(posValue);
159 
160  // Use the setRaw method to check overflow for our given size nBits
161  this->setRaw(raw);
162 }
void setRaw(uint32_t raw)
set the raw data
uint32_t raw() const
access raw data
static const int MAX_VALUE
int value() const
access value as signed int
static const int MAX_NBITS
template<int nBits>
int L1GctTwosComplement< nBits >::size ( void  ) const
inline

return number of bits

Definition at line 66 of file L1GctTwosComplement.h.

Referenced by ntuple._Collection::__iter__(), and ntuple._Collection::__len__().

66 { return m_nBits; }
template<int nBits>
int L1GctTwosComplement< nBits >::value ( void  ) const

access value as signed int

Definition at line 166 of file L1GctTwosComplement.h.

References mps_fire::result, and relativeConstraints::value.

Referenced by average.Average::average(), L1GctMet::inputOverFlow(), and L1GctMet::metVector().

166  {
167  int value, result;
168  int maxValueInNbits;
169  maxValueInNbits = 1<<(m_nBits-1);
170  value = static_cast<int>(m_data);
171  result = value < maxValueInNbits ? value : value - (1<<MAX_NBITS) ;
172  return result;
173 }
tuple result
Definition: mps_fire.py:84
int value() const
access value as signed int
static const int MAX_NBITS

Member Data Documentation

template<int nBits>
uint32_t L1GctTwosComplement< nBits >::m_data
private
template<int nBits>
int L1GctTwosComplement< nBits >::m_nBits
private
template<int nBits>
bool L1GctTwosComplement< nBits >::m_overFlow
private
template<int nBits>
const int L1GctTwosComplement< nBits >::MAX_NBITS = 24
staticprivate

Definition at line 88 of file L1GctTwosComplement.h.

template<int nBits>
const int L1GctTwosComplement< nBits >::MAX_VALUE = 1<<(MAX_NBITS-1)
staticprivate

Definition at line 89 of file L1GctTwosComplement.h.