Skip to content

Commit

Permalink
Merge pull request #21665 from thomreis/unpacker_fix_for_corrupted_ev…
Browse files Browse the repository at this point in the history
…ents_100x

L1T muon unpacker fix for crash with corrupt uGT RO record
  • Loading branch information
cmsbuild committed Dec 12, 2017
2 parents 4bd0b5f + 58a2aec commit fd0b895
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion DataFormats/L1Trigger/interface/BxBlock.h
@@ -1,6 +1,7 @@
#ifndef DataFormats_L1Trigger_BxBlock_h
#define DataFormats_L1Trigger_BxBlock_h

#include <algorithm>
#include <memory>
#include <vector>
#include <cmath>
Expand All @@ -17,7 +18,7 @@ namespace l1t {

bool operator<(const BxBlockHeader& o) const { return getBx() < o.getBx(); };

inline int getBx() const { return (int)id_ - (int)std::floor(totalBx_/2.); };
inline int getBx() const { return (int)id_ + std::min(0, 1 - (int)totalBx_%2 - (int)std::floor(totalBx_/2.)); }; // In case of an even totalBx_ the BX range should be like, e.g. -3 to +4
inline unsigned int getId() const { return id_; };
inline unsigned int getTotalBx() const { return totalBx_; };
inline unsigned int getFlags() const { return flags_; };
Expand Down
@@ -1,6 +1,8 @@
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"


#include "L1Trigger/L1TMuon/interface/MuonRawDigiTranslator.h"

#include "MuonUnpacker.h"
Expand Down Expand Up @@ -43,7 +45,12 @@ namespace l1t {
// Get the BX blocks and unpack them
auto bxBlocks = block.getBxBlocks(nWords_, bxZsEnabled);
for (const auto& bxBlock : bxBlocks) {
unpackBx(bxBlock.header().getBx(), bxBlock.payload());
// Throw an exception if finding a corrupt BX header with out of range BX numbers
const auto bx = bxBlock.header().getBx();
if (bx < firstBX || bx > lastBX) {
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.";
}
unpackBx(bx, bxBlock.payload());
}
return true;
}
Expand Down
@@ -1,4 +1,5 @@
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"

#include "L1Trigger/L1TMuon/interface/RegionalMuonRawDigiTranslator.h"
Expand Down Expand Up @@ -69,6 +70,11 @@ namespace l1t {
// Get the BX blocks and unpack them
auto bxBlocks = block.getBxBlocks(nWords_, bxZsEnabled);
for (const auto& bxBlock : bxBlocks) {
// Throw an exception if finding a corrupt BX header with out of range BX numbers
const auto bx = bxBlock.header().getBx();
if (bx < firstBX || bx > lastBX) {
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.";
}
// Check if there are enough words left in the BX block payload
auto bxPayload = bxBlock.payload();
if (nWords_ <= bxPayload.size()) {
Expand All @@ -83,7 +89,7 @@ namespace l1t {
}
// Detect and ignore comma events
if (raw_data_00_31 == 0x505050bc || raw_data_32_63 == 0x505050bc) {
edm::LogWarning("L1T") << "Comma detected in raw data stream. Orbit number: " << block.amc().getOrbitNumber() << ", BX ID: " << block.amc().getBX() << ", BX: " << bxBlock.header().getBx() << ", linkId: " << linkId << ", Raw data: 0x" << hex << setw(8) << setfill('0') << raw_data_32_63 << setw(8) << setfill('0') << raw_data_00_31 << dec << ". Skip.";
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.";
continue;
}

Expand All @@ -93,11 +99,11 @@ namespace l1t {

LogDebug("L1T") << "Mu" << nWord/2 << ": eta " << mu.hwEta() << " phi " << mu.hwPhi() << " pT " << mu.hwPt() << " qual " << mu.hwQual() << " sign " << mu.hwSign() << " sign valid " << mu.hwSignValid();

res->push_back(bxBlock.header().getBx(), mu);
res->push_back(bx, mu);
}
} else {
unsigned int nWords = nWords_; // This seems unnecessary but it prevents an 'undefined reference' linker error that occurs when using nWords_ directly with LogWarning.
edm::LogWarning("L1T") << "Only " << bxPayload.size() << " 32 bit words in this BX but " << nWords << " are required. Not unpacking the data for BX " << bxBlock.header().getBx() << ".";
edm::LogWarning("L1T") << "Only " << bxPayload.size() << " 32 bit words in this BX but " << nWords << " are required. Not unpacking the data for BX " << bx << ".";
}
}
return true;
Expand Down

0 comments on commit fd0b895

Please sign in to comment.