Skip to content

Commit f0dc95b

Browse files
authored
Merge pull request #46928 from Dr15Jones/improveL1TRawToDigi
Improve L1TRawToDigi
2 parents 04f820c + b38a7de commit f0dc95b

File tree

15 files changed

+193
-122
lines changed

15 files changed

+193
-122
lines changed

DQM/L1TMonitor/plugins/L1TBMTFAlgoSelector.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ void dqmBmtfAlgoSelector::L1TBMTFAlgoSelector::produce(edm::Event &eve, const ed
8282
unsigned algo_ver;
8383
if (!packet.payload().empty()) {
8484
auto payload64 = (packet.payload().at(0)).data();
85-
const uint32_t *start = (const uint32_t *)payload64.get();
86-
const uint32_t *end = start + (packet.payload().at(0).size() * 2);
85+
const uint32_t *start = reinterpret_cast<const uint32_t *>(&payload64.front());
86+
const uint32_t *end = start + (payload64.size() * 2);
8787

8888
l1t::MP7Payload payload(start, end, false);
8989
algo_ver = payload.getAlgorithmFWVersion();

DQM/L1TMonitor/src/L1TMP7ZeroSupp.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,16 @@ void L1TMP7ZeroSupp::analyze(const edm::Event& e, const edm::EventSetup& c) {
231231
continue;
232232

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

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

241-
// getBlock() returns a non-null unique_ptr on success
242-
std::unique_ptr<l1t::Block> block;
243-
while ((block = payload->getBlock()) != nullptr) {
241+
// getBlock() returns a non-nullopt_t optional on success
242+
std::optional<l1t::Block> block;
243+
while ((block = payload->getBlock())) {
244244
if (verbose_) {
245245
std::cout << ">>> check zero suppression for block <<<" << std::endl
246246
<< "hdr: " << std::hex << std::setw(8) << std::setfill('0') << block->header().raw() << std::dec

EventFilter/L1TRawToDigi/interface/AMC13Spec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ namespace amc13 {
8989
bool mtf7_mode = false);
9090
bool write(const edm::Event &ev, unsigned char *ptr, unsigned int skip, unsigned int size) const;
9191

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

9494
private:
9595
Header header_;

EventFilter/L1TRawToDigi/interface/AMCSpec.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <memory>
55
#include <vector>
66
#include <cstdint>
7+
#include <span>
78

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

146-
std::vector<uint64_t> block(unsigned int id) const;
147-
std::unique_ptr<uint64_t[]> data();
147+
std::span<const uint64_t> block(unsigned int id) const;
148+
std::span<const uint64_t> data() const {
149+
// Remove 3 words: 2 for the header, 1 for the trailer
150+
return payload_.empty() ? std::span<const uint64_t>() : std::span<const uint64_t>(payload_).subspan(2, size());
151+
};
148152
BlockHeader blockHeader(unsigned int block = 0) const { return block_header_; };
149153
Header header() const { return header_; };
150154
Trailer trailer() const { return trailer_; };

EventFilter/L1TRawToDigi/interface/Block.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <memory>
55
#include <vector>
6+
#include <optional>
67

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

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

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

179180
private:
180181
// FIXME check values

EventFilter/L1TRawToDigi/plugins/L1TRawToDigi.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <iostream>
2121
#include <iomanip>
2222
#include <memory>
23+
#include <optional>
2324

2425
// user include files
2526
#include "FWCore/Framework/interface/Frameworkfwd.h"
@@ -128,8 +129,7 @@ namespace l1t {
128129

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

131-
edm::Handle<FEDRawDataCollection> feds;
132-
event.getByToken(fedData_, feds);
132+
edm::Handle<FEDRawDataCollection> feds = event.getHandle(fedData_);
133133

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

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

209209
std::unique_ptr<Payload> payload;
210210
if (ctp7_mode_) {
@@ -232,9 +232,9 @@ namespace l1t {
232232

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

235-
// getBlock() returns a non-null unique_ptr on success
236-
std::unique_ptr<Block> block;
237-
while ((block = payload->getBlock()).get()) {
235+
// getBlock() returns a non-null optional on success
236+
std::optional<Block> block;
237+
while ((block = payload->getBlock())) {
238238
// only unpack the Calo Layer 2 MP TMT node if it has processed this BX
239239
unsigned tmtId = board - l1t::stage2::layer2::mp::offsetBoardId + 1;
240240
unsigned bxId = header.bxID();

EventFilter/L1TRawToDigi/plugins/OmtfUnpacker.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ namespace omtf {
309309
// AMC trailer
310310
//
311311
//amc::Trailer trailerAmc = amc.trailer(); //this is the expected way but does not work
312-
amc::Trailer trailerAmc(amc.data().get() + amc.size() -
313-
1); //FIXME: the above is prefered but this works (CMSSW900)
312+
amc::Trailer trailerAmc(&amc.data().back()); //FIXME: the above is prefered but this works (CMSSW900)
314313
if (debug) {
315314
std::ostringstream str;
316315
str << " AMC trailer: " << std::bitset<64>(trailerAmc.raw()) << std::endl;
@@ -323,7 +322,7 @@ namespace omtf {
323322
// AMC payload
324323
//
325324
const auto& payload64 = amc.data();
326-
const Word64* word = payload64.get();
325+
const Word64* word = &payload64.front();
327326
for (unsigned int iWord = 1; iWord <= amc.size(); iWord++, word++) {
328327
if (iWord <= 2)
329328
continue; // two header words for each AMC

EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTCollections.cc

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,25 @@
77
namespace l1t {
88
namespace stage2 {
99
GMTCollections::~GMTCollections() {
10-
event_.put(std::move(regionalMuonCandsBMTF_), "BMTF");
11-
event_.put(std::move(regionalMuonCandsOMTF_), "OMTF");
12-
event_.put(std::move(regionalMuonCandsEMTF_), "EMTF");
13-
event_.put(std::move(muons_[0]), "Muon");
10+
event_.emplace(tokens_.bmtf_, std::move(regionalMuonCandsBMTF_));
11+
event_.emplace(tokens_.omtf_, std::move(regionalMuonCandsOMTF_));
12+
event_.emplace(tokens_.emtf_, std::move(regionalMuonCandsEMTF_));
13+
event_.emplace(tokens_.muon_, std::move(muons_[0]));
14+
assert(NUM_OUTPUT_COPIES == tokens_.muonCopies_.size());
1415
for (size_t i = 1; i < NUM_OUTPUT_COPIES; ++i) {
15-
event_.put(std::move(muons_[i]), "MuonCopy" + std::to_string(i));
16+
event_.emplace(tokens_.muonCopies_[i], std::move(muons_[i]));
1617
}
17-
event_.put(std::move(imdMuonsBMTF_), "imdMuonsBMTF");
18-
event_.put(std::move(imdMuonsEMTFNeg_), "imdMuonsEMTFNeg");
19-
event_.put(std::move(imdMuonsEMTFPos_), "imdMuonsEMTFPos");
20-
event_.put(std::move(imdMuonsOMTFNeg_), "imdMuonsOMTFNeg");
21-
event_.put(std::move(imdMuonsOMTFPos_), "imdMuonsOMTFPos");
18+
event_.emplace(tokens_.imdMuonsBMTF_, std::move(imdMuonsBMTF_));
19+
event_.emplace(tokens_.imdMuonsEMTFNeg_, std::move(imdMuonsEMTFNeg_));
20+
event_.emplace(tokens_.imdMuonsEMTFPos_, std::move(imdMuonsEMTFPos_));
21+
event_.emplace(tokens_.imdMuonsOMTFNeg_, std::move(imdMuonsOMTFNeg_));
22+
event_.emplace(tokens_.imdMuonsOMTFPos_, std::move(imdMuonsOMTFPos_));
2223

23-
event_.put(std::move(regionalMuonShowersEMTF_), "EMTF");
24-
event_.put(std::move(muonShowers_[0]), "MuonShower");
24+
event_.emplace(tokens_.showerEMTF_, std::move(regionalMuonShowersEMTF_));
25+
event_.emplace(tokens_.muonShower_, std::move(muonShowers_[0]));
26+
assert(tokens_.muonShowerCopy_.size() == NUM_OUTPUT_COPIES);
2527
for (size_t i = 1; i < NUM_OUTPUT_COPIES; ++i) {
26-
event_.put(std::move(muonShowers_[i]), "MuonShowerCopy" + std::to_string(i));
28+
event_.emplace(tokens_.muonShowerCopy_[i], std::move(muonShowers_[i]));
2729
}
2830
}
2931
} // namespace stage2

EventFilter/L1TRawToDigi/plugins/implementations_stage2/GMTCollections.h

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "DataFormats/L1Trigger/interface/MuonShower.h"
99

1010
#include "L1TObjectCollections.h"
11+
#include "GMTPutTokens.h"
1112

1213
#include <array>
1314

@@ -19,61 +20,67 @@ namespace l1t {
1920
// fill a collection the BX range cannot be determined.
2021
// Set default values here to then create an empty collection
2122
// with a defined BX range.
22-
GMTCollections(
23-
edm::Event& e, const int iFirstBx = -2, const int iLastBx = 2, const int oFirstBx = -2, const int oLastBx = 2)
23+
GMTCollections(edm::Event& e,
24+
GMTPutTokens const& iTokens,
25+
const int iFirstBx = -2,
26+
const int iLastBx = 2,
27+
const int oFirstBx = -2,
28+
const int oLastBx = 2)
2429
: L1TObjectCollections(e),
25-
regionalMuonCandsBMTF_(std::make_unique<RegionalMuonCandBxCollection>(0, iFirstBx, iLastBx)),
26-
regionalMuonCandsOMTF_(std::make_unique<RegionalMuonCandBxCollection>(0, iFirstBx, iLastBx)),
27-
regionalMuonCandsEMTF_(std::make_unique<RegionalMuonCandBxCollection>(0, iFirstBx, iLastBx)),
28-
muons_(),
29-
imdMuonsBMTF_(std::make_unique<MuonBxCollection>(0, oFirstBx, oLastBx)),
30-
imdMuonsEMTFNeg_(std::make_unique<MuonBxCollection>(0, oFirstBx, oLastBx)),
31-
imdMuonsEMTFPos_(std::make_unique<MuonBxCollection>(0, oFirstBx, oLastBx)),
32-
imdMuonsOMTFNeg_(std::make_unique<MuonBxCollection>(0, oFirstBx, oLastBx)),
33-
imdMuonsOMTFPos_(std::make_unique<MuonBxCollection>(0, oFirstBx, oLastBx)),
34-
35-
regionalMuonShowersEMTF_(std::make_unique<RegionalMuonShowerBxCollection>(0, iFirstBx, iLastBx)),
36-
muonShowers_() {
37-
std::generate(muons_.begin(), muons_.end(), [&oFirstBx, &oLastBx] {
38-
return std::make_unique<MuonBxCollection>(0, oFirstBx, oLastBx);
39-
});
40-
std::generate(muonShowers_.begin(), muonShowers_.end(), [&oFirstBx, &oLastBx] {
41-
return std::make_unique<MuonShowerBxCollection>(0, oFirstBx, oLastBx);
42-
});
43-
};
30+
regionalMuonCandsBMTF_(0, iFirstBx, iLastBx),
31+
regionalMuonCandsOMTF_(0, iFirstBx, iLastBx),
32+
regionalMuonCandsEMTF_(0, iFirstBx, iLastBx),
33+
muons_{{{0, oFirstBx, oLastBx},
34+
{0, oFirstBx, oLastBx},
35+
{0, oFirstBx, oLastBx},
36+
{0, oFirstBx, oLastBx},
37+
{0, oFirstBx, oLastBx},
38+
{0, oFirstBx, oLastBx}}},
39+
imdMuonsBMTF_(0, oFirstBx, oLastBx),
40+
imdMuonsEMTFNeg_(0, oFirstBx, oLastBx),
41+
imdMuonsEMTFPos_(0, oFirstBx, oLastBx),
42+
imdMuonsOMTFNeg_(0, oFirstBx, oLastBx),
43+
imdMuonsOMTFPos_(0, oFirstBx, oLastBx),
44+
regionalMuonShowersEMTF_(0, iFirstBx, iLastBx),
45+
muonShowers_{{{0, oFirstBx, oLastBx},
46+
{0, oFirstBx, oLastBx},
47+
{0, oFirstBx, oLastBx},
48+
{0, oFirstBx, oLastBx},
49+
{0, oFirstBx, oLastBx},
50+
{0, oFirstBx, oLastBx}}},
51+
tokens_(iTokens) {};
4452

4553
~GMTCollections() override;
4654

47-
inline RegionalMuonCandBxCollection* getRegionalMuonCandsBMTF() { return regionalMuonCandsBMTF_.get(); };
48-
inline RegionalMuonCandBxCollection* getRegionalMuonCandsOMTF() { return regionalMuonCandsOMTF_.get(); };
49-
inline RegionalMuonCandBxCollection* getRegionalMuonCandsEMTF() { return regionalMuonCandsEMTF_.get(); };
50-
inline MuonBxCollection* getMuons(const unsigned int copy) override { return muons_[copy].get(); };
51-
inline MuonBxCollection* getImdMuonsBMTF() { return imdMuonsBMTF_.get(); };
52-
inline MuonBxCollection* getImdMuonsEMTFNeg() { return imdMuonsEMTFNeg_.get(); };
53-
inline MuonBxCollection* getImdMuonsEMTFPos() { return imdMuonsEMTFPos_.get(); };
54-
inline MuonBxCollection* getImdMuonsOMTFNeg() { return imdMuonsOMTFNeg_.get(); };
55-
inline MuonBxCollection* getImdMuonsOMTFPos() { return imdMuonsOMTFPos_.get(); };
55+
inline RegionalMuonCandBxCollection* getRegionalMuonCandsBMTF() { return &regionalMuonCandsBMTF_; };
56+
inline RegionalMuonCandBxCollection* getRegionalMuonCandsOMTF() { return &regionalMuonCandsOMTF_; };
57+
inline RegionalMuonCandBxCollection* getRegionalMuonCandsEMTF() { return &regionalMuonCandsEMTF_; };
58+
inline MuonBxCollection* getMuons(const unsigned int copy) override { return &muons_[copy]; };
59+
inline MuonBxCollection* getImdMuonsBMTF() { return &imdMuonsBMTF_; };
60+
inline MuonBxCollection* getImdMuonsEMTFNeg() { return &imdMuonsEMTFNeg_; };
61+
inline MuonBxCollection* getImdMuonsEMTFPos() { return &imdMuonsEMTFPos_; };
62+
inline MuonBxCollection* getImdMuonsOMTFNeg() { return &imdMuonsOMTFNeg_; };
63+
inline MuonBxCollection* getImdMuonsOMTFPos() { return &imdMuonsOMTFPos_; };
5664

57-
inline RegionalMuonShowerBxCollection* getRegionalMuonShowersEMTF() { return regionalMuonShowersEMTF_.get(); };
58-
inline MuonShowerBxCollection* getMuonShowers(const unsigned int copy) override {
59-
return muonShowers_[copy].get();
60-
};
65+
inline RegionalMuonShowerBxCollection* getRegionalMuonShowersEMTF() { return &regionalMuonShowersEMTF_; };
66+
inline MuonShowerBxCollection* getMuonShowers(const unsigned int copy) override { return &muonShowers_[copy]; };
6167

6268
static constexpr size_t NUM_OUTPUT_COPIES{6};
6369

6470
private:
65-
std::unique_ptr<RegionalMuonCandBxCollection> regionalMuonCandsBMTF_;
66-
std::unique_ptr<RegionalMuonCandBxCollection> regionalMuonCandsOMTF_;
67-
std::unique_ptr<RegionalMuonCandBxCollection> regionalMuonCandsEMTF_;
68-
std::array<std::unique_ptr<MuonBxCollection>, 6> muons_;
69-
std::unique_ptr<MuonBxCollection> imdMuonsBMTF_;
70-
std::unique_ptr<MuonBxCollection> imdMuonsEMTFNeg_;
71-
std::unique_ptr<MuonBxCollection> imdMuonsEMTFPos_;
72-
std::unique_ptr<MuonBxCollection> imdMuonsOMTFNeg_;
73-
std::unique_ptr<MuonBxCollection> imdMuonsOMTFPos_;
71+
RegionalMuonCandBxCollection regionalMuonCandsBMTF_;
72+
RegionalMuonCandBxCollection regionalMuonCandsOMTF_;
73+
RegionalMuonCandBxCollection regionalMuonCandsEMTF_;
74+
std::array<MuonBxCollection, 6> muons_;
75+
MuonBxCollection imdMuonsBMTF_;
76+
MuonBxCollection imdMuonsEMTFNeg_;
77+
MuonBxCollection imdMuonsEMTFPos_;
78+
MuonBxCollection imdMuonsOMTFNeg_;
79+
MuonBxCollection imdMuonsOMTFPos_;
7480

75-
std::unique_ptr<RegionalMuonShowerBxCollection> regionalMuonShowersEMTF_;
76-
std::array<std::unique_ptr<MuonShowerBxCollection>, 6> muonShowers_;
81+
RegionalMuonShowerBxCollection regionalMuonShowersEMTF_;
82+
std::array<MuonShowerBxCollection, 6> muonShowers_;
83+
GMTPutTokens tokens_;
7784
};
7885
} // namespace stage2
7986
} // namespace l1t
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef Subsystem_Package_GMTPutTokens_h
2+
#define Subsystem_Package_GMTPutTokens_h
3+
// -*- C++ -*-
4+
//
5+
// Package: Subsystem/Package
6+
// Class : GMTPutTokens
7+
//
8+
/**\class GMTPutTokens GMTPutTokens.h "GMTPutTokens.h"
9+
10+
Description: Holder for the EDPutTokens
11+
12+
Usage:
13+
<usage>
14+
15+
*/
16+
//
17+
// Original Author: Christopher Jones
18+
// Created: Wed, 11 Dec 2024 13:41:10 GMT
19+
//
20+
#include "DataFormats/L1TMuon/interface/RegionalMuonCand.h"
21+
#include "DataFormats/L1Trigger/interface/Muon.h"
22+
23+
#include "DataFormats/L1TMuon/interface/RegionalMuonShower.h"
24+
#include "DataFormats/L1Trigger/interface/MuonShower.h"
25+
26+
#include "L1TObjectCollections.h"
27+
28+
// system include files
29+
#include <vector>
30+
31+
// user include files
32+
#include "FWCore/Utilities/interface/EDPutToken.h"
33+
34+
// forward declarations
35+
36+
namespace l1t {
37+
namespace stage2 {
38+
struct GMTPutTokens {
39+
edm::EDPutTokenT<RegionalMuonCandBxCollection> bmtf_;
40+
edm::EDPutTokenT<RegionalMuonCandBxCollection> omtf_;
41+
edm::EDPutTokenT<RegionalMuonCandBxCollection> emtf_;
42+
43+
edm::EDPutTokenT<MuonBxCollection> muon_;
44+
std::vector<edm::EDPutTokenT<MuonBxCollection>> muonCopies_;
45+
46+
edm::EDPutTokenT<MuonBxCollection> imdMuonsBMTF_;
47+
edm::EDPutTokenT<MuonBxCollection> imdMuonsEMTFNeg_;
48+
edm::EDPutTokenT<MuonBxCollection> imdMuonsEMTFPos_;
49+
edm::EDPutTokenT<MuonBxCollection> imdMuonsOMTFNeg_;
50+
edm::EDPutTokenT<MuonBxCollection> imdMuonsOMTFPos_;
51+
52+
edm::EDPutTokenT<RegionalMuonShowerBxCollection> showerEMTF_;
53+
edm::EDPutTokenT<MuonShowerBxCollection> muonShower_;
54+
std::vector<edm::EDPutTokenT<MuonShowerBxCollection>> muonShowerCopy_;
55+
};
56+
} // namespace stage2
57+
} // namespace l1t
58+
#endif

0 commit comments

Comments
 (0)