Skip to content

Commit

Permalink
GetterOfProducts for output modules, use in DQMRootOutputModule
Browse files Browse the repository at this point in the history
Extends support for GetterOfProducts to output modules
and uses that instead of consumesMany in DQMRootOutputModule
  • Loading branch information
wddgit committed Apr 28, 2023
1 parent 5847de5 commit 9d851e4
Show file tree
Hide file tree
Showing 13 changed files with 543 additions and 50 deletions.
18 changes: 15 additions & 3 deletions DQMServices/FwkIO/plugins/DQMRootOutputModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@
#include "oneapi/tbb/task_arena.h"

// user include files
#include "FWCore/Framework/interface/GetterOfProducts.h"
#include "FWCore/Framework/interface/one/OutputModule.h"
#include "FWCore/Framework/interface/RunForOutput.h"
#include "FWCore/Framework/interface/LuminosityBlockForOutput.h"
#include "FWCore/Framework/interface/TypeMatch.h"
#include "DQMServices/Core/interface/DQMStore.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/MessageLogger/interface/JobReport.h"
#include "FWCore/Utilities/interface/BranchType.h"
#include "FWCore/Utilities/interface/Digest.h"
#include "FWCore/Utilities/interface/GlobalIdentifier.h"

Expand Down Expand Up @@ -235,6 +238,9 @@ class DQMRootOutputModule : public edm::one::OutputModule<> {
std::vector<edm::ProcessHistoryID> m_seenHistories;
edm::ProcessHistoryRegistry m_processHistoryRegistry;
edm::JobReport::Token m_jrToken;

edm::GetterOfProducts<DQMToken> m_getterOfProductsLumi;
edm::GetterOfProducts<DQMToken> m_getterOfProductsRun;
};

