CMS 3D CMS Logo

MuonUnpacker.cc
Go to the documentation of this file.
4 
5 
7 
8 #include "MuonUnpacker.h"
9 
10 namespace l1t {
11  namespace stage2 {
12  MuonUnpacker::MuonUnpacker() : res_(nullptr), algoVersion_(0), muonCopy_(0)
13  {
14  }
15 
16  bool
18  {
19  LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize();
20  // process only if there is a payload
21  // If all BX block were zero suppressed the block header size is 0.
22  if (block.header().getSize() < 1) {
23  return true;
24  }
25 
26  auto payload = block.payload();
27 
28  int nBX, firstBX, lastBX;
29  // Check if per BX zero suppression was enabled
30  bool bxZsEnabled = ((block.header().getFlags() >> bxzs_enable_shift_) & 0x1) == 1;
31  // Calculate the total number of BXs
32  if (bxZsEnabled) {
33  BxBlockHeader bxHeader(payload.at(0));
34  nBX = bxHeader.getTotalBx();
35  } else {
36  nBX = int(ceil(block.header().getSize() / nWords_));
37  }
38  getBXRange(nBX, firstBX, lastBX);
39 
40  // Set the muon collection and the BX range
41  res_ = static_cast<L1TObjectCollections*>(coll)->getMuons(muonCopy_);
42  res_->setBXRange(firstBX, lastBX);
43  LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;
44 
45  // Get the BX blocks and unpack them
46  auto bxBlocks = block.getBxBlocks(nWords_, bxZsEnabled);
47  for (const auto& bxBlock : bxBlocks) {
48  // Throw an exception if finding a corrupt BX header with out of range BX numbers
49  const auto bx = bxBlock.header().getBx();
50  if (bx < firstBX || bx > lastBX) {
51  throw cms::Exception("CorruptData") << "Corrupt RAW data from FED " << fed_ << ", AMC " << block.amc().getAMCNumber() << ". BX number " << bx << " in BX header is outside of the BX range [" << firstBX << "," << lastBX << "] defined in the block header.";
52  }
53  unpackBx(bx, bxBlock.payload());
54  }
55  return true;
56  }
57 
58 
59  void
60  MuonUnpacker::unpackBx(int bx, const std::vector<uint32_t>& payload, unsigned int startIdx)
61  {
62  unsigned int i = startIdx;
63  // Check if there are enough words left in the payload
64  if (i + nWords_ <= payload.size()) {
65  for (unsigned nWord = 0; nWord < nWords_; nWord += 2) {
66  uint32_t raw_data_00_31 = payload[i++];
67  uint32_t raw_data_32_63 = payload[i++];
68  LogDebug("L1T") << "raw_data_00_31 = 0x" << hex << raw_data_00_31 << " raw_data_32_63 = 0x" << raw_data_32_63;
69  // skip empty muons (hwPt == 0)
71  LogDebug("L1T") << "Muon hwPt zero. Skip.";
72  continue;
73  }
74 
75  Muon mu;
76 
77  MuonRawDigiTranslator::fillMuon(mu, raw_data_00_31, raw_data_32_63, fed_, algoVersion_);
78 
79  LogDebug("L1T") << "Mu" << nWord/2 << ": eta " << mu.hwEta() << " phi " << mu.hwPhi() << " pT " << mu.hwPt() << " iso " << mu.hwIso() << " qual " << mu.hwQual() << " charge " << mu.hwCharge() << " charge valid " << mu.hwChargeValid();
80 
81  res_->push_back(bx, mu);
82  }
83  } else {
84  edm::LogWarning("L1T") << "Only " << payload.size() - i << " 32 bit words in this BX but " << nWords_ << " are required. Not unpacking the data for BX " << bx << ".";
85  }
86  }
87  }
88 }
89 
#define LogDebug(id)
unsigned int getID() const
Definition: Block.h:21
MuonBxCollection * res_
Definition: MuonUnpacker.h:29
static unsigned bxzs_enable_shift_
Definition: MuonUnpacker.h:27
void getBXRange(int nbx, int &first, int &last)
BlockHeader header() const
Definition: Block.h:59
int hwPhi() const
Definition: L1Candidate.h:50
delete x;
Definition: CaloConfig.h:22
#define nullptr
std::vector< uint32_t > payload() const
Definition: Block.h:60
bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: MuonUnpacker.cc:17
int hwIso() const
Definition: L1Candidate.h:52
Definition: Muon.py:1
void unpackBx(int bx, const std::vector< uint32_t > &payload, unsigned int startIdx=0)
Definition: MuonUnpacker.cc:60
unsigned int getTotalBx() const
Definition: BxBlock.h:23
const int mu
Definition: Constants.h:22
int hwEta() const
Definition: L1Candidate.h:49
int hwQual() const
Definition: L1Candidate.h:51
static unsigned nWords_
Definition: MuonUnpacker.h:26
JetCorrectorParametersCollection coll
Definition: classes.h:10
int hwPt() const
Definition: L1Candidate.h:48
static const unsigned ptShift_
void setBXRange(int bxFirst, int bxLast)
BxBlocks getBxBlocks(unsigned int payloadWordsPerBx, bool bxHeader) const
Definition: Block.cc:47
#define DEFINE_L1T_UNPACKER(type)
unsigned int getSize() const
Definition: Block.h:22
void amc(const amc::Header &h)
Definition: Block.h:62
int hwChargeValid() const
Definition: Muon.h:83
unsigned int getFlags() const
Definition: Block.h:24
void push_back(int bx, T object)
int hwCharge() const
Definition: Muon.h:82
static const unsigned ptMask_
static void fillMuon(Muon &, uint32_t, uint32_t, int, unsigned int)