CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
112  mu, raw_data_00_31, raw_data_32_63, processor, trackFinder, isKbmtf_, useEmtfDisplacementInfo_);
113 
114  LogDebug("L1T") << "Mu" << nWord / 2 << ": eta " << mu.hwEta() << " phi " << mu.hwPhi() << " pT "
115  << mu.hwPt() << " qual " << mu.hwQual() << " sign " << mu.hwSign() << " sign valid "
116  << mu.hwSignValid() << " unconstrained pT " << mu.hwPtUnconstrained();
117 
118  regionalMuonCollection->push_back(bx, mu);
119  }
120  // Fill RegionalMuonShower objects. For this we need to look at all six words together.
121  RegionalMuonShower muShower;
123  muShower, bxPayload, processor, trackFinder, useEmtfShowers_)) {
124  regionalMuonShowerCollection->push_back(bx, muShower);
125  }
126  } else {
127  unsigned int nWords =
128  nWords_; // This seems unnecessary but it prevents an 'undefined reference' linker error that occurs when using nWords_ directly with LogWarning.
129  edm::LogWarning("L1T") << "Only " << bxPayload.size() << " 32 bit words in this BX but " << nWords
130  << " are required. Not unpacking the data for BX " << bx << ".";
131  }
132  }
133  return true;
134  }
135  } // namespace stage2
136 } // namespace l1t
137 
constexpr int32_t ceil(float num)
const std::vector< uint32_t > & payload() const
Definition: Block.h:86
const int hwSignValid() const
Get charge sign valid bit (0 - not valid (high pT muon); 1 - valid)
unsigned int getID() const
Definition: Block.h:43
void getBXRange(int nbx, int &first, int &last)
BlockHeader header() const
Definition: Block.h:85
Log< level::Error, false > LogError
const int hwQual() const
Get quality code.
bool unpack(const Block &block, UnpackerCollections *coll) override
unsigned int getTotalBx() const
Definition: BxBlock.h:27
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)
BXVector< RegionalMuonShower > RegionalMuonShowerBxCollection
static bool fillRegionalMuonShower(RegionalMuonShower &muShower, std::vector< uint32_t > bxPayload, int proc, tftype tf, bool useEmtfShowers)
void setBXRange(int bxFirst, int bxLast)
BxBlocks getBxBlocks(unsigned int payloadWordsPerBx, bool bxHeader) const
Definition: Block.cc:40
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:44
const int hwSign() const
Get charge sign bit (charge = (-1)^(sign))
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 amc(const amc::Header &h)
Definition: Block.h:88
unsigned int getFlags() const
Definition: Block.h:46
void push_back(int bx, T object)
const int hwPtUnconstrained() const
Get second compressed pT (returned int * 1.0 = pT (GeV))
#define LogDebug(id)
static constexpr unsigned bxzs_enable_shift_