CMS 3D CMS Logo

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...
 
template<int mBits>
 L1GctUnsignedInt (const L1GctUnsignedInt< mBits > &rhs)
 Copy contructor to move data between representations with different numbers of bits. More...
 
 L1GctUnsignedInt (unsigned value)
 Construct an unsigned integer and check for overFlow. 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

◆ L1GctUnsignedInt() [1/3]

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

Construct an unsigned integer with initial value zero.

Definition at line 84 of file L1GctUnsignedInt.h.

84  {
85  m_nBits = nBits > 0 && nBits < MAX_NBITS ? nBits : 16;
86  this->reset();
87 }

◆ L1GctUnsignedInt() [2/3]

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

Construct an unsigned integer and check for overFlow.

Definition at line 90 of file L1GctUnsignedInt.h.

90  {
91  m_nBits = nBits > 0 && nBits < MAX_NBITS ? nBits : 16;
92  m_overFlow = false;
93  this->setValue(value);
94 }

◆ ~L1GctUnsignedInt()

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

Destructor.

Definition at line 97 of file L1GctUnsignedInt.h.

97 {}

◆ L1GctUnsignedInt() [3/3]

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.

103  {
104  m_nBits = nBits > 0 && nBits < MAX_NBITS ? nBits : 16;
105  this->setValue(rhs.value());
106  this->setOverFlow(this->overFlow() || rhs.overFlow());
107 }

Member Function Documentation

◆ operator+()

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

add two numbers

Definition at line 123 of file L1GctUnsignedInt.h.

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 }

◆ operator=()

template<int nBits>
L1GctUnsignedInt< nBits > & L1GctUnsignedInt< nBits >::operator= ( int  value)

overload = operator

Definition at line 144 of file L1GctUnsignedInt.h.

144  {
145  this->setValue(value);
146  return *this;
147 }

◆ overFlow()

template<int nBits>
bool L1GctUnsignedInt< nBits >::overFlow ( ) const
inline

◆ reset()

template<int nBits>
void L1GctUnsignedInt< nBits >::reset ( void  )
inline

reset value and overflow to zero

Definition at line 41 of file L1GctUnsignedInt.h.

41  {
42  m_value = static_cast<unsigned>(0);
43  m_overFlow = false;
44  }

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

◆ setOverFlow()

template<int nBits>
void L1GctUnsignedInt< nBits >::setOverFlow ( bool  oflow)
inline

◆ setValue()

template<int nBits>
void L1GctUnsignedInt< nBits >::setValue ( unsigned  value)

Set value from unsigned.

Definition at line 111 of file L1GctUnsignedInt.h.

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 }

Referenced by L1GctJetFinderBase::doEtSums(), L1GctJetFinderBase::doHtSums(), L1GctWheelEnergyFpga::process(), L1GctGlobalEnergyAlgos::process(), L1GctJetLeafCard::process(), L1GctGlobalEnergyAlgos::setInputWheelEt(), and L1GctGlobalEnergyAlgos::setInputWheelHt().

◆ size()

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; }

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

◆ value()

template<int nBits>
unsigned L1GctUnsignedInt< nBits >::value ( void  ) const
inline

Member Data Documentation

◆ m_nBits

template<int nBits>
int L1GctUnsignedInt< nBits >::m_nBits
protected

◆ m_overFlow

template<int nBits>
bool L1GctUnsignedInt< nBits >::m_overFlow
protected

◆ m_value

template<int nBits>
unsigned L1GctUnsignedInt< nBits >::m_value
protected

◆ MAX_NBITS

template<int nBits>
const int L1GctUnsignedInt< nBits >::MAX_NBITS = 24
staticprotected

Definition at line 77 of file L1GctUnsignedInt.h.

L1GctUnsignedInt::setValue
void setValue(unsigned value)
Set value from unsigned.
Definition: L1GctUnsignedInt.h:111
L1GctUnsignedInt::m_nBits
int m_nBits
Definition: L1GctUnsignedInt.h:69
L1GctUnsignedInt::value
unsigned value() const
access value as unsigned
Definition: L1GctUnsignedInt.h:53
L1GctUnsignedInt::m_value
unsigned m_value
Definition: L1GctUnsignedInt.h:72
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
value
Definition: value.py:1
L1GctUnsignedInt::m_overFlow
bool m_overFlow
Definition: L1GctUnsignedInt.h:75
L1GctUnsignedInt
Definition of unsigned integer types with overflow.
Definition: L1GctUnsignedInt.h:27
L1GctUnsignedInt::MAX_NBITS
static const int MAX_NBITS
Definition: L1GctUnsignedInt.h:77
L1GctUnsignedInt::reset
void reset()
reset value and overflow to zero
Definition: L1GctUnsignedInt.h:41
L1GctUnsignedInt::overFlow
bool overFlow() const
access overflow
Definition: L1GctUnsignedInt.h:56
L1GctUnsignedInt::setOverFlow
void setOverFlow(bool oflow)
set the overflow bit
Definition: L1GctUnsignedInt.h:50