test
CMS 3D CMS Logo

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