CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 28 of file L1GctTwosComplement.h.

Constructor & Destructor Documentation

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

Construct a signed integer with initial value zero.

Definition at line 99 of file L1GctTwosComplement.h.

References reset().

99  {
100  m_nBits = nBits > 0 && nBits < MAX_NBITS ? nBits : 16;
101  this->reset();
102 }
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 106 of file L1GctTwosComplement.h.

106  {
107  m_nBits = nBits > 0 && nBits < MAX_NBITS ? nBits : 16;
108  m_overFlow = false;
109  this->setRaw(raw);
110 }
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 114 of file L1GctTwosComplement.h.

References reco::JetExtendedAssociation::setValue().

114  {
115  m_nBits = nBits > 0 && nBits < MAX_NBITS ? nBits : 16;
116  m_overFlow = false;
117  this->setValue(value);
118 }
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 37 of file L1GctTwosComplement.h.

37 {}
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 124 of file L1GctTwosComplement.h.

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

124  {
125  m_nBits = nBits > 0 && nBits < MAX_NBITS ? nBits : 16;
126  this->setRaw(rhs.raw());
127  this->setOverFlow(this->overFlow() || rhs.overFlow());
128 }
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 217 of file L1GctTwosComplement.h.

References relativeConstraints::value.

217  {
218  uint32_t signBit = 1 << (m_nBits - 1);
219  uint32_t signExtendBits = (static_cast<uint32_t>(MAX_VALUE) - signBit) << 1;
220  // Consider and return only MAX_NBITS least significant bits
221  uint32_t mskRawValue = rawValue & ((1 << MAX_NBITS) - 1);
222  uint32_t value;
223  bool ofl;
224 
225  if ((mskRawValue & signBit) == 0) {
226  value = mskRawValue & ~signExtendBits;
227  } else {
228  value = mskRawValue | signExtendBits;
229  }
230  ofl = value != mskRawValue;
231 
232  maskValue = value;
233  overFlow = ofl;
234 }
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 181 of file L1GctTwosComplement.h.

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

181  {
182  // temporary variable for storing the result (need to set its size)
184  uint32_t sum;
185  bool ofl;
186 
187  // do the addition here
188  sum = this->raw() + rhs.raw();
189  ofl = this->overFlow() || rhs.overFlow();
190 
191  //fill the temporary argument
192  temp.setRaw(sum);
193  temp.setOverFlow(temp.overFlow() || ofl);
194 
195  // return the temporary
196  return temp;
197 }
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 201 of file L1GctTwosComplement.h.

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

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  this->setValue(value);
212  return *this;
213 }
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 132 of file L1GctTwosComplement.h.

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

132  {
133  m_data = static_cast<uint32_t>(0);
134  m_overFlow = false;
135 }
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 139 of file L1GctTwosComplement.h.

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

139  {
141 }
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 145 of file L1GctTwosComplement.h.

References relativeConstraints::value.

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

145  {
146  int chkValue, posValue;
147  uint32_t raw;
148 
149  // Make sure we have an integer in the range MAX_NBITS
150  chkValue = value;
151  if (chkValue < -MAX_VALUE) {
152  chkValue = -MAX_VALUE;
153  m_overFlow = true;
154  }
155  if (chkValue >= MAX_VALUE) {
156  chkValue = MAX_VALUE - 1;
157  m_overFlow = true;
158  }
159 
160  // Transform negative values to large positive values
161  posValue = chkValue < 0 ? chkValue + (1 << MAX_NBITS) : chkValue;
162  raw = static_cast<uint32_t>(posValue);
163 
164  // Use the setRaw method to check overflow for our given size nBits
165  this->setRaw(raw);
166 }
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 65 of file L1GctTwosComplement.h.

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

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

access value as signed int

Definition at line 170 of file L1GctTwosComplement.h.

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

Referenced by Types.int32::__nonzero__(), Types.uint32::__nonzero__(), Types.int64::__nonzero__(), Types.uint64::__nonzero__(), Types.double::__nonzero__(), Types.bool::__nonzero__(), Types.string::__nonzero__(), average.Average::average(), Types.string::configValue(), Types.FileInPath::configValue(), L1GctMet::inputOverFlow(), Types.int32::insertInto(), Types.uint32::insertInto(), Types.int64::insertInto(), Types.uint64::insertInto(), Types.double::insertInto(), Types.bool::insertInto(), Types.string::insertInto(), Types.FileInPath::insertInto(), Types.vint32::insertInto(), Types.vuint32::insertInto(), Types.vint64::insertInto(), Types.vuint64::insertInto(), Types.vdouble::insertInto(), Types.vbool::insertInto(), Types.vstring::insertInto(), and L1GctMet::metVector().

170  {
171  int value, result;
172  int maxValueInNbits;
173  maxValueInNbits = 1 << (m_nBits - 1);
174  value = static_cast<int>(m_data);
175  result = value < maxValueInNbits ? value : value - (1 << MAX_NBITS);
176  return result;
177 }
tuple result
Definition: mps_fire.py:311
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 86 of file L1GctTwosComplement.h.

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

Definition at line 87 of file L1GctTwosComplement.h.