Skip to content

Commit

Permalink
Imported cms-sw#12157 and cms-sw#12385 into a clean 76X
Browse files Browse the repository at this point in the history
  • Loading branch information
forthommel authored and slava77devel committed Nov 13, 2015
1 parent 451075d commit 89aaf59
Show file tree
Hide file tree
Showing 20 changed files with 681 additions and 240 deletions.
43 changes: 29 additions & 14 deletions DataFormats/SiStripCommon/interface/ConstantsForHardwareSystems.h
Expand Up @@ -95,19 +95,27 @@ namespace sistrip {
static const char unknownApvReadoutMode_[] = "UnknownApvReadoutMode";
static const char undefinedApvReadoutMode_[] = "UndefinedApvReadoutMode";

static const char apvPeakMode_[] = "ApvPeakMode";
static const char apvPeakMode_[] = "ApvPeakMode";
static const char apvDeconMode_[] = "ApvDeconMode";
static const char apvMultiMode_[] = "ApvMultiMode";

static const char unknownFedReadoutMode_[] = "UnknownFedReadoutMode";
static const char undefinedFedReadoutMode_[] = "UndefinedFedReadoutMode";

static const char fedScopeMode_[] = "FedScopeMode";
static const char fedVirginRaw_[] = "FedVirginRaw";
static const char fedProcRaw_[] = "FedProcessedRaw";
static const char fedZeroSuppr_[] = "FedZeroSuppressed";
static const char fedZeroSupprLite_[] = "FedZeroSupprressedLite";
static const char fedPreMixRaw_[] = "FedPreMixRaw";
static const char fedScopeMode_[] = "FedScopeMode";
static const char fedVirginRaw_[] = "FedVirginRaw";
static const char fedProcRaw_[] = "FedProcessedRaw";
static const char fedZeroSuppr_[] = "FedZeroSuppressed";
static const char fedZeroSupprCMO_[] = "FedZeroSuppressedCMOverride";
static const char fedZeroSupprLite_[] = "FedZeroSupprressedLite";
static const char fedZeroSupprLiteCMO_[] = "FedZeroSuppressedLiteCMOverride";
static const char fedZeroSupprLite8TT_[] = "FedZeroSuppressedLite8TT";
static const char fedZeroSupprLite8TTCMO_[] = "FedZeroSuppressedLite8TTCMOverride";
static const char fedZeroSupprLite8TB_[] = "FedZeroSuppressedLite8TB";
static const char fedZeroSupprLite8TBCMO_[] = "FedZeroSuppressedLite8TBCMOverride";
static const char fedZeroSupprLite8BB_[] = "FedZeroSuppressedLite8BB";
static const char fedZeroSupprLite8BBCMO_[] = "FedZeroSuppressedLite8BBCMOverride";
static const char fedPreMixRaw_[] = "FedPreMixRaw";

// -------------------- Enumerators --------------------

Expand All @@ -119,13 +127,20 @@ namespace sistrip {
};

enum FedReadoutMode { UNKNOWN_FED_READOUT_MODE = sistrip::unknown_,
UNDEFINED_FED_READOUT_MODE = sistrip::invalid_,
FED_SCOPE_MODE = 1,
FED_VIRGIN_RAW = 2,
FED_PROC_RAW = 6,
FED_ZERO_SUPPR = 10,
FED_ZERO_SUPPR_LITE = 12,
FED_PREMIX_RAW = 15
UNDEFINED_FED_READOUT_MODE = sistrip::invalid_,
FED_SCOPE_MODE = 1,
FED_VIRGIN_RAW = 2,
FED_PROC_RAW = 6,
FED_ZERO_SUPPR = 10,
FED_ZERO_SUPPR_LITE = 3,
FED_ZERO_SUPPR_LITE_CMO = 4,
FED_ZERO_SUPPR_LITE8_TT = 12,
FED_ZERO_SUPPR_LITE8_TT_CMO = 8,
FED_ZERO_SUPPR_LITE8_TB = 5,
FED_ZERO_SUPPR_LITE8_TB_CMO = 7,
FED_ZERO_SUPPR_LITE8_BB = 9,
FED_ZERO_SUPPR_LITE8_BB_CMO = 11,
FED_PREMIX_RAW = 15
};

enum FedReadoutPath { UNKNOWN_FED_READOUT_PATH = sistrip::unknown_,
Expand Down
14 changes: 14 additions & 0 deletions DataFormats/SiStripCommon/src/SiStripEnumsAndStrings.cc
Expand Up @@ -252,6 +252,13 @@ std::string SiStripEnumsAndStrings::fedReadoutMode( const sistrip::FedReadoutMod
else if ( mode == sistrip::FED_PROC_RAW ) { return sistrip::fedProcRaw_; }
else if ( mode == sistrip::FED_ZERO_SUPPR ) { return sistrip::fedZeroSuppr_; }
else if ( mode == sistrip::FED_ZERO_SUPPR_LITE ) { return sistrip::fedZeroSupprLite_; }
else if ( mode == sistrip::FED_ZERO_SUPPR_LITE_CMO ) { return sistrip::fedZeroSupprLiteCMO_; }
else if ( mode == sistrip::FED_ZERO_SUPPR_LITE8_TT ) { return sistrip::fedZeroSupprLite8TT_; }
else if ( mode == sistrip::FED_ZERO_SUPPR_LITE8_TT_CMO ) { return sistrip::fedZeroSupprLite8TTCMO_; }
else if ( mode == sistrip::FED_ZERO_SUPPR_LITE8_TB ) { return sistrip::fedZeroSupprLite8TB_; }
else if ( mode == sistrip::FED_ZERO_SUPPR_LITE8_TB_CMO ) { return sistrip::fedZeroSupprLite8TBCMO_; }
else if ( mode == sistrip::FED_ZERO_SUPPR_LITE8_BB ) { return sistrip::fedZeroSupprLite8BB_; }
else if ( mode == sistrip::FED_ZERO_SUPPR_LITE8_BB_CMO ) { return sistrip::fedZeroSupprLite8BBCMO_; }
else if ( mode == sistrip::UNDEFINED_FED_READOUT_MODE ) { return sistrip::undefinedFedReadoutMode_; }
else { return sistrip::unknownFedReadoutMode_; }
}
Expand All @@ -264,6 +271,13 @@ sistrip::FedReadoutMode SiStripEnumsAndStrings::fedReadoutMode( const std::strin
else if ( mode.find( sistrip::fedProcRaw_ ) != std::string::npos ) { return sistrip::FED_PROC_RAW; }
else if ( mode.find( sistrip::fedZeroSuppr_ ) != std::string::npos ) { return sistrip::FED_ZERO_SUPPR; }
else if ( mode.find( sistrip::fedZeroSupprLite_ ) != std::string::npos ) { return sistrip::FED_ZERO_SUPPR_LITE; }
else if ( mode.find( sistrip::fedZeroSupprLiteCMO_ ) != std::string::npos ) { return sistrip::FED_ZERO_SUPPR_LITE_CMO; }
else if ( mode.find( sistrip::fedZeroSupprLite8TT_ ) != std::string::npos ) { return sistrip::FED_ZERO_SUPPR_LITE8_TT; }
else if ( mode.find( sistrip::fedZeroSupprLite8TTCMO_ ) != std::string::npos ) { return sistrip::FED_ZERO_SUPPR_LITE8_TT_CMO; }
else if ( mode.find( sistrip::fedZeroSupprLite8TB_ ) != std::string::npos ) { return sistrip::FED_ZERO_SUPPR_LITE8_TB; }
else if ( mode.find( sistrip::fedZeroSupprLite8TBCMO_ ) != std::string::npos ) { return sistrip::FED_ZERO_SUPPR_LITE8_TB_CMO; }
else if ( mode.find( sistrip::fedZeroSupprLite8BB_ ) != std::string::npos ) { return sistrip::FED_ZERO_SUPPR_LITE8_BB; }
else if ( mode.find( sistrip::fedZeroSupprLite8BBCMO_ ) != std::string::npos ) { return sistrip::FED_ZERO_SUPPR_LITE8_BB_CMO; }
else if ( mode.find( sistrip::undefinedFedReadoutMode_ ) != std::string::npos ) { return sistrip::UNDEFINED_FED_READOUT_MODE; }
else if ( mode.empty() ) { return sistrip::UNDEFINED_FED_READOUT_MODE; }
else { return sistrip::UNKNOWN_FED_READOUT_MODE; }
Expand Down
153 changes: 146 additions & 7 deletions EventFilter/SiStripRawToDigi/interface/SiStripFEDBuffer.h
Expand Up @@ -7,6 +7,7 @@
#include <memory>
#include <ostream>
#include <cstring>
#include <cmath>
#include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBufferComponents.h"

#include "FWCore/Utilities/interface/GCC11Compatibility.h"
Expand All @@ -23,7 +24,7 @@ namespace sistrip {
public:
//construct from buffer
//if allowBadBuffer is set to true then exceptions will not be thrown if the channel lengths do not make sense or the event format is not recognized
FEDBuffer(const uint8_t* fedBuffer, const size_t fedBufferSize, const bool allowBadBuffer = false);
FEDBuffer(const uint8_t* fedBuffer, const uint16_t fedBufferSize, const bool allowBadBuffer = false);
virtual ~FEDBuffer();
virtual void print(std::ostream& os) const;
const FEDFEHeader* feHeader() const;
Expand All @@ -36,6 +37,7 @@ 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
virtual bool channelGood(const uint8_t internalFEDannelNum, const bool doAPVeCheck=true) 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
Expand Down Expand Up @@ -70,13 +72,14 @@ namespace sistrip {
private:
uint8_t nFEUnitsPresent() const;
void findChannels();
uint8_t getCorrectPacketCode() const;
inline uint8_t getCorrectPacketCode() const { return packetCode(legacyUnpacker_); }
uint16_t calculateFEUnitLength(const uint8_t internalFEUnitNumber) const;
std::auto_ptr<FEDFEHeader> feHeader_;
const uint8_t* payloadPointer_;
uint16_t payloadLength_;
uint8_t validChannels_;
bool fePresent_[FEUNITS_PER_FED];
bool legacyUnpacker_=false;
};

//class for unpacking data from ZS FED channels
Expand All @@ -95,14 +98,14 @@ namespace sistrip {
FEDZSChannelUnpacker& operator ++ (int);
private:
//pointer to beginning of FED or FE data, offset of start of channel payload in data and length of channel payload
FEDZSChannelUnpacker(const uint8_t* payload, const size_t channelPayloadOffset, const int16_t channelPayloadLength, const size_t offsetIncrement=1);
FEDZSChannelUnpacker(const uint8_t* payload, const uint16_t channelPayloadOffset, const int16_t channelPayloadLength, const uint16_t offsetIncrement=1);
void readNewClusterInfo();
static void throwBadChannelLength(const uint16_t length);
void throwBadClusterLength();
static void throwUnorderedData(const uint8_t currentStrip, const uint8_t firstStripOfNewCluster);
const uint8_t* data_;
size_t currentOffset_;
size_t offsetIncrement_;
uint16_t currentOffset_;
uint16_t offsetIncrement_;
uint8_t currentStrip_;
uint8_t valuesLeftInCluster_;
uint16_t channelPayloadOffset_;
Expand All @@ -125,11 +128,44 @@ namespace sistrip {
private:
static void throwBadChannelLength(const uint16_t length);
const uint8_t* data_;
size_t currentOffset_;
uint16_t currentOffset_;
uint8_t currentStrip_;
uint16_t valuesLeft_;
};

//class for unpacking data from any FED channels with a non-integer words bits stripping mode
class FEDBSChannelUnpacker
{
public:
static FEDBSChannelUnpacker virginRawModeUnpacker(const FEDChannel& channel, uint16_t num_bits);
static FEDBSChannelUnpacker zeroSuppressedModeUnpacker(const FEDChannel& channel, uint16_t num_bits);
static FEDBSChannelUnpacker zeroSuppressedLiteModeUnpacker(const FEDChannel& channel, uint16_t num_bits);
FEDBSChannelUnpacker();
uint8_t sampleNumber() const;
uint16_t adc() const;
bool hasData() const;
FEDBSChannelUnpacker& operator ++ ();
FEDBSChannelUnpacker& operator ++ (int);
private:
//pointer to beginning of FED or FE data, offset of start of channel payload in data and length of channel payload
FEDBSChannelUnpacker(const uint8_t* payload, const uint16_t channelPayloadOffset, const int16_t channelPayloadLength, const uint16_t offsetIncrement, bool useZS);
void readNewClusterInfo();
static void throwBadChannelLength(const uint16_t length);
static void throwBadWordLength(const uint16_t word_length);
static void throwUnorderedData(const uint8_t currentStrip, const uint8_t firstStripOfNewCluster);
const uint8_t* data_;
uint16_t oldWordOffset_;
uint16_t currentWordOffset_;
uint16_t currentBitOffset_;
uint16_t currentLocalBitOffset_;
uint16_t bitOffsetIncrement_;
uint8_t currentStrip_;
uint16_t channelPayloadOffset_;
uint16_t channelPayloadLength_;
bool useZS_;
uint8_t valuesLeftInCluster_;
};

//
// Inline function definitions
//
Expand Down Expand Up @@ -165,6 +201,109 @@ namespace sistrip {
{
return checkStatusBits(internalFEDChannelNum(internalFEUnitNum,internalChannelNum));
}

//FEDBSChannelUnpacker

inline FEDBSChannelUnpacker::FEDBSChannelUnpacker()
: data_(NULL),
oldWordOffset_(0), currentWordOffset_(0),
currentBitOffset_(0), currentLocalBitOffset_(0),
bitOffsetIncrement_(10),
currentStrip_(0),
channelPayloadOffset_(0), channelPayloadLength_(0),
useZS_(false), valuesLeftInCluster_(0)
{ }

inline FEDBSChannelUnpacker::FEDBSChannelUnpacker(const uint8_t* payload, const uint16_t channelPayloadOffset, const int16_t channelPayloadLength, const uint16_t offsetIncrement, bool useZS)
: data_(payload),
oldWordOffset_(0), currentWordOffset_(channelPayloadOffset),
currentBitOffset_(0), currentLocalBitOffset_(0),
bitOffsetIncrement_(offsetIncrement),
channelPayloadOffset_(channelPayloadOffset),
channelPayloadLength_(channelPayloadLength),
useZS_(useZS), valuesLeftInCluster_(0)
{
if (bitOffsetIncrement_>16) throwBadWordLength(bitOffsetIncrement_); // more than 2 words... still to be implemented
}

inline FEDBSChannelUnpacker FEDBSChannelUnpacker::virginRawModeUnpacker(const FEDChannel& channel, uint16_t num_bits)
{
uint16_t length = channel.length();
if (length & 0xF000) throwBadChannelLength(length);
if (num_bits<=0 or num_bits>16) throwBadWordLength(num_bits);
FEDBSChannelUnpacker result(channel.data(), channel.offset()+3, length-3, num_bits, false);
return result;
}

inline FEDBSChannelUnpacker FEDBSChannelUnpacker::zeroSuppressedModeUnpacker(const FEDChannel& channel, uint16_t num_bits)
{
uint16_t length = channel.length();
if (length & 0xF000) throwBadChannelLength(length);
FEDBSChannelUnpacker result(channel.data(), channel.offset()+7, length-7, num_bits, true);
return result;
}

inline FEDBSChannelUnpacker FEDBSChannelUnpacker::zeroSuppressedLiteModeUnpacker(const FEDChannel& channel, uint16_t num_bits)
{
uint16_t length = channel.length();
if (length & 0xF000) throwBadChannelLength(length);
FEDBSChannelUnpacker result(channel.data(), channel.offset()+2, length-2, num_bits, true);
return result;
}

inline uint8_t FEDBSChannelUnpacker::sampleNumber() const
{
return currentStrip_;
}

inline uint16_t FEDBSChannelUnpacker::adc() const
{
uint16_t bits_missing = (bitOffsetIncrement_-8)+currentLocalBitOffset_;
uint16_t adc = (data_[currentWordOffset_^7]<<bits_missing);
if (currentWordOffset_>oldWordOffset_) {
adc += ( (data_[(currentWordOffset_+1)^7]>>(8-bits_missing)) );
}
return (adc&((1<<bitOffsetIncrement_)-1));
}

inline bool FEDBSChannelUnpacker::hasData() const
{
return (currentWordOffset_<channelPayloadOffset_+channelPayloadLength_);
}

inline FEDBSChannelUnpacker& FEDBSChannelUnpacker::operator ++ ()
{
oldWordOffset_ = currentWordOffset_;
currentBitOffset_ += bitOffsetIncrement_;
currentLocalBitOffset_ += bitOffsetIncrement_;
while (currentLocalBitOffset_>=8) {
currentWordOffset_++;
currentLocalBitOffset_ -= 8;
}
if (useZS_) {
if (valuesLeftInCluster_) { currentStrip_++; valuesLeftInCluster_--; }
else {
if (hasData()) {
const uint8_t oldStrip = currentStrip_;
readNewClusterInfo();
if ( !(currentStrip_ > oldStrip) ) throwUnorderedData(oldStrip,currentStrip_);
}
}
} else { currentStrip_++; }
return (*this);
}

inline FEDBSChannelUnpacker& FEDBSChannelUnpacker::operator ++ (int)
{
++(*this); return *this;
}

inline void FEDBSChannelUnpacker::readNewClusterInfo()
{
currentStrip_ = data_[(currentWordOffset_++)^7];
valuesLeftInCluster_ = data_[(currentWordOffset_++)^7]-1;
}


//FEDRawChannelUnpacker

Expand Down Expand Up @@ -215,7 +354,7 @@ namespace sistrip {
channelPayloadLength_(0)
{ }

inline FEDZSChannelUnpacker::FEDZSChannelUnpacker(const uint8_t* payload, const size_t channelPayloadOffset, const int16_t channelPayloadLength, const size_t offsetIncrement)
inline FEDZSChannelUnpacker::FEDZSChannelUnpacker(const uint8_t* payload, const uint16_t channelPayloadOffset, const int16_t channelPayloadLength, const uint16_t offsetIncrement)
: data_(payload),
currentOffset_(channelPayloadOffset),
offsetIncrement_(offsetIncrement),
Expand Down

0 comments on commit 89aaf59

Please sign in to comment.