CMS 3D CMS Logo

BMTFUnpackerInputs.cc
Go to the documentation of this file.
2 
3 #include "BMTFUnpackerInputs.h"
4 
7 
8 namespace l1t
9 {
10  namespace stage2
11  {
12  void numWheelSectorTrTag(int& wheelNo, int& tagSegID, int linkNo, int amcNo)
13  {
14  if (linkNo >= 0 && linkNo < 6)
15  wheelNo = -2;
16  else if (linkNo >= 8 && linkNo < 14)
17  wheelNo = -1;
18  else if (linkNo >= 16 && linkNo < 22)
19  wheelNo = 0;
20  else if (linkNo >= 22 && linkNo < 28)
21  wheelNo = 1;
22  else if ( (linkNo >= 28 && linkNo < 30) || (linkNo >= 32 && linkNo < 36))
23  wheelNo = 2;
24 
25  if ( linkNo%2 == 0 )
26  tagSegID = 0;
27  else
28  tagSegID = 1;
29  }
30 
31  bool checkQual(const unsigned int& value, const bool& isNewFw)
32  {
33  if (isNewFw)
34  return (value == 7);
35  else
36  return (value == 0);
37  }
38 
39  bool unpacking(const Block& block, UnpackerCollections *coll, qualityHits& linkAndQual_, const bool& isNewFw)
40  {
41 
42  unsigned int ownLinks[] = {4,5,12,13,20,21,22,23,28,29};
43  bool ownFlag(false);
44  for (int i = 0; i < 10; i++)
45  {
46  if (block.header().getID()/2 == ownLinks[i])
47  ownFlag = true;
48  }
49  if ( !ownFlag )
50  return true;
51 
52  unsigned int blockId = block.header().getID();
53  LogDebug("L1T") << "Block ID: " << blockId << " size: " << block.header().getSize();
54  auto payload = block.payload();
55  int nBX, firstBX, lastBX;
56 
57  nBX = int(ceil(block.header().getSize()/6));
58  getBXRange(nBX, firstBX, lastBX);
59 
60  LogDebug("L1T") << "BX override. Set firstBX = lastBX = 0";
61 
62  L1MuDTChambPhContainer *resPhi = static_cast<BMTFCollections*>(coll)->getInMuonsPh();
63  L1MuDTChambThContainer *resThe = static_cast<BMTFCollections*>(coll)->getInMuonsTh();
64 
67 
68 
69  for(int ibx = firstBX; ibx <= lastBX; ibx++)
70  {
71  uint32_t inputWords[block.header().getSize()/nBX];
72 
73  for(unsigned int iw = 0; iw < block.header().getSize()/nBX; iw++)
74  inputWords[iw] = payload[iw+(ibx+lastBX)*6];
75 
76  int wheel, sector, trTag;
77  numWheelSectorTrTag(wheel, trTag, blockId/2, block.amc().getAMCNumber());
78  sector = block.amc().getBoardID() - 1;
79  if ( sector < 0 || sector > 11 )
80  {
81  edm::LogInfo ("l1t:stage2::BMTFUnpackerInputs::unpack") << "Sector found out of range so it will be calculated by the slot number";
82  if ( block.amc().getAMCNumber()%2 != 0 )
83  sector = block.amc().getAMCNumber()/2 ;
84  else
85  sector = 6 + (block.amc().getAMCNumber()/2 -1);
86  }
87 
88  int mbPhi[4], mbPhiB[4], mbQual[4], mbBxC[4], mbRPC[4];
89  //mbPhiB[2] = 0;
90 
91  for (int iw = 0; iw < 4; iw++)
92  {
93  if ( ((inputWords[iw] & 0xfffffff) == 0) || (inputWords[iw] == 0x505050bc) )
94  continue;
95  else if ( (inputWords[iw] != 0x505050bc) && (inputWords[iw+2] == 0x505050bc) )
96  continue;
97 
98 
99  if ( ((inputWords[iw] >> 11) & 0x1) == 1 )
100  mbPhi[iw] = (inputWords[iw] & 0x7FF ) - 2048;
101  else
102  mbPhi[iw] = (inputWords[iw] & 0xFFF );
103 
104 
105  if ( ((inputWords[iw] >> 21) & 0x1) == 1 )
106  mbPhiB[iw] = ( (inputWords[iw] >> 12) & 0x1FF ) - 512;
107  else
108  mbPhiB[iw] = (inputWords[iw] >> 12) & 0x3FF;
109 
110  mbQual[iw] = (inputWords[iw] >> 22) & 0x7;
111  mbRPC[iw] = (inputWords[iw] >> 26) & 0x1;
112  mbBxC[iw] = (inputWords[iw] >> 30) & 0x3;
113 
114  //if (mbQual[iw] == 0)
115  if (checkQual(mbQual[iw], isNewFw))
116  continue;
117 
118  phiData.push_back( L1MuDTChambPhDigi( ibx, wheel, sector, iw+1, mbPhi[iw], mbPhiB[iw], mbQual[iw], trTag, mbBxC[iw], mbRPC[iw] ) );
119  }//iw
120 
121 
122  int etaHits[3][7];
123  bool zeroFlag[3];
124  for (int i = 0; i < 3; i++)
125  {
126  zeroFlag[i] = false;
127  for(int j=0; j<7; j++)
128  {
129  etaHits[i][j] = (inputWords[4] >> (i*7 + j)) & 0x1;
130  if ( etaHits[i][j]!=0 )
131  zeroFlag[i] = true;
132  }
133  }
134  if ( trTag == 1 )
135  {
136  for (int i = 0; i < 3; i++)
137  {
138  if (zeroFlag[i])
139  theData.push_back(L1MuDTChambThDigi( ibx, wheel, sector, i+1, etaHits[i], linkAndQual_.hits[i]) );
140  }
141 
142  }
143  else
144  {
145  /*
146  qualityHits temp;
147  temp.linkNo = blockId/2;
148  std::copy(&etaHits[0][0], &etaHits[0][0]+3*7,&temp.hits[0][0]);
149  linkAndQual_[blockId/2] = temp;
150  */
151  linkAndQual_.linkNo = blockId/2;
152  std::copy(&etaHits[0][0], &etaHits[0][0]+3*7,&linkAndQual_.hits[0][0]);
153  }
154 
155  }//ibx
156  resThe->setContainer(theData);
157  resPhi->setContainer(phiData);
158 
159  return true;
160 
161  }
162 
164  {
165  return unpacking(block, coll, linkAndQual_, false);
166  }//unpack old quality
167 
169  {
170  return unpacking(block, coll, linkAndQual_, true);
171  }//unpack new quality
172  }//ns2
173 }//ns l1t;
174 
#define LogDebug(id)
The_Container const * getContainer() const
bool unpacking(const Block &block, UnpackerCollections *coll, qualityHits &linkAndQual_, const bool &isNewFw)
unsigned int getID() const
Definition: Block.h:22
void getBXRange(int nbx, int &first, int &last)
BlockHeader header() const
Definition: Block.h:60
virtual bool unpack(const Block &block, UnpackerCollections *coll) override
delete x;
Definition: CaloConfig.h:22
virtual bool unpack(const Block &block, UnpackerCollections *coll) override
bool checkQual(const unsigned int &value, const bool &isNewFw)
std::vector< uint32_t > payload() const
Definition: Block.h:61
payload
payload postfix for testing
std::vector< L1MuDTChambPhDigi > Phi_Container
Definition: value.py:1
std::vector< L1MuDTChambThDigi > The_Container
void setContainer(const The_Container &inputSegments)
JetCorrectorParametersCollection coll
Definition: classes.h:10
void setContainer(const Phi_Container &inputSegments)
Phi_Container const * getContainer() const
#define DEFINE_L1T_UNPACKER(type)
unsigned int getSize() const
Definition: Block.h:23
void amc(const amc::Header &h)
Definition: Block.h:63
void numWheelSectorTrTag(int &wheelNo, int &tagSegID, int linkNo, int amcNo)