Skip to content

Commit

Permalink
Merge pull request #19310 from cms-l1t-offline/PR92x-l1t-integration-…
Browse files Browse the repository at this point in the history
…v95.15

Pr92x L1T Calo (EG, MET, Tau)  2017 emulation of startup (up to l1t integration v95.15)
  • Loading branch information
cmsbuild committed Jun 23, 2017
2 parents 2cd7210 + e9533a7 commit 7bf5e7d
Show file tree
Hide file tree
Showing 53 changed files with 3,672 additions and 319 deletions.
79 changes: 47 additions & 32 deletions EventFilter/L1TRawToDigi/plugins/L1TRawToDigi.cc
Expand Up @@ -39,6 +39,8 @@

#include "PackingSetupFactory.h"

#include "EventFilter/L1TRawToDigi/plugins/implementations_stage2/L1TStage2Layer2Constants.h"

namespace l1t {
class L1TRawToDigi : public edm::stream::EDProducer<> {
public:
Expand Down Expand Up @@ -72,6 +74,8 @@ namespace l1t {
int amc13HeaderSize_;
int amc13TrailerSize_;

bool tmtCheck_;

bool ctp7_mode_;
bool mtf7_mode_;
bool debug_;
Expand All @@ -91,6 +95,7 @@ namespace l1t {
minFeds_(config.getParameter<unsigned int>("MinFeds")),
fwId_(config.getParameter<unsigned int>("FWId")),
fwOverride_(config.getParameter<bool>("FWOverride")),
tmtCheck_(config.getParameter<bool>("TMTCheck")),
ctp7_mode_(config.getUntrackedParameter<bool>("CTP7")),
mtf7_mode_(config.getUntrackedParameter<bool>("MTF7"))
{
Expand Down Expand Up @@ -235,43 +240,52 @@ namespace l1t {

unsigned board = amc.blockHeader().getBoardID();
unsigned amc_no = amc.blockHeader().getAMCNumber();

auto unpackers = prov_->getUnpackers(fedId, board, amc_no, fw);

auto unpackers = prov_->getUnpackers(fedId, board, amc_no, fw);
// getBlock() returns a non-null unique_ptr on success
std::unique_ptr<Block> block;
while ((block = payload->getBlock()).get()) {
if (debug_) {

// only unpack the Calo Layer 2 MP TMT node if it has processed this BX
unsigned tmtId = board - l1t::stage2::layer2::mp::offsetBoardId + 1;
unsigned bxId = header.bxID();
unsigned unpackTMT = ( !tmtCheck_ || ( ( tmtId - 1 ) == ( ( bxId - 1 + 3 ) % 9 ) ) );
unsigned isCaloL2TMT = ( fedId==l1t::stage2::layer2::fedId && ( amc_no != l1t::stage2::layer2::demux::amcSlotNum ) );

if( !isCaloL2TMT || unpackTMT ) {
if (debug_) {
std::cout << ">>> block to unpack <<<" << std::endl
<< "hdr: " << std::hex << std::setw(8) << std::setfill('0') << block->header().raw() << std::dec
<< " (ID " << block->header().getID() << ", size " << block->header().getSize()
<< ", CapID 0x" << std::hex << std::setw(2) << std::setfill('0') << block->header().getCapID()
<< ")" << std::dec << std::endl;
<< "hdr: " << std::hex << std::setw(8) << std::setfill('0') << block->header().raw() << std::dec
<< " (ID " << block->header().getID() << ", size " << block->header().getSize()
<< ", CapID 0x" << std::hex << std::setw(2) << std::setfill('0') << block->header().getCapID()
<< ")" << std::dec << std::endl;
for (const auto& word: block->payload()) {
if (debug_)
std::cout << "data: " << std::hex << std::setw(8) << std::setfill('0') << word << std::dec << std::endl;
}
}

auto unpacker = unpackers.find(block->header().getID());

block->amc(amc.header());

if (unpacker == unpackers.end()) {
LogDebug("L1T") << "Cannot find an unpacker for"
<< "\n\tblock: ID " << block->header().getID() << ", size " << block->header().getSize()
<< "\n\tAMC: # " << amc_no << ", board ID 0x" << std::hex << board << std::dec
<< "\n\tFED ID " << fedId << ", and FW ID " << fw;
// TODO Handle error
} else if (!unpacker->second->unpack(*block, coll.get())) {
LogDebug("L1T") << "Error unpacking data for block ID "
<< block->header().getID() << ", AMC # " << amc_no
<< ", board ID " << board << ", FED ID " << fedId
<< ", and FW ID " << fw << "!";
// TODO Handle error
}
}
}
if (debug_)
std::cout << "data: " << std::hex << std::setw(8) << std::setfill('0') << word << std::dec << std::endl;
}
}

auto unpacker = unpackers.find(block->header().getID());

block->amc(amc.header());

if (unpacker == unpackers.end()) {
LogDebug("L1T") << "Cannot find an unpacker for"
<< "\n\tblock: ID " << block->header().getID() << ", size " << block->header().getSize()
<< "\n\tAMC: # " << amc_no << ", board ID 0x" << std::hex << board << std::dec
<< "\n\tFED ID " << fedId << ", and FW ID " << fw;
// TODO Handle error
} else if (!unpacker->second->unpack(*block, coll.get())) {
LogDebug("L1T") << "Error unpacking data for block ID "
<< block->header().getID() << ", AMC # " << amc_no
<< ", board ID " << board << ", FED ID " << fedId
<< ", and FW ID " << fw << "!";
// TODO Handle error
}
}
}
}
}
if (valid_count < minFeds_){
if (warnsb_ < 5){
Expand All @@ -292,6 +306,7 @@ namespace l1t {
// part of the L1T/HLT interface. They can be cleaned up or updated at will:
desc.add<unsigned int>("FWId",0)->setComment("Ignored unless FWOverride is true. Calo Stage1: 32 bits: if the first eight bits are 0xff, will read the 74x MC format.\n");
desc.add<bool>("FWOverride", false)->setComment("Firmware version should be taken as FWId parameters");
desc.add<bool>("TMTCheck", true)->setComment("Flag for turning on/off Calo Layer 2 TMT node check");
desc.addUntracked<bool>("CTP7", false);
desc.addUntracked<bool>("MTF7", false);
desc.add<edm::InputTag>("InputLabel",edm::InputTag("rawDataCollector"));
Expand Down
Expand Up @@ -17,8 +17,6 @@ namespace stage2 {
unsigned int tmt = block.amc().getBoardID() - l1t::stage2::layer2::mp::offsetBoardId + 1;
unsigned int bxid = block.amc().getBX();

// handle offset between BC0 marker and actual BC0...
if( (tmt-1) != ((bxid-1+3)%9) ) return true;
LogDebug("L1T") << "Unpacking TMT # " << tmt << " for BX " << bxid;

// Link number is block_ID / 2
Expand Down
Expand Up @@ -6,6 +6,7 @@
#include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"

#include "EventFilter/L1TRawToDigi/plugins/implementations_stage2/MuonUnpacker.h"
#include "EventFilter/L1TRawToDigi/plugins/implementations_stage2/IntermediateMuonUnpacker.h"

#include "GMTSetup.h"

Expand Down Expand Up @@ -82,7 +83,8 @@ namespace l1t {
res[iLink] = gmt_in_unp;

// internal muons
auto gmt_imd_unp = UnpackerFactory::get()->make("stage2::IntermediateMuonUnpacker");
auto gmt_imd_unp = static_pointer_cast<l1t::stage2::IntermediateMuonUnpacker>(UnpackerFactory::get()->make("stage2::IntermediateMuonUnpacker"));
gmt_imd_unp->setAlgoVersion(fw);
for (int oLink = 49; oLink < 63; oLink += 2)
res[oLink] = gmt_imd_unp;

Expand Down
Expand Up @@ -9,6 +9,10 @@

namespace l1t {
namespace stage2 {
IntermediateMuonUnpacker::IntermediateMuonUnpacker() : algoVersion_(0)
{
}

bool
IntermediateMuonUnpacker::unpack(const Block& block, UnpackerCollections *coll)
{
Expand Down Expand Up @@ -102,8 +106,8 @@ namespace l1t {
Muon mu;

// The intermediate muons do not have coordinates estimated at the vertex in the RAW data
// Setting FW version to 0 makes the unpacker use the 2016 RAW format
MuonRawDigiTranslator::fillMuon(mu, raw_data_00_31, raw_data_32_63, 1402, 0);
// 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();

Expand Down
Expand Up @@ -7,7 +7,16 @@ namespace l1t {
namespace stage2 {
class IntermediateMuonUnpacker : public Unpacker {
public:
IntermediateMuonUnpacker();
~IntermediateMuonUnpacker() {};

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

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

private:
unsigned int algoVersion_;
};
}
}
Expand Down
@@ -1,6 +1,8 @@

#include "L1TStage2Layer2Constants.h"

int l1t::stage2::layer2::fedId = 1360;

unsigned int l1t::stage2::layer2::mp::offsetBoardId = 0x2210;

unsigned int l1t::stage2::layer2::mp::nInputFramePerBX = 40;
Expand All @@ -11,3 +13,4 @@ unsigned int l1t::stage2::layer2::demux::nEGPerLink = 6;
unsigned int l1t::stage2::layer2::demux::nTauPerLink = 6;
unsigned int l1t::stage2::layer2::demux::nJetPerLink = 6;
unsigned int l1t::stage2::layer2::demux::nEtSumPerLink = 4;
unsigned int l1t::stage2::layer2::demux::amcSlotNum = 12;
Expand Up @@ -8,6 +8,8 @@ namespace l1t {

namespace layer2 {

extern signed int fedId;

namespace mp {

extern unsigned int offsetBoardId;
Expand All @@ -25,6 +27,8 @@ namespace l1t {
extern unsigned int nTauPerLink;
extern unsigned int nJetPerLink;
extern unsigned int nEtSumPerLink;

extern unsigned int amcSlotNum;

}

Expand Down
Expand Up @@ -20,8 +20,6 @@ namespace stage2 {
// check this is the correct MP
unsigned int amc = block.amc().getAMCNumber();
unsigned int bxid = block.amc().getBX();
// if( (amc-1) != (bxid-1)%9 ) return true;
if( (amc-1) != ((bxid-1+3)%9) ) return true; // temporary measure!
LogDebug("L1T") << "Unpacking AMC " << amc << " for BX " << bxid;

auto res1_ = static_cast<CaloCollections*>(coll)->getMPJets();
Expand Down
Expand Up @@ -27,8 +27,6 @@ namespace stage2 {
// check this is the correct MP
unsigned int amc = block.amc().getAMCNumber();
unsigned int bxid = block.amc().getBX();
// if( (amc-1) != (bxid-1)%9 ) return true;
if( (amc-1) != ((bxid-1+3)%9) ) return true; // temporary measure!
LogDebug("L1T") << "Unpacking AMC " << amc << " for BX " << bxid;

auto res1_ = static_cast<CaloCollections*>(coll)->getMPJets();
Expand Down
Expand Up @@ -23,7 +23,7 @@ namespace stage2 {
const unsigned int bxid = block.amc().getBX();

// handle offset between BC0 marker and actual BC0...
if( (tmt-1) != ((bxid-1+3)%9) ) return true;
//if( (tmt-1) != ((bxid-1+3)%9) ) return true;
LogDebug("L1T") << "Unpacking TMT # " << tmt << " for BX " << bxid;

auto res1_ = static_cast<CaloCollections*>(coll)->getMPJets();
Expand Down
Expand Up @@ -23,7 +23,7 @@ namespace stage2 {
unsigned int bxid = block.amc().getBX();

// handle offset between BC0 marker and actual BC0...
if( (tmt-1) != ((bxid-1+3)%9) ) return true;
//if( (tmt-1) != ((bxid-1+3)%9) ) return true;
LogDebug("L1T") << "Unpacking TMT # " << tmt << " for BX " << bxid;

auto res1_ = static_cast<CaloCollections*>(coll)->getMPJets();
Expand Down
3 changes: 3 additions & 0 deletions EventFilter/L1TRawToDigi/python/caloStage2Digis_cfi.py
Expand Up @@ -4,4 +4,7 @@
"L1TRawToDigi",
Setup = cms.string("stage2::CaloSetup"),
FedIds = cms.vint32( 1360, 1366 ),
FWId = cms.uint32(0),
FWOverride = cms.bool(False),
TMTCheck = cms.bool(True)
)
2 changes: 2 additions & 0 deletions EventFilter/L1TRawToDigi/python/l1tRawToDigi_cfi.py
Expand Up @@ -6,6 +6,8 @@
InputLabel = cms.InputTag("l1tDigiToRaw"),
FedIds = cms.vint32(1352),
FWId = cms.uint32(1),
FWOverride = cms.bool(False),
TMTCheck = cms.bool(True),
lenSlinkHeader = cms.untracked.int32(8),
lenSlinkTrailer = cms.untracked.int32(8),
lenAMCHeader = cms.untracked.int32(8),
Expand Down
64 changes: 63 additions & 1 deletion EventFilter/L1TRawToDigi/utils/unpackBuffers-CaloStage2.py
Expand Up @@ -14,6 +14,11 @@
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.int,
"Number of events to skip")
options.register('fwVersion',
268501043,
VarParsing.VarParsing.multiplicity.singleton,
VarParsing.VarParsing.varType.int,
"Firmware version for unpacker configuration")
options.register('mpFramesPerEvent',
40,
VarParsing.VarParsing.multiplicity.singleton,
Expand Down Expand Up @@ -186,6 +191,12 @@
offset = offset + 1
mpOffsets.append(offset)

mpLatencies = cms.untracked.vint32()
for i in range (0,options.nMP):
mpLatencies.append(0)

boardIds = cms.untracked.vint32(range(0,options.nMP))

boardOffset = options.skipEvents % options.nMP

gtOffset = options.gtOffset + (options.skipEvents * options.gtFramesPerEvent)
Expand All @@ -204,15 +215,63 @@
print "mpOffset = ", mpOffsets
print " "

mpBlock = cms.untracked.PSet(
rxBlockLength = cms.untracked.vint32(40,40,40,40, # q0 0-3
40,40,40,40, # q1 4-7
40,40,40,40, # q2 8-11
40,40,40,40, # q3 12-15
40,40,40,40, # q4 16-19
40,40,40,40, # q5 20-23
40,40,40,40, # q6 24-27
40,40,40,40, # q7 28-31
40,40,40,40, # q8 32-35
40,40,40,40, # q9 36-39
40,40,40,40, # q10 40-43
40,40,40,40, # q11 44-47
40,40,40,40, # q12 48-51
40,40,40,40, # q13 52-55
40,40,40,40, # q14 56-59
40,40,40,40, # q15 60-63
40,40,40,40, # q16 64-67
40,40,40,40), # q17 68-71

txBlockLength = cms.untracked.vint32(0,0,0,0, # q0 0-3
0,0,0,0, # q1 4-7
0,0,0,0, # q2 8-11
0,0,0,0, # q3 12-15
0,0,0,0, # q4 16-19
0,0,0,0, # q5 20-23
0,0,0,0, # q6 24-27
0,0,0,0, # q7 28-31
0,0,0,0, # q8 32-35
0,0,0,0, # q9 36-39
0,0,0,0, # q10 40-43
0,0,0,0, # q11 44-47
0,0,0,0, # q12 48-51
0,0,0,0, # q13 52-55
0,0,0,0, # q14 56-59
11,11,11,11, # q15 60-63
11,11,0,0, # q16 64-67
0,0,0,0) # q17 68-71
)

mpBlocks = cms.untracked.VPSet()

for block in range(0,options.nMP):
mpBlocks.append(mpBlock)

process.stage2MPRaw.nFramesPerEvent = cms.untracked.int32(options.mpFramesPerEvent)
process.stage2MPRaw.nFramesOffset = cms.untracked.vuint32(mpOffsets)
process.stage2MPRaw.nFramesLatency = cms.untracked.vuint32(mpLatencies)
process.stage2MPRaw.boardOffset = cms.untracked.int32(boardOffset)
process.stage2MPRaw.rxKeyLink = cms.untracked.int32(options.mpKeyLinkRx)
process.stage2MPRaw.txKeyLink = cms.untracked.int32(options.mpKeyLinkTx)
#process.stage2MPRaw.nFramesLatency = cms.untracked.vuint32(mpLatencies)
process.stage2MPRaw.boardId = cms.untracked.vint32(boardIds)
process.stage2MPRaw.nHeaderFrames = cms.untracked.int32(options.mpHeaderFrames)
process.stage2MPRaw.rxFile = cms.untracked.string("mp_rx_summary.txt")
process.stage2MPRaw.txFile = cms.untracked.string("mp_tx_summary.txt")
process.stage2MPRaw.blocks = cms.untracked.VPSet(mpBlocks)
process.stage2MPRaw.fwVersion = cms.untracked.int32(options.fwVersion)

# Demux config
if (options.doDemux):
Expand Down Expand Up @@ -255,6 +314,9 @@
process.load('EventFilter.L1TRawToDigi.caloStage2Digis_cfi')
process.caloStage2Digis.InputLabel = cms.InputTag('rawDataCollector')
process.caloStage2Digis.debug = cms.untracked.bool(options.debug)
process.caloStage2Digis.FWId = cms.uint32(options.fwVersion)
process.caloStage2Digis.FWOverride = cms.bool(True)
process.caloStage2Digis.TMTCheck = cms.bool(False)

process.load('EventFilter.L1TRawToDigi.gtStage2Digis_cfi')
process.gtStage2Digis.InputLabel = cms.InputTag('rawDataCollector')
Expand Down

0 comments on commit 7bf5e7d

Please sign in to comment.