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:
34  virtual ~L1MuPacking() {}
36  virtual int signFromPacked(unsigned packed) const = 0;
38  virtual int idxFromPacked(unsigned packed) const = 0;
40  virtual unsigned packedFromIdx(int idx) const = 0;
41 };
42 
49 template<unsigned int Bits>
51  public:
53  virtual int signFromPacked(unsigned packed) const { return 0;};
55  virtual int idxFromPacked(unsigned packed) const { return (int) packed;};
57  virtual unsigned packedFromIdx(int idx) const {
58  if (idx >= (1 << Bits) ) edm::LogWarning("ScaleRangeViolation")
59  << "L1MuUnignedPacking::packedFromIdx: warning value " << idx
60  << "exceeds " << Bits << "-bit range !!!";
61  return (unsigned) idx;
62  };
63 };
64 
66  public:
68  static int signFromPacked(unsigned packed, unsigned int nbits) { return 0;};
70  static int idxFromPacked(unsigned packed, unsigned int nbits) { return (int) packed;};
72  static unsigned packedFromIdx(int idx, unsigned int nbits) {
73  if (idx >= (1 << nbits) ) edm::LogWarning("ScaleRangeViolation")
74  << "L1MuUnignedPacking::packedFromIdx: warning value " << idx
75  << "exceeds " << nbits << "-bit range !!!";
76  return (unsigned) idx;
77  };
78 };
79 
86 template<unsigned int Bits>
88  public:
90  virtual int signFromPacked(unsigned packed) const { return packed & (1 << (Bits-1)) ? 1 : 0;};
91 
93  virtual int idxFromPacked(unsigned packed) const { return packed & (1 << (Bits-1)) ? (packed - (1 << Bits) ) : packed;};
95  virtual unsigned packedFromIdx(int idx) const {
96  unsigned maxabs = 1 << (Bits-1) ;
97  if (idx < -(int)maxabs && idx >= (int)maxabs) edm::LogWarning("ScaleRangeViolation")
98  << "L1MuSignedPacking::packedFromIdx: warning value " << idx
99  << "exceeds " << Bits << "-bit range !!!";
100  return ~(~0 << Bits) & (idx < 0 ? (1 << Bits) + idx : idx);
101  };
102 };
103 
105  public:
107  static int signFromPacked(unsigned packed, unsigned int nbits) { return packed & (1 << (nbits-1)) ? 1 : 0;};
108 
110  static int idxFromPacked(unsigned packed, unsigned int nbits) { return packed & (1 << (nbits-1)) ? (packed - (1 << nbits) ) : packed;};
112  static unsigned packedFromIdx(int idx, unsigned int nbits) {
113  unsigned maxabs = 1 << (nbits-1) ;
114  if (idx < -(int)maxabs && idx >= (int)maxabs) edm::LogWarning("ScaleRangeViolation")
115  << "L1MuSignedPacking::packedFromIdx: warning value " << idx
116  << "exceeds " << nbits << "-bit range !!!";
117  return ~(~0 << nbits) & (idx < 0 ? (1 << nbits) + idx : idx);
118  };
119 };
120 
130  public:
133  L1MuPseudoSignedPacking(unsigned int nbits) : m_nbits(nbits) {};
134 
136  virtual int signFromPacked(unsigned packed) const { return ( packed & (1 << (m_nbits-1)) ) ? 1 : 0;};
137 
139  virtual int idxFromPacked(unsigned packed) const {
140  unsigned mask = (1 << (m_nbits-1)) - 1; // for lower bits
141  int absidx = (int) ( packed & mask );
142  unsigned psmask = (1 << (m_nbits-1) );
143  return absidx * ( ( (packed & psmask) == psmask ) ? -1 : 1 ); // pseudo sign==1 is negative
144  };
146  virtual unsigned packedFromIdx(int idx) const {
147  unsigned packed = abs(idx);
148  unsigned maxabs = (1 << (m_nbits-1)) -1;
149  if (packed > maxabs) edm::LogWarning("ScaleRangeViolation")
150  << "L1MuPseudoSignedPacking::packedFromIdx: warning value " << idx
151  << "exceeds " << m_nbits << "-bit range !!!";
152  if (idx < 0) packed |= 1 << (m_nbits-1);
153  return packed;
154  }
155 
157  virtual unsigned packedFromIdx(int idx, int sig) const {
158  unsigned packed = abs(idx);
159  unsigned maxabs = (1 << (m_nbits-1)) -1;
160  if (packed > maxabs) edm::LogWarning("ScaleRangeViolation")
161  << "L1MuPseudoSignedPacking::packedFromIdx: warning value " << idx
162  << "exceeds " << m_nbits << "-bit range !!!";
163  if (sig==1) packed |= 1 << (m_nbits-1); // sig==1 is negative
164  return packed;
165  }
166 
167  private:
168  unsigned int m_nbits;
169 };
170 
171 #endif
static int idxFromPacked(unsigned packed, unsigned int nbits)
get the value from the packed notation (always positive)
Definition: L1MuPacking.h:70
virtual unsigned packedFromIdx(int idx) const
get the packed notation of a value, check the range
Definition: L1MuPacking.h:57
virtual unsigned packedFromIdx(int idx) const
get the packed notation of a value, check range
Definition: L1MuPacking.h:95
static int signFromPacked(unsigned packed, unsigned int nbits)
get the sign from the packed notation. always psitive (0)
Definition: L1MuPacking.h:68
virtual int signFromPacked(unsigned packed) const
get the sign from the packed notation. always psitive (0)
Definition: L1MuPacking.h:53
virtual int idxFromPacked(unsigned packed) const
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:93
virtual int signFromPacked(unsigned packed) const
get the sign from the packed notation (0=positive, 1=negative)
Definition: L1MuPacking.h:90
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check range
Definition: L1MuPacking.h:112
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:110
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
virtual unsigned packedFromIdx(int idx) const
get the packed notation of a value, check range
Definition: L1MuPacking.h:146
virtual int idxFromPacked(unsigned packed) const =0
get the value from the packed notation
virtual ~L1MuPacking()
Definition: L1MuPacking.h:34
virtual ~L1MuPseudoSignedPacking()
Definition: L1MuPacking.h:132
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:139
L1MuPseudoSignedPacking(unsigned int nbits)
Definition: L1MuPacking.h:133
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check the range
Definition: L1MuPacking.h:72
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:157
virtual int idxFromPacked(unsigned packed) const
get the value from the packed notation (always positive)
Definition: L1MuPacking.h:55
virtual int signFromPacked(unsigned packed) const
get the (pseudo-)sign from the packed notation (0=positive, 1=negative)
Definition: L1MuPacking.h:136
static int signFromPacked(unsigned packed, unsigned int nbits)
get the sign from the packed notation (0=positive, 1=negative)
Definition: L1MuPacking.h:107
virtual int signFromPacked(unsigned packed) const =0
get the sign from the packed notation (0=positive, 1=negative)