Definition of signed integer types with overflow. More...
#include <L1GctTwosComplement.h>
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 | |
L1GctTwosComplement & | operator= (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) |
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 http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12
Definition at line 29 of file L1GctTwosComplement.h.
L1GctTwosComplement< nBits >::L1GctTwosComplement | ( | ) |
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); }
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); }
L1GctTwosComplement< nBits >::~L1GctTwosComplement | ( | ) | [inline] |
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().
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; }
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(), L1GctTwosComplement< nBits >::setOverFlow(), L1GctTwosComplement< nBits >::setRaw(), and groupFilesInBlocks::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; }
L1GctTwosComplement< nBits > L1GctTwosComplement< nBits >::operator- | ( | ) | const |
overload unary - (negation) operator
Definition at line 200 of file L1GctTwosComplement.h.
References L1GctTwosComplement< nBits >::overFlow(), L1GctTwosComplement< nBits >::setOverFlow(), L1GctTwosComplement< nBits >::setValue(), groupFilesInBlocks::temp, and relativeConstraints::value.
{ L1GctTwosComplement<nBits> temp; temp.setValue(-this->value()); temp.setOverFlow(temp.overFlow() || this->overFlow()); return temp; }
L1GctTwosComplement< nBits > & L1GctTwosComplement< nBits >::operator= | ( | int | value | ) |
overload = operator
Definition at line 210 of file L1GctTwosComplement.h.
References reco::JetExtendedAssociation::setValue().
bool L1GctTwosComplement< nBits >::overFlow | ( | ) | const [inline] |
access overflow
Definition at line 63 of file L1GctTwosComplement.h.
Referenced by L1GctJetFinderBase::doHtSums(), L1GctMet::inputOverFlow(), L1GctTwosComplement< nBits >::L1GctTwosComplement(), L1GctMet::metVector(), L1GctTwosComplement< nBits >::operator+(), and L1GctTwosComplement< nBits >::operator-().
{ return m_overFlow; }
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; }
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; }
void L1GctTwosComplement< nBits >::setOverFlow | ( | bool | oflow | ) | [inline] |
set the overflow bit
Definition at line 54 of file L1GctTwosComplement.h.
Referenced by L1GctJetFinderBase::doHtSums(), L1GctTwosComplement< nBits >::operator+(), L1GctTwosComplement< nBits >::operator-(), L1GctGlobalEnergyAlgos::setInputWheelEx(), L1GctGlobalEnergyAlgos::setInputWheelEy(), L1GctGlobalEnergyAlgos::setInputWheelHx(), and L1GctGlobalEnergyAlgos::setInputWheelHy().
{ m_overFlow = oflow; }
void L1GctTwosComplement< nBits >::setRaw | ( | uint32_t | raw | ) |
set the raw data
Definition at line 141 of file L1GctTwosComplement.h.
Referenced by L1GctTwosComplement< nBits >::operator+().
{ checkOverFlow(raw, m_data, m_overFlow); }
void L1GctTwosComplement< nBits >::setValue | ( | int | value | ) |
set value from signed int
Definition at line 147 of file L1GctTwosComplement.h.
References 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); }
int L1GctTwosComplement< nBits >::size | ( | void | ) | const [inline] |
int L1GctTwosComplement< nBits >::value | ( | void | ) | 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().
uint32_t L1GctTwosComplement< nBits >::m_data [private] |
Definition at line 83 of file L1GctTwosComplement.h.
Referenced by L1GctTwosComplement< L1GctInternEtSum::kMissExOrEyNBits >::raw().
int L1GctTwosComplement< nBits >::m_nBits [private] |
Definition at line 80 of file L1GctTwosComplement.h.
Referenced by L1GctTwosComplement< L1GctInternEtSum::kMissExOrEyNBits >::size().
bool L1GctTwosComplement< nBits >::m_overFlow [private] |
Definition at line 86 of file L1GctTwosComplement.h.
Referenced by L1GctTwosComplement< L1GctInternEtSum::kMissExOrEyNBits >::overFlow(), and L1GctTwosComplement< L1GctInternEtSum::kMissExOrEyNBits >::setOverFlow().
const int L1GctTwosComplement< nBits >::MAX_NBITS = 24 [static, private] |
Definition at line 88 of file L1GctTwosComplement.h.
const int L1GctTwosComplement< nBits >::MAX_VALUE = 1<<(MAX_NBITS-1) [static, private] |
Definition at line 89 of file L1GctTwosComplement.h.