Skip to content
Snippets Groups Projects

Protect the muon decoding from unexpected data

Merged Rosen Matev requested to merge rm-muon-decoding-protections into master
@@ -51,45 +51,10 @@ namespace LHCb::MuonUpgrade::DAQ {
ByteType single_bit_position[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
}
namespace EC::RawToHits {
enum class ErrorCode : StatusCode::code_t {
BAD_MAGIC = 10,
BANK_TOO_SHORT,
PADDING_TOO_LONG,
TOO_MANY_HITS,
INVALID_TELL1
};
struct ErrorCategory : StatusCode::Category {
const char* name() const override { return "MuonRawBankDecoding"; }
bool isRecoverable( StatusCode::code_t ) const override { return false; }
std::string message( StatusCode::code_t code ) const override {
switch ( static_cast<ErrorCode>( code ) ) {
case ErrorCode::BAD_MAGIC:
return "Incorrect Magic pattern in raw bank";
case ErrorCode::BANK_TOO_SHORT:
return "Muon bank is too short";
case ErrorCode::TOO_MANY_HITS:
return "Muon bank has too many hits for its size";
default:
return StatusCode::default_category().message( code );
}
}
};
} // namespace EC::RawToHits
} // namespace LHCb::MuonUpgrade::DAQ
STATUSCODE_ENUM_DECL( LHCb::MuonUpgrade::DAQ::EC::RawToHits::ErrorCode )
STATUSCODE_ENUM_IMPL( LHCb::MuonUpgrade::DAQ::EC::RawToHits::ErrorCode,
LHCb::MuonUpgrade::DAQ::EC::RawToHits::ErrorCategory )
namespace LHCb::MuonUpgrade::DAQ {
namespace {
[[gnu::noreturn]] void throw_exception( EC::RawToHits::ErrorCode ec, const char* tag ) {
auto sc = StatusCode( ec );
throw GaudiException{sc.message(), tag, std::move( sc )};
}
#define OOPS( x ) throw_exception( x, __PRETTY_FUNCTION__ )
template <typename Iterator>
Iterator addCoordsCrossingMap( Iterator first, Iterator last, CommonMuonHits& commonHits,
const ComputeTilePosition& compute, size_t /* nStations */ ) {
@@ -206,6 +171,11 @@ namespace LHCb::MuonUpgrade::DAQ {
mutable unsigned int local_wrong_hits_counters[44][16] = {};
mutable unsigned int local_acquired_frame[44][16] = {};
mutable Gaudi::Accumulators::MsgCounter<MSG::ERROR> m_invalid_add{this, "invalid add"};
mutable Gaudi::Accumulators::MsgCounter<MSG::ERROR> m_bad_magic{this, "Incorrect Magic pattern in raw bank"};
mutable Gaudi::Accumulators::MsgCounter<MSG::ERROR> m_bank_too_short{this, "Muon bank is too short"};
mutable Gaudi::Accumulators::MsgCounter<MSG::ERROR> m_too_many_hits{this,
"Muon bank has too many hits for its size"};
mutable Gaudi::Accumulators::MsgCounter<MSG::ERROR> m_bad_size_of_link{this, "Size of link is bad (<= 6)"};
mutable Gaudi::Accumulators::Counter<> m_Tell40Size[44]{
{this, "Tell_001_0 size"}, {this, "Tell_001_1 size"}, {this, "Tell_002_0 size"}, {this, "Tell_002_1 size"},
{this, "Tell_003_0 size"}, {this, "Tell_003_1 size"}, {this, "Tell_004_0 size"}, {this, "Tell_004_1 size"},
@@ -335,7 +305,10 @@ namespace LHCb::MuonUpgrade::DAQ {
// std::vector<LHCb::span<ByteType>> lista_link;
// lista_link.reserve( 64 );
for ( const auto& raw_bank : muon_banks ) {
if ( RawBank::MagicPattern != raw_bank->magic() ) { OOPS( EC::RawToHits::ErrorCode::BAD_MAGIC ); }
if ( RawBank::MagicPattern != raw_bank->magic() ) {
++m_bad_magic;
continue;
}
// the Tell40 number is hidden in source ID lower part
unsigned int tell40PCI = raw_bank->sourceID() & 0x00FF;
@@ -350,7 +323,10 @@ namespace LHCb::MuonUpgrade::DAQ {
debug() << " reading tell40 num " << TNumber << " PCI n " << PCINumber << " "
<< " bank size" << (unsigned int)raw_bank->size() << endmsg;
if ( (unsigned int)raw_bank->size() < 1 ) { OOPS( EC::RawToHits::ErrorCode::BANK_TOO_SHORT ); }
if ( (unsigned int)raw_bank->size() < 1 ) {
++m_bank_too_short;
continue;
}
auto range8 = raw_bank->range<ByteType>();
auto range_data = range8.subspan( 1 );
unsigned int link_start_pointer = 0;
@@ -367,7 +343,10 @@ namespace LHCb::MuonUpgrade::DAQ {
debug() << " Synch event " << synch_evt << " aligned fiber info stored " << align_info << endmsg;
}
if ( synch_evt ) continue;
if ( (unsigned int)raw_bank->size() < 1 + 3 * align_info ) { OOPS( EC::RawToHits::ErrorCode::BANK_TOO_SHORT ); }
if ( (unsigned int)raw_bank->size() < 1 + 3 * align_info ) {
++m_bank_too_short;
continue;
}
unsigned int number_of_readout_fibers = 0;
unsigned int map_connected_fibers[24] = {};
@@ -376,7 +355,10 @@ namespace LHCb::MuonUpgrade::DAQ {
if ( !align_info ) {
for ( unsigned int i = 0; i < active_links; i++ ) { map_connected_fibers[i] = i; }
number_of_readout_fibers = active_links;
if ( (unsigned int)raw_bank->size() < active_links + 1 ) { OOPS( EC::RawToHits::ErrorCode::BANK_TOO_SHORT ); }
if ( (unsigned int)raw_bank->size() < active_links + 1 ) {
++m_bank_too_short;
continue;
}
} else {
link_start_pointer = link_start_pointer + 3;
@@ -418,8 +400,10 @@ namespace LHCb::MuonUpgrade::DAQ {
for ( int i = 0; i < 24; i++ ) { verbose() << i << " " << align_vector[i] << endmsg; }
}
number_of_readout_fibers = readout_fibers;
if ( (unsigned int)raw_bank->size() < number_of_readout_fibers + 1 + 3 )
OOPS( EC::RawToHits::ErrorCode::BANK_TOO_SHORT );
if ( (unsigned int)raw_bank->size() < number_of_readout_fibers + 1 + 3 ) {
++m_bank_too_short;
continue;
}
}
if ( (unsigned int)raw_bank->size() > number_of_readout_fibers + 1 + 3 * align_info ) {
if ( msgLevel( MSG::VERBOSE ) ) {
@@ -460,7 +444,25 @@ namespace LHCb::MuonUpgrade::DAQ {
if ( size_of_link > 1 ) {
// get two subpart (there is an overlap due to the 4 bits shift
auto range_link_HitsMap = range_data.subspan( link_start_pointer, 7 );
auto range_link_TDC = range_data.subspan( link_start_pointer + 6, size_of_link - 6 );
if ( size_of_link <= 6 ) {
// Example from data: link = 0, size_of_link = 4, link_start_pointer = 0, raw_bank->m_length = 53
// Raw bank data:
// {m_magic = 52171, m_length = 53, m_type = 13 '\r', m_version = 3 '\003', m_sourceID = 26628, m_data =
// {2420323592}}
//
// all words: [3525579, 1745093389, 2420323592, 35, 4255762696, 224, 4278255661, 0,
// 1879048192, 0, 2154116872, 34, 4287088648, 0]
//
// in hex:
// cb cb 35 00 0d 03 04 68 <- MDF header
// payload:
// 08 35 43 90 23 00 00 00 08 c9 a9 fd e0 00 00 00
// 2d 00 01 ff 00 00 00 00 00 00 00 70 00 00 00 00
// 08 37 65 80 22 00 00 00 08 c8 87 ff 00 00 00 00
++m_bad_size_of_link;
break;
}
auto range_link_TDC = range_data.subspan( link_start_pointer + 6, size_of_link - 6 );
bool first_hitmap_byte = false;
bool last_hitmap_byte = true;
Loading