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 9, 2025
1 parent f0dc95b commit 91b9436
Show file tree
Hide file tree
Showing 35 changed files with 631 additions and 349 deletions.
38 changes: 20 additions & 18 deletions DQM/SiStripMonitorHardware/src/SiStripSpyEventMatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "DataFormats/Provenance/interface/ThinnedAssociationsHelper.h"
#include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
#include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
#include "FWCore/Framework/interface/ProductResolversFactory.h"
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/GetPassID.h"
Expand Down Expand Up @@ -64,6 +65,7 @@ namespace sistrip {
productRegistry_->setFrozen();

eventPrincipal_ = std::make_unique<edm::EventPrincipal>(source_->productRegistry(),
edm::productResolversFactory::makePrimary,
std::make_shared<edm::BranchIDListHelper>(),
std::make_shared<edm::ThinnedAssociationsHelper>(),
*processConfiguration_,
Expand Down Expand Up @@ -183,22 +185,22 @@ namespace sistrip {
CountersPtr inputL1ACounters = getCounters(event, l1aCountersTag_);
CountersPtr inputAPVAddresses = getCounters(event, apvAddressesTag_, false);
const edm::DetSetVector<SiStripRawDigi>* inputScopeDigis =
getProduct<edm::DetSetVector<SiStripRawDigi> >(event, scopeDigisTag_);
getProduct<edm::DetSetVector<SiStripRawDigi>>(event, scopeDigisTag_);
const edm::DetSetVector<SiStripRawDigi>* inputPayloadDigis =
getProduct<edm::DetSetVector<SiStripRawDigi> >(event, payloadDigisTag_);
getProduct<edm::DetSetVector<SiStripRawDigi>>(event, payloadDigisTag_);
const edm::DetSetVector<SiStripRawDigi>* inputReorderedDigis =
getProduct<edm::DetSetVector<SiStripRawDigi> >(event, reorderedDigisTag_);
getProduct<edm::DetSetVector<SiStripRawDigi>>(event, reorderedDigisTag_);
const edm::DetSetVector<SiStripRawDigi>* inputVirginRawDigis =
getProduct<edm::DetSetVector<SiStripRawDigi> >(event, virginRawDigisTag_);
getProduct<edm::DetSetVector<SiStripRawDigi>>(event, virginRawDigisTag_);
//construct the output vectors if the digis were found and they do not exist
if (inputScopeDigis && !mo.outputScopeDigisVector_.get())
mo.outputScopeDigisVector_.reset(new std::vector<edm::DetSet<SiStripRawDigi> >);
mo.outputScopeDigisVector_ = std::make_shared<std::vector<edm::DetSet<SiStripRawDigi>>>();
if (inputPayloadDigis && !mo.outputPayloadDigisVector_.get())
mo.outputPayloadDigisVector_.reset(new std::vector<edm::DetSet<SiStripRawDigi> >);
mo.outputPayloadDigisVector_ = std::make_shared<std::vector<edm::DetSet<SiStripRawDigi>>>();
if (inputReorderedDigis && !mo.outputReorderedDigisVector_.get())
mo.outputReorderedDigisVector_.reset(new std::vector<edm::DetSet<SiStripRawDigi> >);
mo.outputReorderedDigisVector_ = std::make_shared<std::vector<edm::DetSet<SiStripRawDigi>>>();
if (inputVirginRawDigis && !mo.outputVirginRawDigisVector_.get())
mo.outputVirginRawDigisVector_.reset(new std::vector<edm::DetSet<SiStripRawDigi> >);
mo.outputVirginRawDigisVector_ = std::make_shared<std::vector<edm::DetSet<SiStripRawDigi>>>();
//find matching FEDs
std::set<uint16_t> matchingFeds;
findMatchingFeds(eventId, apvAddress, inputTotalEventCounters, inputL1ACounters, inputAPVAddresses, matchingFeds);
Expand Down Expand Up @@ -309,10 +311,10 @@ namespace sistrip {
std::vector<uint32_t>& outputTotalEventCounters,
std::vector<uint32_t>& outputL1ACounters,
std::vector<uint32_t>& outputAPVAddresses,
std::vector<edm::DetSet<SiStripRawDigi> >* outputScopeDigisVector,
std::vector<edm::DetSet<SiStripRawDigi> >* outputPayloadDigisVector,
std::vector<edm::DetSet<SiStripRawDigi> >* outputReorderedDigisVector,
std::vector<edm::DetSet<SiStripRawDigi> >* outputVirginRawDigisVector,
std::vector<edm::DetSet<SiStripRawDigi>>* outputScopeDigisVector,
std::vector<edm::DetSet<SiStripRawDigi>>* outputPayloadDigisVector,
std::vector<edm::DetSet<SiStripRawDigi>>* outputReorderedDigisVector,
std::vector<edm::DetSet<SiStripRawDigi>>* outputVirginRawDigisVector,
const SiStripFedCabling& cabling) {
//reserve space in vectors
if (inputScopeDigis) {
Expand Down Expand Up @@ -391,12 +393,12 @@ namespace sistrip {
SpyEventMatcher::CountersPtr SpyEventMatcher::getCounters(const edm::EventPrincipal& event,
const edm::InputTag& tag,
const bool mapKeyIsByFedID) {
const std::vector<uint32_t>* vectorFromEvent = getProduct<std::vector<uint32_t> >(event, tag);
const std::vector<uint32_t>* vectorFromEvent = getProduct<std::vector<uint32_t>>(event, tag);
if (vectorFromEvent) {
//vector is from event so, will be deleted when the event is destroyed (and not before)
return std::make_shared<CountersWrapper>(vectorFromEvent);
} else {
const std::map<uint32_t, uint32_t>* mapFromEvent = getProduct<std::map<uint32_t, uint32_t> >(event, tag);
const std::map<uint32_t, uint32_t>* mapFromEvent = getProduct<std::map<uint32_t, uint32_t>>(event, tag);
if (mapFromEvent) {
std::vector<uint32_t>* newVector = new std::vector<uint32_t>(FED_ID_MAX + 1, 0);
if (mapKeyIsByFedID) {
Expand Down Expand Up @@ -428,10 +430,10 @@ namespace sistrip {
std::vector<uint32_t>& theTotalEventCounters,
std::vector<uint32_t>& theL1ACounters,
std::vector<uint32_t>& theAPVAddresses,
std::vector<edm::DetSet<SiStripRawDigi> >* theScopeDigisVector,
std::vector<edm::DetSet<SiStripRawDigi> >* thePayloadDigisVector,
std::vector<edm::DetSet<SiStripRawDigi> >* theReorderedDigisVector,
std::vector<edm::DetSet<SiStripRawDigi> >* theVirginRawDigisVector)
std::vector<edm::DetSet<SiStripRawDigi>>* theScopeDigisVector,
std::vector<edm::DetSet<SiStripRawDigi>>* thePayloadDigisVector,
std::vector<edm::DetSet<SiStripRawDigi>>* theReorderedDigisVector,
std::vector<edm::DetSet<SiStripRawDigi>>* theVirginRawDigisVector)
: rawData(new FEDRawDataCollection),
totalEventCounters(new std::vector<uint32_t>),
l1aCounters(new std::vector<uint32_t>),
Expand Down
28 changes: 24 additions & 4 deletions FWCore/Framework/interface/EventPrincipal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ is the DataBlock.
#include "FWCore/Utilities/interface/Signal.h"
#include "FWCore/Utilities/interface/get_underlying_safe.h"
#include "FWCore/Framework/interface/Principal.h"
#include "FWCore/Framework/interface/ProductResolversFactory.h"

#include <map>
#include <memory>
Expand Down Expand Up @@ -51,16 +52,26 @@ 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 <ProductResolversFactory FACTORY>
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>>&& 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 @@ -16,6 +16,7 @@ is the DataBlock.
#include "DataFormats/Provenance/interface/RunID.h"
#include "FWCore/Utilities/interface/LuminosityBlockIndex.h"
#include "FWCore/Framework/interface/Principal.h"
#include "FWCore/Framework/interface/ProductResolversFactory.h"
#include "FWCore/Utilities/interface/propagate_const.h"

#include <memory>
Expand All @@ -33,11 +34,13 @@ namespace edm {
typedef LuminosityBlockAuxiliary Auxiliary;
typedef Principal Base;

template <ProductResolversFactory FACTORY>
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>>&& 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>>&& 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>>&& resolvers,
ProcessConfiguration const&);
unsigned int transitionIndex_() const final;

std::string processName_;
Expand Down
56 changes: 56 additions & 0 deletions FWCore/Framework/interface/ProductResolversFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#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;

template <typename F>
concept ProductResolversFactory =
requires(F&& f, std::string const& name, ProductRegistry const& reg) { f(InEvent, name, reg); };

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 @@ -22,6 +22,7 @@ is the DataBlock.
#include "FWCore/Utilities/interface/propagate_const.h"
#include "FWCore/Utilities/interface/RunIndex.h"
#include "FWCore/Framework/interface/Principal.h"
#include "FWCore/Framework/interface/ProductResolversFactory.h"

namespace edm {

Expand All @@ -36,12 +37,19 @@ namespace edm {
typedef RunAuxiliary Auxiliary;
typedef Principal Base;

template <ProductResolversFactory FACTORY>
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>>&& 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>>&& 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, std::move(resolvers), pc, InEvent, historyAppender),
aux_(),
luminosityBlockPrincipal_(nullptr),
provRetrieverPtr_(new ProductProvenanceRetriever(streamIndex, *reg)),
Expand Down
Loading

0 comments on commit 91b9436

Please sign in to comment.