CMS 3D CMS Logo

L1GctJetCount.h
Go to the documentation of this file.
1 #ifndef L1GCTJETCOUNT_H
2 #define L1GCTJETCOUNT_H
3 
6 
7 #include <ostream>
8 
29 template <int nBits>
30 class L1GctJetCount : public L1GctUnsignedInt<nBits> {
31 public:
33  L1GctJetCount();
35  L1GctJetCount(unsigned value);
38 
40  template <int mBits>
42 
44  void setValue(unsigned value);
45 
47  void setOverFlow(bool oflow);
48 
52 
54  L1GctJetCount operator+(const L1GctJetCount& rhs) const;
55 
58 };
59 
60 template <int nBits>
62 
63 template <int nBits>
65 
66 template <int nBits>
68 
69 // copy contructor to move data between
70 // representations with different numbers of bits
71 template <int nBits>
72 template <int mBits>
74  this->m_nBits = nBits > 0 && nBits < this->MAX_NBITS ? nBits : 16;
75  this->setValue(rhs.value());
76  this->setOverFlow(this->overFlow() || rhs.overFlow());
77 }
78 
79 template <int nBits>
81  // check for overflow
82  if (value >= (static_cast<unsigned>((1 << this->m_nBits) - 1))) {
83  this->m_overFlow = true;
84  this->m_value = ((1 << this->m_nBits) - 1);
85  } else {
86  this->m_value = value;
87  }
88 }
89 
90 template <int nBits>
92  this->m_overFlow = oflow;
93  if (oflow) {
94  this->m_value = ((1 << this->m_nBits) - 1);
95  }
96 }
97 
98 // increment operators
99 template <int nBits>
101  this->setValue(this->m_value + 1);
102  return *this;
103 }
104 
105 template <int nBits>
107  L1GctJetCount<nBits> temp(this->m_value);
108  temp.setOverFlow(this->m_overFlow);
109  this->setValue(this->m_value + 1);
110  return temp;
111 }
112 
113 // add two jet counts
114 template <int nBits>
116  // temporary variable for storing the result (need to set its size)
118 
119  unsigned sum;
120  bool ofl;
121 
122  // do the addition here
123  sum = this->value() + rhs.value();
124  ofl = this->overFlow() || rhs.overFlow();
125 
126  //fill the temporary argument
127  temp.setValue(sum);
128  temp.setOverFlow(temp.overFlow() || ofl);
129 
130  // return the temporary
131  return temp;
132 }
133 
134 // overload assignment by int
135 template <int nBits>
137  this->setValue(value);
138  return *this;
139 }
140 
141 // overload ostream<<
142 template <int nBits>
143 std::ostream& operator<<(std::ostream& s, const L1GctJetCount<nBits>& data) {
144  s << "L1GctJetCount value : " << data.value();
145  if (data.overFlow()) {
146  s << " Overflow set! ";
147  }
148 
149  return s;
150 }
151 
152 // removed typedefs for slc4 compilation
153 
155 //typedef L1GctJetCount<5> L1GctJcFinalType;
157 //typedef L1GctJetCount<3> L1GctJcWheelType;
158 
159 #endif
L1GctJetCount & operator=(int value)
overload = operator
Definition of unsigned integer types with increment and overflow.
Definition: L1GctJetCount.h:30
void setOverFlow(bool oflow)
set the overflow bit
Definition: L1GctJetCount.h:91
unsigned value() const
access value as unsigned
void setValue(unsigned value)
Set value from unsigned.
Definition: L1GctJetCount.h:80
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 ...
bool overFlow() const
access overflow
L1GctJetCount & operator++()
Define increment operators, since this is a counter.
Definition: value.py:1
L1GctJetCount operator+(const L1GctJetCount &rhs) const
add two numbers
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
L1GctJetCount()
Construct a counter and initialise its value to zero.
Definition: L1GctJetCount.h:61
~L1GctJetCount()
Destructor.
Definition: L1GctJetCount.h:67