Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline calling of unscheduled EDProducers #14081

Merged
merged 3 commits into from Apr 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 2 additions & 10 deletions FWCore/Framework/interface/EventPrincipal.h
Expand Up @@ -42,7 +42,7 @@ namespace edm {
class ThinnedAssociationsHelper;
class ProcessHistoryRegistry;
class RunPrincipal;
class UnscheduledHandler;
class UnscheduledConfigurator;

class EventPrincipal : public Principal {
public:
Expand Down Expand Up @@ -138,8 +138,7 @@ namespace edm {

ProductProvenanceRetriever const* productProvenanceRetrieverPtr() const {return provRetrieverPtr_.get();}

void setUnscheduledHandler(std::shared_ptr<UnscheduledHandler> iHandler);
std::shared_ptr<const UnscheduledHandler> unscheduledHandler() const;
void setupUnscheduled(UnscheduledConfigurator const&);

EventSelectionIDVector const& eventSelectionIDs() const;

Expand Down Expand Up @@ -185,10 +184,6 @@ namespace edm {

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

virtual bool unscheduledFill(std::string const& moduleLabel,
SharedResourcesAcquirer* sra,
ModuleCallingContext const* mcc) const override;

virtual void readFromSource_(ProductResolverBase const& phb, ModuleCallingContext const* mcc) const override;

virtual unsigned int transitionIndex_() const override;
Expand All @@ -205,9 +200,6 @@ namespace edm {
// Pointer to the 'retriever' that will get provenance information from the persistent store.
edm::propagate_const<std::shared_ptr<ProductProvenanceRetriever>> provRetrieverPtr_;

// Handler for unscheduled modules
std::shared_ptr<UnscheduledHandler const> unscheduledHandler_;

EventSelectionIDVector eventSelectionIDs_;

std::shared_ptr<BranchIDListHelper const> branchIDListHelper_;
Expand Down
1 change: 0 additions & 1 deletion FWCore/Framework/interface/Frameworkfwd.h
Expand Up @@ -40,7 +40,6 @@ namespace edm {
class RunPrincipal;
class Schedule;
class TypeID;
class UnscheduledHandler;
class ViewBase;

struct EventSummary;
Expand Down
7 changes: 0 additions & 7 deletions FWCore/Framework/interface/LuminosityBlockPrincipal.h
Expand Up @@ -29,7 +29,6 @@ namespace edm {
class ModuleCallingContext;
class ProcessHistoryRegistry;
class RunPrincipal;
class UnscheduledHandler;

class LuminosityBlockPrincipal : public Principal {
public:
Expand Down Expand Up @@ -95,8 +94,6 @@ namespace edm {
return aux_->mergeAuxiliary(aux);
}

void setUnscheduledHandler(std::shared_ptr<UnscheduledHandler>) {}

void put(
BranchDescription const& bd,
std::unique_ptr<WrapperBase> edp) const;
Expand All @@ -110,10 +107,6 @@ namespace edm {

virtual bool isComplete_() const override {return complete_;}

virtual bool unscheduledFill(std::string const&,
SharedResourcesAcquirer* sra,
ModuleCallingContext const*) const override {return false;}

virtual unsigned int transitionIndex_() const override;

edm::propagate_const<std::shared_ptr<RunPrincipal>> runPrincipal_;
Expand Down
16 changes: 8 additions & 8 deletions FWCore/Framework/interface/Principal.h
Expand Up @@ -47,7 +47,6 @@ namespace edm {
class EDConsumerBase;
class SharedResourcesAcquirer;
class InputProductResolver;
class UnscheduledProductResolver;

struct FilledProductPtr {
bool operator()(propagate_const<std::shared_ptr<ProductResolverBase>> const& iObj) { return bool(iObj);}
Expand Down Expand Up @@ -201,6 +200,14 @@ namespace edm {

void putOrMerge(BranchDescription const& bd, std::unique_ptr<WrapperBase> edp) const;

//F must take an argument of type ProductResolverBase*
template <typename F>
void applyToResolvers( F iFunc) {
for(auto& resolver: productResolvers_) {
iFunc(resolver.get());
}
}

private:

// Make my DelayedReader get the EDProduct for a ProductResolver.
Expand All @@ -214,13 +221,6 @@ namespace edm {
readFromSource_(phb, mcc);
}

//This function is only meant to be called by UnscheduledProductResolver
friend class UnscheduledProductResolver;
virtual bool unscheduledFill(std::string const& moduleLabel,
SharedResourcesAcquirer* sra,
ModuleCallingContext const* mcc) const = 0;


void addScheduledProduct(std::shared_ptr<BranchDescription const> bd);
void addSourceProduct(std::shared_ptr<BranchDescription const> bd);
void addInputProduct(std::shared_ptr<BranchDescription const> bd);
Expand Down
2 changes: 2 additions & 0 deletions FWCore/Framework/interface/ProductResolverBase.h
Expand Up @@ -26,6 +26,7 @@ namespace edm {
class ModuleCallingContext;
class SharedResourcesAcquirer;
class Principal;
class UnscheduledConfigurator;

class ProductResolverBase {
public:
Expand Down Expand Up @@ -128,6 +129,7 @@ namespace edm {
}

virtual void connectTo(ProductResolverBase const&, Principal const*) = 0;
virtual void setupUnscheduled(UnscheduledConfigurator const&);

private:
virtual ProductData const* resolveProduct_(ResolveStatus& resolveStatus,
Expand Down
7 changes: 0 additions & 7 deletions FWCore/Framework/interface/RunPrincipal.h
Expand Up @@ -26,7 +26,6 @@ namespace edm {

class HistoryAppender;
class ModuleCallingContext;
class UnscheduledHandler;

class RunPrincipal : public Principal {
public:
Expand Down Expand Up @@ -87,8 +86,6 @@ namespace edm {
return aux_->mergeAuxiliary(aux);
}

void setUnscheduledHandler(std::shared_ptr<UnscheduledHandler>) {}

void put(
BranchDescription const& bd,
std::unique_ptr<WrapperBase> edp) const;
Expand All @@ -101,10 +98,6 @@ namespace edm {

virtual bool isComplete_() const override {return complete_;}

virtual bool unscheduledFill(std::string const&,
SharedResourcesAcquirer* sra,
ModuleCallingContext const*) const override {return false;}

virtual unsigned int transitionIndex_() const override;

edm::propagate_const<std::shared_ptr<RunAuxiliary>> aux_;
Expand Down
99 changes: 35 additions & 64 deletions FWCore/Framework/interface/UnscheduledCallProducer.h
@@ -1,13 +1,27 @@
#ifndef FWCore_Framework_UnscheduledCallProducer_h
#define FWCore_Framework_UnscheduledCallProducer_h

#include "FWCore/Framework/interface/UnscheduledHandler.h"
// -*- C++ -*-
//
// Package: FWCore/Framework
// Class : UnscheduledCallProducer
//
/**\class UnscheduledCallProducer UnscheduledCallProducer.h "UnscheduledCallProducer.h"

Description: Handles calling of EDProducers which are unscheduled

Usage:
<usage>

*/

#include "FWCore/Framework/interface/BranchActionType.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/OccurrenceTraits.h"
#include "FWCore/Framework/src/Worker.h"
#include "FWCore/Framework/src/UnscheduledAuxiliary.h"
#include "FWCore/ServiceRegistry/interface/ParentContext.h"
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"

#include <vector>
#include <unordered_map>
Expand All @@ -18,56 +32,36 @@ namespace edm {

class ModuleCallingContext;

class UnscheduledCallProducer : public UnscheduledHandler {
class UnscheduledCallProducer {
public:

class WorkerLookup {
//Compact way to quickly find workers or to iterate through all of them
public:
WorkerLookup() = default;

using worker_container = std::vector<Worker*>;
using const_iterator = worker_container::const_iterator;

void add(Worker* iWorker) {
auto const& label = iWorker->description().moduleLabel();
size_t index = m_values.size();
m_values.push_back(iWorker);
if( not m_keys.emplace(label.c_str(),index).second) {
//make sure keys are unique
throw cms::Exception("WorkersWithSameLabel")<<"multiple workers use the label "<<label;
}
}

Worker* find(std::string const& iLabel) const {
auto found = m_keys.find(iLabel);
if(found == m_keys.end()) {
return nullptr;
}
return m_values[found->second];
}

const_iterator begin() const { return m_values.begin(); }
const_iterator end() const { return m_values.end(); }

private:
//second element is the index of the key in m_values
std::unordered_map<std::string, size_t> m_keys;
worker_container m_values;
};
using worker_container = std::vector<Worker*>;
using const_iterator = worker_container::const_iterator;

UnscheduledCallProducer() : UnscheduledHandler(), workerLookup_() {}
UnscheduledCallProducer(ActivityRegistry& iReg) : unscheduledWorkers_() {
aux_.preModuleDelayedGetSignal_.connect(std::cref(iReg.preModuleEventDelayedGetSignal_));
aux_.postModuleDelayedGetSignal_.connect(std::cref(iReg.postModuleEventDelayedGetSignal_));
}
void addWorker(Worker* aWorker) {
assert(0 != aWorker);
workerLookup_.add(aWorker);
unscheduledWorkers_.push_back(aWorker);
}

void setEventSetup(EventSetup const& iSetup) {
aux_.setEventSetup(&iSetup);
}

UnscheduledAuxiliary const& auxiliary() const { return aux_; }

const_iterator begin() const { return unscheduledWorkers_.begin(); }
const_iterator end() const { return unscheduledWorkers_.end(); }

template <typename T, typename U>
void runNow(typename T::MyPrincipal& p, EventSetup const& es, StreamID streamID,
typename T::Context const* topContext, U const* context) const {
//do nothing for event since we will run when requested
if(!T::isEvent_) {
for(auto worker: workerLookup_) {
for(auto worker: unscheduledWorkers_) {
try {
ParentContext parentContext(context);
worker->doWork<T>(p, es, streamID, parentContext, topContext);
Expand Down Expand Up @@ -106,31 +100,8 @@ namespace edm {
}

private:
virtual bool tryToFillImpl(std::string const& moduleLabel,
EventPrincipal const& event,
EventSetup const& eventSetup,
ModuleCallingContext const* mcc) const override {
auto worker =
workerLookup_.find(moduleLabel);
if(worker != nullptr) {
try {
ParentContext parentContext(mcc);
worker->doWork<OccurrenceTraits<EventPrincipal, BranchActionStreamBegin> >(event,
eventSetup, event.streamID(), parentContext, mcc->getStreamContext());
}
catch (cms::Exception & ex) {
std::ostringstream ost;
ost << "Calling produce method for unscheduled module "
<< worker->description().moduleName() << "/'"
<< worker->description().moduleLabel() << "'";
ex.addContext(ost.str());
throw;
}
return true;
}
return false;
}
WorkerLookup workerLookup_;
worker_container unscheduledWorkers_;
UnscheduledAuxiliary aux_;
};

}
Expand Down
62 changes: 0 additions & 62 deletions FWCore/Framework/interface/UnscheduledHandler.h

This file was deleted.

11 changes: 3 additions & 8 deletions FWCore/Framework/interface/WorkerManager.h
Expand Up @@ -78,16 +78,11 @@ namespace edm {
void resetAll();

void setupOnDemandSystem(EventPrincipal& principal, EventSetup const& es);

std::shared_ptr<UnscheduledCallProducer const> unscheduled() const {return get_underlying_safe(unscheduled_);}
std::shared_ptr<UnscheduledCallProducer>& unscheduled() {return get_underlying_safe(unscheduled_);}

WorkerRegistry workerReg_;
ExceptionToActionTable const* actionTable_;

AllWorkers allWorkers_;

edm::propagate_const<std::shared_ptr<UnscheduledCallProducer>> unscheduled_;
UnscheduledCallProducer unscheduled_;
void const* lastSetupEventPrincipal_;
};

template <typename T, typename U>
Expand All @@ -107,7 +102,7 @@ namespace edm {
setupOnDemandSystem(dynamic_cast<EventPrincipal&>(ep), es);
} else {
//make sure the unscheduled items see this run or lumi rtansition
unscheduled_->runNow<T,U>(ep, es,streamID, topContext, context);
unscheduled_.runNow<T,U>(ep, es,streamID, topContext, context);
}
}
catch(cms::Exception& e) {
Expand Down