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  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
l1t::Blocks
std::vector< Block > Blocks
Definition: Block.h:99
mps_fire.i
i
Definition: mps_fire.py:428
L1MuDTChambThDigi::position
int position(const int i) const
Definition: L1MuDTChambThDigi.cc:90
MainPageGenerator.link
link
Definition: MainPageGenerator.py:271
L1MuDTChambPhDigi::RpcBit
int RpcBit() const
Definition: L1MuDTChambPhDigi.cc:84
l1t::stage2::BMTFPackerInputs
Definition: BMTFPackerInputs.h:13
l1t::stage2::BMTFPackerInputs::ownLinks_
static const int ownLinks_[]
Definition: BMTFPackerInputs.h:34
edm::Handle< L1MuDTChambPhContainer >
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
L1MuDTChambPhDigi::phiB
int phiB() const
Definition: L1MuDTChambPhDigi.cc:76
L1MuDTChambPhContainer::getContainer
Phi_Container const * getContainer() const
Definition: L1MuDTChambPhContainer.cc:41
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
l1t::stage2::BMTFPackerInputs::qualShift
static const unsigned int qualShift
Definition: BMTFPackerInputs.h:28
l1t::stage2::BMTFPackerInputs::bxCntMask
static const unsigned int bxCntMask
Definition: BMTFPackerInputs.h:31
L1MuDTChambPhDigi::BxCnt
int BxCnt() const
Definition: L1MuDTChambPhDigi.cc:82
L1MuDTChambPhDigi::phi
int phi() const
Definition: L1MuDTChambPhDigi.cc:74
jets_cff.payload
payload
Definition: jets_cff.py:32
BMTFPackerInputs.h
DEFINE_L1T_PACKER
#define DEFINE_L1T_PACKER(type)
Definition: PackerFactory.h:23
l1t
delete x;
Definition: CaloConfig.h:22
l1t::stage2::BMTFPackerInputs::phiBShift
static const unsigned int phiBShift
Definition: BMTFPackerInputs.h:26
createfilelist.int
int
Definition: createfilelist.py:10
l1t::stage2::BMTFPackerInputs::phiBMask
static const unsigned int phiBMask
Definition: BMTFPackerInputs.h:25
L1MuDTChambThContainer::getContainer
The_Container const * getContainer() const
Definition: L1MuDTChambThContainer.cc:41
l1t::stage2::BMTFPackerInputs::phiMask
static const unsigned int phiMask
Definition: BMTFPackerInputs.h:23
l1t::stage2::BMTFPackerInputs::bxCntShift
static const unsigned int bxCntShift
Definition: BMTFPackerInputs.h:32
L1MuDTChambThDigi::quality
int quality(const int i) const
Definition: L1MuDTChambThDigi.cc:97
l1t::PackerTokens
Definition: PackerTokens.h:10
SiStripSourceConfigTier0_cff.stage2
stage2
Definition: SiStripSourceConfigTier0_cff.py:71
l1t::stage2::BMTFPackerInputs::rpcShift
static const unsigned int rpcShift
Definition: BMTFPackerInputs.h:30
L1MuDTChambThDigi
Definition: L1MuDTChambThDigi.h:33
l1t::stage2::BMTFPackerInputs::phiShift
static const unsigned int phiShift
Definition: BMTFPackerInputs.h:24
l1t::stage2::BMTFPackerInputs::pack
Blocks pack(const edm::Event &, const PackerTokens *) override
Definition: BMTFPackerInputs.cc:11
l1t::stage2::BMTFPackerInputs::wordPhMaker
uint32_t wordPhMaker(const L1MuDTChambPhDigi &phInput)
Definition: BMTFPackerInputs.cc:299
l1t::stage2::BMTFPackerInputs::wordThMaker
uint32_t wordThMaker(const L1MuDTChambThDigi &thInput, const bool &qualFlag)
Definition: BMTFPackerInputs.cc:310
l1t::stage2::BMTFPackerInputs::qualMask
static const unsigned int qualMask
Definition: BMTFPackerInputs.h:27
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
L1MuDTChambPhDigi::code
int code() const
Definition: L1MuDTChambPhDigi.cc:78
l1t::Block
Definition: Block.h:70
l1t::stage2::BMTFPackerInputs::rpcMask
static const unsigned int rpcMask
Definition: BMTFPackerInputs.h:29
gather_cfg.blocks
blocks
Definition: gather_cfg.py:90
l1t::Packer::board
unsigned board()
Definition: Packer.h:18
L1MuDTChambPhDigi
Definition: L1MuDTChambPhDigi.h:31