CMS 3D CMS Logo

L1GctTwosComplement< nBits > Class Template Reference

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

#include <L1Trigger/GlobalCaloTrigger/src/L1GctTwosComplement.h>

List of all members.

Public Member Functions

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 (uint32_t raw)
 Construct a signed integer from raw data, checking for overFlow.
 L1GctTwosComplement ()
 Construct a signed integer with initial value zero.
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 (  )  [inline]

Construct a signed integer with initial value zero.

Definition at line 101 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::m_nBits, L1GctTwosComplement< nBits >::MAX_NBITS, and L1GctTwosComplement< nBits >::reset().

00101                                                 {
00102   m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
00103   this->reset();
00104 }

template<int nBits>
L1GctTwosComplement< nBits >::L1GctTwosComplement ( uint32_t  raw  )  [inline]

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

Definition at line 108 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::m_nBits, L1GctTwosComplement< nBits >::m_overFlow, L1GctTwosComplement< nBits >::MAX_NBITS, and L1GctTwosComplement< nBits >::setRaw().

00108                                                             {
00109   m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
00110   m_overFlow = false;
00111   this->setRaw(raw);
00112 }

template<int nBits>
L1GctTwosComplement< nBits >::L1GctTwosComplement ( int  value  )  [inline]

Construct a signed integer, checking for overflow.

Definition at line 116 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::m_nBits, L1GctTwosComplement< nBits >::m_overFlow, L1GctTwosComplement< nBits >::MAX_NBITS, and L1GctTwosComplement< nBits >::setValue().

00116                                                          {
00117   m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
00118   m_overFlow = false;
00119   this->setValue(value);
00120 }

template<int nBits>
L1GctTwosComplement< nBits >::~L1GctTwosComplement (  )  [inline]

Destructor.

Definition at line 38 of file L1GctTwosComplement.h.

00038 { }

template<int nBits>
template<int mBits>
L1GctTwosComplement< nBits >::L1GctTwosComplement ( const L1GctTwosComplement< mBits > &  rhs  )  [inline]

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

Definition at line 126 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::m_nBits, L1GctTwosComplement< nBits >::MAX_NBITS, L1GctTwosComplement< nBits >::overFlow(), L1GctTwosComplement< nBits >::raw(), L1GctTwosComplement< nBits >::setOverFlow(), and L1GctTwosComplement< nBits >::setRaw().

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


Member Function Documentation

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

Definition at line 219 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::m_nBits, L1GctTwosComplement< nBits >::MAX_NBITS, L1GctTwosComplement< nBits >::MAX_VALUE, and L1GctTwosComplement< nBits >::value().

Referenced by L1GctTwosComplement< nBits >::setRaw().

00219                                                                                                      {
00220   uint32_t signBit = 1<<(m_nBits-1);
00221   uint32_t signExtendBits = (static_cast<uint32_t>(MAX_VALUE)-signBit)<<1;
00222   // Consider and return only MAX_NBITS least significant bits
00223   uint32_t mskRawValue = rawValue & ((1<<MAX_NBITS)-1);
00224   uint32_t value;
00225   bool ofl;
00226 
00227   if ((mskRawValue&signBit)==0) {
00228     value = mskRawValue & ~signExtendBits;
00229   } else {
00230     value = mskRawValue | signExtendBits;
00231   }
00232   ofl = value != mskRawValue;
00233 
00234   maskValue = value;
00235   overFlow  = ofl;
00236 
00237 }

template<int nBits>
L1GctTwosComplement< nBits > L1GctTwosComplement< nBits >::operator+ ( const L1GctTwosComplement< nBits > &  rhs  )  const [inline]

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(), sum(), and pyDBSRunClass::temp.

00178                                                                                   {
00179 
00180   // temporary variable for storing the result (need to set its size)
00181   L1GctTwosComplement<nBits> temp;
00182   uint32_t sum;
00183   bool ofl;
00184 
00185   // do the addition here
00186   sum = this->raw() + rhs.raw();
00187   ofl = this->overFlow() || rhs.overFlow();
00188 
00189   //fill the temporary argument
00190   temp.setRaw(sum);
00191   temp.setOverFlow(temp.overFlow() || ofl);
00192 
00193   // return the temporary
00194   return temp;
00195 
00196 }

template<int nBits>
L1GctTwosComplement< nBits > L1GctTwosComplement< nBits >::operator- (  )  const [inline]

overload unary - (negation) operator

Definition at line 200 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::overFlow(), L1GctTwosComplement< nBits >::setOverFlow(), L1GctTwosComplement< nBits >::setValue(), and pyDBSRunClass::temp.

00200                                                                         {
00201 
00202   L1GctTwosComplement<nBits> temp;
00203   temp.setValue(-this->value());
00204   temp.setOverFlow(temp.overFlow() || this->overFlow());
00205   return temp;
00206 }

template<int nBits>
L1GctTwosComplement< nBits > & L1GctTwosComplement< nBits >::operator= ( int  value  )  [inline]

overload = operator

Definition at line 210 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::setValue().

00210                                                                             {
00211   
00212   this->setValue(value);
00213   return *this;
00214 
00215 }

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

access overflow

Definition at line 63 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::m_overFlow.

Referenced by L1GctJetLeafCard::etValueForJetFinder(), L1GctTwosComplement< nBits >::L1GctTwosComplement(), L1GctMet::metVector(), L1GctTwosComplement< nBits >::operator+(), and L1GctTwosComplement< nBits >::operator-().

