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& sectorNo, 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 ( amcNo%2 != 0 )
24  sectorNo = amcNo/2 ;
25  else
26  sectorNo = 6 + (amcNo/2 -1);
27 
28  if ( linkNo%2 == 0 )
29  tagSegID = 0;
30  else
31  tagSegID = 1;
32  }
33 
35  {
36  unsigned int ownLinks[] = {4,5,12,13,20,21,22,23,28,29};
37  bool ownFlag(false);
38  for (int i = 0; i < 10; i++)
39  {
40  if (block.header().getID()/2 == ownLinks[i])
41  ownFlag = true;
42  }
43  if ( !ownFlag )
44  return true;
45 
46  unsigned int blockId = block.header().getID();
47  LogDebug("L1T") << "Block ID: " << blockId << " size: " << block.header().getSize();
48  auto payload = block.payload();
49  int nBX, firstBX, lastBX;
50 
51  nBX = int(ceil(block.header().getSize()/6));
52  getBXRange(nBX, firstBX, lastBX);
53 
54  LogDebug("L1T") << "BX override. Set firstBX = lastBX = 0";
55 
56  L1MuDTChambPhContainer *resPhi;
57  //std::cout << "Checking link: " << blockId << std::endl;
58  //std::cout << "Address before is: " << resPhi << std::endl;
59  L1MuDTChambThContainer *resThe;
60  resPhi = static_cast<BMTFCollections*>(coll)->getInMuonsPh();
61  resThe = static_cast<BMTFCollections*>(coll)->getInMuonsTh();
62  //std::cout << "Address after is: " << resPhi << std::endl;
63  L1MuDTChambPhContainer::Phi_Container phi_data = *(resPhi->getContainer());
64 
65 
67 
68  for(int ibx = firstBX; ibx <= lastBX; ibx++)
69  {
70  uint32_t inputWords[block.header().getSize()/nBX];
71 
72  for(unsigned int iw = 0; iw < block.header().getSize()/nBX; iw++)
73  inputWords[iw] = payload[iw+(ibx+lastBX)*6];
74 
75  int wheel, sector, trTag;
76  numWheelSectorTrTag(wheel, sector, trTag, blockId/2, block.amc().getAMCNumber());
77 
78  int mbPhi[4], mbPhiB[4], mbQual[4], mbBxC[4], mbRPC[4];
79  //mbPhiB[2] = 0;
80 
81  for (int iw = 0; iw < 4; iw++)
82  {
83  if ( ((inputWords[iw] & 0xfffffff) == 0) || (inputWords[iw] == 0x505050bc) )
84  continue;
85  else if ( (inputWords[iw] != 0x505050bc) && (inputWords[iw+2] == 0x505050bc) )
86  continue;
87 
88 
89  if ( ((inputWords[iw] >> 11) & 0x1) == 1 )
90  mbPhi[iw] = (inputWords[iw] & 0x7FF ) - 2048;
91  else
92  mbPhi[iw] = (inputWords[iw] & 0xFFF );
93 
94 
95  if ( ((inputWords[iw] >> 21) & 0x1) == 1 )
96  mbPhiB[iw] = ( (inputWords[iw] >> 12) & 0x1FF ) - 512;
97  else
98  mbPhiB[iw] = (inputWords[iw] >> 12) & 0x3FF;
99 
100  mbQual[iw] = (inputWords[iw] >> 22) & 0xF;
101  mbRPC[iw] = (inputWords[iw] >> 26) & 0x1;
102  mbBxC[iw] = (inputWords[iw] >> 30) & 0x3;
103 
104  //if (wheel>0)
105  // std::cout << iw+1 << "\tWord: " << std::hex << inputWords[iw] << std::dec << "\tLink: " << blockId/2 << "\tamc: " << block.amc().getAMCNumber() << "\twheel: " << wheel << "\tsector: " << sector << std::endl;
106  if (mbQual[iw] == 0)
107  continue;
108 
109  phi_data.push_back( L1MuDTChambPhDigi( ibx, wheel, sector, iw+1, mbPhi[iw], mbPhiB[iw], mbQual[iw], trTag, mbBxC[iw], mbRPC[iw] ) );
110  //std::cout << iw+1 << "\tAfter push: " << std::hex << inputWords[iw] << std::dec << "\tLink: " << blockId/2 << "\tamc: " << block.amc().getAMCNumber() << "\twheel: " << phi_data.back().whNum() << "\tsector: " << phi_data.back().scNum() << "\tTsTag: " << phi_data.back().Ts2Tag() << std::endl;
111  }//iw
112  int mbEta[3][7];//, mbEtaBxC;
113  for (int i = 0; i < 3; i++)
114  {
115  for(int j=0; j<7; j++)
116  mbEta[i][j] = (inputWords[4] >> (i*7 + j)) & 0x1;
117 
118  the_data.push_back(L1MuDTChambThDigi( ibx, wheel, sector, i+1, mbEta[i]) );
119  }
120 
121 
122  //std::cout << "phi_data size: " << phi_data.size() << std::endl;
123 
124  }//ibx
125  //std::cout << "Final size: " << phi_data.size() << std::endl;
126  //std::cout << "Address before set is: " << resPhi << std::endl;
127  resPhi->setContainer(phi_data);
128  //std::cout << "Address after set is: " << resPhi << std::endl;
129  //if (phi_data.size() != 0)
130  //std::cout << "\tAfter set: " << "\twheel: " << phi_data.back().whNum() << "\tsector: " << phi_data.back().scNum() << std::endl;
131  resThe->setContainer(the_data);
132 
133  return true;
134  }//unpack
135  }//ns2
136 }//ns l1t;
137 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
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
void numWheelSectorTrTag(int &wheelNo, int &sectorNo, int &tagSegID, int linkNo, int amcNo)
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