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