Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve L1TRawToDigi #46928

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DQM/L1TMonitor/plugins/L1TBMTFAlgoSelector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ void dqmBmtfAlgoSelector::L1TBMTFAlgoSelector::produce(edm::Event &eve, const ed
unsigned algo_ver;
if (!packet.payload().empty()) {
auto payload64 = (packet.payload().at(0)).data();
const uint32_t *start = (const uint32_t *)payload64.get();
const uint32_t *end = start + (packet.payload().at(0).size() * 2);
const uint32_t *start = reinterpret_cast<const uint32_t *>(&payload64.front());
const uint32_t *end = start + (payload64.size() * 2);

l1t::MP7Payload payload(start, end, false);
algo_ver = payload.getAlgorithmFWVersion();
Expand Down
10 changes: 5 additions & 5 deletions DQM/L1TMonitor/src/L1TMP7ZeroSupp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,16 @@ void L1TMP7ZeroSupp::analyze(const edm::Event& e, const edm::EventSetup& c) {
continue;

auto payload64 = amc.data();
auto start = (const uint32_t*)payload64.get();
auto start = reinterpret_cast<const uint32_t*>(&payload64.front());
// Want to have payload size in 32 bit words, but AMC measures
// it in 64 bit words -> factor 2.
const uint32_t* end = start + (amc.size() * 2);
const uint32_t* end = start + (payload64.size() * 2);

auto payload = std::make_unique<l1t::MP7Payload>(start, end, false);

// getBlock() returns a non-null unique_ptr on success
std::unique_ptr<l1t::Block> block;
while ((block = payload->getBlock()) != nullptr) {
// getBlock() returns a non-nullopt_t optional on success
std::optional<l1t::Block> block;
while ((block = payload->getBlock())) {
if (verbose_) {
std::cout << ">>> check zero suppression for block <<<" << std::endl
<< "hdr: " << std::hex << std::setw(8) << std::setfill('0') << block->header().raw() << std::dec
Expand Down
2 changes: 1 addition & 1 deletion EventFilter/L1TRawToDigi/interface/AMC13Spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace amc13 {
bool mtf7_mode = false);
bool write(const edm::Event &ev, unsigned char *ptr, unsigned int skip, unsigned int size) const;

inline std::vector<amc::Packet> payload() const { return payload_; };
inline const std::vector<amc::Packet> &payload() const { return payload_; };

private:
Header header_;
Expand Down
8 changes: 6 additions & 2 deletions EventFilter/L1TRawToDigi/interface/AMCSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <memory>
#include <vector>
#include <cstdint>
#include <span>

namespace amc {
static const unsigned int split_block_size = 0x1000;
Expand Down Expand Up @@ -143,8 +144,11 @@ namespace amc {
// cross-checks for data consistency.
void finalize(unsigned int lv1, unsigned int bx, bool legacy_mc = false, bool mtf7_mode = false);

std::vector<uint64_t> block(unsigned int id) const;
std::unique_ptr<uint64_t[]> data();
std::span<const uint64_t> block(unsigned int id) const;
std::span<const uint64_t> data() const {
// Remove 3 words: 2 for the header, 1 for the trailer
return payload_.empty() ? std::span<const uint64_t>() : std::span<const uint64_t>(payload_).subspan(2, size());
};
BlockHeader blockHeader(unsigned int block = 0) const { return block_header_; };
Header header() const { return header_; };
Trailer trailer() const { return trailer_; };
Expand Down
7 changes: 4 additions & 3 deletions EventFilter/L1TRawToDigi/interface/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <memory>
#include <vector>
#include <optional>

#include "EventFilter/L1TRawToDigi/interface/AMCSpec.h"
#include "DataFormats/L1Trigger/interface/BxBlock.h"
Expand Down Expand Up @@ -109,7 +110,7 @@ namespace l1t {
// header. Called by getBlock(), which also checks that data_ !=
// end_ before calling (assumes size of one 32 bit word).
virtual BlockHeader getHeader() = 0;
virtual std::unique_ptr<Block> getBlock();
virtual std::optional<Block> getBlock();

protected:
const uint32_t* data_;
Expand All @@ -132,7 +133,7 @@ namespace l1t {
// Unused methods - we override getBlock() instead
unsigned getHeaderSize() const override { return 0; };
BlockHeader getHeader() override { return BlockHeader(nullptr); };
std::unique_ptr<Block> getBlock() override;
std::optional<Block> getBlock() override;

private:
// sizes in 16 bit words
Expand Down Expand Up @@ -174,7 +175,7 @@ namespace l1t {
CTP7Payload(const uint32_t* data, const uint32_t* end, amc::Header amcHeader);
unsigned getHeaderSize() const override { return 2; };
BlockHeader getHeader() override;
std::unique_ptr<Block> getBlock() override;
std::optional<Block> getBlock() override;

private:
// FIXME check values
Expand Down
14 changes: 7 additions & 7 deletions EventFilter/L1TRawToDigi/plugins/L1TRawToDigi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <iostream>
#include <iomanip>
#include <memory>
#include <optional>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
Expand Down Expand Up @@ -128,8 +129,7 @@ namespace l1t {

std::unique_ptr<UnpackerCollections> coll = prov_->getCollections(event);

edm::Handle<FEDRawDataCollection> feds;
event.getByToken(fedData_, feds);
edm::Handle<FEDRawDataCollection> feds = event.getHandle(fedData_);

if (!feds.isValid()) {
LogError("L1T") << "Cannot unpack: no FEDRawDataCollection found";
Expand Down Expand Up @@ -201,10 +201,10 @@ namespace l1t {
continue;

auto payload64 = amc.data();
const uint32_t* start = (const uint32_t*)payload64.get();
const uint32_t* start = reinterpret_cast<const uint32_t*>(&payload64.front());
// Want to have payload size in 32 bit words, but AMC measures
// it in 64 bit words → factor 2.
const uint32_t* end = start + (amc.size() * 2);
const uint32_t* end = start + (payload64.size() * 2);

std::unique_ptr<Payload> payload;
if (ctp7_mode_) {
Expand Down Expand Up @@ -232,9 +232,9 @@ namespace l1t {

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()) {
// getBlock() returns a non-null optional on success
std::optional<Block> block;
while ((block = payload->getBlock())) {
// 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();
Expand Down
5 changes: 2 additions & 3 deletions EventFilter/L1TRawToDigi/plugins/OmtfUnpacker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ namespace omtf {
// AMC trailer
//
//amc::Trailer trailerAmc = amc.trailer(); //this is the expected way but does not work
amc::Trailer trailerAmc(amc.data().get() + amc.size() -
1); //FIXME: the above is prefered but this works (CMSSW900)
amc::Trailer trailerAmc(&amc.data().back()); //FIXME: the above is prefered but this works (CMSSW900)
if (debug) {
std::ostringstream str;
str << " AMC trailer: " << std::bitset<64>(trailerAmc.raw()) << std::endl;
Expand All @@ -323,7 +322,7 @@ namespace omtf {
// AMC payload
//
const auto& payload64 = amc.data();
const Word64* word = payload64.get();
const Word64* word = &payload64.front();
for (unsigned int iWord = 1; iWord <= amc.size(); iWord++, word++) {
if (iWord <= 2)
continue; // two header words for each AMC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@
namespace l1t {
namespace stage2 {
GMTCollections::~GMTCollections() {
event_.put(std::move(regionalMuonCandsBMTF_), "BMTF");
event_.put(std::move(regionalMuonCandsOMTF_), "OMTF");
event_.put(std::move(regionalMuonCandsEMTF_), "EMTF");
event_.put(std::move(muons_[0]), "Muon");
event_.emplace(tokens_.bmtf_, std::move(regionalMuonCandsBMTF_));
event_.emplace(tokens_.omtf_, std::move(regionalMuonCandsOMTF_));
event_.emplace(tokens_.emtf_, std::move(regionalMuonCandsEMTF_));
event_.emplace(tokens_.muon_, std::move(muons_[0]));
assert(NUM_OUTPUT_COPIES == tokens_.muonCopies_.size());
for (size_t i = 1; i < NUM_OUTPUT_COPIES; ++i) {
event_.put(std::move(muons_[i]), "MuonCopy" + std::to_string(i));
event_.emplace(tokens_.muonCopies_[i], std::move(muons_[i]));
}
event_.put(std::move(imdMuonsBMTF_), "imdMuonsBMTF");
event_.put(std::move(imdMuonsEMTFNeg_), "imdMuonsEMTFNeg");
event_.put(std::move(imdMuonsEMTFPos_), "imdMuonsEMTFPos");
event_.put(std::move(imdMuonsOMTFNeg_), "imdMuonsOMTFNeg");
event_.put(std::move(imdMuonsOMTFPos_), "imdMuonsOMTFPos");
event_.emplace(tokens_.imdMuonsBMTF_, std::move(imdMuonsBMTF_));
event_.emplace(tokens_.imdMuonsEMTFNeg_, std::move(imdMuonsEMTFNeg_));
event_.emplace(tokens_.imdMuonsEMTFPos_, std::move(imdMuonsEMTFPos_));
event_.emplace(tokens_.imdMuonsOMTFNeg_, std::move(imdMuonsOMTFNeg_));
event_.emplace(tokens_.imdMuonsOMTFPos_, std::move(imdMuonsOMTFPos_));

event_.put(std::move(regionalMuonShowersEMTF_), "EMTF");
event_.put(std::move(muonShowers_[0]), "MuonShower");
event_.emplace(tokens_.showerEMTF_, std::move(regionalMuonShowersEMTF_));
event_.emplace(tokens_.muonShower_, std::move(muonShowers_[0]));
assert(tokens_.muonShowerCopy_.size() == NUM_OUTPUT_COPIES);
for (size_t i = 1; i < NUM_OUTPUT_COPIES; ++i) {
event_.put(std::move(muonShowers_[i]), "MuonShowerCopy" + std::to_string(i));
event_.emplace(tokens_.muonShowerCopy_[i], std::move(muonShowers_[i]));
}
}
} // namespace stage2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "DataFormats/L1Trigger/interface/MuonShower.h"

#include "L1TObjectCollections.h"
#include "GMTPutTokens.h"

#include <array>

Expand All @@ -19,61 +20,67 @@ namespace l1t {
// fill a collection the BX range cannot be determined.
// Set default values here to then create an empty collection
// with a defined BX range.
GMTCollections(
edm::Event& e, const int iFirstBx = -2, const int iLastBx = 2, const int oFirstBx = -2, const int oLastBx = 2)
GMTCollections(edm::Event& e,
GMTPutTokens const& iTokens,
const int iFirstBx = -2,
const int iLastBx = 2,
const int oFirstBx = -2,
const int oLastBx = 2)
: L1TObjectCollections(e),
regionalMuonCandsBMTF_(std::make_unique<RegionalMuonCandBxCollection>(0, iFirstBx, iLastBx)),
regionalMuonCandsOMTF_(std::make_unique<RegionalMuonCandBxCollection>(0, iFirstBx, iLastBx)),
regionalMuonCandsEMTF_(std::make_unique<RegionalMuonCandBxCollection>(0, iFirstBx, iLastBx)),
muons_(),
imdMuonsBMTF_(std::make_unique<MuonBxCollection>(0, oFirstBx, oLastBx)),
imdMuonsEMTFNeg_(std::make_unique<MuonBxCollection>(0, oFirstBx, oLastBx)),
imdMuonsEMTFPos_(std::make_unique<MuonBxCollection>(0, oFirstBx, oLastBx)),
imdMuonsOMTFNeg_(std::make_unique<MuonBxCollection>(0, oFirstBx, oLastBx)),
imdMuonsOMTFPos_(std::make_unique<MuonBxCollection>(0, oFirstBx, oLastBx)),

regionalMuonShowersEMTF_(std::make_unique<RegionalMuonShowerBxCollection>(0, iFirstBx, iLastBx)),
muonShowers_() {
std::generate(muons_.begin(), muons_.end(), [&oFirstBx, &oLastBx] {
return std::make_unique<MuonBxCollection>(0, oFirstBx, oLastBx);
});
std::generate(muonShowers_.begin(), muonShowers_.end(), [&oFirstBx, &oLastBx] {
return std::make_unique<MuonShowerBxCollection>(0, oFirstBx, oLastBx);
});
};
regionalMuonCandsBMTF_(0, iFirstBx, iLastBx),
regionalMuonCandsOMTF_(0, iFirstBx, iLastBx),
regionalMuonCandsEMTF_(0, iFirstBx, iLastBx),
muons_{{{0, oFirstBx, oLastBx},
{0, oFirstBx, oLastBx},
{0, oFirstBx, oLastBx},
{0, oFirstBx, oLastBx},
{0, oFirstBx, oLastBx},
{0, oFirstBx, oLastBx}}},
imdMuonsBMTF_(0, oFirstBx, oLastBx),
imdMuonsEMTFNeg_(0, oFirstBx, oLastBx),
imdMuonsEMTFPos_(0, oFirstBx, oLastBx),
imdMuonsOMTFNeg_(0, oFirstBx, oLastBx),
imdMuonsOMTFPos_(0, oFirstBx, oLastBx),
regionalMuonShowersEMTF_(0, iFirstBx, iLastBx),
muonShowers_{{{0, oFirstBx, oLastBx},
{0, oFirstBx, oLastBx},
{0, oFirstBx, oLastBx},
{0, oFirstBx, oLastBx},
{0, oFirstBx, oLastBx},
{0, oFirstBx, oLastBx}}},
tokens_(iTokens) {};

~GMTCollections() override;

inline RegionalMuonCandBxCollection* getRegionalMuonCandsBMTF() { return regionalMuonCandsBMTF_.get(); };
inline RegionalMuonCandBxCollection* getRegionalMuonCandsOMTF() { return regionalMuonCandsOMTF_.get(); };
inline RegionalMuonCandBxCollection* getRegionalMuonCandsEMTF() { return regionalMuonCandsEMTF_.get(); };
inline MuonBxCollection* getMuons(const unsigned int copy) override { return muons_[copy].get(); };
inline MuonBxCollection* getImdMuonsBMTF() { return imdMuonsBMTF_.get(); };
inline MuonBxCollection* getImdMuonsEMTFNeg() { return imdMuonsEMTFNeg_.get(); };
inline MuonBxCollection* getImdMuonsEMTFPos() { return imdMuonsEMTFPos_.get(); };
inline MuonBxCollection* getImdMuonsOMTFNeg() { return imdMuonsOMTFNeg_.get(); };
inline MuonBxCollection* getImdMuonsOMTFPos() { return imdMuonsOMTFPos_.get(); };
inline RegionalMuonCandBxCollection* getRegionalMuonCandsBMTF() { return &regionalMuonCandsBMTF_; };
inline RegionalMuonCandBxCollection* getRegionalMuonCandsOMTF() { return &regionalMuonCandsOMTF_; };
inline RegionalMuonCandBxCollection* getRegionalMuonCandsEMTF() { return &regionalMuonCandsEMTF_; };
inline MuonBxCollection* getMuons(const unsigned int copy) override { return &muons_[copy]; };
inline MuonBxCollection* getImdMuonsBMTF() { return &imdMuonsBMTF_; };
inline MuonBxCollection* getImdMuonsEMTFNeg() { return &imdMuonsEMTFNeg_; };
inline MuonBxCollection* getImdMuonsEMTFPos() { return &imdMuonsEMTFPos_; };
inline MuonBxCollection* getImdMuonsOMTFNeg() { return &imdMuonsOMTFNeg_; };
inline MuonBxCollection* getImdMuonsOMTFPos() { return &imdMuonsOMTFPos_; };

inline RegionalMuonShowerBxCollection* getRegionalMuonShowersEMTF() { return regionalMuonShowersEMTF_.get(); };
inline MuonShowerBxCollection* getMuonShowers(const unsigned int copy) override {
return muonShowers_[copy].get();
};
inline RegionalMuonShowerBxCollection* getRegionalMuonShowersEMTF() { return &regionalMuonShowersEMTF_; };
inline MuonShowerBxCollection* getMuonShowers(const unsigned int copy) override { return &muonShowers_[copy]; };

static constexpr size_t NUM_OUTPUT_COPIES{6};

private:
std::unique_ptr<RegionalMuonCandBxCollection> regionalMuonCandsBMTF_;
std::unique_ptr<RegionalMuonCandBxCollection> regionalMuonCandsOMTF_;
std::unique_ptr<RegionalMuonCandBxCollection> regionalMuonCandsEMTF_;
std::array<std::unique_ptr<MuonBxCollection>, 6> muons_;
std::unique_ptr<MuonBxCollection> imdMuonsBMTF_;
std::unique_ptr<MuonBxCollection> imdMuonsEMTFNeg_;
std::unique_ptr<MuonBxCollection> imdMuonsEMTFPos_;
std::unique_ptr<MuonBxCollection> imdMuonsOMTFNeg_;
std::unique_ptr<MuonBxCollection> imdMuonsOMTFPos_;
RegionalMuonCandBxCollection regionalMuonCandsBMTF_;
RegionalMuonCandBxCollection regionalMuonCandsOMTF_;
RegionalMuonCandBxCollection regionalMuonCandsEMTF_;
std::array<MuonBxCollection, 6> muons_;
MuonBxCollection imdMuonsBMTF_;
MuonBxCollection imdMuonsEMTFNeg_;
MuonBxCollection imdMuonsEMTFPos_;
MuonBxCollection imdMuonsOMTFNeg_;
MuonBxCollection imdMuonsOMTFPos_;

std::unique_ptr<RegionalMuonShowerBxCollection> regionalMuonShowersEMTF_;
std::array<std::unique_ptr<MuonShowerBxCollection>, 6> muonShowers_;
RegionalMuonShowerBxCollection regionalMuonShowersEMTF_;
std::array<MuonShowerBxCollection, 6> muonShowers_;
GMTPutTokens tokens_;
};
} // namespace stage2
} // namespace l1t
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef Subsystem_Package_GMTPutTokens_h
#define Subsystem_Package_GMTPutTokens_h
// -*- C++ -*-
//
// Package: Subsystem/Package
// Class : GMTPutTokens
//
/**\class GMTPutTokens GMTPutTokens.h "GMTPutTokens.h"
Description: Holder for the EDPutTokens
Usage:
<usage>
*/
//
// Original Author: Christopher Jones
// Created: Wed, 11 Dec 2024 13:41:10 GMT
//
#include "DataFormats/L1TMuon/interface/RegionalMuonCand.h"
#include "DataFormats/L1Trigger/interface/Muon.h"

#include "DataFormats/L1TMuon/interface/RegionalMuonShower.h"
#include "DataFormats/L1Trigger/interface/MuonShower.h"

#include "L1TObjectCollections.h"

// system include files
#include <vector>

// user include files
#include "FWCore/Utilities/interface/EDPutToken.h"

// forward declarations

namespace l1t {
namespace stage2 {
struct GMTPutTokens {
edm::EDPutTokenT<RegionalMuonCandBxCollection> bmtf_;
edm::EDPutTokenT<RegionalMuonCandBxCollection> omtf_;
edm::EDPutTokenT<RegionalMuonCandBxCollection> emtf_;

edm::EDPutTokenT<MuonBxCollection> muon_;
std::vector<edm::EDPutTokenT<MuonBxCollection>> muonCopies_;

edm::EDPutTokenT<MuonBxCollection> imdMuonsBMTF_;
edm::EDPutTokenT<MuonBxCollection> imdMuonsEMTFNeg_;
edm::EDPutTokenT<MuonBxCollection> imdMuonsEMTFPos_;
edm::EDPutTokenT<MuonBxCollection> imdMuonsOMTFNeg_;
edm::EDPutTokenT<MuonBxCollection> imdMuonsOMTFPos_;

edm::EDPutTokenT<RegionalMuonShowerBxCollection> showerEMTF_;
edm::EDPutTokenT<MuonShowerBxCollection> muonShower_;
std::vector<edm::EDPutTokenT<MuonShowerBxCollection>> muonShowerCopy_;
};
} // namespace stage2
} // namespace l1t
#endif
Loading