Skip to content

Commit

Permalink
Moved construction of ProductResolvers to a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr15Jones committed Jan 7, 2025
1 parent 803864d commit 31c0d22
Show file tree
Hide file tree
Showing 34 changed files with 612 additions and 334 deletions.
28 changes: 24 additions & 4 deletions FWCore/Framework/interface/EventPrincipal.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,27 @@ namespace edm {
typedef Principal Base;

typedef Base::ConstProductResolverPtr ConstProductResolverPtr;
static int const invalidBunchXing = EventAuxiliary::invalidBunchXing;
static int const invalidStoreNumber = EventAuxiliary::invalidStoreNumber;
static constexpr int invalidBunchXing = EventAuxiliary::invalidBunchXing;
static constexpr int invalidStoreNumber = EventAuxiliary::invalidStoreNumber;
template <typename FACTORY>
requires(requires(FACTORY&& f, std::string const& name, ProductRegistry const& reg) { f(InEvent, name, reg); })
EventPrincipal(std::shared_ptr<ProductRegistry const> reg,
FACTORY&& iFactory,
std::shared_ptr<BranchIDListHelper const> branchIDListHelper,
std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper,
ProcessConfiguration const& pc,
HistoryAppender* historyAppender,
unsigned int streamIndex = 0,
bool isForPrimaryProcess = true,
ProcessBlockHelperBase const* processBlockHelper = nullptr);
ProcessBlockHelperBase const* processBlockHelper = nullptr)
: EventPrincipal(reg,
iFactory(InEvent, pc.processName(), *reg),
branchIDListHelper,
thinnedAssociationsHelper,
pc,
historyAppender,
streamIndex,
processBlockHelper) {}

~EventPrincipal() override {}

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

private:
EventPrincipal(std::shared_ptr<ProductRegistry const> reg,
std::vector<std::shared_ptr<ProductResolverBase>> const& resolvers,
std::shared_ptr<BranchIDListHelper const> branchIDListHelper,
std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper,
ProcessConfiguration const& pc,
HistoryAppender* historyAppender,
unsigned int streamIndex,
ProcessBlockHelperBase const* processBlockHelper);

BranchID pidToBid(ProductID const& pid) const;

edm::ThinnedAssociation const* getThinnedAssociation(edm::BranchID const& branchID) const;
Expand Down
12 changes: 10 additions & 2 deletions FWCore/Framework/interface/LuminosityBlockPrincipal.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ namespace edm {
typedef LuminosityBlockAuxiliary Auxiliary;
typedef Principal Base;

template <typename FACTORY>
requires(requires(FACTORY&& f, std::string const& name, ProductRegistry const& reg) { f(InLumi, name, reg); })
LuminosityBlockPrincipal(std::shared_ptr<ProductRegistry const> reg,
FACTORY&& iFactory,
ProcessConfiguration const& pc,
HistoryAppender* historyAppender,
unsigned int index,
bool isForPrimaryProcess = true);
unsigned int index)
: LuminosityBlockPrincipal(reg, iFactory(InLumi, pc.processName(), *reg), pc, historyAppender, index) {}

~LuminosityBlockPrincipal() override {}

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

private:
LuminosityBlockPrincipal(std::shared_ptr<ProductRegistry const> reg,
std::vector<std::shared_ptr<ProductResolverBase>> const& resolvers,
ProcessConfiguration const& pc,
HistoryAppender* historyAppender,
unsigned int index);
unsigned int transitionIndex_() const override;

edm::propagate_const<std::shared_ptr<RunPrincipal>> runPrincipal_;
Expand Down
14 changes: 3 additions & 11 deletions FWCore/Framework/interface/Principal.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ namespace edm {
typedef std::string ProcessName;

Principal(std::shared_ptr<ProductRegistry const> reg,
std::shared_ptr<ProductResolverIndexHelper const> productLookup,
std::vector<std::shared_ptr<ProductResolverBase>> const& resolvers,
ProcessConfiguration const& pc,
BranchType bt,
HistoryAppender* historyAppender,
bool isForPrimaryProcess = true);
HistoryAppender* historyAppender);

~Principal() override;

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

