CMS 3D CMS Logo

RegionalMuonGMTUnpacker.cc
Go to the documentation of this file.
4 
7 
8 namespace l1t {
9  namespace stage2 {
11  unsigned int blockId = block.header().getID();
12  LogDebug("L1T") << "Block ID = " << blockId << " size = " << block.header().getSize();
13  // Process only if there is a payload.
14  // If all BX block were zero suppressed the block header size is 0.
15  if (block.header().getSize() < 1) {
16  return true;
17  }
18 
19  auto payload = block.payload();
20 
21  int nBX, firstBX, lastBX;
22  // Check if per BX zero suppression was enabled
23  bool bxZsEnabled = ((block.header().getFlags() >> bxzs_enable_shift_) & 0x1) == 1;
24  // Calculate the total number of BXs
25  if (bxZsEnabled) {
26  BxBlockHeader bxHeader(payload.at(0));
27  nBX = bxHeader.getTotalBx();
28  } else {
29  nBX = int(ceil(block.header().getSize() / nWords_));
30  }
31  getBXRange(nBX, firstBX, lastBX);
32 
33  // decide which collection to use according to the link ID
34  unsigned int linkId = blockId / 2;
35  int processor;
36  RegionalMuonCandBxCollection* regionalMuonCollection;
37  RegionalMuonShowerBxCollection* regionalMuonShowerCollection;
38  tftype trackFinder;
39  if (linkId > 47 && linkId < 60) {
40  regionalMuonCollection = static_cast<GMTCollections*>(coll)->getRegionalMuonCandsBMTF();
41  regionalMuonShowerCollection =
42  new RegionalMuonShowerBxCollection(); // To avoid warning re uninitialised collection
43  trackFinder = tftype::bmtf;
44  processor = linkId - 48;
45  } else if (linkId > 41 && linkId < 66) {
46  regionalMuonCollection = static_cast<GMTCollections*>(coll)->getRegionalMuonCandsOMTF();
47  regionalMuonShowerCollection =
48  new RegionalMuonShowerBxCollection(); // To avoid warning re uninitialised collection
49  if (linkId < 48) {
50  trackFinder = tftype::omtf_pos;
51  processor = linkId - 42;
52  } else {
53  trackFinder = tftype::omtf_neg;
54  processor = linkId - 60;
55  }
56  } else if (linkId > 35 && linkId < 72) {
57  regionalMuonCollection = static_cast<GMTCollections*>(coll)->getRegionalMuonCandsEMTF();
58  regionalMuonShowerCollection = static_cast<GMTCollections*>(coll)->getRegionalMuonShowersEMTF();
59  if (linkId < 42) {
60  trackFinder = tftype::emtf_pos;
61  processor = linkId - 36;
62  } else {
63  trackFinder = tftype::emtf_neg;
64  processor = linkId - 66;
65  }
66  } else {
67  edm::LogError("L1T") << "No TF muon expected for link " << linkId;
68  return false;
69  }
70  regionalMuonCollection->setBXRange(firstBX, lastBX);
71  regionalMuonShowerCollection->setBXRange(firstBX, lastBX);
72 
73  LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;
74 
75  // Get the BX blocks and unpack them
76  auto bxBlocks = block.getBxBlocks(nWords_, bxZsEnabled);
77  for (const auto& bxBlock : bxBlocks) {
78  // Throw an exception if finding a corrupt BX header with out of range BX numbers
79  const auto bx = bxBlock.header().getBx();
80  if (bx < firstBX || bx > lastBX) {
81  throw cms::Exception("CorruptData") << "Corrupt RAW data from AMC " << block.amc().getAMCNumber()
82  << ". BX number " << bx << " in BX header is outside of the BX range ["
83  << firstBX << "," << lastBX << "] defined in the block header.";
84  }
85  // Check if there are enough words left in the BX block payload
86  auto bxPayload = bxBlock.payload();
87  if (nWords_ <= bxPayload.size()) {
88  for (unsigned nWord = 0; nWord < nWords_; nWord += 2) {
89  uint32_t raw_data_00_31 = bxPayload[nWord];
90  uint32_t raw_data_32_63 = bxPayload[nWord + 1];
91  LogDebug("L1T") << "raw_data_00_31 = 0x" << hex << setw(8) << setfill('0') << raw_data_00_31
92  << " raw_data_32_63 = 0x" << setw(8) << setfill('0') << raw_data_32_63;
93  // skip empty muons (hwPt == 0)
94  if (((raw_data_00_31 >> l1t::RegionalMuonRawDigiTranslator::ptShift_) &
96  LogDebug("L1T") << "Muon hwPt zero. Skip.";
97  continue;
98  }
99  // Detect and ignore comma events
100  if (raw_data_00_31 == 0x505050bc || raw_data_32_63 == 0x505050bc) {
101  edm::LogWarning("L1T") << "Comma detected in raw data stream. Orbit number: "
102  << block.amc().getOrbitNumber() << ", BX ID: " << block.amc().getBX()
103  << ", BX: " << bx << ", linkId: " << linkId << ", Raw data: 0x" << hex << setw(8)
104  << setfill('0') << raw_data_32_63 << setw(8) << setfill('0') << raw_data_00_31
105  << dec << ". Skip.";
106  continue;
107  }
108 
110  mu.setMuIdx(nWord / 2);
111 
113  mu, raw_data_00_31, raw_data_32_63, processor, trackFinder, isKbmtf_, useEmtfDisplacementInfo_);
114 
115  LogDebug("L1T") << "Mu" << nWord / 2 << ": eta " << mu.hwEta() << " phi " << mu.hwPhi() << " pT "
116  << mu.hwPt() << " qual " << mu.hwQual() << " sign " << mu.hwSign() << " sign valid "
117  << mu.hwSignValid() << " unconstrained pT " << mu.hwPtUnconstrained();
118 
119  regionalMuonCollection->push_back(bx, mu);
120  }
121  // Fill RegionalMuonShower objects. For this we need to look at all six words together.
122  RegionalMuonShower muShower;
124  muShower, bxPayload, processor, trackFinder, useEmtfNominalTightShowers_, useEmtfLooseShowers_)) {
125  regionalMuonShowerCollection->push_back(bx, muShower);
126  }
127  } else {
128  unsigned int nWords =
129  nWords_; // This seems unnecessary but it prevents an 'undefined reference' linker error that occurs when using nWords_ directly with LogWarning.
130  edm::LogWarning("L1T") << "Only " << bxPayload.size() << " 32 bit words in this BX but " << nWords
131  << " are required. Not unpacking the data for BX " << bx << ".";
132  }
133  }
134  return true;
135  }
136  } // namespace stage2
137 } // namespace l1t
138 
constexpr int32_t ceil(float num)
void getBXRange(int nbx, int &first, int &last)
delete x;
Definition: CaloConfig.h:22
Log< level::Error, false > LogError
bool unpack(const Block &block, UnpackerCollections *coll) override
unsigned int getTotalBx() const
Definition: BxBlock.h:27
static bool fillRegionalMuonShower(RegionalMuonShower &muShower, std::vector< uint32_t > bxPayload, int proc, tftype tf, bool useEmtfNominalTightShowers, bool useEmtfLooseShowers)
BXVector< RegionalMuonShower > RegionalMuonShowerBxCollection
void setBXRange(int bxFirst, int bxLast)
#define DEFINE_L1T_UNPACKER(type)
Log< level::Warning, false > LogWarning
static void fillRegionalMuonCand(RegionalMuonCand &mu, uint32_t raw_data_00_31, uint32_t raw_data_32_63, int proc, tftype tf, bool isKbmtf, bool useEmtfDisplacementInfo)
void push_back(int bx, T object)
#define LogDebug(id)
static constexpr unsigned bxzs_enable_shift_