CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MuonUnpacker.cc
Go to the documentation of this file.
4 
6 
7 #include "MuonUnpacker.h"
8 
9 namespace l1t {
10  namespace stage2 {
11  MuonUnpacker::MuonUnpacker() : res_(nullptr), muonCopy_(0) {}
12 
14  LogDebug("L1T") << "Block ID = " << block.header().getID() << " 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  // Set the muon collection and the BX range
36  res_ = static_cast<L1TObjectCollections*>(coll)->getMuons(muonCopy_);
37  res_->setBXRange(firstBX, lastBX);
38  LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;
39 
40  // Get the BX blocks and unpack them
41  auto bxBlocks = block.getBxBlocks(nWords_, bxZsEnabled);
42  for (const auto& bxBlock : bxBlocks) {
43  // Throw an exception if finding a corrupt BX header with out of range BX numbers
44  const auto bx = bxBlock.header().getBx();
45  if (bx < firstBX || bx > lastBX) {
46  throw cms::Exception("CorruptData")
47  << "Corrupt RAW data from FED " << fed_ << ", AMC " << block.amc().getAMCNumber() << ". BX number " << bx
48  << " in BX header is outside of the BX range [" << firstBX << "," << lastBX
49  << "] defined in the block header.";
50  }
51  unpackBx(bx, bxBlock.payload());
52  }
53  return true;
54  }
55 
56  void MuonUnpacker::unpackBx(int bx, const std::vector<uint32_t>& payload, unsigned int startIdx) {
57  unsigned int i = startIdx + 2; // Only words 2-5 are "standard" muon words.
58  // Check if there are enough words left in the payload
59  if (startIdx + nWords_ <= payload.size()) {
60  for (unsigned nWord = 2; nWord < nWords_; nWord += 2) { // Only words 2-5 are "standard" muon words.
61  uint32_t raw_data_spare = payload[startIdx + 1];
62  uint32_t raw_data_00_31 = payload[i++];
63  uint32_t raw_data_32_63 = payload[i++];
64  LogDebug("L1T") << "raw_data_spare = 0x" << hex << raw_data_spare << " raw_data_00_31 = 0x" << raw_data_00_31
65  << " raw_data_32_63 = 0x" << raw_data_32_63;
66  // skip empty muons (hwPt == 0)
68  LogDebug("L1T") << "Muon hwPt zero. Skip.";
69  continue;
70  }
71 
72  Muon mu;
73 
75  mu, raw_data_spare, raw_data_00_31, raw_data_32_63, fed_, getAlgoVersion(), nWord / 2);
76 
77  LogDebug("L1T") << "Mu" << nWord / 2 << ": eta " << mu.hwEta() << " phi " << mu.hwPhi() << " pT " << mu.hwPt()
78  << " iso " << mu.hwIso() << " qual " << mu.hwQual() << " charge " << mu.hwCharge()
79  << " 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_
85  << " are required. Not unpacking the data for BX " << bx << ".";
86  }
87  }
88  } // namespace stage2
89 } // namespace l1t
90 
constexpr int32_t ceil(float num)
const std::vector< uint32_t > & payload() const
Definition: Block.h:86
unsigned int getID() const
Definition: Block.h:43
unsigned int getAlgoVersion()
Definition: Unpacker.h:18
MuonBxCollection * res_
Definition: MuonUnpacker.h:27
void getBXRange(int nbx, int &first, int &last)
BlockHeader header() const
Definition: Block.h:85
static constexpr unsigned bxzs_enable_shift_
Definition: MuonUnpacker.h:25
static constexpr unsigned nWords_
Definition: MuonUnpacker.h:24
int hwPhi() const
Definition: L1Candidate.h:37
bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: MuonUnpacker.cc:13
int hwIso() const
Definition: L1Candidate.h:39
void unpackBx(int bx, const std::vector< uint32_t > &payload, unsigned int startIdx=0)
Definition: MuonUnpacker.cc:56
unsigned int getTotalBx() const
Definition: BxBlock.h:27
const int mu
Definition: Constants.h:22
int hwEta() const
Definition: L1Candidate.h:36
int hwQual() const
Definition: L1Candidate.h:38
static constexpr unsigned ptShift_
Definition: Muon.h:21
int hwPt() const
Definition: L1Candidate.h:35
void setBXRange(int bxFirst, int bxLast)
BxBlocks getBxBlocks(unsigned int payloadWordsPerBx, bool bxHeader) const
Definition: Block.cc:40
static void fillMuon(Muon &mu, uint32_t raw_data_spare, uint32_t raw_data_00_31, uint32_t raw_data_32_63, int fed, unsigned int fw, int muInBx)
#define DEFINE_L1T_UNPACKER(type)
unsigned int getSize() const
Definition: Block.h:44
Log< level::Warning, false > LogWarning
void amc(const amc::Header &h)
Definition: Block.h:88
int hwChargeValid() const
Definition: Muon.h:97
unsigned int getFlags() const
Definition: Block.h:46
static constexpr unsigned ptMask_
void push_back(int bx, T object)
#define LogDebug(id)
int hwCharge() const
Definition: Muon.h:96