CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  int theta_iterators = 0; //debug
119  for (const auto& ithe : *(thInputs->getContainer())) {
120  // Only allow -2 <= bxNum <= 2, as in Stage2 data
121  if (std::abs(ithe.bxNum()) > 2)
122  continue;
123 
124  if (ithe.bxNum() != 0)
125  moreBXeta = true;
126 
127  theta_iterators++; //debug
128 
129  //debug
130  // std::cout << "scNum+1 = " << ithe.scNum()+1 << ", board_id = " << board_id << std::endl;
131  // std::cout << "bx, station = " << ithe.bxNum() << ", " << ithe.stNum() << std::endl;
132  // std::cout << "related link: " << ownLinks_[4+2*(ithe.whNum())] << std::endl;
133 
134  if (ithe.scNum() + 1 != board_id)
135  continue;
136 
137  if (link != ownLinks_[4 + 2 * (ithe.whNum())])
138  continue;
139 
140  bxPresent[2 + ithe.bxNum()] = true;
141 
142  //positions for the next link
143  uint32_t posEta_7bit = wordThMaker(ithe, false);
144 
145  //qualities for this link
146  uint32_t qualEta_7bit = wordThMaker(ithe, true);
147  qualEta_32bit = qualEta_32bit | ((qualEta_7bit & 0x7F) << 7 * (ithe.stNum() - 1));
148 
149  //write the eta-pos and eta-qual information at the correct payload per BX
150  if (bxPresent[0]) {
151  payload_n2[4] = qualEta_32bit;
152  payload_n2[5] = etaNull_32bit | (2 & 0x2);
153  posEta_n2_32bit = posEta_n2_32bit | ((posEta_7bit & 0x7F) << 7 * (ithe.stNum() - 1));
154  } else if (bxPresent[1]) {
155  payload_n1[4] = qualEta_32bit;
156  payload_n1[5] = etaNull_32bit | (2 & 0x2);
157  posEta_n1_32bit = posEta_n1_32bit | ((posEta_7bit & 0x7F) << 7 * (ithe.stNum() - 1));
158  } else if (bxPresent[2]) {
159  payload_0[4] = qualEta_32bit;
160  payload_0[5] = etaNull_32bit | (2 & 0x2);
161  posEta_0_32bit = posEta_0_32bit | ((posEta_7bit & 0x7F) << 7 * (ithe.stNum() - 1));
162  } else if (bxPresent[3]) {
163  payload_p1[4] = qualEta_32bit;
164  payload_p1[5] = etaNull_32bit | (2 & 0x2);
165  posEta_p1_32bit = posEta_p1_32bit | ((posEta_7bit & 0x7F) << 7 * (ithe.stNum() - 1));
166  } else if (bxPresent[4]) {
167  payload_p2[4] = qualEta_32bit;
168  payload_p2[5] = etaNull_32bit | (2 & 0x2);
169  posEta_p2_32bit = posEta_p2_32bit | ((posEta_7bit & 0x7F) << 7 * (ithe.stNum() - 1));
170  }
171 
172  bxPresent.assign(5, false);
173 
174  } //theCont_itr
175 
176  } else { //now that we are in the next prime link #, write the buffered eta-qual
177 
178  if (moreBXeta) {
179  payload_n2[4] = posEta_n2_32bit;
180  payload_n2[5] = etaNull_32bit;
181 
182  payload_n1[4] = posEta_n1_32bit;
183  payload_n1[5] = etaNull_32bit;
184  }
185 
186  payload_0[4] = posEta_0_32bit;
187  payload_0[5] = etaNull_32bit;
188 
189  if (moreBXeta) {
190  payload_p1[4] = posEta_p1_32bit;
191  payload_p1[5] = etaNull_32bit;
192 
193  payload_p2[4] = posEta_p2_32bit;
194  payload_p2[5] = etaNull_32bit;
195  }
196  }
197 
198  //std::cout << "moreBXphi" << moreBXphi << std::endl;
199  //std::cout << "moreBXeta" << moreBXeta << std::endl;
200 
201  bool moreBX = moreBXphi || moreBXeta;
202  //std::cout << "moreBX" << moreBX << std::endl;
203 
204  //case where phi words are notcreated
205  for (int iSt = 0; iSt <= 3; iSt++) {
206  if (moreBX && payload_n2[iSt] == 0)
207  payload_n2[iSt] = phiNull_32bit;
208 
209  if (moreBX && payload_n1[iSt] == 0)
210  payload_n1[iSt] = phiNull_32bit;
211 
212  if (payload_0[iSt] == 0)
213  payload_0[iSt] = phiNull_32bit;
214 
215  if (moreBX && payload_p1[iSt] == 0)
216  payload_p1[iSt] = phiNull_32bit;
217 
218  if (moreBX && payload_p2[iSt] == 0)
219  payload_p2[iSt] = phiNull_32bit;
220  }
221 
222  //case where eta words are notcreated
223  for (int word = 4; word <= 5; word++) {
224  if (moreBX && payload_n2[word] == 0)
225  payload_n2[word] = etaNull_32bit;
226 
227  if (moreBX && payload_n1[word] == 0)
228  payload_n1[word] = etaNull_32bit;
229 
230  if (payload_0[word] == 0)
231  payload_0[word] = etaNull_32bit;
232 
233  if (moreBX && payload_p1[word] == 0)
234  payload_p1[word] = etaNull_32bit;
235 
236  if (moreBX && payload_p2[word] == 0)
237  payload_p2[word] = etaNull_32bit;
238  }
239 
240  //============================================================================================
241 
242  /*
243 
244  //debug
245  std::cout << "payload created : " << std::endl;
246  if (moreBX){
247  for (auto &word : payload_n2) //
248  std::cout << std::bitset<32>(word).to_string() << std::endl;
249 
250  for (auto &word : payload_n1) //
251  std::cout << std::bitset<32>(word).to_string() << std::endl;
252  }
253 
254  for (auto &word : payload_0) //
255  std::cout << std::bitset<32>(word).to_string() << std::endl;
256 
257  if (moreBX){
258  for (auto &word : payload_p1) //
259  std::cout << std::bitset<32>(word).to_string() << std::endl;
260 
261  for (auto &word : payload_p2) //
262  std::cout << std::bitset<32>(word).to_string() << std::endl;
263  }
264  */
265  //============================================================================================
266 
267  std::vector<uint32_t> payload;
268 
269  if (moreBX) { //push -2,-1 bx payloads
270  for (int i = 0; i < 6; i++)
271  payload.push_back(payload_n2[i]);
272  for (int i = 0; i < 6; i++)
273  payload.push_back(payload_n1[i]);
274  }
275 
276  for (int i = 0; i < 6; i++) //zero bx payload
277  payload.push_back(payload_0[i]);
278 
279  if (moreBX) { //push +1,+2 bx payloads
280  for (int i = 0; i < 6; i++)
281  payload.push_back(payload_p1[i]);
282  for (int i = 0; i < 6; i++)
283  payload.push_back(payload_p2[i]);
284  }
285 
286  //in format Block(id,payload)
287  blocks.push_back(Block(block_id, payload));
288 
289  if (link % 2 != 0) {
290  moreBXphi = false;
291  moreBXeta = false;
292  }
293 
294  } //link_itr
295 
296  return blocks;
297  }
298 
300  uint32_t temp(0);
301 
302  temp = (phInput.phi() & phiMask) << phiShift | (phInput.phiB() & phiBMask) << phiBShift |
303  (phInput.code() & qualMask) << qualShift | (phInput.RpcBit() & rpcMask) << rpcShift | (0) << 29 |
304  (phInput.BxCnt() & bxCntMask) << bxCntShift;
305 
306  // 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;
307  return temp;
308  }
309 
310  uint32_t BMTFPackerInputs::wordThMaker(const L1MuDTChambThDigi& thInput, const bool& qualFlag) {
311  uint32_t temp(0);
312  if (!qualFlag) {
313  for (int i = 6; i >= 0; i--) {
314  temp = temp << 1;
315  temp = temp | (thInput.position(i) & 0x1);
316  }
317  } else {
318  for (int i = 6; i >= 0; i--) {
319  temp = temp << 1;
320  temp = temp | (thInput.quality(i) & 0x1);
321  }
322  }
323 
324  return temp;
325  }
326 
327  } // namespace stage2
328 } // 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
tuple blocks
Definition: gather_cfg.py:90
uint32_t wordThMaker(const L1MuDTChambThDigi &thInput, const bool &qualFlag)
int quality(const int i) const
int position(const int i) 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
#define DEFINE_L1T_PACKER(type)
Definition: PackerFactory.h:23
static const unsigned int rpcMask
unsigned board()
Definition: Packer.h:18
static const unsigned int phiBShift
Blocks pack(const edm::Event &, const PackerTokens *) override