Skip to content

Commit 31c0d22

Browse files
committed
Moved construction of ProductResolvers to a separate function
1 parent 803864d commit 31c0d22

34 files changed

+612
-334
lines changed

FWCore/Framework/interface/EventPrincipal.h

+24-4
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,27 @@ namespace edm {
5151
typedef Principal Base;
5252

5353
typedef Base::ConstProductResolverPtr ConstProductResolverPtr;
54-
static int const invalidBunchXing = EventAuxiliary::invalidBunchXing;
55-
static int const invalidStoreNumber = EventAuxiliary::invalidStoreNumber;
54+
static constexpr int invalidBunchXing = EventAuxiliary::invalidBunchXing;
55+
static constexpr int invalidStoreNumber = EventAuxiliary::invalidStoreNumber;
56+
template <typename FACTORY>
57+
requires(requires(FACTORY&& f, std::string const& name, ProductRegistry const& reg) { f(InEvent, name, reg); })
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>> const& 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

+10-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ namespace edm {
3333
typedef LuminosityBlockAuxiliary Auxiliary;
3434
typedef Principal Base;
3535

36+
template <typename FACTORY>
37+
requires(requires(FACTORY&& f, std::string const& name, ProductRegistry const& reg) { f(InLumi, name, reg); })
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>> const& 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

+3-11
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>> const& 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

+9-3
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>> const& resolvers,
43+
ProcessConfiguration const&);
3844
unsigned int transitionIndex_() const final;
3945

4046
std::string processName_;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
namespace productResolversFactory {
34+
std::vector<std::shared_ptr<ProductResolverBase>> make(BranchType bt,
35+
std::string_view iProcessName,
36+
ProductRegistry const& iReg,
37+
bool isForPrimaryProcess);
38+
inline std::vector<std::shared_ptr<ProductResolverBase>> makePrimary(BranchType bt,
39+
std::string_view iProcessName,
40+
ProductRegistry const& iReg) {
41+
return make(bt, iProcessName, iReg, true);
42+
}
43+
inline std::vector<std::shared_ptr<ProductResolverBase>> makeSubProcess(BranchType bt,
44+
std::string_view iProcessName,
45+
ProductRegistry const& iReg) {
46+
return make(bt, iProcessName, iReg, false);
47+
}
48+
49+
}; // namespace productResolversFactory
50+
} // namespace edm
51+
52+
#endif

FWCore/Framework/interface/RunPrincipal.h

+16-2
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,20 @@ namespace edm {
3636
typedef RunAuxiliary Auxiliary;
3737
typedef Principal Base;
3838

39+
template <typename FACTORY>
40+
requires(requires(FACTORY&& f, std::string const& name, ProductRegistry const& reg) { f(InRun, name, reg); })
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>> const& 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

+2-2
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>> const& 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, resolvers, pc, InEvent, historyAppender),
4343
aux_(),
4444
luminosityBlockPrincipal_(nullptr),
4545
provRetrieverPtr_(new ProductProvenanceRetriever(streamIndex, *reg)),

FWCore/Framework/src/EventProcessor.cc

+14-7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "FWCore/Framework/interface/globalTransitionAsync.h"
4343
#include "FWCore/Framework/interface/TriggerNamesService.h"
4444
#include "FWCore/Framework/src/SendSourceTerminationSignalIfException.h"
45+
#include "FWCore/Framework/interface/ProductResolversFactory.h"
4546

4647
#include "FWCore/MessageLogger/interface/MessageLogger.h"
4748

@@ -543,33 +544,39 @@ namespace edm {
543544
for (unsigned int index = 0; index < preallocations_.numberOfStreams(); ++index) {
544545
// Reusable event principal
545546
auto ep = std::make_shared<EventPrincipal>(preg(),
547+
productResolversFactory::makePrimary,
546548
branchIDListHelper(),
547549
thinnedAssociationsHelper(),
548550
*processConfiguration_,
549551
historyAppender_.get(),
550552
index,
551-
true /*primary process*/,
552553
&*processBlockHelper_);
553554
principalCache_.insert(std::move(ep));
554555
}
555556

556557
for (unsigned int index = 0; index < preallocations_.numberOfRuns(); ++index) {
557-
auto rp = std::make_unique<RunPrincipal>(
558-
preg(), *processConfiguration_, historyAppender_.get(), index, true, &mergeableRunProductProcesses_);
558+
auto rp = std::make_unique<RunPrincipal>(preg(),
559+
productResolversFactory::makePrimary,
560+
*processConfiguration_,
561+
historyAppender_.get(),
562+
index,
563+
&mergeableRunProductProcesses_);
559564
principalCache_.insert(std::move(rp));
560565
}
561566

562567
for (unsigned int index = 0; index < preallocations_.numberOfLuminosityBlocks(); ++index) {
563-
auto lp =
564-
std::make_unique<LuminosityBlockPrincipal>(preg(), *processConfiguration_, historyAppender_.get(), index);
568+
auto lp = std::make_unique<LuminosityBlockPrincipal>(
569+
preg(), productResolversFactory::makePrimary, *processConfiguration_, historyAppender_.get(), index);
565570
principalCache_.insert(std::move(lp));
566571
}
567572

568573
{
569-
auto pb = std::make_unique<ProcessBlockPrincipal>(preg(), *processConfiguration_);
574+
auto pb = std::make_unique<ProcessBlockPrincipal>(
575+
preg(), productResolversFactory::makePrimary, *processConfiguration_);
570576
principalCache_.insert(std::move(pb));
571577

572-
auto pbForInput = std::make_unique<ProcessBlockPrincipal>(preg(), *processConfiguration_);
578+
auto pbForInput = std::make_unique<ProcessBlockPrincipal>(
579+
preg(), productResolversFactory::makePrimary, *processConfiguration_);
573580
principalCache_.insertForInput(std::move(pbForInput));
574581
}
575582

FWCore/Framework/src/LuminosityBlockPrincipal.cc

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
#include "DataFormats/Provenance/interface/ProductRegistry.h"
44

55
namespace edm {
6-
76
LuminosityBlockPrincipal::LuminosityBlockPrincipal(std::shared_ptr<ProductRegistry const> reg,
7+
std::vector<std::shared_ptr<ProductResolverBase>> const& resolvers,
88
ProcessConfiguration const& pc,
99
HistoryAppender* historyAppender,
10-
unsigned int index,
11-
bool isForPrimaryProcess)
12-
: Base(reg, reg->productLookup(InLumi), pc, InLumi, historyAppender, isForPrimaryProcess),
13-
runPrincipal_(),
14-
index_(index) {}
10+
unsigned int index)
11+
: Base(reg, resolvers, pc, InLumi, historyAppender), runPrincipal_(), index_(index) {}
1512

1613
void LuminosityBlockPrincipal::fillLuminosityBlockPrincipal(ProcessHistory const* processHistory,
1714
DelayedReader* reader) {

0 commit comments

Comments
 (0)