CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
21 #ifndef CondFormatsL1TObjects_L1MuPacking_h
22 #define CondFormatsL1TObjects_L1MuPacking_h
23 
25 
32 class L1MuPacking {
33  public:
35  virtual int signFromPacked(unsigned packed) const = 0;
37  virtual int idxFromPacked(unsigned packed) const = 0;
39  virtual unsigned packedFromIdx(int idx) const = 0;
40 };
41 
48 template<unsigned int Bits>
50  public:
52  virtual int signFromPacked(unsigned packed) const { return 0;};
54  virtual int idxFromPacked(unsigned packed) const { return (int) packed;};
56  virtual unsigned packedFromIdx(int idx) const {
57  if (idx >= (1 << Bits) ) edm::LogWarning("ScaleRangeViolation")
58  << "L1MuUnignedPacking::packedFromIdx: warning value " << idx
59  << "exceeds " << Bits << "-bit range !!!";
60  return (unsigned) idx;
61  };
62 };
63 
65  public:
67  static int signFromPacked(unsigned packed, unsigned int nbits) { return 0;};
69  static int idxFromPacked(unsigned packed, unsigned int nbits) { return (int) packed;};
71  static unsigned packedFromIdx(int idx, unsigned int nbits) {
72  if (idx >= (1 << nbits) ) edm::LogWarning("ScaleRangeViolation")
73  << "L1MuUnignedPacking::packedFromIdx: warning value " << idx
74  << "exceeds " << nbits << "-bit range !!!";
75  return (unsigned) idx;
76  };
77 };
78 
85 template<unsigned int Bits>
87  public:
89  virtual int signFromPacked(unsigned packed) const { return packed & (1 << (Bits-1)) ? 1 : 0;};
90 
92  virtual int idxFromPacked(unsigned packed) const { return packed & (1 << (Bits-1)) ? (packed - (1 << Bits) ) : packed;};
94  virtual unsigned packedFromIdx(int idx) const {
95  unsigned maxabs = 1 << (Bits-1) ;
96  if (idx < -(int)maxabs && idx >= (int)maxabs) edm::LogWarning("ScaleRangeViolation")
97  << "L1MuSignedPacking::packedFromIdx: warning value " << idx
98  << "exceeds " << Bits << "-bit range !!!";
99  return ~(~0 << Bits) & (idx < 0 ? (1 << Bits) + idx : idx);
100  };
101 };
102 
104  public:
106  static int signFromPacked(unsigned packed, unsigned int nbits) { return packed & (1 << (nbits-1)) ? 1 : 0;};
107 
109  static int idxFromPacked(unsigned packed, unsigned int nbits) { return packed & (1 << (nbits-1)) ? (packed - (1 << nbits) ) : packed;};
111  static unsigned packedFromIdx(int idx, unsigned int nbits) {
112  unsigned maxabs = 1 << (nbits-1) ;
113  if (idx < -(int)maxabs && idx >= (int)maxabs) edm::LogWarning("ScaleRangeViolation")
114  << "L1MuSignedPacking::packedFromIdx: warning value " << idx
115  << "exceeds " << nbits << "-bit range !!!";
116  return ~(~0 << nbits) & (idx < 0 ? (1 << nbits) + idx : idx);
117  };
118 };
119 
129  public:
131  L1MuPseudoSignedPacking(unsigned int nbits) : m_nbits(nbits) {};
132 
134  virtual int signFromPacked(unsigned packed) const { return ( packed & (1 << (m_nbits-1)) ) ? 1 : 0;};
135 
137  virtual int idxFromPacked(unsigned packed) const {
138  unsigned mask = (1 << (m_nbits-1)) - 1; // for lower bits
139  int absidx = (int) ( packed & mask );
140  unsigned psmask = (1 << (m_nbits-1) );
141  return absidx * ( ( (packed & psmask) == psmask ) ? -1 : 1 ); // pseudo sign==1 is negative
142  };
144  virtual unsigned packedFromIdx(int idx) const {
145  unsigned packed = abs(idx);
146  unsigned maxabs = (1 << (m_nbits-1)) -1;
147  if (packed > maxabs) edm::LogWarning("ScaleRangeViolation")
148  << "L1MuPseudoSignedPacking::packedFromIdx: warning value " << idx
149  << "exceeds " << m_nbits << "-bit range !!!";
150  if (idx < 0) packed |= 1 << (m_nbits-1);
151  return packed;
152  }
153 
155  virtual unsigned packedFromIdx(int idx, int sig) const {
156  unsigned packed = abs(idx);
157  unsigned maxabs = (1 << (m_nbits-1)) -1;
158  if (packed > maxabs) edm::LogWarning("ScaleRangeViolation")
159  << "L1MuPseudoSignedPacking::packedFromIdx: warning value " << idx
160  << "exceeds " << m_nbits << "-bit range !!!";
161  if (sig==1) packed |= 1 << (m_nbits-1); // sig==1 is negative
162  return packed;
163  }
164 
165  private:
166  unsigned int m_nbits;
167 };
168 
169 #endif
static int idxFromPacked(unsigned packed, unsigned int nbits)
get the value from the packed notation (always positive)
Definition: L1MuPacking.h:69
virtual unsigned packedFromIdx(int idx) const
get the packed notation of a value, check the range
Definition: L1MuPacking.h:56
virtual unsigned packedFromIdx(int idx) const
get the packed notation of a value, check range
Definition: L1MuPacking.h:94
static int signFromPacked(unsigned packed, unsigned int nbits)
get the sign from the packed notation. always psitive (0)
Definition: L1MuPacking.h:67
virtual int signFromPacked(unsigned packed) const
get the sign from the packed notation. always psitive (0)
Definition: L1MuPacking.h:52
#define abs(x)
Definition: mlp_lapack.h:159
virtual int idxFromPacked(unsigned packed) const
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:92
virtual int signFromPacked(unsigned packed) const
get the sign from the packed notation (0=positive, 1=negative)
Definition: L1MuPacking.h:89
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check range
Definition: L1MuPacking.h:111
virtual unsigned packedFromIdx(int idx) const =0
get the packed notation of a value
static int idxFromPacked(unsigned packed, unsigned int nbits)
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:109
virtual unsigned packedFromIdx(int idx) const
get the packed notation of a value, check range
Definition: L1MuPacking.h:144
virtual int idxFromPacked(unsigned packed) const =0
get the value from the packed notation
virtual int idxFromPacked(unsigned packed) const
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:137
L1MuPseudoSignedPacking(unsigned int nbits)
Definition: L1MuPacking.h:131
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check the range
Definition: L1MuPacking.h:71
virtual unsigned packedFromIdx(int idx, int sig) const
get the packed notation of a value, check range; sets the sign separately, 1 is neg. sign(!)
Definition: L1MuPacking.h:155
virtual int idxFromPacked(unsigned packed) const
get the value from the packed notation (always positive)
Definition: L1MuPacking.h:54
virtual int signFromPacked(unsigned packed) const
get the (pseudo-)sign from the packed notation (0=positive, 1=negative)
Definition: L1MuPacking.h:134
static int signFromPacked(unsigned packed, unsigned int nbits)
get the sign from the packed notation (0=positive, 1=negative)
Definition: L1MuPacking.h:106
virtual int signFromPacked(unsigned packed) const =0
get the sign from the packed notation (0=positive, 1=negative)