CMS 3D CMS Logo

WorkerManager.cc
Go to the documentation of this file.
3 
10 
11 static const std::string kFilterType("EDFilter");
12 static const std::string kProducerType("EDProducer");
13 
14 namespace edm {
15  // -----------------------------
16 
17  WorkerManager::WorkerManager(std::shared_ptr<ActivityRegistry> areg, ExceptionToActionTable const& actions)
18  : workerReg_(areg),
19  actionTable_(&actions),
20  allWorkers_(),
21  unscheduled_(*areg),
22  lastSetupEventPrincipal_(nullptr) {} // WorkerManager::WorkerManager
23 
24  WorkerManager::WorkerManager(std::shared_ptr<ModuleRegistry> modReg,
25  std::shared_ptr<ActivityRegistry> areg,
27  : workerReg_(areg, modReg),
28  actionTable_(&actions),
29  allWorkers_(),
30  unscheduled_(*areg),
31  lastSetupEventPrincipal_(nullptr) {} // WorkerManager::WorkerManager
32 
34  ProductRegistry& preg,
35  PreallocationConfiguration const* prealloc,
36  std::shared_ptr<ProcessConfiguration const> processConfiguration,
37  std::string const& label) {
38  WorkerParams params(&pset, preg, prealloc, processConfiguration, *actionTable_);
39  return workerReg_.getWorker(params, label);
40  }
41 
43  ProductRegistry& preg,
44  PreallocationConfiguration const* prealloc,
45  std::shared_ptr<ProcessConfiguration> processConfiguration,
47  std::set<std::string>& unscheduledLabels,
48  std::vector<std::string>& shouldBeUsedLabels) {
49  //Need to
50  // 1) create worker
51  // 2) if it is a WorkerT<EDProducer>, add it to our list
52  auto modType = pset.getParameter<std::string>("@module_edm_type");
53  if (modType == kProducerType || modType == kFilterType) {
54  Worker* newWorker = getWorker(pset, preg, prealloc, processConfiguration, label);
55  assert(newWorker->moduleType() == Worker::kProducer || newWorker->moduleType() == Worker::kFilter);
56  unscheduledLabels.insert(label);
57  unscheduled_.addWorker(newWorker);
58  //add to list so it gets reset each new event
59  addToAllWorkers(newWorker);
60  } else {
61  shouldBeUsedLabels.push_back(label);
62  }
63  }
64 
66  for (auto& worker : allWorkers_) {
67  worker->endJob();
68  }
69  }
70 
72  for (auto& worker : allWorkers_) {
73  try {
74  convertException::wrap([&]() { worker->endJob(); });
75  } catch (cms::Exception const& ex) {
76  collector.addException(ex);
77  }
78  }
79  }
80 
82  eventsetup::ESRecordsToProxyIndices const& iESIndices) {
83  auto const runLookup = iRegistry.productLookup(InRun);
84  auto const lumiLookup = iRegistry.productLookup(InLumi);
85  auto const eventLookup = iRegistry.productLookup(InEvent);
86  if (!allWorkers_.empty()) {
87  auto const& processName = allWorkers_[0]->description().processName();
88  auto runModuleToIndicies = runLookup->indiciesForModulesInProcess(processName);
89  auto lumiModuleToIndicies = lumiLookup->indiciesForModulesInProcess(processName);
90  auto eventModuleToIndicies = eventLookup->indiciesForModulesInProcess(processName);
91  for (auto& worker : allWorkers_) {
92  worker->updateLookup(InRun, *runLookup);
93  worker->updateLookup(InLumi, *lumiLookup);
94  worker->updateLookup(InEvent, *eventLookup);
95  worker->updateLookup(iESIndices);
96  worker->resolvePutIndicies(InRun, runModuleToIndicies);
97  worker->resolvePutIndicies(InLumi, lumiModuleToIndicies);
98  worker->resolvePutIndicies(InEvent, eventModuleToIndicies);
99  }
100 
101  for_all(allWorkers_, std::bind(&Worker::beginJob, std::placeholders::_1));
102  }
103  }
104 
106  for (auto& worker : allWorkers_) {
107  worker->beginStream(iID, streamContext);
108  }
109  }
110 
111  void WorkerManager::endStream(StreamID iID, StreamContext& streamContext) {
112  for (auto& worker : allWorkers_) {
113  worker->endStream(iID, streamContext);
114  }
115  }
116 
117  void WorkerManager::resetAll() { for_all(allWorkers_, std::bind(&Worker::reset, std::placeholders::_1)); }
118 
120  if (!search_all(allWorkers_, w)) {
121  allWorkers_.push_back(w);
122  }
123  }
124 
126  this->resetAll();
128  if (&ep != lastSetupEventPrincipal_) {
130  ep.setupUnscheduled(config);
132  }
133  }
134 
135 } // namespace edm
T getParameter(std::string const &) const
void addException(cms::Exception const &exception)
void setupUnscheduled(UnscheduledConfigurator const &)
Definition: Principal.cc:390
roAction_t actions[nactions]
Definition: GenABIO.cc:181
void endStream(StreamID iID, StreamContext &streamContext)
const double w
Definition: UKUtility.cc:23
static const std::string kFilterType("EDFilter")
void beginJob(ProductRegistry const &iRegistry, eventsetup::ESRecordsToProxyIndices const &)
UnscheduledCallProducer unscheduled_
void addToUnscheduledWorkers(ParameterSet &pset, ProductRegistry &preg, PreallocationConfiguration const *prealloc, std::shared_ptr< ProcessConfiguration > processConfiguration, std::string label, std::set< std::string > &unscheduledLabels, std::vector< std::string > &shouldBeUsedLabels)
AllWorkers allWorkers_
#define nullptr
ExceptionToActionTable const * actionTable_
void const * lastSetupEventPrincipal_
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:14
config
Definition: looper.py:291
char const * label
void setupOnDemandSystem(Principal &principal, EventSetupImpl const &es)
void setEventSetup(EventSetupImpl const &iSetup)
void reset()
Definition: Worker.h:180
void beginStream(StreamID iID, StreamContext &streamContext)
static const std::string kProducerType("EDProducer")
UnscheduledAuxiliary const & auxiliary() const
bool search_all(ForwardSequence const &s, Datum const &d)
Definition: Algorithms.h:36
std::shared_ptr< ProductResolverIndexHelper const > productLookup(BranchType branchType) const
HLT enums.
void beginJob()
Definition: Worker.cc:284
WorkerRegistry workerReg_
Worker * getWorker(WorkerParams const &p, std::string const &moduleLabel)
Retrieve the particular instance of the worker.
virtual Types moduleType() const =0
auto wrap(F iFunc) -> decltype(iFunc())
WorkerManager(std::shared_ptr< ActivityRegistry > actReg, ExceptionToActionTable const &actions)
Worker * getWorker(ParameterSet &pset, ProductRegistry &preg, PreallocationConfiguration const *prealloc, std::shared_ptr< ProcessConfiguration const > processConfiguration, std::string const &label)
void addToAllWorkers(Worker *w)