File indexing completed on 2024-04-06 12:19:51
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
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 template <int nBits>
0030 class L1GctJetCount : public L1GctUnsignedInt<nBits> {
0031 public:
0032
0033 L1GctJetCount();
0034
0035 L1GctJetCount(unsigned value);
0036
0037 ~L1GctJetCount();
0038
0039
0040 template <int mBits>
0041 L1GctJetCount(const L1GctJetCount<mBits>& rhs);
0042
0043
0044 void setValue(unsigned value);
0045
0046
0047 void setOverFlow(bool oflow);
0048
0049
0050 L1GctJetCount& operator++();
0051 L1GctJetCount operator++(int);
0052
0053
0054 L1GctJetCount operator+(const L1GctJetCount& rhs) const;
0055
0056
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
0070
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
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
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
0114 template <int nBits>
0115 L1GctJetCount<nBits> L1GctJetCount<nBits>::operator+(const L1GctJetCount<nBits>& rhs) const {
0116
0117 L1GctJetCount<nBits> temp;
0118
0119 unsigned sum;
0120 bool ofl;
0121
0122
0123 sum = this->value() + rhs.value();
0124 ofl = this->overFlow() || rhs.overFlow();
0125
0126
0127 temp.setValue(sum);
0128 temp.setOverFlow(temp.overFlow() || ofl);
0129
0130
0131 return temp;
0132 }
0133
0134
0135 template <int nBits>
0136 L1GctJetCount<nBits>& L1GctJetCount<nBits>::operator=(int value) {
0137 this->setValue(value);
0138 return *this;
0139 }
0140
0141
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
0153
0154
0155
0156
0157
0158
0159 #endif