Skip to content

Commit

Permalink
Merge pull request #20634 from rekovic/pr94x-l1t-uGMT-clang-cleaning-…
Browse files Browse the repository at this point in the history
…multithread-bis

[94x] l1t Muon Unpacker Zero Suppression and DQM. Clang cleaning.
  • Loading branch information
cmsbuild committed Sep 25, 2017
2 parents 630acaf + 0c12ad1 commit e4fd1ba
Show file tree
Hide file tree
Showing 29 changed files with 546 additions and 357 deletions.
18 changes: 10 additions & 8 deletions DQM/L1TMonitor/interface/L1TMP7ZeroSupp.h
Expand Up @@ -24,23 +24,23 @@ class L1TMP7ZeroSupp : public DQMEDAnalyzer {
public:

L1TMP7ZeroSupp(const edm::ParameterSet& ps);
virtual ~L1TMP7ZeroSupp();
~L1TMP7ZeroSupp() override;
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

protected:

virtual void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
virtual void beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) override;
virtual void bookHistograms(DQMStore::IBooker&, const edm::Run&, const edm::EventSetup&) override;
virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
void dqmBeginRun(const edm::Run& r, const edm::EventSetup& c) override;
void beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) override;
void bookHistograms(DQMStore::IBooker&, const edm::Run&, const edm::EventSetup&) override;
void analyze(const edm::Event& e, const edm::EventSetup& c) override;

private:

void bookCapIdHistograms(DQMStore::IBooker&, const unsigned int&);
void bookCapIdHistograms(DQMStore::IBooker& ibooker, const unsigned int& id);

// Add additional bins only before NBINLABELS
enum binlabels {EVTS=0, EVTSGOOD, EVTSBAD, BLOCKS, ZSBLKSGOOD, ZSBLKSBAD, ZSBLKSBADFALSEPOS, ZSBLKSBADFALSENEG, NBINLABELS};
enum ratioBinlabels {REVTS=0, RBLKS, RBLKSFALSEPOS, RBLKSFALSENEG, RNBINLABELS};
enum binlabels {EVTS=0, EVTSGOOD, EVTSBAD, BLOCKS, ZSBLKSGOOD, ZSBLKSBAD, ZSBLKSBADFALSEPOS, ZSBLKSBADFALSENEG, BXBLOCKS, ZSBXBLKSGOOD, ZSBXBLKSBAD, ZSBXBLKSBADFALSEPOS, ZSBXBLKSBADFALSENEG, NBINLABELS};
enum ratioBinlabels {REVTS=0, RBLKS, RBLKSFALSEPOS, RBLKSFALSENEG, RBXBLKS, RBXBLKSFALSEPOS, RBXBLKSFALSENEG, RNBINLABELS};

