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 | 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 27 of file L1GctUnsignedInt.h.

Constructor & Destructor Documentation

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

Construct an unsigned integer with initial value zero.

Definition at line 84 of file L1GctUnsignedInt.h.

References reset().

84  {
85  m_nBits = nBits > 0 && nBits < MAX_NBITS ? nBits : 16;
86  this->reset();
87 }
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 90 of file L1GctUnsignedInt.h.

References reco::JetExtendedAssociation::setValue().

90  {
91  m_nBits = nBits > 0 && nBits < MAX_NBITS ? nBits : 16;
92  m_overFlow = false;
93  this->setValue(value);
94 }
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 97 of file L1GctUnsignedInt.h.

97 {}
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 103 of file L1GctUnsignedInt.h.

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

103  {
104  m_nBits = nBits > 0 && nBits < MAX_NBITS ? nBits : 16;
105  this->setValue(rhs.value());
106  this->setOverFlow(this->overFlow() || rhs.overFlow());
107 }
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 123 of file L1GctUnsignedInt.h.

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

123  {
124  // temporary variable for storing the result (need to set its size)
126 
127  unsigned sum;
128  bool ofl;
129 
130  // do the addition here
131  sum = this->value() + rhs.value();
132  ofl = this->overFlow() || rhs.overFlow();
133 
134  //fill the temporary argument
135  temp.setValue(sum);
136  temp.setOverFlow(temp.overFlow() || ofl);
137 
138  // return the temporary
139  return temp;
140 }
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 144 of file L1GctUnsignedInt.h.

References reco::JetExtendedAssociation::setValue().

144  {
145  this->setValue(value);
146  return *this;
147 }
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 41 of file L1GctUnsignedInt.h.

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

41  {
42  m_value = static_cast<unsigned>(0);
43  m_overFlow = false;
44  }
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 111 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().

111  {
112  // check for overflow
113  if (value >= (static_cast<unsigned>(1 << m_nBits))) {
114  m_overFlow = true;
115  }
116 
117  // set value with bitmask
118  m_value = value & ((1 << m_nBits) - 1);
119 }
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.

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

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 77 of file L1GctUnsignedInt.h.