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 
45  //Checks if the given block coresponds to 1 of the OWN links
46  for (int i = 0; i < 10; i++)
47  {
48  if (block.header().getID()/2 == ownLinks[i])
49  ownFlag = true;
50  }
51  if ( !ownFlag )//if not returns that the "job here done"
52  return true;
53 
54 
55  //Get header ID and payload from the given Block
56  unsigned int blockId = block.header().getID();
57  LogDebug("L1T") << "Block ID: " << blockId << " size: " << block.header().getSize();
58  auto payload = block.payload();
59 
60  //Make output CMSSW collections
61  L1MuDTChambPhContainer *resPhi = static_cast<BMTFCollections*>(coll)->getInMuonsPh();
62  L1MuDTChambThContainer *resThe = static_cast<BMTFCollections*>(coll)->getInMuonsTh();
63 
64  //Get input phi & eta Containers
67 
68  //ZeroSuppresion Handler
69  BxBlocks bxBlocks;
70  bool ZS_enabled = (bool)((block.header().getFlags() >> 1) & 0x01);//getFlags() returns first 8-bits from the amc header
71  if (ZS_enabled)
72  bxBlocks = block.getBxBlocks((unsigned int)6, true);//it returnes 7-32bit bxBlocks originated from the amc13 Block
73  else
74  bxBlocks = block.getBxBlocks((unsigned int)6, false);//it returnes 6-32bit bxBlocks originated from the amc13 Block
75 
76 
77  for(auto ibx : bxBlocks)//Bx iteration
78  {
79 
80  int bxNum = ibx.header().getBx();
81  uint32_t inputWords[ibx.getSize()]; //array of 6 uint32_t payload-words (size of the payload in the BxBlock)
82 
83  //Fill the above uint32_t array
84  for(unsigned int iw = 0; iw < ibx.getSize(); iw++)
85  inputWords[iw] = (ibx.payload())[iw];
86 
87  int wheel, sector, trTag;//Container information
88  numWheelSectorTrTag(wheel, trTag, blockId/2, block.amc().getAMCNumber());//this returns wheel & tsTag
89  sector = block.amc().getBoardID() - 1;
90 
91  //Check if the sector is "out of range" - (trys then to use AMC13 information?)
92  if ( sector < 0 || sector > 11 )
93  {
94  edm::LogInfo ("l1t:stage2::BMTFUnpackerInputs::unpack") << "Sector found out of range so it will be calculated by the slot number";
95  if ( block.amc().getAMCNumber()%2 != 0 )
96  sector = block.amc().getAMCNumber()/2 ;
97  else
98  sector = 6 + (block.amc().getAMCNumber()/2 -1);
99  }
100 
101  int mbPhi[4], mbPhiB[4], mbQual[4], mbBxC[4], mbRPC[4];//Container information
102  //mbPhiB[2] = 0;
103 
104  for (int iw = 0; iw < 4; iw++)// 4 phi (32-bit) words
105  {
106  if ( ((inputWords[iw] & 0xfffffff) == 0) || (inputWords[iw] == 0x505050bc) )
107  continue;
108  else if ( (inputWords[iw] != 0x505050bc) && (inputWords[iw+2] == 0x505050bc) )
109  continue;
110 
111 
112  if ( ((inputWords[iw] >> 11) & 0x1) == 1 )
113  mbPhi[iw] = (inputWords[iw] & 0x7FF ) - 2048;
114  else
115  mbPhi[iw] = (inputWords[iw] & 0xFFF );
116 
117 
118  if ( ((inputWords[iw] >> 21) & 0x1) == 1 )
119  mbPhiB[iw] = ( (inputWords[iw] >> 12) & 0x1FF ) - 512;
120  else
121  mbPhiB[iw] = (inputWords[iw] >> 12) & 0x3FF;
122 
123  mbQual[iw] = (inputWords[iw] >> 22) & 0x7;
124  mbRPC[iw] = (inputWords[iw] >> 26) & 0x1;
125  mbBxC[iw] = (inputWords[iw] >> 30) & 0x3;
126 
127  //if (mbQual[iw] == 0)
128  if (checkQual(mbQual[iw], isNewFw))
129  continue;
130 
131  phiData.push_back( L1MuDTChambPhDigi( bxNum, wheel, sector, iw+1, mbPhi[iw], mbPhiB[iw], mbQual[iw], trTag, mbBxC[iw], mbRPC[iw] ) );
132 
133  }//4 phi words
134 
135 
136  int etaHits[3][7];//Container information
137  bool zeroFlag[3];
138  for (int i = 0; i < 3; i++)// 3 eta (7-bit) words
139  {
140  zeroFlag[i] = false;
141  for(int j=0; j<7; j++)
142  {
143  etaHits[i][j] = (inputWords[4] >> (i*7 + j)) & 0x1;
144  if ( etaHits[i][j]!=0 )
145  zeroFlag[i] = true;
146  }
147  }//3 eta words
148 
149 
150  if ( trTag == 1 )
151  {
152  for (int i = 0; i < 3; i++)
153  {
154  if (zeroFlag[i])
155  theData.push_back(L1MuDTChambThDigi( bxNum, wheel, sector, i+1, etaHits[i], linkAndQual_.hits[i]) );
156  }
157 
158  }
159  else
160  {
161  /*
162  qualityHits temp;
163  temp.linkNo = blockId/2;
164  std::copy(&etaHits[0][0], &etaHits[0][0]+3*7,&temp.hits[0][0]);
165  linkAndQual_[blockId/2] = temp;
166  */
167  linkAndQual_.linkNo = blockId/2;
168  std::copy(&etaHits[0][0], &etaHits[0][0]+3*7,&linkAndQual_.hits[0][0]);
169  }
170 
171 
172  }//iBxBlock
173 
174  //Fill Containers
175  resThe->setContainer(theData);
176  resPhi->setContainer(phiData);
177 
178  return true;
179 
180  }
181 
183  {
184  return unpacking(block, coll, linkAndQual_, false);
185  }//unpack old quality
186 
188  {
189  return unpacking(block, coll, linkAndQual_, true);
190  }//unpack new quality
191  }//ns2
192 }//ns l1t;
193 
#define LogDebug(id)
The_Container const * getContainer() const
bool unpacking(const Block &block, UnpackerCollections *coll, qualityHits &linkAndQual_, const bool &isNewFw)
const std::vector< uint32_t > & payload() const
Definition: Block.h:60
unsigned int getID() const
Definition: Block.h:21
def copy(args, dbName)
BlockHeader header() const
Definition: Block.h:59
bool unpack(const Block &block, UnpackerCollections *coll) override
delete x;
Definition: CaloConfig.h:22
bool unpack(const Block &block, UnpackerCollections *coll) override
bool checkQual(const unsigned int &value, const bool &isNewFw)
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
std::vector< BxBlock > BxBlocks
Definition: BxBlock.h:68
void setContainer(const Phi_Container &inputSegments)
Phi_Container const * getContainer() const
BxBlocks getBxBlocks(unsigned int payloadWordsPerBx, bool bxHeader) const
Definition: Block.cc:47
#define DEFINE_L1T_UNPACKER(type)
unsigned int getSize() const
Definition: Block.h:22
void amc(const amc::Header &h)
Definition: Block.h:62
unsigned int getFlags() const
Definition: Block.h:24
void numWheelSectorTrTag(int &wheelNo, int &tagSegID, int linkNo, int amcNo)