//
Expand Down Expand Up @@ -293,14 +299,20 @@ DQMRootOutputModule::DQMRootOutputModule(edm::ParameterSet const& pset)
m_presentHistoryIndex(0),
m_filterOnRun(pset.getUntrackedParameter<unsigned int>("filterOnRun")),
m_fullNameBufferPtr(&m_fullNameBuffer),
m_indicesTree(nullptr) {
m_indicesTree(nullptr),
m_getterOfProductsLumi(edm::TypeMatch(), this, edm::InLumi),
m_getterOfProductsRun(edm::TypeMatch(), this, edm::InRun) {
// Declare dependencies for all Lumi and Run tokens here. In
// principle could use the keep statements, but then DQMToken would
// have to be made persistent (transient products are ignored),
// which would lead to a need to (finally) remove underscores from
// DQM module labels.
consumesMany<DQMToken, edm::InLumi>();
consumesMany<DQMToken, edm::InRun>();
// This is needed to support unscheduled DQM modules now that
// non-consumed EDProducers are deleted from the job at beginJob.
callWhenNewProductsRegistered([this](edm::BranchDescription const& bd) {
m_getterOfProductsLumi(bd);
m_getterOfProductsRun(bd);
});
}

// DQMRootOutputModule::DQMRootOutputModule(const DQMRootOutputModule& rhs)
Expand Down
76 changes: 37 additions & 39 deletions FWCore/Framework/interface/GetterOfProducts.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,13 @@ There are some variants for special cases
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Provenance/interface/BranchDescription.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventForOutput.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"
#include "FWCore/Framework/interface/LuminosityBlockForOutput.h"
#include "FWCore/Framework/interface/ProcessBlock.h"
#include "FWCore/Framework/interface/ProcessBlockForOutput.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/Framework/interface/RunForOutput.h"
#include "FWCore/Framework/interface/WillGetIfMatch.h"
#include "FWCore/Utilities/interface/BranchType.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
Expand All @@ -116,6 +120,35 @@ There are some variants for special cases

namespace edm {

template <typename U>
struct BranchTypeForContainerType {
static const BranchType branchType = InEvent;
};
template <>
struct BranchTypeForContainerType<LuminosityBlock> {
static const BranchType branchType = InLumi;
};
template <>
struct BranchTypeForContainerType<LuminosityBlockForOutput> {
static const BranchType branchType = InLumi;
};
template <>
struct BranchTypeForContainerType<Run> {
static const BranchType branchType = InRun;
};
template <>
struct BranchTypeForContainerType<RunForOutput> {
static const BranchType branchType = InRun;
};
template <>
struct BranchTypeForContainerType<ProcessBlock> {
static const BranchType branchType = InProcess;
};
template <>
struct BranchTypeForContainerType<ProcessBlockForOutput> {
static const BranchType branchType = InProcess;
};

template <typename T>
class GetterOfProducts {
public:
Expand All @@ -139,48 +172,13 @@ namespace edm {
}
}

void fillHandles(edm::Event const& event, std::vector<edm::Handle<T>>& handles) const {
handles.clear();
if (branchType_ == edm::InEvent) {
handles.reserve(tokens_->size());
for (auto const& token : *tokens_) {
if (auto handle = event.getHandle(token)) {
handles.push_back(handle);
}
}
}
}

void fillHandles(edm::LuminosityBlock const& lumi, std::vector<edm::Handle<T>>& handles) const {
handles.clear();
if (branchType_ == edm::InLumi) {
handles.reserve(tokens_->size());
for (auto const& token : *tokens_) {
if (auto handle = lumi.getHandle(token)) {
handles.push_back(handle);
}
}
}
}

void fillHandles(edm::Run const& run, std::vector<edm::Handle<T>>& handles) const {
handles.clear();
if (branchType_ == edm::InRun) {
handles.reserve(tokens_->size());
for (auto const& token : *tokens_) {
if (auto handle = run.getHandle(token)) {
handles.push_back(handle);
}
}
}
}

void fillHandles(edm::ProcessBlock const& processBlock, std::vector<edm::Handle<T>>& handles) const {
template <typename ProductContainer>
void fillHandles(ProductContainer const& productContainer, std::vector<edm::Handle<T>>& handles) const {
handles.clear();
if (branchType_ == edm::InProcess) {
if (branchType_ == BranchTypeForContainerType<ProductContainer>::branchType) {
handles.reserve(tokens_->size());
for (auto const& token : *tokens_) {
if (auto handle = processBlock.getHandle(token)) {
if (auto handle = productContainer.getHandle(token)) {
handles.push_back(handle);
}
}
Expand Down
10 changes: 9 additions & 1 deletion FWCore/Framework/interface/OutputModuleCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

// system include files
#include <array>
#include <functional>
#include <memory>
#include <string>
#include <vector>
Expand All @@ -28,6 +29,7 @@
#include <set>

// user include files
#include "DataFormats/Provenance/interface/BranchDescription.h"
#include "DataFormats/Provenance/interface/BranchID.h"
#include "DataFormats/Provenance/interface/BranchIDList.h"
#include "DataFormats/Provenance/interface/ModuleDescription.h"
Expand Down Expand Up @@ -112,6 +114,10 @@ namespace edm {

const ModuleDescription& moduleDescription() const { return moduleDescription_; }

void callWhenNewProductsRegistered(std::function<void(BranchDescription const&)> const& func) {
callWhenNewProductsRegistered_ = func;
}

protected:
ModuleDescription const& description() const;

Expand Down Expand Up @@ -190,6 +196,8 @@ namespace edm {

OutputProcessBlockHelper outputProcessBlockHelper_;

std::function<void(BranchDescription const&)> callWhenNewProductsRegistered_;

//------------------------------------------------------------------
// private member functions
//------------------------------------------------------------------
Expand All @@ -207,7 +215,7 @@ namespace edm {
/// Tell the OutputModule that is must end the current file.
void doCloseFile();

void registerProductsAndCallbacks(OutputModuleCore const*, ProductRegistry const*) {}
void registerProductsAndCallbacks(OutputModuleCore const*, ProductRegistry*);

bool needToRunSelection() const;
std::vector<ProductResolverIndexAndSkipBit> productsUsedBySelection() const;
Expand Down
2 changes: 0 additions & 2 deletions FWCore/Framework/interface/global/OutputModuleBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ namespace edm {
private:
std::string workerType() const { return "WorkerT<edm::global::OutputModuleBase>"; }

void registerProductsAndCallbacks(OutputModuleBase const*, ProductRegistry const*) {}

virtual void preallocStreams(unsigned int) {}
virtual void preallocate(PreallocationConfiguration const&) {}
virtual void doBeginStream_(StreamID) {}
Expand Down
2 changes: 0 additions & 2 deletions FWCore/Framework/interface/limited/OutputModuleBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ namespace edm {

std::string workerType() const { return "WorkerT<edm::limited::OutputModuleBase>"; }

void registerProductsAndCallbacks(OutputModuleBase const*, ProductRegistry const*) {}

virtual void preallocStreams(unsigned int) {}
virtual void preallocate(PreallocationConfiguration const&) {}
virtual void doBeginStream_(StreamID) {}
Expand Down
2 changes: 0 additions & 2 deletions FWCore/Framework/interface/one/OutputModuleBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ namespace edm {

std::string workerType() const { return "WorkerT<edm::one::OutputModuleBase>"; }

void registerProductsAndCallbacks(OutputModuleBase const*, ProductRegistry const*) {}

virtual void preActionBeforeRunEventAsync(WaitingTaskHolder iTask,
ModuleCallingContext const& iModuleCallingContext,
Principal const& iPrincipal) const {}
Expand Down
10 changes: 10 additions & 0 deletions FWCore/Framework/src/OutputModuleCore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "DataFormats/Provenance/interface/BranchKey.h"
#include "DataFormats/Provenance/interface/ProductRegistry.h"
#include "DataFormats/Provenance/interface/ThinnedAssociationsHelper.h"
#include "FWCore/Framework/interface/ConstProductRegistry.h"
#include "FWCore/Framework/interface/EventForOutput.h"
#include "FWCore/Framework/interface/EventPrincipal.h"
#include "FWCore/Framework/src/insertSelectedProcesses.h"
Expand Down Expand Up @@ -256,6 +257,15 @@ namespace edm {

void OutputModuleCore::doEndJob() { endJob(); }

void OutputModuleCore::registerProductsAndCallbacks(OutputModuleCore const*, ProductRegistry* reg) {
if (callWhenNewProductsRegistered_) {
reg->callForEachBranch(callWhenNewProductsRegistered_);

Service<ConstProductRegistry> regService;
regService->watchProductAdditions(callWhenNewProductsRegistered_);
}
}

bool OutputModuleCore::needToRunSelection() const { return !wantAllEvents_; }

std::vector<ProductResolverIndexAndSkipBit> OutputModuleCore::productsUsedBySelection() const {
Expand Down
2 changes: 1 addition & 1 deletion FWCore/Integration/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<use name="FWCore/Utilities"/>
</library>

<library file="ThingProducer.cc,ThingAlgorithm.cc,TrackOfThingsProducer.cc,ThinningTestAnalyzer.cc,ThinnedRefFromTestAnalyzer.cc,DetSetVectorThingProducer.cc,TrackOfDSVThingsProducer.cc,ThinningDSVThingProducer.cc,SlimmingDSVThingProducer.cc,ThinningDSVTestAnalyzer.cc,ThingSource.cc,ThingExtSource.cc,ThingWithMergeProducer.cc,TestGetterOfProducts.cc,PutOrMergeTestSource.cc,TestGetByLabelAnalyzer.cc,ThingAnalyzer.cc"
<library file="ThingProducer.cc,ThingAlgorithm.cc,TrackOfThingsProducer.cc,ThinningTestAnalyzer.cc,ThinnedRefFromTestAnalyzer.cc,DetSetVectorThingProducer.cc,TrackOfDSVThingsProducer.cc,ThinningDSVThingProducer.cc,SlimmingDSVThingProducer.cc,ThinningDSVTestAnalyzer.cc,ThingSource.cc,ThingExtSource.cc,ThingWithMergeProducer.cc,TestGetterOfProducts.cc,PutOrMergeTestSource.cc,TestGetByLabelAnalyzer.cc,ThingAnalyzer.cc,TestOutputWithGetterOfProducts.cc,TestOutputWithGetterOfProductsGlobal.cc,TestOutputWithGetterOfProductsLimited.cc"
name="FWCoreIntegrationTestWithThing">
<flags EDM_PLUGIN="1"/>
<use name="FWCore/Framework"/>
Expand Down
Loading

0 comments on commit 9d851e4

Please sign in to comment.