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