Skip to content

Commit

Permalink
Changes from cms-sw#28304 in EventFilter/SiStripRawToDigi
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterdavid committed May 28, 2020
1 parent 442ae07 commit 45a901c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 37 deletions.
22 changes: 19 additions & 3 deletions EventFilter/SiStripRawToDigi/interface/SiStripFEDBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace sistrip {
* @see sistrip::preconstructCheckFEDBuffer() sistrip::FEDBuffer::findChannels()
*/
explicit FEDBuffer(const FEDRawData& fedBuffer, const bool allowBadBuffer = false);
~FEDBuffer() override;
~FEDBuffer() override {}

/**
* Read the channel lengths from the payload
Expand All @@ -64,13 +64,13 @@ namespace sistrip {
bool fePresent(uint8_t internalFEUnitNum) const;
//check that a channel is present in data, found, on a good FE unit and has no errors flagged in status bits
using sistrip::FEDBufferBase::channelGood;
virtual bool channelGood(const uint8_t internalFEDannelNum, const bool doAPVeCheck = true) const;
bool channelGood(const uint8_t internalFEDannelNum, const bool doAPVeCheck) const;
void setLegacyMode(bool legacy) { legacyUnpacker_ = legacy; }

//functions to check buffer. All return true if there is no problem.
//minimum checks to do before using buffer
using sistrip::FEDBufferBase::doChecks;
virtual bool doChecks(bool doCRC = true) const;
bool doChecks(bool doCRC) const;

//additional checks to check for corrupt buffers
//check channel lengths fit inside to buffer length
Expand Down Expand Up @@ -153,6 +153,13 @@ namespace sistrip {

inline const FEDFEHeader* FEDBuffer::feHeader() const { return feHeader_.get(); }

inline bool FEDBuffer::channelGood(const uint8_t internalFEDChannelNum, const bool doAPVeCheck) const {
return ((internalFEDChannelNum < validChannels_) &&
((doAPVeCheck && feGood(internalFEDChannelNum / FEDCH_PER_FEUNIT)) ||
(!doAPVeCheck && feGoodWithoutAPVEmulatorCheck(internalFEDChannelNum / FEDCH_PER_FEUNIT))) &&
(this->readoutMode() == sistrip::READOUT_MODE_SCOPE || checkStatusBits(internalFEDChannelNum)));
}

inline bool FEDBuffer::feGood(const uint8_t internalFEUnitNum) const {
return (!majorityAddressErrorForFEUnit(internalFEUnitNum) && !feOverflow(internalFEUnitNum) &&
fePresent(internalFEUnitNum));
Expand All @@ -172,6 +179,15 @@ namespace sistrip {
return checkStatusBits(internalFEDChannelNum(internalFEUnitNum, internalChannelNum));
}

inline bool FEDBuffer::doChecks(bool doCRC) const {
//check that all channels were unpacked properly
return (validChannels_ == FEDCH_PER_FED) &
//do checks from base class
(FEDBufferBase::doChecks()) &
// check crc if required
(!doCRC || checkCRC());
}

namespace fedchannelunpacker {
enum class StatusCode { SUCCESS = 0, BAD_CHANNEL_LENGTH, UNORDERED_DATA, BAD_PACKET_CODE, ZERO_PACKET_CODE };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,12 @@ namespace sistrip {
//holds information about position of a channel in the buffer for use by unpacker
class FEDChannel {
public:
FEDChannel(const uint8_t* const data, const size_t offset, const uint16_t length);
FEDChannel(const uint8_t* const data, const uint32_t offset, const uint16_t length);
//gets length from first 2 bytes (assuming normal FED channel)
FEDChannel(const uint8_t* const data, const size_t offset);
FEDChannel(const uint8_t* const data, const uint32_t offset);
uint16_t length() const;
const uint8_t* data() const;
size_t offset() const;
uint32_t offset() const;
/**
* Retrieve the APV CM median for a non-lite zero-suppressed channel
*
Expand All @@ -635,7 +635,7 @@ namespace sistrip {
private:
friend class FEDBuffer;
const uint8_t* data_;
size_t offset_;
uint32_t offset_;
uint16_t length_;
};

Expand Down Expand Up @@ -702,7 +702,7 @@ namespace sistrip {
//check for errors in DAQ heaqder and trailer (not including bad CRC)
bool doDAQHeaderAndTrailerChecks() const;
//do both
virtual bool doChecks() const;
bool doChecks() const;
//print the result of all detailed checks
virtual std::string checkSummary() const;

Expand Down Expand Up @@ -855,7 +855,7 @@ namespace sistrip {
const auto nibble = trackerEventTypeNibble();
//if it is scope mode then return as is (it cannot be fake data)
//if it is premix then return as is: stripping last bit would make it spy data !
if ((nibble == READOUT_MODE_SCOPE) || (nibble == READOUT_MODE_PREMIX_RAW))
if ((nibble == READOUT_MODE_SCOPE) || (nibble == READOUT_MODE_PREMIX_RAW)) // 0x or 0xf
return FEDReadoutMode(nibble);
//if not then ignore the last bit which indicates if it is real or fake
else {
Expand Down Expand Up @@ -1430,6 +1430,8 @@ namespace sistrip {

inline FEDReadoutMode FEDBufferBase::readoutMode() const { return specialHeader_.readoutMode(); }

inline bool FEDBufferBase::doChecks() const { return doTrackerSpecialHeaderChecks() & doDAQHeaderAndTrailerChecks(); }

inline uint8_t FEDBufferBase::packetCode(bool legacy, const uint8_t internalFEDChannelNum) const {
if (legacy) {
FEDLegacyReadoutMode mode = legacyReadoutMode();
Expand Down Expand Up @@ -1553,11 +1555,11 @@ namespace sistrip {

//FEDChannel

inline FEDChannel::FEDChannel(const uint8_t* const data, const size_t offset) : data_(data), offset_(offset) {
inline FEDChannel::FEDChannel(const uint8_t* const data, const uint32_t offset) : data_(data), offset_(offset) {
length_ = (data_[(offset_) ^ 7] + (data_[(offset_ + 1) ^ 7] << 8));
}

inline FEDChannel::FEDChannel(const uint8_t* const data, const size_t offset, const uint16_t length)
inline FEDChannel::FEDChannel(const uint8_t* const data, const uint32_t offset, const uint16_t length)
: data_(data), offset_(offset), length_(length) {}

inline uint16_t FEDChannel::length() const { return length_; }
Expand All @@ -1574,7 +1576,7 @@ namespace sistrip {

inline const uint8_t* FEDChannel::data() const { return data_; }

inline size_t FEDChannel::offset() const { return offset_; }
inline uint32_t FEDChannel::offset() const { return offset_; }
} // namespace sistrip

#endif //ndef EventFilter_SiStripRawToDigi_FEDBufferComponents_H
24 changes: 1 addition & 23 deletions EventFilter/SiStripRawToDigi/src/SiStripFEDBuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ namespace sistrip {
}
}

FEDBuffer::~FEDBuffer() {}

FEDBufferStatusCode FEDBuffer::findChannels() {
auto st = FEDBufferStatusCode::SUCCESS;
//set min length to 2 for ZSLite, 7 for ZS and 3 for raw
Expand Down Expand Up @@ -97,7 +95,7 @@ namespace sistrip {
break;
}

channels_.push_back(FEDChannel(payloadPointer_, offsetBeginningOfChannel));
channels_.emplace_back(payloadPointer_, offsetBeginningOfChannel);
//get length and check that whole channel fits into buffer
uint16_t channelLength = channels_.back().length();

Expand Down Expand Up @@ -146,26 +144,6 @@ namespace sistrip {
return st;
}

bool FEDBuffer::channelGood(const uint8_t internalFEDChannelNum, const bool doAPVeCheck) const {
return ((internalFEDChannelNum < validChannels_) &&
((doAPVeCheck && feGood(internalFEDChannelNum / FEDCH_PER_FEUNIT)) ||
(!doAPVeCheck && feGoodWithoutAPVEmulatorCheck(internalFEDChannelNum / FEDCH_PER_FEUNIT))) &&
(this->readoutMode() == sistrip::READOUT_MODE_SCOPE || checkStatusBits(internalFEDChannelNum)));
}

bool FEDBuffer::doChecks(bool doCRC) const {
//check that all channels were unpacked properly
if (validChannels_ != FEDCH_PER_FED)
return false;
//do checks from base class
if (!FEDBufferBase::doChecks())
return false;
//check CRC
if (doCRC && !checkCRC())
return false;
return true;
}

bool FEDBuffer::doCorruptBufferChecks() const {
return (checkCRC() && checkChannelLengthsMatchBufferLength() && checkChannelPacketCodes() &&
//checkClusterLengths() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1353,8 +1353,6 @@ namespace sistrip {
return (!majorityAddressErrorForFEUnit(feUnit) && feEnabled(feUnit) && !feOverflow(feUnit));
}

bool FEDBufferBase::doChecks() const { return (doTrackerSpecialHeaderChecks() && doDAQHeaderAndTrailerChecks()); }

std::string FEDBufferBase::checkSummary() const {
std::ostringstream summary;
summary << "Check buffer type valid: " << (checkBufferFormat() ? "passed" : "FAILED") << std::endl;
Expand Down

0 comments on commit 45a901c

Please sign in to comment.