CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EMTFBlockSP.cc
Go to the documentation of this file.
1 // Code to unpack the "SP Output Data Record"
2 
4 #include "EMTFCollections.h"
5 #include "EMTFUnpackerTools.h"
6 
7 // This is the "header" - no EMTFBlockSP.h file is needed
8 namespace l1t {
9  namespace stage2 {
10  namespace emtf {
11 
12  class SPBlockUnpacker : public Unpacker { // "SPBlockUnpacker" inherits from "Unpacker"
13  public:
14  virtual int checkFormat(const Block& block);
15  virtual bool unpack(const Block& block, UnpackerCollections *coll) override; // Apparently it's always good to use override in C++
16  // virtual bool packBlock(const Block& block, UnpackerCollections *coll) override;
17  };
18 
19 
20  // class SPBlockPacker : public Packer { // "SPBlockPacker" inherits from "Packer"
21  // public:
22  // virtual bool unpack(const Block& block, UnpackerCollections *coll) override; // Apparently it's always good to use override in C++
23  // };
24 
25  }
26  }
27 }
28 
29 namespace l1t {
30  namespace stage2 {
31  namespace emtf {
32 
34 
35  auto payload = block.payload();
36  int errors = 0;
37 
38  //Check the number of 16-bit words
39  if(payload.size() != 8) { errors += 1; edm::LogError("L1T|EMTF") << "Payload size in 'SP Output Data Record' is different than expected"; }
40 
41  //Check that each word is 16 bits
42  if(GetHexBits(payload[0], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[0] has more than 16 bits in 'SP Output Data Record'"; }
43  if(GetHexBits(payload[1], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[1] has more than 16 bits in 'SP Output Data Record'"; }
44  if(GetHexBits(payload[2], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[2] has more than 16 bits in 'SP Output Data Record'"; }
45  if(GetHexBits(payload[3], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'SP Output Data Record'"; }
46  if(GetHexBits(payload[4], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[4] has more than 16 bits in 'SP Output Data Record'"; }
47  if(GetHexBits(payload[5], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[5] has more than 16 bits in 'SP Output Data Record'"; }
48  if(GetHexBits(payload[6], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[6] has more than 16 bits in 'SP Output Data Record'"; }
49  if(GetHexBits(payload[7], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[7] has more than 16 bits in 'SP Output Data Record'"; }
50 
51  uint16_t SP1a = payload[0];
52  uint16_t SP1b = payload[1];
53  uint16_t SP1c = payload[2];
54  uint16_t SP1d = payload[3];
55  uint16_t SP2a = payload[4];
56  uint16_t SP2b = payload[5];
57  uint16_t SP2c = payload[6];
58  uint16_t SP2d = payload[7];
59 
60 
61  //Check Format
62  if(GetHexBits(SP1a, 15, 15) != 1) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in SP1a are incorrect"; }
63  if(GetHexBits(SP1b, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in SP1b are incorrect"; }
64  if(GetHexBits(SP1b, 8, 11) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in SP1b are incorrect"; }
65  if(GetHexBits(SP1c, 15, 15) != 1) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in SP1c are incorrect"; }
66  if(GetHexBits(SP1d, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in SP1d are incorrect"; }
67  if(GetHexBits(SP2a, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in SP2a are incorrect"; }
68  if(GetHexBits(SP2b, 15, 15) != 1) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in SP2b are incorrect"; }
69  if(GetHexBits(SP2c, 15, 15) != 1) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in SP2c are incorrect"; }
70  if(GetHexBits(SP2d, 15, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in SP2d are incorrect"; }
71 
72  return errors;
73 
74  }
75 
76 
78 
79  // Get the payload for this block, made up of 16-bit words (0xffff)
80  // Format defined in MTF7Payload::getBlock() in src/Block.cc
81  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
82  auto payload = block.payload();
83 
84  // Check Format of Payload
85  l1t::emtf::SP SP_;
86  for (int err = 0; err < checkFormat(block); err++) SP_.add_format_error();
87 
88  // Assign payload to 16-bit words
89  uint16_t SP1a = payload[0];
90  uint16_t SP1b = payload[1];
91  uint16_t SP1c = payload[2];
92  uint16_t SP1d = payload[3];
93  uint16_t SP2a = payload[4];
94  uint16_t SP2b = payload[5];
95  uint16_t SP2c = payload[6];
96  uint16_t SP2d = payload[7];
97 
98  // res is a pointer to a collection of EMTFOutput class objects
99  // There is one EMTFOutput for each MTF7 (60 deg. sector) in the event
101  res = static_cast<EMTFCollections*>(coll)->getEMTFOutputs();
102  int iOut = res->size() - 1;
103 
105  res_cand = static_cast<EMTFCollections*>(coll)->getRegionalMuonCands();
106  RegionalMuonCand mu_;
107 
108  if (SP_.Format_Errors() > 0) goto write;
109 
111  // Unpack the SP Output Data Record
113 
114  SP_.set_phi_local_int ( GetHexBits(SP1a, 0, 11) );
115  SP_.set_phi_global ( SP_.Phi_local(), (res->at(iOut)).GetEventHeader().Sector() );
116  SP_.set_vc ( GetHexBits(SP1a, 12, 12) );
117  SP_.set_c ( GetHexBits(SP1a, 13, 13) );
118  SP_.set_hl ( GetHexBits(SP1a, 14, 14) );
119 
120  SP_.set_phi_GMT_int ( TwosCompl(8, GetHexBits(SP1b, 0, 7)) );
121  SP_.set_phi_GMT_global ( SP_.Phi_GMT(), (res->at(iOut)).GetEventHeader().Sector() );
122  mu_.setHwPhi ( TwosCompl(8, GetHexBits(SP1b, 0, 7)) );
123  SP_.set_bc0 ( GetHexBits(SP1b, 12, 12) );
124  SP_.set_se ( GetHexBits(SP1b, 13, 13) );
125  SP_.set_vt ( GetHexBits(SP1b, 14, 14) );
126 
127  SP_.set_eta_GMT_int ( TwosCompl(9, GetHexBits(SP1c, 0, 8)) );
128  mu_.setHwEta ( TwosCompl(9, GetHexBits(SP1c, 0, 8)) );
129  SP_.set_quality ( GetHexBits(SP1c, 9, 12) );
130  mu_.setHwQual ( GetHexBits(SP1c, 9, 12) );
131  SP_.set_bx ( GetHexBits(SP1c, 13, 14) );
132 
133  SP_.set_pt_int ( GetHexBits(SP1d, 0, 8) );
134  mu_.setHwPt ( GetHexBits(SP1d, 0, 8) );
135  SP_.set_me1_trk_stub_num( GetHexBits(SP1d, 9, 9) );
136  SP_.set_me1_csc_id ( GetHexBits(SP1d, 10, 13) );
137  SP_.set_me1_subsector ( GetHexBits(SP1d, 14, 14) );
138 
139  SP_.set_me2_trk_stub_num( GetHexBits(SP2a, 0, 0 ) );
140  SP_.set_me2_csc_id ( GetHexBits(SP2a, 1, 4 ) );
141  SP_.set_me3_trk_stub_num( GetHexBits(SP2a, 5, 5 ) );
142  SP_.set_me3_csc_id ( GetHexBits(SP2a, 6, 9 ) );
143  SP_.set_me4_trk_stub_num( GetHexBits(SP2a, 10, 10) );
144  SP_.set_me4_csc_id ( GetHexBits(SP2a, 11, 14) );
145 
146  SP_.set_me1_TBIN ( GetHexBits(SP2b, 0, 2) );
147  SP_.set_me2_TBIN ( GetHexBits(SP2b, 3, 5) );
148  SP_.set_me3_TBIN ( GetHexBits(SP2b, 6, 8) );
149  SP_.set_me4_TBIN ( GetHexBits(SP2b, 9, 11) );
150  SP_.set_TBIN_num ( GetHexBits(SP2b, 12, 14) );
151 
152  SP_.set_pt_lut_address ( GetHexBits(SP2c, 0, 14, SP2d, 0, 14) );
153 
154  // SP_.set_dataword ( uint64_t dataword );
155  // mu_.set_dataword ( uint64_t dataword );
156 
157  write:
158 
159  (res->at(iOut)).push_SP(SP_);
160 
161  res_cand->setBXRange(0, 0);
162  res_cand->push_back(0, mu_);
163 
164  // int iOut_cand = res_cand->size(0) - 1;
165  // (res_cand->at(iOut_cand)).setBXRange(0, 0);
166  // (res_cand->at(iOut_cand)).push_back(0, mu_);
167 
168  // Finished with unpacking one SP Output Data Record
169  return true;
170 
171  } // End bool SPBlockUnpacker::unpack
172 
173  // bool SPBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
174  // std::cout << "Inside SPBlockPacker::pack" << std::endl;
175  // return true;
176  // } // End bool SPBlockPacker::pack
177 
178  } // End namespace emtf
179  } // End namespace stage2
180 } // End namespace l1t
181 
183 // DEFINE_L1T_PACKER(l1t::stage2::SPBlockPacker);
void set_me3_trk_stub_num(int bits)
Definition: SP.h:108
const float Phi_local() const
Definition: SP.h:157
void set_me1_trk_stub_num(int bits)
Definition: SP.h:113
void set_vt(int bits)
Definition: SP.h:122
void setHwPhi(int bits)
Set compressed relative phi as transmitted by hardware LSB = 2*pi/576 (8 bits)
void set_pt_lut_address(int bits)
Definition: SP.h:102
void set_phi_GMT_global(float loc, int sect)
Definition: SP.h:94
virtual int checkFormat(const Block &block)
Definition: EMTFBlockSP.cc:33
void set_me2_trk_stub_num(int bits)
Definition: SP.h:106
void set_bx(int bits)
Definition: SP.h:104
void set_pt_int(int bits)
Definition: SP.h:65
const int Format_Errors() const
Definition: SP.h:165
std::vector< uint32_t > payload() const
Definition: Block.h:57
void set_phi_GMT_int(int bits)
Definition: SP.h:80
#define DEFINE_L1T_UNPACKER(type)
Definition: Unpacker.h:31
void set_me4_TBIN(int bits)
Definition: SP.h:114
void set_se(int bits)
Definition: SP.h:123
void set_phi_local_int(int bits)
Definition: SP.h:70
void set_me2_csc_id(int bits)
Definition: SP.h:105
void set_me4_csc_id(int bits)
Definition: SP.h:109
int TwosCompl(int nBits, int bits)
const float Phi_GMT() const
Definition: SP.h:160
void set_hl(int bits)
Definition: SP.h:119
std::vector< EMTFOutput > EMTFOutputCollection
Definition: EMTFOutput.h:104
void set_me3_TBIN(int bits)
Definition: SP.h:115
void set_bc0(int bits)
Definition: SP.h:124
void set_me4_trk_stub_num(int bits)
Definition: SP.h:110
void set_me2_TBIN(int bits)
Definition: SP.h:116
void set_c(int bits)
Definition: SP.h:120
void set_vc(int bits)
Definition: SP.h:121
void setHwQual(int bits)
Set compressed quality code as transmitted by hardware (4 bits)
void setHwPt(int bits)
Set compressed pT as transmitted by hardware LSB = 0.5 (9 bits)
void set_eta_GMT_int(int bits)
Definition: SP.h:96
void setHwEta(int bits)
Set compressed eta as transmitted by hardware LSB = 0.010875 (9 bits)
void set_quality(int bits)
Definition: SP.h:103
JetCorrectorParametersCollection coll
Definition: classes.h:10
virtual bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: EMTFBlockSP.cc:77
void set_TBIN_num(int bits)
Definition: SP.h:118
void setBXRange(int bxFirst, int bxLast)
void set_me3_csc_id(int bits)
Definition: SP.h:107
void set_me1_csc_id(int bits)
Definition: SP.h:112
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)
void set_me1_subsector(int bits)
Definition: SP.h:111
void set_me1_TBIN(int bits)
Definition: SP.h:117
void set_phi_global(float loc, int sect)
Definition: SP.h:93
void add_format_error()
Definition: SP.h:125
void push_back(int bx, T object)