void addScheduledProduct(std::shared_ptr<BranchDescription const> bd);
void addSourceProduct(std::shared_ptr<BranchDescription const> bd);
//called by adjustIndexesAfterProductRegistryAddition
void addDelayedReaderInputProduct(std::shared_ptr<BranchDescription const> bd);
void addPutOnReadInputProduct(std::shared_ptr<BranchDescription const> bd);
void addUnscheduledProduct(std::shared_ptr<BranchDescription const> bd);
void addTransformProduct(std::shared_ptr<BranchDescription const> bd);
void addAliasedProduct(std::shared_ptr<BranchDescription const> bd);
void addSwitchProducerProduct(std::shared_ptr<BranchDescription const> bd);
void addSwitchAliasProduct(std::shared_ptr<BranchDescription const> bd);
void addParentProcessProduct(std::shared_ptr<BranchDescription const> bd);

WrapperBase const* getIt(ProductID const&) const override;
std::optional<std::tuple<WrapperBase const*, unsigned int>> getThinnedProduct(ProductID const&,
Expand Down
12 changes: 9 additions & 3 deletions FWCore/Framework/interface/ProcessBlockPrincipal.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ namespace edm {

class ProcessBlockPrincipal : public Principal {
public:
ProcessBlockPrincipal(std::shared_ptr<ProductRegistry const>,
ProcessConfiguration const&,
bool isForPrimaryProcess = true);
template <typename FACTORY>
requires(requires(FACTORY&& f, std::string const& name, ProductRegistry const& reg) { f(InProcess, name, reg); })
ProcessBlockPrincipal(std::shared_ptr<ProductRegistry const> iReg,
FACTORY&& iFactory,
ProcessConfiguration const& iConfig)
: ProcessBlockPrincipal(iReg, iFactory(InProcess, iConfig.processName(), *iReg), iConfig) {}

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

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

private:
ProcessBlockPrincipal(std::shared_ptr<ProductRegistry const>,
std::vector<std::shared_ptr<ProductResolverBase>> const& resolvers,
ProcessConfiguration const&);
unsigned int transitionIndex_() const final;

std::string processName_;
Expand Down
52 changes: 52 additions & 0 deletions FWCore/Framework/interface/ProductResolversFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef FWCore_Framework_ProductResolversFactory_h
#define FWCore_Framework_ProductResolversFactory_h
// -*- C++ -*-
//
// Package: FWCore/Framework
// Class : ProductResolversFactory
//
/**\class edm::ProductResolversFactory ProductResolversFactory.h "ProductResolversFactory.h"
Description: Creates ProductResolvers
Usage:
<usage>
*/
//
// Original Author: Chris Jones
// Created: Mon, 30 Dec 2024
//

// system include files
#include <memory>
#include "DataFormats/Provenance/interface/ProductRegistry.h"

// user include files

// forward declarations
namespace edm {

class ProductResolverBase;
class ProductResolverIndexHelper;

namespace productResolversFactory {
std::vector<std::shared_ptr<ProductResolverBase>> make(BranchType bt,
std::string_view iProcessName,
ProductRegistry const& iReg,
bool isForPrimaryProcess);
inline std::vector<std::shared_ptr<ProductResolverBase>> makePrimary(BranchType bt,
std::string_view iProcessName,
ProductRegistry const& iReg) {
return make(bt, iProcessName, iReg, true);
}
inline std::vector<std::shared_ptr<ProductResolverBase>> makeSubProcess(BranchType bt,
std::string_view iProcessName,
ProductRegistry const& iReg) {
return make(bt, iProcessName, iReg, false);
}

}; // namespace productResolversFactory
} // namespace edm

#endif
18 changes: 16 additions & 2 deletions FWCore/Framework/interface/RunPrincipal.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,20 @@ namespace edm {
typedef RunAuxiliary Auxiliary;
typedef Principal Base;

template <typename FACTORY>
requires(requires(FACTORY&& f, std::string const& name, ProductRegistry const& reg) { f(InRun, name, reg); })
RunPrincipal(std::shared_ptr<ProductRegistry const> reg,
FACTORY&& iFactory,
ProcessConfiguration const& pc,
HistoryAppender* historyAppender,
unsigned int iRunIndex,
bool isForPrimaryProcess = true,
MergeableRunProductProcesses const* mergeableRunProductProcesses = nullptr);
MergeableRunProductProcesses const* mergeableRunProductProcesses = nullptr)
: RunPrincipal(reg,
iFactory(InRun, pc.processName(), *reg),
pc,
historyAppender,
iRunIndex,
mergeableRunProductProcesses) {}
~RunPrincipal() override;

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

private:
RunPrincipal(std::shared_ptr<ProductRegistry const> reg,
std::vector<std::shared_ptr<ProductResolverBase>> const& resolvers,
ProcessConfiguration const& pc,
HistoryAppender* historyAppender,
unsigned int iRunIndex,
MergeableRunProductProcesses const* mergeableRunProductProcesses);
unsigned int transitionIndex_() const override;

RunAuxiliary aux_;
Expand Down
4 changes: 2 additions & 2 deletions FWCore/Framework/src/EventPrincipal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@

namespace edm {
EventPrincipal::EventPrincipal(std::shared_ptr<ProductRegistry const> reg,
std::vector<std::shared_ptr<ProductResolverBase>> const& resolvers,
std::shared_ptr<BranchIDListHelper const> branchIDListHelper,
std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper,
ProcessConfiguration const& pc,
HistoryAppender* historyAppender,
unsigned int streamIndex,
bool isForPrimaryProcess,
ProcessBlockHelperBase const* processBlockHelper)
: Base(reg, reg->productLookup(InEvent), pc, InEvent, historyAppender, isForPrimaryProcess),
: Base(reg, resolvers, pc, InEvent, historyAppender),
aux_(),
luminosityBlockPrincipal_(nullptr),
provRetrieverPtr_(new ProductProvenanceRetriever(streamIndex, *reg)),
Expand Down
21 changes: 14 additions & 7 deletions FWCore/Framework/src/EventProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "FWCore/Framework/interface/globalTransitionAsync.h"
#include "FWCore/Framework/interface/TriggerNamesService.h"
#include "FWCore/Framework/src/SendSourceTerminationSignalIfException.h"
#include "FWCore/Framework/interface/ProductResolversFactory.h"

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

Expand Down Expand Up @@ -543,33 +544,39 @@ namespace edm {
for (unsigned int index = 0; index < preallocations_.numberOfStreams(); ++index) {
// Reusable event principal
auto ep = std::make_shared<EventPrincipal>(preg(),
productResolversFactory::makePrimary,
branchIDListHelper(),
thinnedAssociationsHelper(),
*processConfiguration_,
historyAppender_.get(),
index,
true /*primary process*/,
&*processBlockHelper_);
principalCache_.insert(std::move(ep));
}

for (unsigned int index = 0; index < preallocations_.numberOfRuns(); ++index) {
auto rp = std::make_unique<RunPrincipal>(
preg(), *processConfiguration_, historyAppender_.get(), index, true, &mergeableRunProductProcesses_);
auto rp = std::make_unique<RunPrincipal>(preg(),
productResolversFactory::makePrimary,
*processConfiguration_,
historyAppender_.get(),
index,
&mergeableRunProductProcesses_);
principalCache_.insert(std::move(rp));
}

for (unsigned int index = 0; index < preallocations_.numberOfLuminosityBlocks(); ++index) {
auto lp =
std::make_unique<LuminosityBlockPrincipal>(preg(), *processConfiguration_, historyAppender_.get(), index);
auto lp = std::make_unique<LuminosityBlockPrincipal>(
preg(), productResolversFactory::makePrimary, *processConfiguration_, historyAppender_.get(), index);
principalCache_.insert(std::move(lp));
}

{
auto pb = std::make_unique<ProcessBlockPrincipal>(preg(), *processConfiguration_);
auto pb = std::make_unique<ProcessBlockPrincipal>(
preg(), productResolversFactory::makePrimary, *processConfiguration_);
principalCache_.insert(std::move(pb));

auto pbForInput = std::make_unique<ProcessBlockPrincipal>(preg(), *processConfiguration_);
auto pbForInput = std::make_unique<ProcessBlockPrincipal>(
preg(), productResolversFactory::makePrimary, *processConfiguration_);
principalCache_.insertForInput(std::move(pbForInput));
}

Expand Down
9 changes: 3 additions & 6 deletions FWCore/Framework/src/LuminosityBlockPrincipal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
#include "DataFormats/Provenance/interface/ProductRegistry.h"

namespace edm {

LuminosityBlockPrincipal::LuminosityBlockPrincipal(std::shared_ptr<ProductRegistry const> reg,
std::vector<std::shared_ptr<ProductResolverBase>> const& resolvers,
ProcessConfiguration const& pc,
HistoryAppender* historyAppender,
unsigned int index,
bool isForPrimaryProcess)
: Base(reg, reg->productLookup(InLumi), pc, InLumi, historyAppender, isForPrimaryProcess),
runPrincipal_(),
index_(index) {}
unsigned int index)
: Base(reg, resolvers, pc, InLumi, historyAppender), runPrincipal_(), index_(index) {}

void LuminosityBlockPrincipal::fillLuminosityBlockPrincipal(ProcessHistory const* processHistory,
DelayedReader* reader) {
Expand Down
Loading

0 comments on commit 31c0d22

Please sign in to comment.