CMS 3D CMS Logo

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

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

#include <L1GctUnsignedInt.h>

Inheritance diagram for L1GctUnsignedInt< nBits >:
L1GctJetCount< nBits > L1GctJetCount< kHfCountBits > L1GctJetCount< kHfEtSumBits >

Public Member Functions

 L1GctUnsignedInt ()
 Construct an unsigned integer with initial value zero. More...
 
 L1GctUnsignedInt (unsigned value)
 Construct an unsigned integer and check for overFlow. More...
 
template<int mBits>
 L1GctUnsignedInt (const L1GctUnsignedInt< mBits > &rhs)
 Copy contructor to move data between representations with different numbers of bits. More...
 
L1GctUnsignedInt operator+ (const L1GctUnsignedInt &rhs) const
 add two numbers More...
 
L1GctUnsignedIntoperator= (int value)
 overload = operator More...
 
bool overFlow () const
 access overflow More...
 
void reset ()
 reset value and overflow to zero More...
 
void setOverFlow (bool oflow)
 set the overflow bit More...
 
void setValue (unsigned value)
 Set value from unsigned. More...
 
int size () const
 return number of bits More...
 
unsigned value () const
 access value as unsigned More...
 
 ~L1GctUnsignedInt ()
 Destructor. More...
 

Protected Attributes

int m_nBits
 
bool m_overFlow
 
unsigned m_value
 

Static Protected Attributes

static const int MAX_NBITS = 24
 

Detailed Description

template<int nBits>
class L1GctUnsignedInt< nBits >

Definition of unsigned integer types with overflow.

This file defines the template class L1GctUnsignedInt. 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 unsigned integers; signed integers are represented by L1GctTwosComplement. 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 L1GctUnsignedInt.h.

Constructor & Destructor Documentation

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

Construct an unsigned integer with initial value zero.

Definition at line 86 of file L1GctUnsignedInt.h.

References reset().

86  {
87 
88  m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
89  this->reset();
90 }
static const int MAX_NBITS
void reset()
reset value and overflow to zero
template<int nBits>
L1GctUnsignedInt< nBits >::L1GctUnsignedInt ( unsigned  value)

Construct an unsigned integer and check for overFlow.

Definition at line 93 of file L1GctUnsignedInt.h.

References reco::JetExtendedAssociation::setValue().

93  {
94 
95  m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
96  m_overFlow = false;
97  this->setValue(value);
98 }
unsigned value() const
access value as unsigned
static const int MAX_NBITS
void setValue(unsigned value)
Set value from unsigned.
template<int nBits>
L1GctUnsignedInt< nBits >::~L1GctUnsignedInt ( )

Destructor.

Definition at line 101 of file L1GctUnsignedInt.h.

102 {
103 
104 }
template<int nBits>
template<int mBits>
L1GctUnsignedInt< nBits >::L1GctUnsignedInt ( const L1GctUnsignedInt< mBits > &  rhs)

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

Definition at line 110 of file L1GctUnsignedInt.h.

References L1GctUnsignedInt< nBits >::overFlow(), reco::JetExtendedAssociation::setValue(), and L1GctUnsignedInt< nBits >::value().

110  {
111  m_nBits = nBits>0 && nBits<MAX_NBITS ? nBits : 16 ;
112  this->setValue( rhs.value() );
113  this->setOverFlow( this->overFlow() || rhs.overFlow() );
114 }
void setOverFlow(bool oflow)
set the overflow bit
unsigned value() const
access value as unsigned
static const int MAX_NBITS
void setValue(unsigned value)
Set value from unsigned.
bool overFlow() const
access overflow

Member Function Documentation

template<int nBits>
L1GctUnsignedInt< nBits > L1GctUnsignedInt< nBits >::operator+ ( const L1GctUnsignedInt< nBits > &  rhs) const

add two numbers

Definition at line 133 of file L1GctUnsignedInt.h.

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

133  {
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 }
void setOverFlow(bool oflow)
set the overflow bit
Definition of unsigned integer types with overflow.
unsigned value() const
access value as unsigned
void setValue(unsigned value)
Set value from unsigned.
bool overFlow() const
access overflow
template<int nBits>
L1GctUnsignedInt< nBits > & L1GctUnsignedInt< nBits >::operator= ( int  value)

overload = operator

Definition at line 156 of file L1GctUnsignedInt.h.

References reco::JetExtendedAssociation::setValue().

156  {
157 
158  this->setValue(value);
159  return *this;
160 
161 }
unsigned value() const
access value as unsigned
void setValue(unsigned value)
Set value from unsigned.
template<int nBits>
bool L1GctUnsignedInt< nBits >::overFlow ( ) const
inline
template<int nBits>
void L1GctUnsignedInt< nBits >::reset ( void  )
inline

reset value and overflow to zero

Definition at line 44 of file L1GctUnsignedInt.h.

Referenced by L1GctJetFinderBase::hfTowerSumsType::reset(), L1GctWheelEnergyFpga::resetProcessor(), L1GctJetLeafCard::resetProcessor(), and L1GctGlobalEnergyAlgos::resetProcessor().

44 { m_value = static_cast<unsigned>(0); m_overFlow = false; }
template<int nBits>
void L1GctUnsignedInt< nBits >::setOverFlow ( bool  oflow)
inline
template<int nBits>
void L1GctUnsignedInt< nBits >::setValue ( unsigned  value)

Set value from unsigned.

Definition at line 118 of file L1GctUnsignedInt.h.

Referenced by L1GctJetFinderBase::doEtSums(), L1GctJetFinderBase::doHtSums(), L1GctMet::metVector(), L1GctUnsignedInt< nBits >::operator+(), L1GctWheelEnergyFpga::process(), L1GctGlobalEnergyAlgos::process(), L1GctJetLeafCard::process(), L1GctGlobalEnergyAlgos::setInputWheelEt(), and L1GctGlobalEnergyAlgos::setInputWheelHt().

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 }
unsigned value() const
access value as unsigned
template<int nBits>
int L1GctUnsignedInt< nBits >::size ( void  ) const
inline

return number of bits

Definition at line 59 of file L1GctUnsignedInt.h.

59 { return m_nBits; }
template<int nBits>
unsigned L1GctUnsignedInt< nBits >::value ( void  ) const
inline

Member Data Documentation

template<int nBits>
int L1GctUnsignedInt< nBits >::m_nBits
protected
template<int nBits>
bool L1GctUnsignedInt< nBits >::m_overFlow
protected
template<int nBits>
unsigned L1GctUnsignedInt< nBits >::m_value
protected
template<int nBits>
const int L1GctUnsignedInt< nBits >::MAX_NBITS = 24
staticprotected

Definition at line 78 of file L1GctUnsignedInt.h.