CMS 3D CMS Logo

RegionalMuonGMTUnpacker.cc
Go to the documentation of this file.
4 
7 
8 namespace l1t {
9  namespace stage2 {
10  bool
12  {
13  unsigned int blockId = block.header().getID();
14  LogDebug("L1T") << "Block ID = " << blockId << " size = " << block.header().getSize();
15  // Process only if there is a payload.
16  // If all BX block were zero suppressed the block header size is 0.
17  if (block.header().getSize() < 1) {
18  return true;
19  }
20 
21  auto payload = block.payload();
22 
23  int nBX, firstBX, lastBX;
24  // Check if per BX zero suppression was enabled
25  bool bxZsEnabled = ((block.header().getFlags() >> bxzs_enable_shift_) & 0x1) == 1;
26  // Calculate the total number of BXs
27  if (bxZsEnabled) {
28  BxBlockHeader bxHeader(payload.at(0));
29  nBX = bxHeader.getTotalBx();
30  } else {
31  nBX = int(ceil(block.header().getSize() / nWords_));
32  }
33  getBXRange(nBX, firstBX, lastBX);
34 
35  // decide which collection to use according to the link ID
36  unsigned int linkId = blockId / 2;
37  int processor;
39  tftype trackFinder;
40  if (linkId > 47 && linkId < 60) {
41  res = static_cast<GMTCollections*>(coll)->getRegionalMuonCandsBMTF();
42  trackFinder = tftype::bmtf;
43  processor = linkId - 48;
44  } else if (linkId > 41 && linkId < 66) {
45  res = static_cast<GMTCollections*>(coll)->getRegionalMuonCandsOMTF();
46  if (linkId < 48) {
47  trackFinder = tftype::omtf_pos;
48  processor = linkId - 42;
49  } else {
50  trackFinder = tftype::omtf_neg;
51  processor = linkId - 60;
52  }
53  } else if (linkId > 35 && linkId < 72) {
54  res = static_cast<GMTCollections*>(coll)->getRegionalMuonCandsEMTF();
55  if (linkId < 42) {
56  trackFinder = tftype::emtf_pos;
57  processor = linkId - 36;
58  } else {
59  trackFinder = tftype::emtf_neg;
60  processor = linkId - 66;
61  }
62  } else {
63  edm::LogError("L1T") << "No TF muon expected for link " << linkId;
64  return false;
65  }
66  res->setBXRange(firstBX, lastBX);
67 
68  LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;
69 
70  // Get the BX blocks and unpack them
71  auto bxBlocks = block.getBxBlocks(nWords_, bxZsEnabled);
72  for (const auto& bxBlock : bxBlocks) {
73  // Throw an exception if finding a corrupt BX header with out of range BX numbers
74  const auto bx = bxBlock.header().getBx();
75  if (bx < firstBX || bx > lastBX) {
76  throw cms::Exception("CorruptData") << "Corrupt RAW data from AMC " << block.amc().getAMCNumber() << ". BX number " << bx << " in BX header is outside of the BX range [" << firstBX << "," << lastBX << "] defined in the block header.";
77  }
78  // Check if there are enough words left in the BX block payload
79  auto bxPayload = bxBlock.payload();
80  if (nWords_ <= bxPayload.size()) {
81  for (unsigned nWord = 0; nWord < nWords_; nWord += 2) {
82  uint32_t raw_data_00_31 = bxPayload[nWord];
83  uint32_t raw_data_32_63 = bxPayload[nWord+1];
84  LogDebug("L1T") << "raw_data_00_31 = 0x" << hex << setw(8) << setfill('0') << raw_data_00_31 << " raw_data_32_63 = 0x" << setw(8) << setfill('0') << raw_data_32_63;
85  // skip empty muons (hwPt == 0)
87  LogDebug("L1T") << "Muon hwPt zero. Skip.";
88  continue;
89  }
90  // Detect and ignore comma events
91  if (raw_data_00_31 == 0x505050bc || raw_data_32_63 == 0x505050bc) {
92  edm::LogWarning("L1T") << "Comma detected in raw data stream. Orbit number: " << block.amc().getOrbitNumber() << ", BX ID: " << block.amc().getBX() << ", BX: " << bx << ", linkId: " << linkId << ", Raw data: 0x" << hex << setw(8) << setfill('0') << raw_data_32_63 << setw(8) << setfill('0') << raw_data_00_31 << dec << ". Skip.";
93  continue;
94  }
95 
97 
98  RegionalMuonRawDigiTranslator::fillRegionalMuonCand(mu, raw_data_00_31, raw_data_32_63, processor, trackFinder);
99 
100  LogDebug("L1T") << "Mu" << nWord/2 << ": eta " << mu.hwEta() << " phi " << mu.hwPhi() << " pT " << mu.hwPt() << " qual " << mu.hwQual() << " sign " << mu.hwSign() << " sign valid " << mu.hwSignValid();
101 
102  res->push_back(bx, mu);
103  }
104  } else {
105  unsigned int nWords = nWords_; // This seems unnecessary but it prevents an 'undefined reference' linker error that occurs when using nWords_ directly with LogWarning.
106  edm::LogWarning("L1T") << "Only " << bxPayload.size() << " 32 bit words in this BX but " << nWords << " are required. Not unpacking the data for BX " << bx << ".";
107  }
108  }
109  return true;
110  }
111  }
112 }
113 
#define LogDebug(id)
const int hwSignValid() const
Get charge sign valid bit (0 - not valid (high pT muon); 1 - valid)
unsigned int getID() const
Definition: Block.h:21
void getBXRange(int nbx, int &first, int &last)
BlockHeader header() const
Definition: Block.h:59
delete x;
Definition: CaloConfig.h:22
std::vector< uint32_t > payload() const
Definition: Block.h:60
Definition: Electron.h:4
const int hwQual() const
Get quality code.
bool unpack(const Block &block, UnpackerCollections *coll) override
unsigned int getTotalBx() const
Definition: BxBlock.h:23
const int hwEta() const
Get compressed eta (returned int * 0.010875 = eta)
const int mu
Definition: Constants.h:22
const int hwPhi() const
Get compressed local phi (returned int * 2*pi/576 = local phi in rad)
JetCorrectorParametersCollection coll
Definition: classes.h:10
static void fillRegionalMuonCand(RegionalMuonCand &, uint32_t, uint32_t, int, tftype)
void setBXRange(int bxFirst, int bxLast)
BxBlocks getBxBlocks(unsigned int payloadWordsPerBx, bool bxHeader) const
Definition: Block.cc:47
const int hwPt() const
Get compressed pT (returned int * 0.5 = pT (GeV))
#define DEFINE_L1T_UNPACKER(type)
unsigned int getSize() const
Definition: Block.h:22
const int hwSign() const
Get charge sign bit (charge = (-1)^(sign))
void amc(const amc::Header &h)
Definition: Block.h:62
unsigned int getFlags() const
Definition: Block.h:24
void push_back(int bx, T object)