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: 2012/08/14 13:05:11 $
10 // $Revision: 1.5 $
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:
132  L1MuPseudoSignedPacking(unsigned int nbits) : m_nbits(nbits) {};
133 
135  virtual int signFromPacked(unsigned packed) const { return ( packed & (1 << (m_nbits-1)) ) ? 1 : 0;};
136 
138  virtual int idxFromPacked(unsigned packed) const {
139  unsigned mask = (1 << (m_nbits-1)) - 1; // for lower bits
140  int absidx = (int) ( packed & mask );
141  unsigned psmask = (1 << (m_nbits-1) );
142  return absidx * ( ( (packed & psmask) == psmask ) ? -1 : 1 ); // pseudo sign==1 is negative
143  };
145  virtual unsigned packedFromIdx(int idx) const {
146  unsigned packed = abs(idx);
147  unsigned maxabs = (1 << (m_nbits-1)) -1;
148  if (packed > maxabs) edm::LogWarning("ScaleRangeViolation")
149  << "L1MuPseudoSignedPacking::packedFromIdx: warning value " << idx
150  << "exceeds " << m_nbits << "-bit range !!!";
151  if (idx < 0) packed |= 1 << (m_nbits-1);
152  return packed;
153  }
154 
156  virtual unsigned packedFromIdx(int idx, int sig) const {
157  unsigned packed = abs(idx);
158  unsigned maxabs = (1 << (m_nbits-1)) -1;
159  if (packed > maxabs) edm::LogWarning("ScaleRangeViolation")
160  << "L1MuPseudoSignedPacking::packedFromIdx: warning value " << idx
161  << "exceeds " << m_nbits << "-bit range !!!";
162  if (sig==1) packed |= 1 << (m_nbits-1); // sig==1 is negative
163  return packed;
164  }
165 
166  private:
167  unsigned int m_nbits;
168 };
169 
170 #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:145
virtual int idxFromPacked(unsigned packed) const =0
get the value from the packed notation
virtual ~L1MuPseudoSignedPacking()
Definition: L1MuPacking.h:131
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
virtual int idxFromPacked(unsigned packed) const
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:138
L1MuPseudoSignedPacking(unsigned int nbits)
Definition: L1MuPacking.h:132
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:156
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:135
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)