Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-02 03:45:49

0001 #ifndef L1GCTJETCOUNT_H
0002 #define L1GCTJETCOUNT_H
0003 
0004 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctUnsignedInt.h"
0005 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctTwosComplement.h"
0006 
0007 #include <ostream>
0008 
0009 /*!
0010  * \class L1GctJetCount
0011  * \brief Definition of unsigned integer types with increment and overflow
0012  *
0013  * This file defines the template class L1GctJetCount. It is used to store
0014  * energy values that are represented in a given number of bits in hardware.
0015  * The value is set to the maximum (all bits set to '1') to represent an overFlow
0016  * condition, if the number to be represented is outside the allowed range
0017  * for that number of bits. The counters are unsigned integers.
0018  * Functions are defined to increment the counter, to add two values,
0019  * and to copy data into a different number of bits.
0020  *
0021  * this header file contains method definitions because these are template classes
0022  * see http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12
0023  *
0024  * \author Jim Brooke & Greg Heath
0025  * \date May 2006
0026  * 
0027  */
0028 
0029 template <int nBits>
0030 class L1GctJetCount : public L1GctUnsignedInt<nBits> {
0031 public:
0032   /// Construct a counter and initialise its value to zero
0033   L1GctJetCount();
0034   /// Construct a counter, checking for overFlow
0035   L1GctJetCount(unsigned value);
0036   /// Destructor
0037   ~L1GctJetCount();
0038 
0039   /// Copy contructor to move data between representations with different numbers of bits
0040   template <int mBits>
0041   L1GctJetCount(const L1GctJetCount<mBits>& rhs);
0042 
0043   /// Set value from unsigned
0044   void setValue(unsigned value);
0045 
0046   /// set the overflow bit
0047   void setOverFlow(bool oflow);
0048 
0049   /// Define increment operators, since this is a counter.
0050   L1GctJetCount& operator++();
0051   L1GctJetCount operator++(int);
0052 
0053   /// add two numbers
0054   L1GctJetCount operator+(const L1GctJetCount& rhs) const;
0055 
0056   /// overload = operator
0057   L1GctJetCount& operator=(int value);
0058 };
0059 
0060 template <int nBits>
0061 L1GctJetCount<nBits>::L1GctJetCount() : L1GctUnsignedInt<nBits>() {}
0062 
0063 template <int nBits>
0064 L1GctJetCount<nBits>::L1GctJetCount(unsigned value) : L1GctUnsignedInt<nBits>(value) {}
0065 
0066 template <int nBits>
0067 L1GctJetCount<nBits>::~L1GctJetCount() {}
0068 
0069 // copy contructor to move data between
0070 // representations with different numbers of bits
0071 template <int nBits>
0072 template <int mBits>
0073 L1GctJetCount<nBits>::L1GctJetCount(const L1GctJetCount<mBits>& rhs) {
0074   this->m_nBits = nBits > 0 && nBits < this->MAX_NBITS ? nBits : 16;
0075   this->setValue(rhs.value());
0076   this->setOverFlow(this->overFlow() || rhs.overFlow());
0077 }
0078 
0079 template <int nBits>
0080 void L1GctJetCount<nBits>::setValue(unsigned value) {
0081   // check for overflow
0082   if (value >= (static_cast<unsigned>((1 << this->m_nBits) - 1))) {
0083     this->m_overFlow = true;
0084     this->m_value = ((1 << this->m_nBits) - 1);
0085   } else {
0086     this->m_value = value;
0087   }
0088 }
0089 
0090 template <int nBits>
0091 void L1GctJetCount<nBits>::setOverFlow(bool oflow) {
0092   this->m_overFlow = oflow;
0093   if (oflow) {
0094     this->m_value = ((1 << this->m_nBits) - 1);
0095   }
0096 }
0097 
0098 // increment operators
0099 template <int nBits>
0100 L1GctJetCount<nBits>& L1GctJetCount<nBits>::operator++() {
0101   this->setValue(this->m_value + 1);
0102   return *this;
0103 }
0104 
0105 template <int nBits>
0106 L1GctJetCount<nBits> L1GctJetCount<nBits>::operator++(int) {
0107   L1GctJetCount<nBits> temp(this->m_value);
0108   temp.setOverFlow(this->m_overFlow);
0109   this->setValue(this->m_value + 1);
0110   return temp;
0111 }
0112 
0113 // add two jet counts
0114 template <int nBits>
0115 L1GctJetCount<nBits> L1GctJetCount<nBits>::operator+(const L1GctJetCount<nBits>& rhs) const {
0116   // temporary variable for storing the result (need to set its size)
0117   L1GctJetCount<nBits> temp;
0118 
0119   unsigned sum;
0120   bool ofl;
0121 
0122   // do the addition here
0123   sum = this->value() + rhs.value();
0124   ofl = this->overFlow() || rhs.overFlow();
0125 
0126   //fill the temporary argument
0127   temp.setValue(sum);
0128   temp.setOverFlow(temp.overFlow() || ofl);
0129 
0130   // return the temporary
0131   return temp;
0132 }
0133 
0134 // overload assignment by int
0135 template <int nBits>
0136 L1GctJetCount<nBits>& L1GctJetCount<nBits>::operator=(int value) {
0137   this->setValue(value);
0138   return *this;
0139 }
0140 
0141 // overload ostream<<
0142 template <int nBits>
0143 std::ostream& operator<<(std::ostream& s, const L1GctJetCount<nBits>& data) {
0144   s << "L1GctJetCount value : " << data.value();
0145   if (data.overFlow()) {
0146     s << " Overflow set! ";
0147   }
0148 
0149   return s;
0150 }
0151 
0152 // removed typedefs for slc4 compilation
0153 
0154 /// typedef for the data type used for final output jet counts
0155 //typedef L1GctJetCount<5>        L1GctJcFinalType;
0156 /// typedef for the data type used for Wheel card jet counts
0157 //typedef L1GctJetCount<3>        L1GctJcWheelType;
0158 
0159 #endif