Skip to content

Commit d7b551b

Browse files
authored
Merge pull request #47051 from Dr15Jones/productResolverFactory
Moved construction of ProductResolvers to a separate function
2 parents 1cea75c + 91b9436 commit d7b551b

35 files changed

+631
-349
lines changed

DQM/SiStripMonitorHardware/src/SiStripSpyEventMatcher.cc

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "DataFormats/Provenance/interface/ThinnedAssociationsHelper.h"
1717
#include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
1818
#include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
19+
#include "FWCore/Framework/interface/ProductResolversFactory.h"
1920
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
2021
#include "FWCore/Utilities/interface/Exception.h"
2122
#include "FWCore/Utilities/interface/GetPassID.h"
@@ -64,6 +65,7 @@ namespace sistrip {
6465
productRegistry_->setFrozen();
6566

6667
eventPrincipal_ = std::make_unique<edm::EventPrincipal>(source_->productRegistry(),
68+
edm::productResolversFactory::makePrimary,
6769
std::make_shared<edm::BranchIDListHelper>(),
6870
std::make_shared<edm::ThinnedAssociationsHelper>(),
6971
*processConfiguration_,
@@ -183,22 +185,22 @@ namespace sistrip {
183185
CountersPtr inputL1ACounters = getCounters(event, l1aCountersTag_);
184186
CountersPtr inputAPVAddresses = getCounters(event, apvAddressesTag_, false);
185187
const edm::DetSetVector<SiStripRawDigi>* inputScopeDigis =
186-
getProduct<edm::DetSetVector<SiStripRawDigi> >(event, scopeDigisTag_);
188+
getProduct<edm::DetSetVector<SiStripRawDigi>>(event, scopeDigisTag_);
187189
const edm::DetSetVector<SiStripRawDigi>* inputPayloadDigis =
188-
getProduct<edm::DetSetVector<SiStripRawDigi> >(event, payloadDigisTag_);
190+
getProduct<edm::DetSetVector<SiStripRawDigi>>(event, payloadDigisTag_);
189191
const edm::DetSetVector<SiStripRawDigi>* inputReorderedDigis =
190-
getProduct<edm::DetSetVector<SiStripRawDigi> >(event, reorderedDigisTag_);
192+
getProduct<edm::DetSetVector<SiStripRawDigi>>(event, reorderedDigisTag_);
191193
const edm::DetSetVector<SiStripRawDigi>* inputVirginRawDigis =
192-
getProduct<edm::DetSetVector<SiStripRawDigi> >(event, virginRawDigisTag_);
194+
getProduct<edm::DetSetVector<SiStripRawDigi>>(event, virginRawDigisTag_);
193195
//construct the output vectors if the digis were found and they do not exist
194196
if (inputScopeDigis && !mo.outputScopeDigisVector_.get())
195-
mo.outputScopeDigisVector_.reset(new std::vector<edm::DetSet<SiStripRawDigi> >);
197+
mo.outputScopeDigisVector_ = std::make_shared<std::vector<edm::DetSet<SiStripRawDigi>>>();
196198
if (inputPayloadDigis && !mo.outputPayloadDigisVector_.get())
197-
mo.outputPayloadDigisVector_.reset(new std::vector<edm::DetSet<SiStripRawDigi> >);
199+
mo.outputPayloadDigisVector_ = std::make_shared<std::vector<edm::DetSet<SiStripRawDigi>>>();
198200
if (inputReorderedDigis && !mo.outputReorderedDigisVector_.get())
199-
mo.outputReorderedDigisVector_.reset(new std::vector<edm::DetSet<SiStripRawDigi> >);
201+
mo.outputReorderedDigisVector_ = std::make_shared<std::vector<edm::DetSet<SiStripRawDigi>>>();
200202
if (inputVirginRawDigis && !mo.outputVirginRawDigisVector_.get())
201-
mo.outputVirginRawDigisVector_.reset(new std::vector<edm::DetSet<SiStripRawDigi> >);
203+
mo.outputVirginRawDigisVector_ = std::make_shared<std::vector<edm::DetSet<SiStripRawDigi>>>();
202204
//find matching FEDs
203205
std::set<uint16_t> matchingFeds;
204206
findMatchingFeds(eventId, apvAddress, inputTotalEventCounters, inputL1ACounters, inputAPVAddresses, matchingFeds);
@@ -309,10 +311,10 @@ namespace sistrip {
309311
std::vector<uint32_t>& outputTotalEventCounters,
310312
std::vector<uint32_t>& outputL1ACounters,
311313
std::vector<uint32_t>& outputAPVAddresses,
312-
std::vector<edm::DetSet<SiStripRawDigi> >* outputScopeDigisVector,
313-
std::vector<edm::DetSet<SiStripRawDigi> >* outputPayloadDigisVector,
314-
std::vector<edm::DetSet<SiStripRawDigi> >* outputReorderedDigisVector,
315-
std::vector<edm::DetSet<SiStripRawDigi> >* outputVirginRawDigisVector,
314+
std::vector<edm::DetSet<SiStripRawDigi>>* outputScopeDigisVector,
315+
std::vector<edm::DetSet<SiStripRawDigi>>* outputPayloadDigisVector,
316+
std::vector<edm::DetSet<SiStripRawDigi>>* outputReorderedDigisVector,
317+
std::vector<edm::DetSet<SiStripRawDigi>>* outputVirginRawDigisVector,
316318
const SiStripFedCabling& cabling) {
317319
//reserve space in vectors
318320
if (inputScopeDigis) {
@@ -391,12 +393,12 @@ namespace sistrip {
391393
SpyEventMatcher::CountersPtr SpyEventMatcher::getCounters(const edm::EventPrincipal& event,
392394
const edm::InputTag& tag,
393395
const bool mapKeyIsByFedID) {
394-
const std::vector<uint32_t>* vectorFromEvent = getProduct<std::vector<uint32_t> >(event, tag);
396+
const std::vector<uint32_t>* vectorFromEvent = getProduct<std::vector<uint32_t>>(event, tag);
395397
if (vectorFromEvent) {
396398
//vector is from event so, will be deleted when the event is destroyed (and not before)
397399
return std::make_shared<CountersWrapper>(vectorFromEvent);
398400
} else {
399-
const std::map<uint32_t, uint32_t>* mapFromEvent = getProduct<std::map<uint32_t, uint32_t> >(event, tag);
401+
const std::map<uint32_t, uint32_t>* mapFromEvent = getProduct<std::map<uint32_t, uint32_t>>(event, tag);
400402
if (mapFromEvent) {
401403
std::vector<uint32_t>* newVector = new std::vector<uint32_t>(FED_ID_MAX + 1, 0);
402404
if (mapKeyIsByFedID) {
@@ -428,10 +430,10 @@ namespace sistrip {
428430
std::vector<uint32_t>& theTotalEventCounters,
429431
std::vector<uint32_t>& theL1ACounters,
430432
std::vector<uint32_t>& theAPVAddresses,
431-
std::vector<edm::DetSet<SiStripRawDigi> >* theScopeDigisVector,
432-
std::vector<edm::DetSet<SiStripRawDigi> >* thePayloadDigisVector,
433-
std::vector<edm::DetSet<SiStripRawDigi> >* theReorderedDigisVector,
434-
std::vector<edm::DetSet<SiStripRawDigi> >* theVirginRawDigisVector)
433+
std::vector<edm::DetSet<SiStripRawDigi>>* theScopeDigisVector,
434+
std::vector<edm::DetSet<SiStripRawDigi>>* thePayloadDigisVector,
435+
std::vector<edm::DetSet<SiStripRawDigi>>* theReorderedDigisVector,
436+
std::vector<edm::DetSet<SiStripRawDigi>>* theVirginRawDigisVector)
435437
: rawData(new FEDRawDataCollection),
436438
totalEventCounters(new std::vector<uint32_t>),
437439
l1aCounters(new std::vector<uint32_t>),

FWCore/Framework/interface/EventPrincipal.h

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ is the DataBlock.
2323
#include "FWCore/Utilities/interface/Signal.h"
2424
#include "FWCore/Utilities/interface/get_underlying_safe.h"
2525
#include "FWCore/Framework/interface/Principal.h"
26+
#include "FWCore/Framework/interface/ProductResolversFactory.h"
2627

2728
#include <map>
2829
#include <memory>
@@ -51,16 +52,26 @@ namespace edm {
5152
typedef Principal Base;
5253

5354
typedef Base::ConstProductResolverPtr ConstProductResolverPtr;
54-
static int const invalidBunchXing = EventAuxiliary::invalidBunchXing;
55-
static int const invalidStoreNumber = EventAuxiliary::invalidStoreNumber;
55+
static constexpr int invalidBunchXing = EventAuxiliary::invalidBunchXing;
56+
static constexpr int invalidStoreNumber = EventAuxiliary::invalidStoreNumber;
57+
template <ProductResolversFactory FACTORY>
5658
EventPrincipal(std::shared_ptr<ProductRegistry const> reg,
59+
FACTORY&& iFactory,
5760
std::shared_ptr<BranchIDListHelper const> branchIDListHelper,
5861
std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper,
5962
ProcessConfiguration const& pc,
6063
HistoryAppender* historyAppender,
6164
unsigned int streamIndex = 0,
62-
bool isForPrimaryProcess = true,
63-
ProcessBlockHelperBase const* processBlockHelper = nullptr);
65+
ProcessBlockHelperBase const* processBlockHelper = nullptr)
66+
: EventPrincipal(reg,
67+
iFactory(InEvent, pc.processName(), *reg),
68+
branchIDListHelper,
69+
thinnedAssociationsHelper,
70+
pc,
71+
historyAppender,
72+
streamIndex,
73+
processBlockHelper) {}
74+
6475
~EventPrincipal() override {}
6576

6677
void fillEventPrincipal(EventAuxiliary const& aux,
@@ -161,6 +172,15 @@ namespace edm {
161172
unsigned int processBlockIndex(std::string const& processName) const override;
162173

163174
private:
175+
EventPrincipal(std::shared_ptr<ProductRegistry const> reg,
176+
std::vector<std::shared_ptr<ProductResolverBase>>&& resolvers,
177+
std::shared_ptr<BranchIDListHelper const> branchIDListHelper,
178+
std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper,
179+
ProcessConfiguration const& pc,
180+
HistoryAppender* historyAppender,
181+
unsigned int streamIndex,
182+
ProcessBlockHelperBase const* processBlockHelper);
183+
164184
BranchID pidToBid(ProductID const& pid) const;
165185

166186
edm::ThinnedAssociation const* getThinnedAssociation(edm::BranchID const& branchID) const;

FWCore/Framework/interface/LuminosityBlockPrincipal.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ is the DataBlock.
1616
#include "DataFormats/Provenance/interface/RunID.h"
1717
#include "FWCore/Utilities/interface/LuminosityBlockIndex.h"
1818
#include "FWCore/Framework/interface/Principal.h"
19+
#include "FWCore/Framework/interface/ProductResolversFactory.h"
1920
#include "FWCore/Utilities/interface/propagate_const.h"
2021

2122
#include <memory>
@@ -33,11 +34,13 @@ namespace edm {
3334
typedef LuminosityBlockAuxiliary Auxiliary;
3435
typedef Principal Base;
3536

37+
template <ProductResolversFactory FACTORY>
3638
LuminosityBlockPrincipal(std::shared_ptr<ProductRegistry const> reg,
39+
FACTORY&& iFactory,
3740
ProcessConfiguration const& pc,
3841
HistoryAppender* historyAppender,
39-
unsigned int index,
40-
bool isForPrimaryProcess = true);
42+
unsigned int index)
43+
: LuminosityBlockPrincipal(reg, iFactory(InLumi, pc.processName(), *reg), pc, historyAppender, index) {}
4144

4245
~LuminosityBlockPrincipal() override {}
4346

@@ -77,6 +80,11 @@ namespace edm {
7780
void setShouldWriteLumi(ShouldWriteLumi value) { shouldWriteLumi_ = value; }
7881

7982
private:
83+
LuminosityBlockPrincipal(std::shared_ptr<ProductRegistry const> reg,
84+
std::vector<std::shared_ptr<ProductResolverBase>>&& resolvers,
85+
ProcessConfiguration const& pc,
86+
HistoryAppender* historyAppender,
87+
unsigned int index);
8088
unsigned int transitionIndex_() const override;
8189

8290
edm::propagate_const<std::shared_ptr<RunPrincipal>> runPrincipal_;

FWCore/Framework/interface/Principal.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ namespace edm {
6767
typedef std::string ProcessName;
6868

6969
Principal(std::shared_ptr<ProductRegistry const> reg,
70-
std::shared_ptr<ProductResolverIndexHelper const> productLookup,
70+
std::vector<std::shared_ptr<ProductResolverBase>>&& resolvers,
7171
ProcessConfiguration const& pc,
7272
BranchType bt,
73-
HistoryAppender* historyAppender,
74-
bool isForPrimaryProcess = true);
73+
HistoryAppender* historyAppender);
7574

7675
~Principal() override;
7776

@@ -218,16 +217,9 @@ namespace edm {
218217
//called by adjustIndexesAfterProductRegistryAddition only if an index actually changed
219218
virtual void changedIndexes_() {}
220219

221-
void addScheduledProduct(std::shared_ptr<BranchDescription const> bd);
222-
void addSourceProduct(std::shared_ptr<BranchDescription const> bd);
220+
//called by adjustIndexesAfterProductRegistryAddition
223221
void addDelayedReaderInputProduct(std::shared_ptr<BranchDescription const> bd);
224222
void addPutOnReadInputProduct(std::shared_ptr<BranchDescription const> bd);
225-
void addUnscheduledProduct(std::shared_ptr<BranchDescription const> bd);
226-
void addTransformProduct(std::shared_ptr<BranchDescription const> bd);
227-
void addAliasedProduct(std::shared_ptr<BranchDescription const> bd);
228-
void addSwitchProducerProduct(std::shared_ptr<BranchDescription const> bd);
229-
void addSwitchAliasProduct(std::shared_ptr<BranchDescription const> bd);
230-
void addParentProcessProduct(std::shared_ptr<BranchDescription const> bd);
231223

232224
WrapperBase const* getIt(ProductID const&) const override;
233225
std::optional<std::tuple<WrapperBase const*, unsigned int>> getThinnedProduct(ProductID const&,

FWCore/Framework/interface/ProcessBlockPrincipal.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ namespace edm {
2121

2222
class ProcessBlockPrincipal : public Principal {
2323
public:
24-
ProcessBlockPrincipal(std::shared_ptr<ProductRegistry const>,
25-
ProcessConfiguration const&,
26-
bool isForPrimaryProcess = true);
24+
template <typename FACTORY>
25+
requires(requires(FACTORY&& f, std::string const& name, ProductRegistry const& reg) { f(InProcess, name, reg); })
26+
ProcessBlockPrincipal(std::shared_ptr<ProductRegistry const> iReg,
27+
FACTORY&& iFactory,
28+
ProcessConfiguration const& iConfig)
29+
: ProcessBlockPrincipal(iReg, iFactory(InProcess, iConfig.processName(), *iReg), iConfig) {}
2730

2831
void fillProcessBlockPrincipal(std::string const& processName, DelayedReader* reader = nullptr);
2932

@@ -35,6 +38,9 @@ namespace edm {
3538
unsigned int index() const { return 0; }
3639

3740
private:
41+
ProcessBlockPrincipal(std::shared_ptr<ProductRegistry const>,
42+
std::vector<std::shared_ptr<ProductResolverBase>>&& resolvers,
43+
ProcessConfiguration const&);
3844
unsigned int transitionIndex_() const final;
3945

4046
std::string processName_;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#ifndef FWCore_Framework_ProductResolversFactory_h
2+
#define FWCore_Framework_ProductResolversFactory_h
3+
// -*- C++ -*-
4+
//
5+
// Package: FWCore/Framework
6+
// Class : ProductResolversFactory
7+
//
8+
/**\class edm::ProductResolversFactory ProductResolversFactory.h "ProductResolversFactory.h"
9+
10+
Description: Creates ProductResolvers
11+
12+
Usage:
13+
<usage>
14+
15+
*/
16+
//
17+
// Original Author: Chris Jones
18+
// Created: Mon, 30 Dec 2024
19+
//
20+
21+
// system include files
22+
#include <memory>
23+
#include "DataFormats/Provenance/interface/ProductRegistry.h"
24+
25+
// user include files
26+
27+
// forward declarations
28+
namespace edm {
29+
30+
class ProductResolverBase;
31+
class ProductResolverIndexHelper;
32+
33+
template <typename F>
34+
concept ProductResolversFactory =
35+
requires(F&& f, std::string const& name, ProductRegistry const& reg) { f(InEvent, name, reg); };
36+
37+
namespace productResolversFactory {
38+
std::vector<std::shared_ptr<ProductResolverBase>> make(BranchType bt,
39+
std::string_view iProcessName,
40+
ProductRegistry const& iReg,
41+
bool isForPrimaryProcess);
42+
inline std::vector<std::shared_ptr<ProductResolverBase>> makePrimary(BranchType bt,
43+
std::string_view iProcessName,
44+
ProductRegistry const& iReg) {
45+
return make(bt, iProcessName, iReg, true);
46+
}
47+
inline std::vector<std::shared_ptr<ProductResolverBase>> makeSubProcess(BranchType bt,
48+
std::string_view iProcessName,
49+
ProductRegistry const& iReg) {
50+
return make(bt, iProcessName, iReg, false);
51+
}
52+
53+
}; // namespace productResolversFactory
54+
} // namespace edm
55+
56+
#endif

FWCore/Framework/interface/RunPrincipal.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ is the DataBlock.
2222
#include "FWCore/Utilities/interface/propagate_const.h"
2323
#include "FWCore/Utilities/interface/RunIndex.h"
2424
#include "FWCore/Framework/interface/Principal.h"
25+
#include "FWCore/Framework/interface/ProductResolversFactory.h"
2526

2627
namespace edm {
2728

@@ -36,12 +37,19 @@ namespace edm {
3637
typedef RunAuxiliary Auxiliary;
3738
typedef Principal Base;
3839

40+
template <ProductResolversFactory FACTORY>
3941
RunPrincipal(std::shared_ptr<ProductRegistry const> reg,
42+
FACTORY&& iFactory,
4043
ProcessConfiguration const& pc,
4144
HistoryAppender* historyAppender,
4245
unsigned int iRunIndex,
43-
bool isForPrimaryProcess = true,
44-
MergeableRunProductProcesses const* mergeableRunProductProcesses = nullptr);
46+
MergeableRunProductProcesses const* mergeableRunProductProcesses = nullptr)
47+
: RunPrincipal(reg,
48+
iFactory(InRun, pc.processName(), *reg),
49+
pc,
50+
historyAppender,
51+
iRunIndex,
52+
mergeableRunProductProcesses) {}
4553
~RunPrincipal() override;
4654

4755
void fillRunPrincipal(ProcessHistoryRegistry const& processHistoryRegistry, DelayedReader* reader = nullptr);
@@ -87,6 +95,12 @@ namespace edm {
8795
void setShouldWriteRun(ShouldWriteRun value) { shouldWriteRun_ = value; }
8896

8997
private:
98+
RunPrincipal(std::shared_ptr<ProductRegistry const> reg,
99+
std::vector<std::shared_ptr<ProductResolverBase>>&& resolvers,
100+
ProcessConfiguration const& pc,
101+
HistoryAppender* historyAppender,
102+
unsigned int iRunIndex,
103+
MergeableRunProductProcesses const* mergeableRunProductProcesses);
90104
unsigned int transitionIndex_() const override;
91105

92106
RunAuxiliary aux_;

FWCore/Framework/src/EventPrincipal.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232

3333
namespace edm {
3434
EventPrincipal::EventPrincipal(std::shared_ptr<ProductRegistry const> reg,
35+
std::vector<std::shared_ptr<ProductResolverBase>>&& resolvers,
3536
std::shared_ptr<BranchIDListHelper const> branchIDListHelper,
3637
std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper,
3738
ProcessConfiguration const& pc,
3839
HistoryAppender* historyAppender,
3940
unsigned int streamIndex,
40-
bool isForPrimaryProcess,
4141
ProcessBlockHelperBase const* processBlockHelper)
42-
: Base(reg, reg->productLookup(InEvent), pc, InEvent, historyAppender, isForPrimaryProcess),
42+
: Base(reg, std::move(resolvers), pc, InEvent, historyAppender),
4343
aux_(),
4444
luminosityBlockPrincipal_(nullptr),
4545
provRetrieverPtr_(new ProductProvenanceRetriever(streamIndex, *reg)),

0 commit comments

Comments
 (0)