CMS 3D CMS Logo

L1MuPacking.h
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
3 /* L1MuPacking
4  *
5  * define abstract packing and three implementations
6  *
7 */
8 //
9 // $Date: 2008/04/16 23:25:10 $
10 // $Revision: 1.4 $
11 //
12 // Original Author :
13 // H. Sakulin HEPHY Vienna
14 //
15 // Migrated to CMSSW:
16 // I. Mikulec
17 //
18 //--------------------------------------------------
19 
20 #ifndef CondFormatsL1TObjects_L1MuPacking_h
21 #define CondFormatsL1TObjects_L1MuPacking_h
22 
24 
26 
27 #include <cstdlib>
28 #include <limits>
29 
36 class L1MuPacking {
37 public:
38  virtual ~L1MuPacking(){};
39 
41  virtual int signFromPacked(unsigned packed) const = 0;
43  virtual int idxFromPacked(unsigned packed) const = 0;
45  virtual unsigned packedFromIdx(int idx) const = 0;
46 
48 };
49 
56 template <unsigned int Bits>
58 public:
60  int signFromPacked(unsigned packed) const override { return 0; };
62  int idxFromPacked(unsigned packed) const override { return (int)packed; };
64  unsigned packedFromIdx(int idx) const override {
65  if (idx >= (1 << Bits))
66  edm::LogWarning("ScaleRangeViolation")
67  << "L1MuUnignedPacking::packedFromIdx: warning value " << idx << "exceeds " << Bits << "-bit range !!!";
68  return (unsigned)idx;
69  };
70 };
71 
73 public:
75  static int signFromPacked(unsigned packed, unsigned int nbits) { return 0; };
77  static int idxFromPacked(unsigned packed, unsigned int nbits) { return (int)packed; };
79  static unsigned packedFromIdx(int idx, unsigned int nbits) {
80  if (idx >= (1 << nbits))
81  edm::LogWarning("ScaleRangeViolation")
82  << "L1MuUnignedPacking::packedFromIdx: warning value " << idx << "exceeds " << nbits << "-bit range !!!";
83  return (unsigned)idx;
84  };
85 };
86 
93 template <unsigned int Bits>
95 public:
97  int signFromPacked(unsigned packed) const override { return packed & (1 << (Bits - 1)) ? 1 : 0; };
98 
100  int idxFromPacked(unsigned packed) const override {
101  return packed & (1 << (Bits - 1)) ? (packed - (1 << Bits)) : packed;
102  };
104  unsigned packedFromIdx(int idx) const override {
105  unsigned maxabs = 1U << (Bits - 1);
106  if (idx < -(int)maxabs && idx >= (int)maxabs)
107  edm::LogWarning("ScaleRangeViolation")
108  << "L1MuSignedPacking::packedFromIdx: warning value " << idx << "exceeds " << Bits << "-bit range !!!";
109  return ~(std::numeric_limits<unsigned>::max() << Bits) & (idx < 0 ? (1U << Bits) + idx : idx);
110  };
111 };
112 
114 public:
116  static int signFromPacked(unsigned packed, unsigned int nbits) { return packed & (1 << (nbits - 1)) ? 1 : 0; };
117 
119  static int idxFromPacked(unsigned packed, unsigned int nbits) {
120  return packed & (1 << (nbits - 1)) ? (packed - (1 << nbits)) : packed;
121  };
123  static unsigned packedFromIdx(int idx, unsigned int nbits) {
124  unsigned maxabs = 1U << (nbits - 1);
125  if (idx < -(int)maxabs && idx >= (int)maxabs)
126  edm::LogWarning("ScaleRangeViolation")
127  << "L1MuSignedPacking::packedFromIdx: warning value " << idx << "exceeds " << nbits << "-bit range !!!";
128  return ~(std::numeric_limits<unsigned>::max() << nbits) & (idx < 0 ? (1U << nbits) + idx : idx);
129  };
130 };
131 
141 public:
144  L1MuPseudoSignedPacking(unsigned int nbits) : m_nbits(nbits){};
145 
147  int signFromPacked(unsigned packed) const override { return (packed & (1 << (m_nbits - 1))) ? 1 : 0; };
148 
150  int idxFromPacked(unsigned packed) const override {
151  unsigned mask = (1 << (m_nbits - 1)) - 1; // for lower bits
152  int absidx = (int)(packed & mask);
153  unsigned psmask = (1 << (m_nbits - 1));
154  return absidx * (((packed & psmask) == psmask) ? -1 : 1); // pseudo sign==1 is negative
155  };
157  unsigned packedFromIdx(int idx) const override {
158  unsigned packed = std::abs(idx);
159  unsigned maxabs = (1 << (m_nbits - 1)) - 1;
160  if (packed > maxabs)
161  edm::LogWarning("ScaleRangeViolation") << "L1MuPseudoSignedPacking::packedFromIdx: warning value " << idx
162  << "exceeds " << m_nbits << "-bit range !!!";
163  if (idx < 0)
164  packed |= 1 << (m_nbits - 1);
165  return packed;
166  }
167 
169  virtual unsigned packedFromIdx(int idx, int sig) const {
170  unsigned packed = std::abs(idx);
171  unsigned maxabs = (1 << (m_nbits - 1)) - 1;
172  if (packed > maxabs)
173  edm::LogWarning("ScaleRangeViolation") << "L1MuPseudoSignedPacking::packedFromIdx: warning value " << idx
174  << "exceeds " << m_nbits << "-bit range !!!";
175  if (sig == 1)
176  packed |= 1 << (m_nbits - 1); // sig==1 is negative
177  return packed;
178  }
179 
180 private:
181  unsigned int m_nbits;
182 
184 };
185 
186 #endif
L1MuPseudoSignedPacking::packedFromIdx
unsigned packedFromIdx(int idx) const override
get the packed notation of a value, check range
Definition: L1MuPacking.h:157
edm::module::AbilityBits::Bits
Bits
Definition: moduleAbilityEnums.h:54
MessageLogger.h
L1MuUnsignedPackingGeneric
Definition: L1MuPacking.h:72
L1MuUnsignedPackingGeneric::idxFromPacked
static int idxFromPacked(unsigned packed, unsigned int nbits)
get the value from the packed notation (always positive)
Definition: L1MuPacking.h:77
L1MuUnsignedPacking::idxFromPacked
int idxFromPacked(unsigned packed) const override
get the value from the packed notation (always positive)
Definition: L1MuPacking.h:62
L1MuSignedPackingGeneric::signFromPacked
static int signFromPacked(unsigned packed, unsigned int nbits)
get the sign from the packed notation (0=positive, 1=negative)
Definition: L1MuPacking.h:116
COND_SERIALIZABLE
#define COND_SERIALIZABLE
Definition: Serializable.h:39
L1MuUnsignedPackingGeneric::signFromPacked
static int signFromPacked(unsigned packed, unsigned int nbits)
get the sign from the packed notation. always psitive (0)
Definition: L1MuPacking.h:75
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
L1MuSignedPackingGeneric::idxFromPacked
static int idxFromPacked(unsigned packed, unsigned int nbits)
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:119
L1MuPseudoSignedPacking
Definition: L1MuPacking.h:140
L1MuPseudoSignedPacking::idxFromPacked
int idxFromPacked(unsigned packed) const override
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:150
L1MuPacking::idxFromPacked
virtual int idxFromPacked(unsigned packed) const =0
get the value from the packed notation
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
L1MuSignedPackingGeneric::packedFromIdx
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check range
Definition: L1MuPacking.h:123
L1MuPseudoSignedPacking::signFromPacked
int signFromPacked(unsigned packed) const override
get the (pseudo-)sign from the packed notation (0=positive, 1=negative)
Definition: L1MuPacking.h:147
L1MuPseudoSignedPacking::packedFromIdx
virtual unsigned packedFromIdx(int idx, int sig) const
get the packed notation of a value, check range; sets the sign separately, 1 is neg....
Definition: L1MuPacking.h:169
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
createfilelist.int
int
Definition: createfilelist.py:10
L1MuPacking::~L1MuPacking
virtual ~L1MuPacking()
Definition: L1MuPacking.h:38
Serializable.h
L1MuPacking::packedFromIdx
virtual unsigned packedFromIdx(int idx) const =0
get the packed notation of a value
L1MuPseudoSignedPacking::~L1MuPseudoSignedPacking
~L1MuPseudoSignedPacking() override
Definition: L1MuPacking.h:143
L1MuUnsignedPacking::signFromPacked
int signFromPacked(unsigned packed) const override
get the sign from the packed notation. always psitive (0)
Definition: L1MuPacking.h:60
L1MuSignedPackingGeneric
Definition: L1MuPacking.h:113
L1MuPseudoSignedPacking::m_nbits
unsigned int m_nbits
Definition: L1MuPacking.h:181
L1MuUnsignedPacking
Definition: L1MuPacking.h:57
L1MuSignedPacking::idxFromPacked
int idxFromPacked(unsigned packed) const override
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:100
L1MuUnsignedPackingGeneric::packedFromIdx
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check the range
Definition: L1MuPacking.h:79
L1MuPacking
Definition: L1MuPacking.h:36
L1MuSignedPacking::signFromPacked
int signFromPacked(unsigned packed) const override
get the sign from the packed notation (0=positive, 1=negative)
Definition: L1MuPacking.h:97
L1MuSignedPacking
Definition: L1MuPacking.h:94
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
L1MuPseudoSignedPacking::L1MuPseudoSignedPacking
L1MuPseudoSignedPacking(unsigned int nbits)
Definition: L1MuPacking.h:144
L1MuPseudoSignedPacking::L1MuPseudoSignedPacking
L1MuPseudoSignedPacking()
Definition: L1MuPacking.h:142
L1MuSignedPacking::packedFromIdx
unsigned packedFromIdx(int idx) const override
get the packed notation of a value, check range
Definition: L1MuPacking.h:104
L1MuPacking::signFromPacked
virtual int signFromPacked(unsigned packed) const =0
get the sign from the packed notation (0=positive, 1=negative)
L1MuUnsignedPacking::packedFromIdx
unsigned packedFromIdx(int idx) const override
get the packed notation of a value, check the range
Definition: L1MuPacking.h:64