test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1GctJetCount.h
Go to the documentation of this file.
1 #ifndef L1GCTJETCOUNT_H
2 #define L1GCTJETCOUNT_H
3 
6 
7 #include <boost/cstdint.hpp>
8 #include <ostream>
9 
30 template <int nBits>
31 class L1GctJetCount : public L1GctUnsignedInt<nBits> {
32 
33  public:
34 
36  L1GctJetCount();
38  L1GctJetCount(unsigned value);
41 
43  template <int mBits>
45 
47  void setValue(unsigned value);
48 
50  void setOverFlow(bool oflow);
51 
53  L1GctJetCount& operator++ ();
54  L1GctJetCount operator++ (int);
55 
57  L1GctJetCount operator+ (const L1GctJetCount &rhs) const;
58 
60  L1GctJetCount& operator= (int value);
61 
62 };
63 
64 template <int nBits>
66 
67 template <int nBits>
69 
70 template <int nBits>
72 
73 // copy contructor to move data between
74 // representations with different numbers of bits
75 template <int nBits>
76 template <int mBits>
78  this->m_nBits = nBits>0 && nBits<this->MAX_NBITS ? nBits : 16 ;
79  this->setValue( rhs.value() );
80  this->setOverFlow( this->overFlow() || rhs.overFlow() );
81 }
82 
83 template <int nBits>
85 {
86  // check for overflow
87  if (value >= (static_cast<unsigned>((1<<this->m_nBits) - 1)) ) {
88  this->m_overFlow = true;
89  this->m_value = ((1<<this->m_nBits) - 1);
90  } else {
91  this->m_value = value;
92  }
93 
94 }
95 
96 template <int nBits>
98 {
99  this->m_overFlow = oflow;
100  if (oflow) { this->m_value = ((1<<this->m_nBits) - 1); }
101 }
102 
103 // increment operators
104 template <int nBits>
107 
108  this->setValue(this->m_value+1);
109  return *this;
110 }
111 
112 template <int nBits>
115 
116  L1GctJetCount<nBits> temp(this->m_value);
117  temp.setOverFlow(this->m_overFlow);
118  this->setValue(this->m_value+1);
119  return temp;
120 }
121 
122 // add two jet counts
123 template <int nBits>
126 
127  // temporary variable for storing the result (need to set its size)
129 
130  unsigned sum;
131  bool ofl;
132 
133  // do the addition here
134  sum = this->value() + rhs.value();
135  ofl = this->overFlow() || rhs.overFlow();
136 
137  //fill the temporary argument
138  temp.setValue(sum);
139  temp.setOverFlow(temp.overFlow() || ofl);
140 
141  // return the temporary
142  return temp;
143 
144 }
145 
146 // overload assignment by int
147 template <int nBits>
149 
150  this->setValue(value);
151  return *this;
152 
153 }
154 
155 // overload ostream<<
156 template <int nBits>
157 std::ostream& operator<<(std::ostream& s, const L1GctJetCount<nBits>& data) {
158 
159  s << "L1GctJetCount value : " << data.value();
160  if (data.overFlow()) { s << " Overflow set! "; }
161 
162  return s;
163 
164 }
165 
166 // removed typedefs for slc4 compilation
167 
169 //typedef L1GctJetCount<5> L1GctJcFinalType;
171 //typedef L1GctJetCount<3> L1GctJcWheelType;
172 
173 
174 #endif
L1GctJetCount & operator=(int value)
overload = operator
Definition of unsigned integer types with increment and overflow.
Definition: L1GctJetCount.h:31
void setOverFlow(bool oflow)
set the overflow bit
Definition: L1GctJetCount.h:97
void setValue(unsigned value)
Set value from unsigned.
Definition: L1GctJetCount.h:84
Definition of unsigned integer types with overflow.
bool setValue(Container &, const reco::JetBaseRef &, const JetExtendedData &)
associate jet with value. Returns false and associate nothing if jet is already associated ...
L1GctJetCount & operator++()
Define increment operators, since this is a counter.
unsigned value() const
access value as unsigned
L1GctJetCount operator+(const L1GctJetCount &rhs) const
add two numbers
bool overFlow() const
access overflow
L1GctJetCount()
Construct a counter and initialise its value to zero.
Definition: L1GctJetCount.h:65
~L1GctJetCount()
Destructor.
Definition: L1GctJetCount.h:71