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