CMS 3D CMS Logo

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>

List of all members.

Public Member Functions

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

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 https://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().

                                                {
  m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
  this->reset();
}
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.

                                                            {
  m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
  m_overFlow = false;
  this->setRaw(raw);
}
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().

                                                         {
  m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
  m_overFlow = false;
  this->setValue(value);
}
template<int nBits>
L1GctTwosComplement< nBits >::~L1GctTwosComplement ( ) [inline]

Destructor.

Definition at line 38 of file L1GctTwosComplement.h.

{ }
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().

                                                                                     {
  m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
  this->setRaw( rhs.raw() );
  this->setOverFlow( this->overFlow() || rhs.overFlow() );
}

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.

                                                                                                     {
  uint32_t signBit = 1<<(m_nBits-1);
  uint32_t signExtendBits = (static_cast<uint32_t>(MAX_VALUE)-signBit)<<1;
  // Consider and return only MAX_NBITS least significant bits
  uint32_t mskRawValue = rawValue & ((1<<MAX_NBITS)-1);
  uint32_t value;
  bool ofl;

  if ((mskRawValue&signBit)==0) {
    value = mskRawValue & ~signExtendBits;
  } else {
    value = mskRawValue | signExtendBits;
  }
  ofl = value != mskRawValue;

  maskValue = value;
  overFlow  = ofl;

}
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(), runTheMatrix_dev::raw, L1GctTwosComplement< nBits >::setOverFlow(), L1GctTwosComplement< nBits >::setRaw(), and cond::rpcobtemp::temp.

                                                                                  {

  // temporary variable for storing the result (need to set its size)
  L1GctTwosComplement<nBits> temp;
  uint32_t sum;
  bool ofl;

  // do the addition here
  sum = this->raw() + rhs.raw();
  ofl = this->overFlow() || rhs.overFlow();

  //fill the temporary argument
  temp.setRaw(sum);
  temp.setOverFlow(temp.overFlow() || ofl);

  // return the temporary
  return temp;

}
template<int nBits>
L1GctTwosComplement< nBits > L1GctTwosComplement< nBits >::operator- ( ) const
template<int nBits>
L1GctTwosComplement< nBits > & L1GctTwosComplement< nBits >::operator= ( int  value)

overload = operator

Definition at line 210 of file L1GctTwosComplement.h.

References reco::JetExtendedAssociation::setValue().

                                                                            {
  
  this->setValue(value);
  return *this;

}
template<int nBits>
bool L1GctTwosComplement< nBits >::overFlow ( ) const [inline]
template<int nBits>
uint32_t L1GctTwosComplement< nBits >::raw ( ) const [inline]

access raw data

Definition at line 57 of file L1GctTwosComplement.h.

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

{ return m_data; }
template<int nBits>
void L1GctTwosComplement< nBits >::reset ( void  )

reset value and overflow to zero

Definition at line 134 of file L1GctTwosComplement.h.

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

                                       {
  m_data = static_cast<uint32_t>(0);
  m_overFlow = false;
}
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+().

template<int nBits>
void L1GctTwosComplement< nBits >::setValue ( int  value)

set value from signed int

Definition at line 147 of file L1GctTwosComplement.h.

References runTheMatrix_dev::raw, and relativeConstraints::value.

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

                                                   {
  int chkValue, posValue;
  uint32_t raw;

  // Make sure we have an integer in the range MAX_NBITS
  chkValue = value;
  if (chkValue<-MAX_VALUE) { chkValue =  -MAX_VALUE; m_overFlow = true; }
  if (chkValue>=MAX_VALUE) { chkValue = MAX_VALUE-1; m_overFlow = true; }

  // Transform negative values to large positive values
  posValue = chkValue<0 ? chkValue + (1<<MAX_NBITS) : chkValue ;
  raw = static_cast<uint32_t>(posValue);

  // Use the setRaw method to check overflow for our given size nBits
  this->setRaw(raw);
}
template<int nBits>
int L1GctTwosComplement< nBits >::size ( void  ) const [inline]

return number of bits

Definition at line 66 of file L1GctTwosComplement.h.

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

access value as signed int

Definition at line 166 of file L1GctTwosComplement.h.

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

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

                                            {
  int value, result;
  int maxValueInNbits;
  maxValueInNbits = 1<<(m_nBits-1);
  value  = static_cast<int>(m_data);
  result = value < maxValueInNbits ? value : value - (1<<MAX_NBITS) ;
  return result;
}

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 [static, private]

Definition at line 88 of file L1GctTwosComplement.h.

template<int nBits>
const int L1GctTwosComplement< nBits >::MAX_VALUE = 1<<(MAX_NBITS-1) [static, private]

Definition at line 89 of file L1GctTwosComplement.h.