edm::EDGetTokenT<FEDRawDataCollection> fedDataToken_;
bool zsEnabled_;
Expand All @@ -54,7 +54,9 @@ class L1TMP7ZeroSupp : public DQMEDAnalyzer {
int amc13TrailerSize_;
int amcHeaderSize_;
int amcTrailerSize_;
int newZsFlagMask_;
int zsFlagMask_;
int dataInvFlagMask_;

int maxFedReadoutSize_;

Expand Down
200 changes: 146 additions & 54 deletions DQM/L1TMonitor/src/L1TMP7ZeroSupp.cc

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions DataFormats/L1Trigger/interface/BxBlock.h
@@ -0,0 +1,70 @@
#ifndef DataFormats_L1Trigger_BxBlock_h
#define DataFormats_L1Trigger_BxBlock_h

#include <memory>
#include <vector>
#include <cmath>

namespace l1t {
class BxBlockHeader {
public:
BxBlockHeader() : id_(0), totalBx_(0), flags_(0) {};
BxBlockHeader(unsigned int id, unsigned int totalBx, unsigned int flags=0) : id_(id), totalBx_(totalBx), flags_(flags) {};
// Create a BX header: everything is contained in the raw uint32
BxBlockHeader(const uint32_t raw) : id_(((raw >> id_shift) & id_mask) / n_words)
, totalBx_(((raw >> totalBx_shift) & totalBx_mask) / n_words)
, flags_((raw >> flags_shift) & flags_mask) {};

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

inline int getBx() const { return (int)id_ - (int)std::floor(totalBx_/2.); };
inline unsigned int getId() const { return id_; };
inline unsigned int getTotalBx() const { return totalBx_; };
inline unsigned int getFlags() const { return flags_; };

inline uint32_t raw() const { return (((id_ & id_mask) << id_shift) * n_words)
| (((totalBx_ & totalBx_mask) << totalBx_shift) * n_words)
| ((flags_ & flags_mask) << flags_shift); };

private:
static const unsigned int n_words = 6; // every link transmits 6 32 bit words per bx
static const unsigned int id_shift = 24;
static const unsigned int id_mask = 0xff;
static const unsigned int totalBx_shift = 16;
static const unsigned int totalBx_mask = 0xff;
static const unsigned int flags_shift = 0;
static const unsigned int flags_mask = 0xffff;

unsigned int id_;
unsigned int totalBx_;
unsigned int flags_;
};

class BxBlock {
public:
BxBlock(std::vector<uint32_t>::const_iterator bx_start, std::vector<uint32_t>::const_iterator bx_end) :
header_(*bx_start), payload_(bx_start+1, bx_end) {};
BxBlock(const BxBlockHeader& h, std::vector<uint32_t>::const_iterator payload_start, std::vector<uint32_t>::const_iterator payload_end) :
header_(h), payload_(payload_start, payload_end) {};
BxBlock(unsigned int id, unsigned int totalBx, std::vector<uint32_t>::const_iterator payload_start, std::vector<uint32_t>::const_iterator payload_end, unsigned int flags=0) :
header_(id, totalBx, flags), payload_(payload_start, payload_end) {};
BxBlock(unsigned int id, unsigned int totalBx, const std::vector<uint32_t>& payload, unsigned int flags=0) :
header_(id, totalBx, flags), payload_(payload) {};
~BxBlock() {};

bool operator<(const BxBlock& o) const { return header() < o.header(); };

inline unsigned int getSize() const { return payload_.size(); };

BxBlockHeader header() const { return header_; };
std::vector<uint32_t> payload() const { return payload_; };

private:
BxBlockHeader header_;
std::vector<uint32_t> payload_;
};

typedef std::vector<BxBlock> BxBlocks;
}

#endif
20 changes: 11 additions & 9 deletions EventFilter/L1TRawToDigi/interface/Block.h
Expand Up @@ -5,6 +5,7 @@
#include <vector>

#include "EventFilter/L1TRawToDigi/interface/AMCSpec.h"
#include "DataFormats/L1Trigger/interface/BxBlock.h"

namespace l1t {
enum block_t { MP7 = 0, CTP7, MTF7 };
Expand Down Expand Up @@ -50,8 +51,8 @@ namespace l1t {
public:
Block(const BlockHeader& h, const uint32_t * payload_start, const uint32_t * payload_end) :
header_(h), payload_(payload_start, payload_end) {};
Block(unsigned int id, const std::vector<uint32_t>& payload, unsigned int capID=0, block_t type=MP7) :
header_(id, payload.size(), capID, type), payload_(payload) {};
Block(unsigned int id, const std::vector<uint32_t>& payload, unsigned int capID=0, unsigned int flags=0, block_t type=MP7) :
header_(id, payload.size(), capID, flags, type), payload_(payload) {};

bool operator<(const Block& o) const { return header() < o.header(); };

Expand All @@ -63,6 +64,7 @@ namespace l1t {
void amc(const amc::Header& h) { amc_ = h; };
amc::Header amc() const { return amc_; };

BxBlocks getBxBlocks(unsigned int payloadWordsPerBx, bool bxHeader) const;
private:
BlockHeader header_;
amc::Header amc_;
Expand Down Expand Up @@ -94,17 +96,17 @@ namespace l1t {
class MP7Payload : public Payload {
public:
MP7Payload(const uint32_t * data, const uint32_t * end, bool legacy_mc=false);
virtual unsigned getHeaderSize() const override { return 1; };
virtual BlockHeader getHeader() override;
unsigned getHeaderSize() const override { return 1; };
BlockHeader getHeader() override;
};

class MTF7Payload : public Payload {
public:
MTF7Payload(const uint32_t * data, const uint32_t * end);
// Unused methods - we override getBlock() instead
virtual unsigned getHeaderSize() const override { return 0; };
virtual BlockHeader getHeader() override { return BlockHeader(0); };
virtual std::unique_ptr<Block> getBlock() override;
unsigned getHeaderSize() const override { return 0; };
BlockHeader getHeader() override { return BlockHeader(nullptr); };
std::unique_ptr<Block> getBlock() override;
private:
// sizes in 16 bit words
static const unsigned int header_size = 12;
Expand All @@ -123,8 +125,8 @@ namespace l1t {
class CTP7Payload : public Payload {
public:
CTP7Payload(const uint32_t * data, const uint32_t * end);
virtual unsigned getHeaderSize() const override { return 2; };
virtual BlockHeader getHeader() override;
unsigned getHeaderSize() const override { return 2; };
BlockHeader getHeader() override;
private:
// FIXME check values
static const unsigned int size_mask = 0xff;
Expand Down
Expand Up @@ -9,27 +9,36 @@

namespace l1t {
namespace stage2 {
IntermediateMuonUnpacker::IntermediateMuonUnpacker() : algoVersion_(0)
IntermediateMuonUnpacker::IntermediateMuonUnpacker() : res1_(nullptr), res2_(nullptr), algoVersion_(0), coll1Cnt_(0)
{
}

bool
IntermediateMuonUnpacker::unpack(const Block& block, UnpackerCollections *coll)
{
LogDebug("L1T") << "Block ID = " << block.header().getID() << " size = " << block.header().getSize();
// process only if there is a payload
// If all BX block were zero suppressed the block header size is 0.
if (block.header().getSize() < 1) {
return true;
}

auto payload = block.payload();

const unsigned int nWords = 6; // every link transmits 6 words (3 muons) per bx
int nBX, firstBX, lastBX;
nBX = int(ceil(block.header().getSize() / nWords));
// Check if per BX zero suppression was enabled
bool bxZsEnabled = ((block.header().getFlags() >> bxzs_enable_shift_) & 0x1) == 1;
// Calculate the total number of BXs
if (bxZsEnabled) {
BxBlockHeader bxHeader(payload.at(0));
nBX = bxHeader.getTotalBx();
} else {
nBX = int(ceil(block.header().getSize() / nWords_));
}
getBXRange(nBX, firstBX, lastBX);

// decide which collections to use according to the link ID
unsigned int linkId = (block.header().getID() - 1) / 2;
unsigned int coll1Cnt = 0;
MuonBxCollection* res1;
MuonBxCollection* res2;
// Intermediate muons come on uGMT output links 24-31.
// Each link can transmit 3 muons and we receive 4 intermediate muons from
// EMTF/OMTF on each detector side and 8 intermediate muons from BMTF.
Expand All @@ -39,61 +48,70 @@ namespace l1t {
// and 4 from EMTF neg.
switch (linkId) {
case 24:
res1 = static_cast<GMTCollections*>(coll)->getImdMuonsEMTFPos();
res2 = static_cast<GMTCollections*>(coll)->getImdMuonsEMTFPos();
coll1Cnt = 3;
res1_ = static_cast<GMTCollections*>(coll)->getImdMuonsEMTFPos();
res2_ = static_cast<GMTCollections*>(coll)->getImdMuonsEMTFPos();
coll1Cnt_ = 3;
break;
case 25:
res1 = static_cast<GMTCollections*>(coll)->getImdMuonsEMTFPos();
res2 = static_cast<GMTCollections*>(coll)->getImdMuonsOMTFPos();
coll1Cnt = 1;
res1_ = static_cast<GMTCollections*>(coll)->getImdMuonsEMTFPos();
res2_ = static_cast<GMTCollections*>(coll)->getImdMuonsOMTFPos();
coll1Cnt_ = 1;
break;
case 26:
res1 = static_cast<GMTCollections*>(coll)->getImdMuonsOMTFPos();
res2 = static_cast<GMTCollections*>(coll)->getImdMuonsBMTF();
coll1Cnt = 2;
res1_ = static_cast<GMTCollections*>(coll)->getImdMuonsOMTFPos();
res2_ = static_cast<GMTCollections*>(coll)->getImdMuonsBMTF();
coll1Cnt_ = 2;
break;
case 27:
res1 = static_cast<GMTCollections*>(coll)->getImdMuonsBMTF();
res2 = static_cast<GMTCollections*>(coll)->getImdMuonsBMTF();
coll1Cnt = 3;
res1_ = static_cast<GMTCollections*>(coll)->getImdMuonsBMTF();
res2_ = static_cast<GMTCollections*>(coll)->getImdMuonsBMTF();
coll1Cnt_ = 3;
break;
case 28:
res1 = static_cast<GMTCollections*>(coll)->getImdMuonsBMTF();
res2 = static_cast<GMTCollections*>(coll)->getImdMuonsBMTF();
coll1Cnt = 3;
res1_ = static_cast<GMTCollections*>(coll)->getImdMuonsBMTF();
res2_ = static_cast<GMTCollections*>(coll)->getImdMuonsBMTF();
coll1Cnt_ = 3;
break;
case 29:
res1 = static_cast<GMTCollections*>(coll)->getImdMuonsBMTF();
res2 = static_cast<GMTCollections*>(coll)->getImdMuonsOMTFNeg();
coll1Cnt = 1;
res1_ = static_cast<GMTCollections*>(coll)->getImdMuonsBMTF();
res2_ = static_cast<GMTCollections*>(coll)->getImdMuonsOMTFNeg();
coll1Cnt_ = 1;
break;
case 30:
res1 = static_cast<GMTCollections*>(coll)->getImdMuonsOMTFNeg();
res2 = static_cast<GMTCollections*>(coll)->getImdMuonsEMTFNeg();
coll1Cnt = 2;
res1_ = static_cast<GMTCollections*>(coll)->getImdMuonsOMTFNeg();
res2_ = static_cast<GMTCollections*>(coll)->getImdMuonsEMTFNeg();
coll1Cnt_ = 2;
break;
case 31:
res1 = static_cast<GMTCollections*>(coll)->getImdMuonsEMTFNeg();
res2 = static_cast<GMTCollections*>(coll)->getImdMuonsEMTFNeg();
coll1Cnt = 3;
res1_ = static_cast<GMTCollections*>(coll)->getImdMuonsEMTFNeg();
res2_ = static_cast<GMTCollections*>(coll)->getImdMuonsEMTFNeg();
coll1Cnt_ = 3;
break;
default:
edm::LogWarning("L1T") << "Block ID " << block.header().getID() << " not associated with intermediate muons. Skip.";
return false;
}
res1->setBXRange(firstBX, lastBX);
res2->setBXRange(firstBX, lastBX);

res1_->setBXRange(firstBX, lastBX);
res2_->setBXRange(firstBX, lastBX);
LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX;

// Initialise indices
unsigned int i = 0;
// Get the BX blocks and unpack them
auto bxBlocks = block.getBxBlocks(nWords_, bxZsEnabled);
for (const auto& bxBlock : bxBlocks) {
unpackBx(bxBlock.header().getBx(), bxBlock.payload());
}
return true;
}


// Loop over multiple BX and then number of muons filling muon collection
for (int bx = firstBX; bx <= lastBX; ++bx) {
void
IntermediateMuonUnpacker::unpackBx(int bx, const std::vector<uint32_t>& payload, unsigned int startIdx)
{
unsigned int i = startIdx;
// Check if there are enough words left in the payload
if (i + nWords_ <= payload.size()) {
unsigned int muonCnt = 0;
for (unsigned nWord = 0; nWord < nWords && i < block.header().getSize(); nWord += 2, ++muonCnt) {
for (unsigned nWord = 0; nWord < nWords_; nWord += 2, ++muonCnt) {
uint32_t raw_data_00_31 = payload[i++];
uint32_t raw_data_32_63 = payload[i++];
LogDebug("L1T") << "raw_data_00_31 = 0x" << hex << raw_data_00_31 << " raw_data_32_63 = 0x" << raw_data_32_63;
Expand All @@ -105,22 +123,25 @@ namespace l1t {

Muon mu;

// The intermediate muons do not have coordinates estimated at the vertex in the RAW data
// The corresponding bits are set to zero
// The intermediate muons of the uGMT (FED number 1402) do not
// have coordinates estimated at the vertex in the RAW data.
// The corresponding bits are set to zero.
MuonRawDigiTranslator::fillMuon(mu, raw_data_00_31, raw_data_32_63, 1402, algoVersion_);

LogDebug("L1T") << "Mu" << nWord/2 << ": eta " << mu.hwEta() << " phi " << mu.hwPhi() << " pT " << mu.hwPt() << " iso " << mu.hwIso() << " qual " << mu.hwQual() << " charge " << mu.hwCharge() << " charge valid " << mu.hwChargeValid();

if (muonCnt < coll1Cnt) {
res1->push_back(bx, mu);
if (muonCnt < coll1Cnt_) {
res1_->push_back(bx, mu);
} else {
res2->push_back(bx, mu);
res2_->push_back(bx, mu);
}
}
} else {
edm::LogWarning("L1T") << "Only " << payload.size() - i << " 32 bit words in this BX but " << nWords_ << " are required. Not unpacking the data for BX " << bx << ".";
}
return true;
}
}
}

} // namespace stage2
} // namespace l1t

DEFINE_L1T_UNPACKER(l1t::stage2::IntermediateMuonUnpacker);
Expand Up @@ -8,15 +8,23 @@ namespace l1t {
class IntermediateMuonUnpacker : public Unpacker {
public:
IntermediateMuonUnpacker();
~IntermediateMuonUnpacker() {};
~IntermediateMuonUnpacker() override {};

virtual bool unpack(const Block& block, UnpackerCollections *coll) override;
bool unpack(const Block& block, UnpackerCollections *coll) override;

inline unsigned int getAlgoVersion() { return algoVersion_; };
inline void setAlgoVersion(const unsigned int version) { algoVersion_ = version; };

private:
static const unsigned int nWords_ = 6; // every link transmits 6 words (3 muons) per bx
static const unsigned int bxzs_enable_shift_ = 1;

MuonBxCollection* res1_;
MuonBxCollection* res2_;
unsigned int algoVersion_;
unsigned int coll1Cnt_;

void unpackBx(int bx, const std::vector<uint32_t>& payload, unsigned int startIdx=0);
};
}
}
Expand Down

0 comments on commit e4fd1ba

Please sign in to comment.