00063 { return m_overFlow; }

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

access raw data

Definition at line 57 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::m_data.

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

00057 { return m_data; }

template<int nBits>
void L1GctTwosComplement< nBits >::reset ( void   )  [inline]

reset value and overflow to zero

Definition at line 134 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::m_data, and L1GctTwosComplement< nBits >::m_overFlow.

Referenced by L1GctTwosComplement< nBits >::L1GctTwosComplement(), L1GctJetLeafCard::process(), L1GctJetLeafCard::resetProcessor(), L1GctWheelJetFpga::resetProcessor(), L1GctGlobalEnergyAlgos::resetProcessor(), and L1GctWheelEnergyFpga::resetProcessor().

00134                                        {
00135   m_data = static_cast<uint32_t>(0);
00136   m_overFlow = false;
00137 }

template<int nBits>
void L1GctTwosComplement< nBits >::setOverFlow ( bool  oflow  )  [inline]

set the overflow bit

Definition at line 54 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::m_overFlow.

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

00054 { m_overFlow = oflow; }

template<int nBits>
void L1GctTwosComplement< nBits >::setRaw ( uint32_t  raw  )  [inline]

set the raw data

Definition at line 141 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::checkOverFlow(), L1GctTwosComplement< nBits >::m_data, and L1GctTwosComplement< nBits >::m_overFlow.

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

00141                                                     {
00142   checkOverFlow(raw, m_data, m_overFlow);
00143 }

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

set value from signed int

Definition at line 147 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::m_overFlow, L1GctTwosComplement< nBits >::MAX_NBITS, L1GctTwosComplement< nBits >::MAX_VALUE, L1GctTwosComplement< nBits >::raw(), and L1GctTwosComplement< nBits >::setRaw().

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

00147                                                    {
00148   int chkValue, posValue;
00149   uint32_t raw;
00150 
00151   // Make sure we have an integer in the range MAX_NBITS
00152   chkValue = value;
00153   if (chkValue<-MAX_VALUE) { chkValue =  -MAX_VALUE; m_overFlow = true; }
00154   if (chkValue>=MAX_VALUE) { chkValue = MAX_VALUE-1; m_overFlow = true; }
00155 
00156   // Transform negative values to large positive values
00157   posValue = chkValue<0 ? chkValue + (1<<MAX_NBITS) : chkValue ;
00158   raw = static_cast<uint32_t>(posValue);
00159 
00160   // Use the setRaw method to check overflow for our given size nBits
00161   this->setRaw(raw);
00162 }

template<int nBits>
int L1GctTwosComplement< nBits >::size ( void   )  const [inline]

return number of bits

Definition at line 66 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::m_nBits.

00066 { return m_nBits; }

template<int nBits>
int L1GctTwosComplement< nBits >::value ( void   )  const [inline]

access value as signed int

Definition at line 166 of file L1GctTwosComplement.h.

References L1GctTwosComplement< nBits >::m_data, L1GctTwosComplement< nBits >::m_nBits, L1GctTwosComplement< nBits >::MAX_NBITS, and HLT_VtxMuL3::result.

Referenced by L1GctTwosComplement< nBits >::checkOverFlow(), and L1GctMet::metVector().

00166                                             {
00167   int value, result;
00168   int maxValueInNbits;
00169   maxValueInNbits = 1<<(m_nBits-1);
00170   value  = static_cast<int>(m_data);
00171   result = value < maxValueInNbits ? value : value - (1<<MAX_NBITS) ;
00172   return result;
00173 }


Member Data Documentation

template<int nBits>
uint32_t L1GctTwosComplement< nBits >::m_data [private]

Definition at line 83 of file L1GctTwosComplement.h.

Referenced by L1GctTwosComplement< nBits >::raw(), L1GctTwosComplement< nBits >::reset(), L1GctTwosComplement< nBits >::setRaw(), and L1GctTwosComplement< nBits >::value().

template<int nBits>
int L1GctTwosComplement< nBits >::m_nBits [private]

Definition at line 80 of file L1GctTwosComplement.h.

Referenced by L1GctTwosComplement< nBits >::checkOverFlow(), L1GctTwosComplement< nBits >::L1GctTwosComplement(), L1GctTwosComplement< nBits >::size(), and L1GctTwosComplement< nBits >::value().

template<int nBits>
bool L1GctTwosComplement< nBits >::m_overFlow [private]

Definition at line 86 of file L1GctTwosComplement.h.

Referenced by L1GctTwosComplement< nBits >::L1GctTwosComplement(), L1GctTwosComplement< nBits >::overFlow(), L1GctTwosComplement< nBits >::reset(), L1GctTwosComplement< nBits >::setOverFlow(), L1GctTwosComplement< nBits >::setRaw(), and L1GctTwosComplement< nBits >::setValue().

template<int nBits>
const int L1GctTwosComplement< nBits >::MAX_NBITS = 24 [static, private]

Definition at line 88 of file L1GctTwosComplement.h.

Referenced by L1GctTwosComplement< nBits >::checkOverFlow(), L1GctTwosComplement< nBits >::L1GctTwosComplement(), L1GctTwosComplement< nBits >::setValue(), and L1GctTwosComplement< nBits >::value().

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

Definition at line 89 of file L1GctTwosComplement.h.

Referenced by L1GctTwosComplement< nBits >::checkOverFlow(), and L1GctTwosComplement< nBits >::setValue().


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:26:39 2009 for CMSSW by  doxygen 1.5.4