CMS 3D CMS Logo

BMTFPackerInputs.cc
Go to the documentation of this file.
1 #include "BMTFPackerInputs.h"
2 
3 #include <vector>
4 //#include <bitset>//debug
5 
6 namespace l1t {
7  namespace stage2 {
8 
9  const int BMTFPackerInputs::ownLinks_[] = {4, 5, 12, 13, 20, 21, 22, 23, 28, 29};
10 
12  int board_id = (int)board();
13 
14  auto muonPhToken = static_cast<const BMTFTokens*>(toks)->getInputMuonTokenPh();
15  auto muonThToken = static_cast<const BMTFTokens*>(toks)->getInputMuonTokenTh();
16 
17  Blocks blocks;
18 
20  event.getByToken(muonPhToken, phInputs);
22  event.getByToken(muonThToken, thInputs);
23 
24  uint32_t qualEta_32bit = 0;
25  uint32_t posEta_0_32bit = 0;
26  uint32_t posEta_n2_32bit = 0, posEta_n1_32bit = 0;
27  uint32_t posEta_p2_32bit = 0, posEta_p1_32bit = 0;
28 
29  bool moreBXeta = false;
30  for (int link = 0; link <= 35; link++) {
31  // std::cout << "link : " << link << std::endl;
32 
33  if ((link >= 6 && link < 8) || (link >= 14 && link < 16) || (link >= 30 && link < 32))
34  continue;
35 
36  //initializing null block_payloads and block_id
37  std::vector<uint32_t> payload_0(6, 0);
38  std::vector<uint32_t> payload_p1(6, 0);
39  std::vector<uint32_t> payload_n1(6, 0);
40  std::vector<uint32_t> payload_p2(6, 0);
41  std::vector<uint32_t> payload_n2(6, 0);
42 
43  unsigned int block_id = 2 * link;
44 
45  std::vector<bool> bxPresent(5, false);
46  bool moreBXphi = false;
47 
48  unsigned int BC = 0;
49 
50  //The first 4 phi words for the link's payload
51 
52  for (const auto& iphi : *(phInputs->getContainer())) {
53  // Only allow -2 <= bxNum <= 2, as in Stage2 data
54  if (std::abs(iphi.bxNum()) > 2)
55  continue;
56 
57  if (iphi.bxNum() != 0)
58  moreBXphi = true;
59 
60  // std::cout << "scNum+1 = " << iphi->scNum()+1 << ", board_id = " << board_id << std::endl;
61  // std::cout << "bx, station = " << iphi->bxNum() << ", " << iphi->stNum() << std::endl;
62 
63  //BC = iphi->BxCnt();//this thing here is not completely functional
64 
65  if (iphi.scNum() + 1 != board_id)
66  continue;
67  // std::cout << "correct board" << std::endl;
68 
69  if (link != ownLinks_[4 + 2 * (iphi.whNum()) + iphi.Ts2Tag()])
70  continue;
71  // std::cout << "correct link" << std::endl;
72 
73  bxPresent[2 + iphi.bxNum()] = true;
74 
75  //1 create 32word, 2 insert 32word in correct Block Slot
76  uint32_t word_32bit = wordPhMaker(iphi); //1
77  if (bxPresent[0]) {
78  payload_n2[iphi.stNum() - 1] = word_32bit;
79  } else if (bxPresent[1]) {
80  payload_n1[iphi.stNum() - 1] = word_32bit;
81  } else if (bxPresent[2])
82  payload_0[iphi.stNum() - 1] = word_32bit;
83  else if (bxPresent[3]) {
84  payload_p1[iphi.stNum() - 1] = word_32bit;
85  } else if (bxPresent[4]) {
86  payload_p2[iphi.stNum() - 1] = word_32bit;
87  }
88 
89  bxPresent.assign(5, false);
90 
91  } //phiCont_itr
92 
93  //============================================================================================
94 
95  //Create phiNull words (use the old format for null words because Packer gives fw_id=1)
96  //uint32_t phiNull_32bit = 0 | (BC & 0x3) << 30 | (7 & 0x7) << 22; //for the new fw
97  uint32_t phiNull_32bit = 0 | (BC & 0x3) << 30; //for the old fw
98  //phiNull = (BC)000001110000000000000000000000
99  uint32_t etaNull_32bit = 0 | (BC & 0x3) << 30;
100  //etaNull = (BC)000000000000000000000000000000
101 
102  //============================================================================================
103 
104  //The 5th & 6th words of the link's payload
105  // std::cout << "link%2 = " << link%2 << std::endl;
106  if (link % 2 == 0) {
107  //these Eta vars have to be declared out of link itr scope in order to maintain its information for the next link
108  //Using these as the basis for the pos and qual 32bit eta word
109  //in case there are les than 3 hits, the entries will be zero.
110  posEta_0_32bit = etaNull_32bit;
111  posEta_n2_32bit = etaNull_32bit;
112  posEta_n1_32bit = etaNull_32bit;
113  posEta_p2_32bit = etaNull_32bit;
114  posEta_p1_32bit = etaNull_32bit;
115 
116  qualEta_32bit = etaNull_32bit;
117 
118  for (const auto& ithe : *(thInputs->getContainer())) {
119  // Only allow -2 <= bxNum <= 2, as in Stage2 data
120  if (std::abs(ithe.bxNum()) > 2)
121  continue;
122 
123  if (ithe.bxNum() != 0)
124  moreBXeta = true;
125 
126  //debug
127  // std::cout << "scNum+1 = " << ithe.scNum()+1 << ", board_id = " << board_id << std::endl;
128  // std::cout << "bx, station = " << ithe.bxNum() << ", " << ithe.stNum() << std::endl;
129  // std::cout << "related link: " << ownLinks_[4+2*(ithe.whNum())] << std::endl;
130 
131  if (ithe.scNum() + 1 != board_id)
132  continue;
133 
134  if (link != ownLinks_[4 + 2 * (ithe.whNum())])
135  continue;
136 
137  bxPresent[2 + ithe.bxNum()] = true;
138 
139  //positions for the next link
140  uint32_t posEta_7bit = wordThMaker(ithe, false);
141 
142  //qualities for this link
143  uint32_t qualEta_7bit = wordThMaker(ithe, true);
144  qualEta_32bit = qualEta_32bit | ((qualEta_7bit & 0x7F) << 7 * (ithe.stNum() - 1));
145 
146  //write the eta-pos and eta-qual information at the correct payload per BX
147  if (bxPresent[0]) {
148  payload_n2[4] = qualEta_32bit;
149  payload_n2[5] = etaNull_32bit | (2 & 0x2);
150  posEta_n2_32bit = posEta_n2_32bit | ((posEta_7bit & 0x7F) << 7 * (ithe.stNum() - 1));
151  } else if (bxPresent[1]) {
152  payload_n1[4] = qualEta_32bit;
153  payload_n1[5] = etaNull_32bit | (2 & 0x2);
154  posEta_n1_32bit = posEta_n1_32bit | ((posEta_7bit & 0x7F) << 7 * (ithe.stNum() - 1));
155  } else if (bxPresent[2]) {
156  payload_0[4] = qualEta_32bit;
157  payload_0[5] = etaNull_32bit | (2 & 0x2);
158  posEta_0_32bit = posEta_0_32bit | ((posEta_7bit & 0x7F) << 7 * (ithe.stNum() - 1));
159  } else if (bxPresent[3]) {
160  payload_p1[4] = qualEta_32bit;
161  payload_p1[5] = etaNull_32bit | (2 & 0x2);
162  posEta_p1_32bit = posEta_p1_32bit | ((posEta_7bit & 0x7F) << 7 * (ithe.stNum() - 1));
163  } else if (bxPresent[4]) {
164  payload_p2[4] = qualEta_32bit;
165  payload_p2[5] = etaNull_32bit | (2 & 0x2);
166  posEta_p2_32bit = posEta_p2_32bit | ((posEta_7bit & 0x7F) << 7 * (ithe.stNum() - 1));
167  }
168 
169  bxPresent.assign(5, false);
170 
171  } //theCont_itr
172 
173  } else { //now that we are in the next prime link #, write the buffered eta-qual
174 
175  if (moreBXeta) {
176  payload_n2[4] = posEta_n2_32bit;
177  payload_n2[5] = etaNull_32bit;
178 
179  payload_n1[4] = posEta_n1_32bit;
180  payload_n1[5] = etaNull_32bit;
181  }
182 
183  payload_0[4] = posEta_0_32bit;
184  payload_0[5] = etaNull_32bit;
185 
186  if (moreBXeta) {
187  payload_p1[4] = posEta_p1_32bit;
188  payload_p1[5] = etaNull_32bit;
189 
190  payload_p2[4] = posEta_p2_32bit;
191  payload_p2[5] = etaNull_32bit;
192  }
193  }
194 
195  //std::cout << "moreBXphi" << moreBXphi << std::endl;
196  //std::cout << "moreBXeta" << moreBXeta << std::endl;
197 
198  bool moreBX = moreBXphi || moreBXeta;
199  //std::cout << "moreBX" << moreBX << std::endl;
200 
201  //case where phi words are notcreated
202  for (int iSt = 0; iSt <= 3; iSt++) {
203  if (moreBX && payload_n2[iSt] == 0)
204  payload_n2[iSt] = phiNull_32bit;
205 
206  if (moreBX && payload_n1[iSt] == 0)
207  payload_n1[iSt] = phiNull_32bit;
208 
209  if (payload_0[iSt] == 0)
210  payload_0[iSt] = phiNull_32bit;
211 
212  if (moreBX && payload_p1[iSt] == 0)
213  payload_p1[iSt] = phiNull_32bit;
214 
215  if (moreBX && payload_p2[iSt] == 0)
216  payload_p2[iSt] = phiNull_32bit;
217  }
218 
219  //case where eta words are notcreated
220  for (int word = 4; word <= 5; word++) {
221  if (moreBX && payload_n2[word] == 0)
222  payload_n2[word] = etaNull_32bit;
223 
224  if (moreBX && payload_n1[word] == 0)
225  payload_n1[word] = etaNull_32bit;
226 
227  if (payload_0[word] == 0)
228  payload_0[word] = etaNull_32bit;
229 
230  if (moreBX && payload_p1[word] == 0)
231  payload_p1[word] = etaNull_32bit;
232 
233  if (moreBX && payload_p2[word] == 0)
234  payload_p2[word] = etaNull_32bit;
235  }
236 
237  //============================================================================================
238 
239  /*
240 
241  //debug
242  std::cout << "payload created : " << std::endl;
243  if (moreBX){
244  for (auto &word : payload_n2) //
245  std::cout << std::bitset<32>(word).to_string() << std::endl;
246 
247  for (auto &word : payload_n1) //
248  std::cout << std::bitset<32>(word).to_string() << std::endl;
249  }
250 
251  for (auto &word : payload_0) //
252  std::cout << std::bitset<32>(word).to_string() << std::endl;
253 
254  if (moreBX){
255  for (auto &word : payload_p1) //
256  std::cout << std::bitset<32>(word).to_string() << std::endl;
257 
258  for (auto &word : payload_p2) //
259  std::cout << std::bitset<32>(word).to_string() << std::endl;
260  }
261  */
262  //============================================================================================
263 
264  std::vector<uint32_t> payload;
265 
266  if (moreBX) { //push -2,-1 bx payloads
267  for (int i = 0; i < 6; i++)
268  payload.push_back(payload_n2[i]);
269  for (int i = 0; i < 6; i++)
270  payload.push_back(payload_n1[i]);
271  }
272 
273  for (int i = 0; i < 6; i++) //zero bx payload
274  payload.push_back(payload_0[i]);
275 
276  if (moreBX) { //push +1,+2 bx payloads
277  for (int i = 0; i < 6; i++)
278  payload.push_back(payload_p1[i]);
279  for (int i = 0; i < 6; i++)
280  payload.push_back(payload_p2[i]);
281  }
282 
283  //in format Block(id,payload)
284  blocks.push_back(Block(block_id, payload));
285 
286  if (link % 2 != 0) {
287  moreBXeta = false;
288  }
289 
290  } //link_itr
291 
292  return blocks;
293  }
294 
296  uint32_t temp(0);
297 
298  temp = (phInput.phi() & phiMask) << phiShift | (phInput.phiB() & phiBMask) << phiBShift |
299  (phInput.code() & qualMask) << qualShift | (phInput.RpcBit() & rpcMask) << rpcShift | (0) << 29 |
300  (phInput.BxCnt() & bxCntMask) << bxCntShift;
301 
302  // std::cout<<"uint32_t temp is: "<<std::bitset<32>(temp).to_string()<<"---- phi="<<phInput.phi()<<", phiB()="<<phInput.phiB()<<", code(qual?)="<<phInput.code()<<", RPC="<<phInput.RpcBit()<<", BC="<<phInput.BxCnt()<<std::endl;
303  return temp;
304  }
305 
306  uint32_t BMTFPackerInputs::wordThMaker(const L1MuDTChambThDigi& thInput, const bool& qualFlag) {
307  uint32_t temp(0);
308  if (!qualFlag) {
309  for (int i = 6; i >= 0; i--) {
310  temp = temp << 1;
311  temp = temp | (thInput.position(i) & 0x1);
312  }
313  } else {
314  for (int i = 6; i >= 0; i--) {
315  temp = temp << 1;
316  temp = temp | (thInput.quality(i) & 0x1);
317  }
318  }
319 
320  return temp;
321  }
322 
323  } // namespace stage2
324 } // namespace l1t
uint32_t wordPhMaker(const L1MuDTChambPhDigi &phInput)
static const unsigned int rpcShift
static const unsigned int bxCntShift
static const unsigned int phiShift
static const unsigned int phiMask
int position(const int i) const
delete x;
Definition: CaloConfig.h:22
uint32_t wordThMaker(const L1MuDTChambThDigi &thInput, const bool &qualFlag)
The_Container const * getContainer() const
uint64_t word
static const unsigned int phiBMask
std::vector< Block > Blocks
Definition: Block.h:99
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static const unsigned int qualMask
static const unsigned int qualShift
static const unsigned int bxCntMask
Phi_Container const * getContainer() const
#define DEFINE_L1T_PACKER(type)
Definition: PackerFactory.h:23
static const unsigned int rpcMask
int quality(const int i) const
unsigned board()
Definition: Packer.h:18
static const unsigned int phiBShift
Definition: event.py:1
Blocks pack(const edm::Event &, const PackerTokens *) override