From f00a113a07e3b3c09ca140c8919dda99ac38df03 Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Wed, 11 Dec 2024 16:50:40 -0600 Subject: [PATCH 1/2] Fixed memory leak in RegionalMuonGMTUnpacker --- .../RegionalMuonGMTUnpacker.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/EventFilter/L1TRawToDigi/plugins/implementations_stage2/RegionalMuonGMTUnpacker.cc b/EventFilter/L1TRawToDigi/plugins/implementations_stage2/RegionalMuonGMTUnpacker.cc index 6251276b417a2..46d956f27eed1 100644 --- a/EventFilter/L1TRawToDigi/plugins/implementations_stage2/RegionalMuonGMTUnpacker.cc +++ b/EventFilter/L1TRawToDigi/plugins/implementations_stage2/RegionalMuonGMTUnpacker.cc @@ -34,18 +34,14 @@ namespace l1t { unsigned int linkId = blockId / 2; int processor; RegionalMuonCandBxCollection* regionalMuonCollection; - RegionalMuonShowerBxCollection* regionalMuonShowerCollection; + RegionalMuonShowerBxCollection* regionalMuonShowerCollection = nullptr; tftype trackFinder; if (linkId > 47 && linkId < 60) { regionalMuonCollection = static_cast(coll)->getRegionalMuonCandsBMTF(); - regionalMuonShowerCollection = - new RegionalMuonShowerBxCollection(); // To avoid warning re uninitialised collection trackFinder = tftype::bmtf; processor = linkId - 48; } else if (linkId > 41 && linkId < 66) { regionalMuonCollection = static_cast(coll)->getRegionalMuonCandsOMTF(); - regionalMuonShowerCollection = - new RegionalMuonShowerBxCollection(); // To avoid warning re uninitialised collection if (linkId < 48) { trackFinder = tftype::omtf_pos; processor = linkId - 42; @@ -68,8 +64,9 @@ namespace l1t { return false; } regionalMuonCollection->setBXRange(firstBX, lastBX); - regionalMuonShowerCollection->setBXRange(firstBX, lastBX); - + if (regionalMuonShowerCollection) { + regionalMuonShowerCollection->setBXRange(firstBX, lastBX); + } LogDebug("L1T") << "nBX = " << nBX << " first BX = " << firstBX << " lastBX = " << lastBX; // Get the BX blocks and unpack them @@ -127,7 +124,8 @@ namespace l1t { // Fill RegionalMuonShower objects. For this we need to look at all six words together. RegionalMuonShower muShower; if (RegionalMuonRawDigiTranslator::fillRegionalMuonShower( - muShower, bxPayload, processor, trackFinder, useEmtfNominalTightShowers_, useEmtfLooseShowers_)) { + muShower, bxPayload, processor, trackFinder, useEmtfNominalTightShowers_, useEmtfLooseShowers_) and + regionalMuonShowerCollection) { regionalMuonShowerCollection->push_back(bx, muShower); } } else { From b38a7defc9d1a4b67469c83331911ed61e0c3b8c Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Thu, 12 Dec 2024 12:02:50 -0600 Subject: [PATCH 2/2] Improve L1TRawToDigi - decrease number of allocations - use more efficient framework APIs --- DQM/L1TMonitor/plugins/L1TBMTFAlgoSelector.cc | 4 +- DQM/L1TMonitor/src/L1TMP7ZeroSupp.cc | 10 +- .../L1TRawToDigi/interface/AMC13Spec.h | 2 +- EventFilter/L1TRawToDigi/interface/AMCSpec.h | 8 +- EventFilter/L1TRawToDigi/interface/Block.h | 7 +- .../L1TRawToDigi/plugins/L1TRawToDigi.cc | 14 +-- .../L1TRawToDigi/plugins/OmtfUnpacker.cc | 5 +- .../implementations_stage2/GMTCollections.cc | 28 +++--- .../implementations_stage2/GMTCollections.h | 97 ++++++++++--------- .../implementations_stage2/GMTPutTokens.h | 58 +++++++++++ .../implementations_stage2/GMTSetup.cc | 35 ++++--- .../plugins/implementations_stage2/GMTSetup.h | 3 + EventFilter/L1TRawToDigi/src/AMCSpec.cc | 18 +--- EventFilter/L1TRawToDigi/src/Block.cc | 24 ++--- .../plugins/L1UpgradeTfMuonTreeProducer.cc | 2 +- 15 files changed, 193 insertions(+), 122 deletions(-) create mode 100644 EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTPutTokens.h diff --git a/DQM/L1TMonitor/plugins/L1TBMTFAlgoSelector.cc b/DQM/L1TMonitor/plugins/L1TBMTFAlgoSelector.cc index e0767e21f63f5..c73240e356b26 100644 --- a/DQM/L1TMonitor/plugins/L1TBMTFAlgoSelector.cc +++ b/DQM/L1TMonitor/plugins/L1TBMTFAlgoSelector.cc @@ -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(&payload64.front()); + const uint32_t *end = start + (payload64.size() * 2); l1t::MP7Payload payload(start, end, false); algo_ver = payload.getAlgorithmFWVersion(); diff --git a/DQM/L1TMonitor/src/L1TMP7ZeroSupp.cc b/DQM/L1TMonitor/src/L1TMP7ZeroSupp.cc index 0d99bb0ae7cd3..5e77c2e452e4d 100644 --- a/DQM/L1TMonitor/src/L1TMP7ZeroSupp.cc +++ b/DQM/L1TMonitor/src/L1TMP7ZeroSupp.cc @@ -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(&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(start, end, false); - // getBlock() returns a non-null unique_ptr on success - std::unique_ptr block; - while ((block = payload->getBlock()) != nullptr) { + // getBlock() returns a non-nullopt_t optional on success + std::optional 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 diff --git a/EventFilter/L1TRawToDigi/interface/AMC13Spec.h b/EventFilter/L1TRawToDigi/interface/AMC13Spec.h index cb77d7d1a46ca..3e3a37dccd60f 100644 --- a/EventFilter/L1TRawToDigi/interface/AMC13Spec.h +++ b/EventFilter/L1TRawToDigi/interface/AMC13Spec.h @@ -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 payload() const { return payload_; }; + inline const std::vector &payload() const { return payload_; }; private: Header header_; diff --git a/EventFilter/L1TRawToDigi/interface/AMCSpec.h b/EventFilter/L1TRawToDigi/interface/AMCSpec.h index 4b2206bfba9a7..2d1e22af44633 100644 --- a/EventFilter/L1TRawToDigi/interface/AMCSpec.h +++ b/EventFilter/L1TRawToDigi/interface/AMCSpec.h @@ -4,6 +4,7 @@ #include #include #include +#include namespace amc { static const unsigned int split_block_size = 0x1000; @@ -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 block(unsigned int id) const; - std::unique_ptr data(); + std::span block(unsigned int id) const; + std::span data() const { + // Remove 3 words: 2 for the header, 1 for the trailer + return payload_.empty() ? std::span() : std::span(payload_).subspan(2, size()); + }; BlockHeader blockHeader(unsigned int block = 0) const { return block_header_; }; Header header() const { return header_; }; Trailer trailer() const { return trailer_; }; diff --git a/EventFilter/L1TRawToDigi/interface/Block.h b/EventFilter/L1TRawToDigi/interface/Block.h index b91469d126368..607a2b76e5b1c 100644 --- a/EventFilter/L1TRawToDigi/interface/Block.h +++ b/EventFilter/L1TRawToDigi/interface/Block.h @@ -3,6 +3,7 @@ #include #include +#include #include "EventFilter/L1TRawToDigi/interface/AMCSpec.h" #include "DataFormats/L1Trigger/interface/BxBlock.h" @@ -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 getBlock(); + virtual std::optional getBlock(); protected: const uint32_t* data_; @@ -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 getBlock() override; + std::optional getBlock() override; private: // sizes in 16 bit words @@ -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 getBlock() override; + std::optional getBlock() override; private: // FIXME check values diff --git a/EventFilter/L1TRawToDigi/plugins/L1TRawToDigi.cc b/EventFilter/L1TRawToDigi/plugins/L1TRawToDigi.cc index 49c0817b54483..b31a2309c7f2d 100644 --- a/EventFilter/L1TRawToDigi/plugins/L1TRawToDigi.cc +++ b/EventFilter/L1TRawToDigi/plugins/L1TRawToDigi.cc @@ -20,6 +20,7 @@ #include #include #include +#include // user include files #include "FWCore/Framework/interface/Frameworkfwd.h" @@ -128,8 +129,7 @@ namespace l1t { std::unique_ptr coll = prov_->getCollections(event); - edm::Handle feds; - event.getByToken(fedData_, feds); + edm::Handle feds = event.getHandle(fedData_); if (!feds.isValid()) { LogError("L1T") << "Cannot unpack: no FEDRawDataCollection found"; @@ -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(&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; if (ctp7_mode_) { @@ -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; - while ((block = payload->getBlock()).get()) { + // getBlock() returns a non-null optional on success + std::optional 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(); diff --git a/EventFilter/L1TRawToDigi/plugins/OmtfUnpacker.cc b/EventFilter/L1TRawToDigi/plugins/OmtfUnpacker.cc index c872db2d4aa72..f98c19ec7d1f5 100644 --- a/EventFilter/L1TRawToDigi/plugins/OmtfUnpacker.cc +++ b/EventFilter/L1TRawToDigi/plugins/OmtfUnpacker.cc @@ -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; @@ -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 diff --git a/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTCollections.cc b/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTCollections.cc index 8f998e86820a7..95b993ce8d9c7 100644 --- a/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTCollections.cc +++ b/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTCollections.cc @@ -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 diff --git a/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTCollections.h b/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTCollections.h index a02b15d107cc7..a1fd5b87c4bb0 100644 --- a/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTCollections.h +++ b/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTCollections.h @@ -8,6 +8,7 @@ #include "DataFormats/L1Trigger/interface/MuonShower.h" #include "L1TObjectCollections.h" +#include "GMTPutTokens.h" #include @@ -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(0, iFirstBx, iLastBx)), - regionalMuonCandsOMTF_(std::make_unique(0, iFirstBx, iLastBx)), - regionalMuonCandsEMTF_(std::make_unique(0, iFirstBx, iLastBx)), - muons_(), - imdMuonsBMTF_(std::make_unique(0, oFirstBx, oLastBx)), - imdMuonsEMTFNeg_(std::make_unique(0, oFirstBx, oLastBx)), - imdMuonsEMTFPos_(std::make_unique(0, oFirstBx, oLastBx)), - imdMuonsOMTFNeg_(std::make_unique(0, oFirstBx, oLastBx)), - imdMuonsOMTFPos_(std::make_unique(0, oFirstBx, oLastBx)), - - regionalMuonShowersEMTF_(std::make_unique(0, iFirstBx, iLastBx)), - muonShowers_() { - std::generate(muons_.begin(), muons_.end(), [&oFirstBx, &oLastBx] { - return std::make_unique(0, oFirstBx, oLastBx); - }); - std::generate(muonShowers_.begin(), muonShowers_.end(), [&oFirstBx, &oLastBx] { - return std::make_unique(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 ®ionalMuonCandsBMTF_; }; + inline RegionalMuonCandBxCollection* getRegionalMuonCandsOMTF() { return ®ionalMuonCandsOMTF_; }; + inline RegionalMuonCandBxCollection* getRegionalMuonCandsEMTF() { return ®ionalMuonCandsEMTF_; }; + 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 ®ionalMuonShowersEMTF_; }; + inline MuonShowerBxCollection* getMuonShowers(const unsigned int copy) override { return &muonShowers_[copy]; }; static constexpr size_t NUM_OUTPUT_COPIES{6}; private: - std::unique_ptr regionalMuonCandsBMTF_; - std::unique_ptr regionalMuonCandsOMTF_; - std::unique_ptr regionalMuonCandsEMTF_; - std::array, 6> muons_; - std::unique_ptr imdMuonsBMTF_; - std::unique_ptr imdMuonsEMTFNeg_; - std::unique_ptr imdMuonsEMTFPos_; - std::unique_ptr imdMuonsOMTFNeg_; - std::unique_ptr imdMuonsOMTFPos_; + RegionalMuonCandBxCollection regionalMuonCandsBMTF_; + RegionalMuonCandBxCollection regionalMuonCandsOMTF_; + RegionalMuonCandBxCollection regionalMuonCandsEMTF_; + std::array muons_; + MuonBxCollection imdMuonsBMTF_; + MuonBxCollection imdMuonsEMTFNeg_; + MuonBxCollection imdMuonsEMTFPos_; + MuonBxCollection imdMuonsOMTFNeg_; + MuonBxCollection imdMuonsOMTFPos_; - std::unique_ptr regionalMuonShowersEMTF_; - std::array, 6> muonShowers_; + RegionalMuonShowerBxCollection regionalMuonShowersEMTF_; + std::array muonShowers_; + GMTPutTokens tokens_; }; } // namespace stage2 } // namespace l1t diff --git a/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTPutTokens.h b/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTPutTokens.h new file mode 100644 index 0000000000000..7ae50450d8b87 --- /dev/null +++ b/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTPutTokens.h @@ -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: + + +*/ +// +// 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 + +// user include files +#include "FWCore/Utilities/interface/EDPutToken.h" + +// forward declarations + +namespace l1t { + namespace stage2 { + struct GMTPutTokens { + edm::EDPutTokenT bmtf_; + edm::EDPutTokenT omtf_; + edm::EDPutTokenT emtf_; + + edm::EDPutTokenT muon_; + std::vector> muonCopies_; + + edm::EDPutTokenT imdMuonsBMTF_; + edm::EDPutTokenT imdMuonsEMTFNeg_; + edm::EDPutTokenT imdMuonsEMTFPos_; + edm::EDPutTokenT imdMuonsOMTFNeg_; + edm::EDPutTokenT imdMuonsOMTFPos_; + + edm::EDPutTokenT showerEMTF_; + edm::EDPutTokenT muonShower_; + std::vector> muonShowerCopy_; + }; + } // namespace stage2 +} // namespace l1t +#endif diff --git a/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTSetup.cc b/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTSetup.cc index bbfd05ee74ec8..214b67053a0ce 100644 --- a/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTSetup.cc +++ b/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTSetup.cc @@ -75,28 +75,33 @@ namespace l1t { } void GMTSetup::registerProducts(edm::ProducesCollector prod) { - prod.produces("BMTF"); - prod.produces("OMTF"); - prod.produces("EMTF"); - prod.produces("Muon"); + putTokens_.bmtf_ = prod.produces("BMTF"); + putTokens_.omtf_ = prod.produces("OMTF"); + putTokens_.emtf_ = prod.produces("EMTF"); + putTokens_.muon_ = prod.produces("Muon"); + putTokens_.muonCopies_.reserve(GMTCollections::NUM_OUTPUT_COPIES); + putTokens_.muonCopies_.emplace_back(); //first one is never used for (size_t i = 1; i < GMTCollections::NUM_OUTPUT_COPIES; ++i) { - prod.produces("MuonCopy" + std::to_string(i)); + putTokens_.muonCopies_.emplace_back(prod.produces("MuonCopy" + std::to_string(i))); } - prod.produces("imdMuonsBMTF"); - prod.produces("imdMuonsEMTFNeg"); - prod.produces("imdMuonsEMTFPos"); - prod.produces("imdMuonsOMTFNeg"); - prod.produces("imdMuonsOMTFPos"); - - prod.produces("EMTF"); - prod.produces("MuonShower"); + putTokens_.imdMuonsBMTF_ = prod.produces("imdMuonsBMTF"); + putTokens_.imdMuonsEMTFNeg_ = prod.produces("imdMuonsEMTFNeg"); + putTokens_.imdMuonsEMTFPos_ = prod.produces("imdMuonsEMTFPos"); + putTokens_.imdMuonsOMTFNeg_ = prod.produces("imdMuonsOMTFNeg"); + putTokens_.imdMuonsOMTFPos_ = prod.produces("imdMuonsOMTFPos"); + + putTokens_.showerEMTF_ = prod.produces("EMTF"); + putTokens_.muonShower_ = prod.produces("MuonShower"); + putTokens_.muonShowerCopy_.reserve(GMTCollections::NUM_OUTPUT_COPIES); + putTokens_.muonShowerCopy_.emplace_back(); //first one is never used for (size_t i = 1; i < GMTCollections::NUM_OUTPUT_COPIES; ++i) { - prod.produces("MuonShowerCopy" + std::to_string(i)); + putTokens_.muonShowerCopy_.emplace_back( + prod.produces("MuonShowerCopy" + std::to_string(i))); } } std::unique_ptr GMTSetup::getCollections(edm::Event& e) { - return std::unique_ptr(new GMTCollections(e)); + return std::unique_ptr(new GMTCollections(e, putTokens_)); } UnpackerMap GMTSetup::getUnpackers(int fed, int board, int amc, unsigned int fw) { diff --git a/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTSetup.h b/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTSetup.h index 80209069ba194..251cc278405e4 100644 --- a/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTSetup.h +++ b/EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTSetup.h @@ -9,6 +9,7 @@ #include "GMTCollections.h" #include "GMTTokens.h" +#include "GMTPutTokens.h" namespace l1t { namespace stage2 { @@ -20,6 +21,8 @@ namespace l1t { void registerProducts(edm::ProducesCollector) override; std::unique_ptr getCollections(edm::Event& e) override; UnpackerMap getUnpackers(int fed, int board, int amc, unsigned int fw) override; + + GMTPutTokens putTokens_; }; } // namespace stage2 } // namespace l1t diff --git a/EventFilter/L1TRawToDigi/src/AMCSpec.cc b/EventFilter/L1TRawToDigi/src/AMCSpec.cc index 5a97da5013a59..f37878e1e259b 100644 --- a/EventFilter/L1TRawToDigi/src/AMCSpec.cc +++ b/EventFilter/L1TRawToDigi/src/AMCSpec.cc @@ -140,22 +140,14 @@ namespace amc { } } - std::vector Packet::block(unsigned int id) const { + std::span Packet::block(unsigned int id) const { if (id == 0 and id == block_header_.getBlocks() - 1) { - return payload_; + return std::span(payload_); } else if (id == block_header_.getBlocks() - 1) { - return std::vector(payload_.begin() + id * split_block_size, payload_.end()); + return std::span(payload_.begin() + id * split_block_size, payload_.end()); } else { - return std::vector(payload_.begin() + id * split_block_size, - payload_.begin() + (id + 1) * split_block_size); + return std::span(payload_.begin() + id * split_block_size, + payload_.begin() + (id + 1) * split_block_size); } } - - std::unique_ptr Packet::data() { - // Remove 3 words: 2 for the header, 1 for the trailer - std::unique_ptr res(new uint64_t[payload_.size() - 3]); - for (unsigned int i = 0; i < payload_.size() - 3; ++i) - res.get()[i] = payload_[i + 2]; - return res; - } } // namespace amc diff --git a/EventFilter/L1TRawToDigi/src/Block.cc b/EventFilter/L1TRawToDigi/src/Block.cc index fe4b04452d92e..216b06bf238b1 100644 --- a/EventFilter/L1TRawToDigi/src/Block.cc +++ b/EventFilter/L1TRawToDigi/src/Block.cc @@ -61,10 +61,10 @@ namespace l1t { return bxBlocks; } - std::unique_ptr Payload::getBlock() { + std::optional Payload::getBlock() { if (end_ - data_ < getHeaderSize()) { LogDebug("L1T") << "Reached end of payload"; - return std::unique_ptr(); + return {}; } if (data_[0] == 0xffffffff) { @@ -78,12 +78,12 @@ namespace l1t { if (end_ - data_ < header.getSize()) { edm::LogError("L1T") << "Expecting a block size of " << header.getSize() << " but only " << (end_ - data_) << " words remaining"; - return std::unique_ptr(); + return {}; } LogTrace("L1T") << "Creating block with size " << header.getSize(); - auto res = std::make_unique(header, data_, data_ + header.getSize()); + Block res(header, data_, data_ + header.getSize()); data_ += header.getSize(); return res; } @@ -170,9 +170,9 @@ namespace l1t { return false; } - std::unique_ptr MTF7Payload::getBlock() { + std::optional MTF7Payload::getBlock() { if (end_ - data_ < 2) - return std::unique_ptr(); + return {}; const uint16_t* data16 = reinterpret_cast(data_); const uint16_t* end16 = reinterpret_cast(end_); @@ -195,11 +195,11 @@ namespace l1t { if (not valid(pattern)) { edm::LogWarning("L1T") << "MTF7 block with unrecognized id 0x" << std::hex << pattern; - return std::unique_ptr(); + return {}; } data_ += (i + 1) * 2; - return std::make_unique(pattern, payload, 0, MTF7); + return Block(pattern, payload, 0, MTF7); } CTP7Payload::CTP7Payload(const uint32_t* data, const uint32_t* end, amc::Header amcHeader) @@ -233,10 +233,10 @@ namespace l1t { return BlockHeader(blockId, blockSize, capId_, blockFlags, CTP7); } - std::unique_ptr CTP7Payload::getBlock() { + std::optional CTP7Payload::getBlock() { if (end_ - data_ < getHeaderSize()) { LogDebug("L1T") << "Reached end of payload"; - return std::unique_ptr(); + return {}; } if (capId_ > bx_per_l1a_) { edm::LogWarning("L1T") << "CTP7 with more bunch crossings than expected"; @@ -247,12 +247,12 @@ namespace l1t { if (end_ - data_ < header.getSize()) { edm::LogError("L1T") << "Expecting a block size of " << header.getSize() << " but only " << (end_ - data_) << " words remaining"; - return std::unique_ptr(); + return {}; } LogTrace("L1T") << "Creating block with size " << header.getSize(); - auto res = std::make_unique(header, data_, data_ + header.getSize()); + Block res(header, data_, data_ + header.getSize()); data_ += header.getSize(); capId_++; return res; diff --git a/L1Trigger/L1TNtuples/plugins/L1UpgradeTfMuonTreeProducer.cc b/L1Trigger/L1TNtuples/plugins/L1UpgradeTfMuonTreeProducer.cc index 7cb566c8b5ac2..36c346ef5b3b5 100644 --- a/L1Trigger/L1TNtuples/plugins/L1UpgradeTfMuonTreeProducer.cc +++ b/L1Trigger/L1TNtuples/plugins/L1UpgradeTfMuonTreeProducer.cc @@ -257,7 +257,7 @@ unsigned L1UpgradeTfMuonTreeProducer::getAlgoFwVersion() { if (!packet.payload().empty()) { auto payload64 = (packet.payload().at(0)).data(); - const uint32_t* start = (const uint32_t*)payload64.get(); + const uint32_t* start = reinterpret_cast(&payload64.front()); const uint32_t* end = start + (packet.payload().at(0).size() * 2); l1t::MP7Payload payload(start, end, false);