CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/L1Trigger/GlobalCaloTrigger/src/L1GctJetCount.h

Go to the documentation of this file.
00001 #ifndef L1GCTJETCOUNT_H
00002 #define L1GCTJETCOUNT_H
00003 
00004 #include "L1Trigger/GlobalCaloTrigger/src/L1GctUnsignedInt.h"
00005 #include "L1Trigger/GlobalCaloTrigger/src/L1GctTwosComplement.h"
00006 
00007 #include <boost/cstdint.hpp>
00008 #include <ostream>
00009 
00030 template <int nBits>
00031 class L1GctJetCount : public L1GctUnsignedInt<nBits> {
00032 
00033  public:
00034 
00036   L1GctJetCount();
00038   L1GctJetCount(unsigned value);
00040   ~L1GctJetCount();
00041 
00043   template <int mBits>
00044   L1GctJetCount(const L1GctJetCount<mBits>& rhs);
00045 
00047   void setValue(unsigned value);
00048 
00050   void setOverFlow(bool oflow);
00051 
00053   L1GctJetCount& operator++ ();
00054   L1GctJetCount operator++ (int);
00055 
00057   L1GctJetCount operator+ (const L1GctJetCount &rhs) const;
00058 
00060   L1GctJetCount& operator= (int value);
00061 
00062 };
00063 
00064 template <int nBits>
00065 L1GctJetCount<nBits>::L1GctJetCount() : L1GctUnsignedInt<nBits>() {}
00066 
00067 template <int nBits>
00068 L1GctJetCount<nBits>::L1GctJetCount(unsigned value) : L1GctUnsignedInt<nBits>(value) {}
00069 
00070 template <int nBits>
00071 L1GctJetCount<nBits>::~L1GctJetCount() {}
00072 
00073 // copy contructor to move data between
00074 // representations with different numbers of bits
00075 template <int nBits>
00076 template <int mBits>
00077 L1GctJetCount<nBits>::L1GctJetCount(const L1GctJetCount<mBits>& rhs) {
00078   this->m_nBits = nBits>0 && nBits<this->MAX_NBITS ? nBits : 16 ;
00079   this->setValue( rhs.value() );
00080   this->setOverFlow( this->overFlow() || rhs.overFlow() );
00081 }
00082 
00083 template <int nBits>
00084 void L1GctJetCount<nBits>::setValue(unsigned value)
00085 {
00086   // check for overflow
00087   if (value >= (static_cast<unsigned>((1<<this->m_nBits) - 1)) ) {
00088     this->m_overFlow = true;
00089     this->m_value = ((1<<this->m_nBits) - 1);
00090   } else {
00091     this->m_value = value;
00092   }
00093 
00094 }
00095 
00096 template <int nBits>
00097 void L1GctJetCount<nBits>::setOverFlow(bool oflow)
00098 {
00099   this->m_overFlow = oflow;
00100   if (oflow) { this->m_value = ((1<<this->m_nBits) - 1); }
00101 }
00102 
00103 // increment operators
00104 template <int nBits>
00105 L1GctJetCount<nBits>&
00106 L1GctJetCount<nBits>::operator++ () {
00107 
00108   this->setValue(this->m_value+1);
00109   return *this;
00110 }
00111 
00112 template <int nBits>
00113 L1GctJetCount<nBits>
00114 L1GctJetCount<nBits>::operator++ (int) {
00115 
00116   L1GctJetCount<nBits> temp(this->m_value);
00117   temp.setOverFlow(this->m_overFlow);
00118   this->setValue(this->m_value+1);
00119   return temp;
00120 }
00121 
00122 // add two jet counts
00123 template <int nBits>
00124 L1GctJetCount<nBits>
00125 L1GctJetCount<nBits>::operator+ (const L1GctJetCount<nBits> &rhs) const {
00126 
00127   // temporary variable for storing the result (need to set its size)
00128   L1GctJetCount<nBits> temp;
00129 
00130   unsigned sum;
00131   bool ofl;
00132 
00133   // do the addition here
00134   sum = this->value() + rhs.value();
00135   ofl = this->overFlow() || rhs.overFlow();
00136 
00137   //fill the temporary argument
00138   temp.setValue(sum);
00139   temp.setOverFlow(temp.overFlow() || ofl);
00140 
00141   // return the temporary
00142   return temp;
00143 
00144 }
00145 
00146 // overload assignment by int
00147 template <int nBits>
00148 L1GctJetCount<nBits>& L1GctJetCount<nBits>::operator= (int value) {
00149   
00150   this->setValue(value);
00151   return *this;
00152 
00153 }
00154 
00155 // overload ostream<<
00156 template <int nBits>
00157 std::ostream& operator<<(std::ostream& s, const L1GctJetCount<nBits>& data) {
00158 
00159   s << "L1GctJetCount value : " << data.value();
00160   if (data.overFlow()) { s << " Overflow set! "; }
00161 
00162   return s;
00163 
00164 }
00165 
00166 // removed typedefs for slc4 compilation
00167 
00169 //typedef L1GctJetCount<5>        L1GctJcFinalType;
00171 //typedef L1GctJetCount<3>        L1GctJcWheelType;
00172 
00173 
00174 #endif