CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
WorkerManager.cc
Go to the documentation of this file.
2 
8 
9 static const std::string kFilterType("EDFilter");
10 static const std::string kProducerType("EDProducer");
11 
12 namespace edm {
13  // -----------------------------
14 
15  WorkerManager::WorkerManager(boost::shared_ptr<ActivityRegistry> areg, ExceptionToActionTable const& actions) :
16  workerReg_(areg),
17  actionTable_(&actions),
18  allWorkers_(),
19  unscheduled_(new UnscheduledCallProducer) {
20  } // WorkerManager::WorkerManager
21 
22  WorkerManager::WorkerManager(boost::shared_ptr<ModuleRegistry> modReg,
23  boost::shared_ptr<ActivityRegistry> areg,
25  workerReg_(areg,modReg),
26  actionTable_(&actions),
27  allWorkers_(),
28  unscheduled_(new UnscheduledCallProducer) {
29  } // WorkerManager::WorkerManager
30 
34  boost::shared_ptr<ProcessConfiguration const> processConfiguration,
35  std::string const & label) {
36  WorkerParams params(&pset, preg, prealloc, processConfiguration, *actionTable_);
37  return workerReg_.getWorker(params, label);
38  }
39 
43  boost::shared_ptr<ProcessConfiguration> processConfiguration,
45  bool useStopwatch,
46  std::set<std::string>& unscheduledLabels,
47  std::vector<std::string>& shouldBeUsedLabels) {
48  //Need to
49  // 1) create worker
50  // 2) if it is a WorkerT<EDProducer>, add it to our list
51  auto modType = pset.getParameter<std::string>("@module_edm_type");
52  if(modType == kProducerType || modType == kFilterType) {
53  Worker* newWorker = getWorker(pset, preg, prealloc, processConfiguration, label);
54  assert(newWorker->moduleType() == Worker::kProducer || newWorker->moduleType() == Worker::kFilter);
55  unscheduledLabels.insert(label);
56  unscheduled_->addWorker(newWorker);
57  //add to list so it gets reset each new event
58  addToAllWorkers(newWorker, useStopwatch);
59  } else {
60  shouldBeUsedLabels.push_back(label);
61  }
62  }
63 
64  void WorkerManager::setOnDemandProducts(ProductRegistry& pregistry, std::set<std::string> const& unscheduledLabels) const {
65  for(auto& prod : pregistry.productListUpdator()) {
66  if(prod.second.produced() &&
67  prod.second.branchType() == InEvent &&
68  unscheduledLabels.end() != unscheduledLabels.find(prod.second.moduleLabel())) {
69  prod.second.setOnDemand(true);
70  }
71  }
72  }
73 
75  for(auto& worker : allWorkers_) {
76  worker->endJob();
77  }
78  }
79 
81  for(auto& worker : allWorkers_) {
82  try {
83  try {
84  worker->endJob();
85  }
86  catch (cms::Exception& e) { throw; }
87  catch (std::bad_alloc& bda) { convertException::badAllocToEDM(); }
90  catch (char const* c) { convertException::charPtrToEDM(c); }
91  catch (...) { convertException::unknownToEDM(); }
92  }
93  catch (cms::Exception const& ex) {
94  collector.addException(ex);
95  }
96  }
97  }
98 
99 
100  void WorkerManager::beginJob(ProductRegistry const& iRegistry) {
101  auto const runLookup = iRegistry.productLookup(InRun);
102  auto const lumiLookup = iRegistry.productLookup(InLumi);
103  auto const eventLookup = iRegistry.productLookup(InEvent);
104  for(auto& worker : allWorkers_) {
105  worker->updateLookup(InRun,*runLookup);
106  worker->updateLookup(InLumi,*lumiLookup);
107  worker->updateLookup(InEvent,*eventLookup);
108  }
109 
110  for_all(allWorkers_, boost::bind(&Worker::beginJob, _1));
112  }
113 
114  void
116  for(auto& worker: allWorkers_) {
117  worker->beginStream(iID, streamContext);
118  }
119  }
120 
121  void
123  for(auto& worker: allWorkers_) {
124  worker->endStream(iID, streamContext);
125  }
126  }
127 
128  void
130  for_all(allWorkers_, boost::bind(&Worker::reset, _1));
131  }
132 
133  void
134  WorkerManager::addToAllWorkers(Worker* w, bool useStopwatch) {
135  if(!search_all(allWorkers_, w)) {
136  if(useStopwatch) {
137  w->useStopwatch();
138  }
139  allWorkers_.push_back(w);
140  }
141  }
142 
143  void
145  // NOTE: who owns the productdescrption? Just copied by value
146  unscheduled_->setEventSetup(es);
148  }
149 
150 }
T getParameter(std::string const &) const
void addException(cms::Exception const &exception)
void endStream(StreamID iID, StreamContext &streamContext)
static const std::string kFilterType("EDFilter")
void setOnDemandProducts(ProductRegistry &pregistry, std::set< std::string > const &unscheduledLabels) const
AllWorkers allWorkers_
Definition: WorkerManager.h:85
void addToUnscheduledWorkers(ParameterSet &pset, ProductRegistry &preg, PreallocationConfiguration const *prealloc, boost::shared_ptr< ProcessConfiguration > processConfiguration, std::string label, bool useStopwatch, std::set< std::string > &unscheduledLabels, std::vector< std::string > &shouldBeUsedLabels)
void beginJob(ProductRegistry const &iRegistry)
processConfiguration
Definition: Schedule.cc:362
actions
Definition: Schedule.cc:362
ExceptionToActionTable const * actionTable_
Definition: WorkerManager.h:83
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:16
boost::shared_ptr< ProductHolderIndexHelper > const & productLookup(BranchType branchType) const
Worker * getWorker(ParameterSet &pset, ProductRegistry &preg, PreallocationConfiguration const *prealloc, boost::shared_ptr< ProcessConfiguration const > processConfiguration, std::string const &label)
void reset()
Definition: Worker.h:92
void stdToEDM(std::exception const &e)
void useStopwatch()
Definition: Worker.cc:215
boost::shared_ptr< UnscheduledCallProducer > unscheduled_
Definition: WorkerManager.h:87
areg
Definition: Schedule.cc:362
virtual Types moduleType() const =0
void beginStream(StreamID iID, StreamContext &streamContext)
void charPtrToEDM(char const *c)
void stringToEDM(std::string &s)
WorkerManager(boost::shared_ptr< ActivityRegistry > actReg, ExceptionToActionTable const &actions)
static const std::string kProducerType("EDProducer")
bool search_all(ForwardSequence const &s, Datum const &d)
Definition: Algorithms.h:46
ProductList & productListUpdator()
void loadMissingDictionaries()
void beginJob()
Definition: Worker.cc:111
WorkerRegistry workerReg_
Definition: WorkerManager.h:82
Worker * getWorker(WorkerParams const &p, std::string const &moduleLabel)
Retrieve the particular instance of the worker.
void setUnscheduledHandler(boost::shared_ptr< UnscheduledHandler > iHandler)
T w() const
void addToAllWorkers(Worker *w, bool useStopwatch)
preg
Definition: Schedule.cc:362
void setupOnDemandSystem(EventPrincipal &principal, EventSetup const &es)
prealloc
Definition: Schedule.cc:362