test
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 
27 
34 class L1MuPacking {
35  public:
36  virtual ~L1MuPacking() {};
37 
39  virtual int signFromPacked(unsigned packed) const = 0;
41  virtual int idxFromPacked(unsigned packed) const = 0;
43  virtual unsigned packedFromIdx(int idx) const = 0;
44 
46 };
47 
54 template<unsigned int Bits>
56  public:
58  virtual int signFromPacked(unsigned packed) const { return 0;};
60  virtual int idxFromPacked(unsigned packed) const { return (int) packed;};
62  virtual unsigned packedFromIdx(int idx) const {
63  if (idx >= (1 << Bits) ) edm::LogWarning("ScaleRangeViolation")
64  << "L1MuUnignedPacking::packedFromIdx: warning value " << idx
65  << "exceeds " << Bits << "-bit range !!!";
66  return (unsigned) idx;
67  };
68 };
69 
71  public:
73  static int signFromPacked(unsigned packed, unsigned int nbits) { return 0;};
75  static int idxFromPacked(unsigned packed, unsigned int nbits) { return (int) packed;};
77  static unsigned packedFromIdx(int idx, unsigned int nbits) {
78  if (idx >= (1 << nbits) ) edm::LogWarning("ScaleRangeViolation")
79  << "L1MuUnignedPacking::packedFromIdx: warning value " << idx
80  << "exceeds " << nbits << "-bit range !!!";
81  return (unsigned) idx;
82  };
83 };
84 
91 template<unsigned int Bits>
93  public:
95  virtual int signFromPacked(unsigned packed) const { return packed & (1 << (Bits-1)) ? 1 : 0;};
96 
98  virtual int idxFromPacked(unsigned packed) const { return packed & (1 << (Bits-1)) ? (packed - (1 << Bits) ) : packed;};
100  virtual unsigned packedFromIdx(int idx) const {
101  unsigned maxabs = 1 << (Bits-1) ;
102  if (idx < -(int)maxabs && idx >= (int)maxabs) edm::LogWarning("ScaleRangeViolation")
103  << "L1MuSignedPacking::packedFromIdx: warning value " << idx
104  << "exceeds " << Bits << "-bit range !!!";
105  return ~(~0 << Bits) & (idx < 0 ? (1 << Bits) + idx : idx);
106  };
107 };
108 
110  public:
112  static int signFromPacked(unsigned packed, unsigned int nbits) { return packed & (1 << (nbits-1)) ? 1 : 0;};
113 
115  static int idxFromPacked(unsigned packed, unsigned int nbits) { return packed & (1 << (nbits-1)) ? (packed - (1 << nbits) ) : packed;};
117  static unsigned packedFromIdx(int idx, unsigned int nbits) {
118  unsigned maxabs = 1 << (nbits-1) ;
119  if (idx < -(int)maxabs && idx >= (int)maxabs) edm::LogWarning("ScaleRangeViolation")
120  << "L1MuSignedPacking::packedFromIdx: warning value " << idx
121  << "exceeds " << nbits << "-bit range !!!";
122  return ~(~0 << nbits) & (idx < 0 ? (1 << nbits) + idx : idx);
123  };
124 };
125 
135  public:
138  L1MuPseudoSignedPacking(unsigned int nbits) : m_nbits(nbits) {};
139 
141  virtual int signFromPacked(unsigned packed) const { return ( packed & (1 << (m_nbits-1)) ) ? 1 : 0;};
142 
144  virtual int idxFromPacked(unsigned packed) const {
145  unsigned mask = (1 << (m_nbits-1)) - 1; // for lower bits
146  int absidx = (int) ( packed & mask );
147  unsigned psmask = (1 << (m_nbits-1) );
148  return absidx * ( ( (packed & psmask) == psmask ) ? -1 : 1 ); // pseudo sign==1 is negative
149  };
151  virtual unsigned packedFromIdx(int idx) const {
152  unsigned packed = abs(idx);
153  unsigned maxabs = (1 << (m_nbits-1)) -1;
154  if (packed > maxabs) edm::LogWarning("ScaleRangeViolation")
155  << "L1MuPseudoSignedPacking::packedFromIdx: warning value " << idx
156  << "exceeds " << m_nbits << "-bit range !!!";
157  if (idx < 0) packed |= 1 << (m_nbits-1);
158  return packed;
159  }
160 
162  virtual unsigned packedFromIdx(int idx, int sig) const {
163  unsigned packed = abs(idx);
164  unsigned maxabs = (1 << (m_nbits-1)) -1;
165  if (packed > maxabs) edm::LogWarning("ScaleRangeViolation")
166  << "L1MuPseudoSignedPacking::packedFromIdx: warning value " << idx
167  << "exceeds " << m_nbits << "-bit range !!!";
168  if (sig==1) packed |= 1 << (m_nbits-1); // sig==1 is negative
169  return packed;
170  }
171 
172  private:
173  unsigned int m_nbits;
174 
176 };
177 
178 #endif
static int idxFromPacked(unsigned packed, unsigned int nbits)
get the value from the packed notation (always positive)
Definition: L1MuPacking.h:75
virtual unsigned packedFromIdx(int idx) const
get the packed notation of a value, check the range
Definition: L1MuPacking.h:62
virtual unsigned packedFromIdx(int idx) const
get the packed notation of a value, check range
Definition: L1MuPacking.h:100
static int signFromPacked(unsigned packed, unsigned int nbits)
get the sign from the packed notation. always psitive (0)
Definition: L1MuPacking.h:73
virtual int signFromPacked(unsigned packed) const
get the sign from the packed notation. always psitive (0)
Definition: L1MuPacking.h:58
virtual int idxFromPacked(unsigned packed) const
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:98
virtual int signFromPacked(unsigned packed) const
get the sign from the packed notation (0=positive, 1=negative)
Definition: L1MuPacking.h:95
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check range
Definition: L1MuPacking.h:117
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:115
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:151
virtual int idxFromPacked(unsigned packed) const =0
get the value from the packed notation
virtual ~L1MuPacking()
Definition: L1MuPacking.h:36
virtual ~L1MuPseudoSignedPacking()
Definition: L1MuPacking.h:137
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
#define COND_SERIALIZABLE
Definition: Serializable.h:30
virtual int idxFromPacked(unsigned packed) const
get the value from the packed notation (+/-)
Definition: L1MuPacking.h:144
L1MuPseudoSignedPacking(unsigned int nbits)
Definition: L1MuPacking.h:138
static unsigned packedFromIdx(int idx, unsigned int nbits)
get the packed notation of a value, check the range
Definition: L1MuPacking.h:77
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:162
virtual int idxFromPacked(unsigned packed) const
get the value from the packed notation (always positive)
Definition: L1MuPacking.h:60
virtual int signFromPacked(unsigned packed) const
get the (pseudo-)sign from the packed notation (0=positive, 1=negative)
Definition: L1MuPacking.h:141
static int signFromPacked(unsigned packed, unsigned int nbits)
get the sign from the packed notation (0=positive, 1=negative)
Definition: L1MuPacking.h:112
virtual int signFromPacked(unsigned packed) const =0
get the sign from the packed notation (0=positive, 1=negative)