CMS 3D CMS Logo

Schedule.cc
Go to the documentation of this file.
2 
38 
39 #include <array>
40 #include <algorithm>
41 #include <cassert>
42 #include <cstdlib>
43 #include <functional>
44 #include <iomanip>
45 #include <list>
46 #include <map>
47 #include <set>
48 #include <exception>
49 #include <sstream>
50 
52 #include "processEDAliases.h"
53 
54 namespace edm {
55 
56  class Maker;
57 
58  namespace {
59  using std::placeholders::_1;
60 
61  bool binary_search_string(std::vector<std::string> const& v, std::string const& s) {
62  return std::binary_search(v.begin(), v.end(), s);
63  }
64 
65  // Here we make the trigger results inserter directly. This should
66  // probably be a utility in the WorkerRegistry or elsewhere.
67 
68  std::shared_ptr<TriggerResultInserter> makeInserter(
69  ParameterSet& proc_pset,
70  PreallocationConfiguration const& iPrealloc,
71  ProductRegistry& preg,
72  ExceptionToActionTable const& actions,
73  std::shared_ptr<ActivityRegistry> areg,
74  std::shared_ptr<ProcessConfiguration const> processConfiguration) {
75  ParameterSet* trig_pset = proc_pset.getPSetForUpdate("@trigger_paths");
76  trig_pset->registerIt();
77 
78  WorkerParams work_args(trig_pset, preg, &iPrealloc, processConfiguration, actions);
79  ModuleDescription md(trig_pset->id(),
80  "TriggerResultInserter",
81  "TriggerResults",
82  processConfiguration.get(),
84 
85  areg->preModuleConstructionSignal_(md);
86  bool postCalled = false;
87  std::shared_ptr<TriggerResultInserter> returnValue;
88  // Caught exception is rethrown
89  CMS_SA_ALLOW try {
90  maker::ModuleHolderT<TriggerResultInserter> holder(
91  make_shared_noexcept_false<TriggerResultInserter>(*trig_pset, iPrealloc.numberOfStreams()),
92  static_cast<Maker const*>(nullptr));
93  holder.setModuleDescription(md);
94  holder.registerProductsAndCallbacks(&preg);
95  returnValue = holder.module();
96  postCalled = true;
97  // if exception then post will be called in the catch block
98  areg->postModuleConstructionSignal_(md);
99  } catch (...) {
100  if (!postCalled) {
101  CMS_SA_ALLOW try { areg->postModuleConstructionSignal_(md); } catch (...) {
102  // If post throws an exception ignore it because we are already handling another exception
103  }
104  }
105  throw;
106  }
107  return returnValue;
108  }
109 
110  template <typename T>
111  void makePathStatusInserters(std::vector<edm::propagate_const<std::shared_ptr<T>>>& pathStatusInserters,
112  std::vector<std::string> const& pathNames,
113  PreallocationConfiguration const& iPrealloc,
114  ProductRegistry& preg,
115  std::shared_ptr<ActivityRegistry> areg,
116  std::shared_ptr<ProcessConfiguration const> processConfiguration,
117  std::string const& moduleTypeName) {
119  pset.addParameter<std::string>("@module_type", moduleTypeName);
120  pset.addParameter<std::string>("@module_edm_type", "EDProducer");
121  pset.registerIt();
122 
123  pathStatusInserters.reserve(pathNames.size());
124 
125  for (auto const& pathName : pathNames) {
126  ModuleDescription md(
127  pset.id(), moduleTypeName, pathName, processConfiguration.get(), ModuleDescription::getUniqueID());
128 
129  areg->preModuleConstructionSignal_(md);
130  bool postCalled = false;
131  // Caught exception is rethrown
132  CMS_SA_ALLOW try {
133  maker::ModuleHolderT<T> holder(make_shared_noexcept_false<T>(iPrealloc.numberOfStreams()),
134  static_cast<Maker const*>(nullptr));
135  holder.setModuleDescription(md);
136  holder.registerProductsAndCallbacks(&preg);
137  pathStatusInserters.emplace_back(holder.module());
138  postCalled = true;
139  // if exception then post will be called in the catch block
140  areg->postModuleConstructionSignal_(md);
141  } catch (...) {
142  if (!postCalled) {
143  CMS_SA_ALLOW try { areg->postModuleConstructionSignal_(md); } catch (...) {
144  // If post throws an exception ignore it because we are already handling another exception
145  }
146  }
147  throw;
148  }
149  }
150  }
151 
152  typedef std::vector<std::string> vstring;
153 
154  void processSwitchProducers(ParameterSet const& proc_pset, std::string const& processName, ProductRegistry& preg) {
155  // Update Switch BranchDescriptions for the chosen case
156  struct BranchesCases {
157  BranchesCases(std::vector<std::string> cases) : caseLabels{std::move(cases)} {}
158  std::vector<BranchKey> chosenBranches;
159  std::vector<std::string> caseLabels;
160  };
161  std::map<std::string, BranchesCases> switchMap;
162  for (auto& prod : preg.productListUpdator()) {
163  if (prod.second.isSwitchAlias()) {
164  auto it = switchMap.find(prod.second.moduleLabel());
165  if (it == switchMap.end()) {
166  auto const& switchPSet = proc_pset.getParameter<edm::ParameterSet>(prod.second.moduleLabel());
167  auto inserted = switchMap.emplace(prod.second.moduleLabel(),
168  switchPSet.getParameter<std::vector<std::string>>("@all_cases"));
169  assert(inserted.second);
170  it = inserted.first;
171  }
172 
173  bool found = false;
174  for (auto const& productIter : preg.productList()) {
175  BranchKey const& branchKey = productIter.first;
176  // The alias-for product must be in the same process as
177  // the SwitchProducer (earlier processes or SubProcesses
178  // may contain products with same type, module label, and
179  // instance name)
180  if (branchKey.processName() != processName) {
181  continue;
182  }
183 
184  BranchDescription const& desc = productIter.second;
185  if (desc.branchType() == prod.second.branchType() and
186  desc.unwrappedTypeID().typeInfo() == prod.second.unwrappedTypeID().typeInfo() and
187  branchKey.moduleLabel() == prod.second.switchAliasModuleLabel() and
188  branchKey.productInstanceName() == prod.second.productInstanceName()) {
189  prod.second.setSwitchAliasForBranch(desc);
190  if (!prod.second.transient()) {
191  it->second.chosenBranches.push_back(prod.first); // with moduleLabel of the Switch
192  }
193  found = true;
194  }
195  }
196  if (not found) {
198  ex << "Trying to find a BranchDescription to be aliased-for by SwitchProducer with\n"
199  << " friendly class name = " << prod.second.friendlyClassName() << "\n"
200  << " module label = " << prod.second.moduleLabel() << "\n"
201  << " product instance name = " << prod.second.productInstanceName() << "\n"
202  << " process name = " << processName
203  << "\n\nbut did not find any. Please contact a framework developer.";
204  ex.addContext("Calling Schedule.cc:processSwitchProducers()");
205  throw ex;
206  }
207  }
208  }
209  if (switchMap.empty())
210  return;
211 
212  for (auto& elem : switchMap) {
213  std::sort(elem.second.chosenBranches.begin(), elem.second.chosenBranches.end());
214  }
215 
216  auto addProductsToException = [&preg, &processName](auto const& caseLabels, edm::Exception& ex) {
217  std::map<std::string, std::vector<BranchKey>> caseBranches;
218  for (auto const& item : preg.productList()) {
219  if (item.first.processName() != processName)
220  continue;
221 
222  if (auto found = std::find(caseLabels.begin(), caseLabels.end(), item.first.moduleLabel());
223  found != caseLabels.end()) {
224  caseBranches[*found].push_back(item.first);
225  }
226  }
227 
228  for (auto const& caseLabel : caseLabels) {
229  ex << "Products for case " << caseLabel << " (friendly class name, product instance name):\n";
230  auto& branches = caseBranches[caseLabel];
231  std::sort(branches.begin(), branches.end());
232  for (auto const& branch : branches) {
233  ex << " " << branch.friendlyClassName() << " " << branch.productInstanceName() << "\n";
234  }
235  }
236  };
237 
238  // Check that non-chosen cases declare exactly the same non-transient branches
239  // Also set the alias-for branches to transient
240  std::vector<bool> foundBranches;
241  for (auto const& switchItem : switchMap) {
242  auto const& switchLabel = switchItem.first;
243  auto const& chosenBranches = switchItem.second.chosenBranches;
244  auto const& caseLabels = switchItem.second.caseLabels;
245  foundBranches.resize(chosenBranches.size());
246  for (auto const& caseLabel : caseLabels) {
247  std::fill(foundBranches.begin(), foundBranches.end(), false);
248  for (auto& nonConstItem : preg.productListUpdator()) {
249  auto const& item = nonConstItem;
250  if (item.first.moduleLabel() == caseLabel and item.first.processName() == processName) {
251  // Check that products which are not transient in the dictionary are consistent between
252  // all the cases of a SwitchProducer.
253  if (!item.second.transient()) {
254  auto range = std::equal_range(chosenBranches.begin(),
255  chosenBranches.end(),
256  BranchKey(item.first.friendlyClassName(),
257  switchLabel,
258  item.first.productInstanceName(),
259  item.first.processName()));
260  if (range.first == range.second) {
262  ex << "SwitchProducer " << switchLabel << " has a case " << caseLabel << " with a product "
263  << item.first << " that is not produced by the chosen case "
264  << proc_pset.getParameter<edm::ParameterSet>(switchLabel)
265  .getUntrackedParameter<std::string>("@chosen_case")
266  << " and that product is not transient. "
267  << "If the intention is to produce only a subset of the non-transient products listed below, each "
268  "case with more non-transient products needs to be replaced with an EDAlias to only the "
269  "necessary products, and the EDProducer itself needs to be moved to a Task.\n\n";
270  addProductsToException(caseLabels, ex);
271  throw ex;
272  }
273  assert(std::distance(range.first, range.second) == 1);
274  foundBranches[std::distance(chosenBranches.begin(), range.first)] = true;
275  }
276 
277  // Set the alias-for branch as transient so it gets fully ignored in output.
278  // I tried first to implicitly drop all branches with
279  // '@' in ProductSelector, but that gave problems on
280  // input (those branches would be implicitly dropped on
281  // input as well, leading to the SwitchProducer branches
282  // do be dropped as dependent ones, as the alias
283  // detection logic in RootFile says that the
284  // SwitchProducer branches are not alias branches)
285  nonConstItem.second.setTransient(true);
286 
287  // Check that there are no BranchAliases for any of the cases
288  auto const& bd = item.second;
289  if (not bd.branchAliases().empty()) {
291  << "SwitchProducer does not support ROOT branch aliases. Got the following ROOT branch "
292  "aliases for SwitchProducer with label "
293  << switchLabel << " for case " << caseLabel << ":";
294  for (auto const& branchAlias : bd.branchAliases()) {
295  ex << " " << branchAlias;
296  }
297  throw ex;
298  }
299  }
300  }
301 
302  for (size_t i = 0; i < chosenBranches.size(); i++) {
303  if (not foundBranches[i]) {
304  auto chosenLabel = proc_pset.getParameter<edm::ParameterSet>(switchLabel)
305  .getUntrackedParameter<std::string>("@chosen_case");
307  ex << "SwitchProducer " << switchLabel << " has a case " << caseLabel
308  << " that does not produce a product " << chosenBranches[i] << " that is produced by the chosen case "
309  << chosenLabel << " and that product is not transient. "
310  << "If the intention is to produce only a subset of the non-transient products listed below, each "
311  "case with more non-transient products needs to be replaced with an EDAlias to only the "
312  "necessary products, and the EDProducer itself needs to be moved to a Task.\n\n";
313  addProductsToException(caseLabels, ex);
314  throw ex;
315  }
316  }
317  }
318  }
319  }
320 
321  void reduceParameterSet(ParameterSet& proc_pset,
322  vstring const& end_path_name_list,
323  vstring& modulesInConfig,
324  std::set<std::string> const& usedModuleLabels,
325  std::map<std::string, std::vector<std::pair<std::string, int>>>& outputModulePathPositions) {
326  // Before calculating the ParameterSetID of the top level ParameterSet or
327  // saving it in the registry drop from the top level ParameterSet all
328  // OutputModules and EDAnalyzers not on trigger paths. If unscheduled
329  // production is not enabled also drop all the EDFilters and EDProducers
330  // that are not scheduled. Drop the ParameterSet used to configure the module
331  // itself. Also drop the other traces of these labels in the top level
332  // ParameterSet: Remove that labels from @all_modules and from all the
333  // end paths. If this makes any end paths empty, then remove the end path
334  // name from @end_paths, and @paths.
335 
336  // First make a list of labels to drop
337  vstring outputModuleLabels;
338  std::string edmType;
339  std::string const moduleEdmType("@module_edm_type");
340  std::string const outputModule("OutputModule");
341  std::string const edAnalyzer("EDAnalyzer");
342  std::string const edFilter("EDFilter");
343  std::string const edProducer("EDProducer");
344 
345  std::set<std::string> modulesInConfigSet(modulesInConfig.begin(), modulesInConfig.end());
346 
347  //need a list of all modules on paths in order to determine
348  // if an EDAnalyzer only appears on an end path
349  vstring scheduledPaths = proc_pset.getParameter<vstring>("@paths");
350  std::set<std::string> modulesOnPaths;
351  {
352  std::set<std::string> noEndPaths(scheduledPaths.begin(), scheduledPaths.end());
353  for (auto const& endPath : end_path_name_list) {
354  noEndPaths.erase(endPath);
355  }
356  {
357  vstring labels;
358  for (auto const& path : noEndPaths) {
359  labels = proc_pset.getParameter<vstring>(path);
360  modulesOnPaths.insert(labels.begin(), labels.end());
361  }
362  }
363  }
364  //Initially fill labelsToBeDropped with all module mentioned in
365  // the configuration but which are not being used by the system
366  std::vector<std::string> labelsToBeDropped;
367  labelsToBeDropped.reserve(modulesInConfigSet.size());
368  std::set_difference(modulesInConfigSet.begin(),
369  modulesInConfigSet.end(),
370  usedModuleLabels.begin(),
371  usedModuleLabels.end(),
372  std::back_inserter(labelsToBeDropped));
373 
374  const unsigned int sizeBeforeOutputModules = labelsToBeDropped.size();
375  for (auto const& modLabel : usedModuleLabels) {
376  // Do nothing for modules that do not have a ParameterSet. Modules of type
377  // PathStatusInserter and EndPathStatusInserter will not have a ParameterSet.
378  if (proc_pset.existsAs<ParameterSet>(modLabel)) {
379  edmType = proc_pset.getParameterSet(modLabel).getParameter<std::string>(moduleEdmType);
380  if (edmType == outputModule) {
381  outputModuleLabels.push_back(modLabel);
382  labelsToBeDropped.push_back(modLabel);
383  }
384  if (edmType == edAnalyzer) {
385  if (modulesOnPaths.end() == modulesOnPaths.find(modLabel)) {
386  labelsToBeDropped.push_back(modLabel);
387  }
388  }
389  }
390  }
391  //labelsToBeDropped must be sorted
392  std::inplace_merge(
393  labelsToBeDropped.begin(), labelsToBeDropped.begin() + sizeBeforeOutputModules, labelsToBeDropped.end());
394 
395  // drop the parameter sets used to configure the modules
396  for_all(labelsToBeDropped, std::bind(&ParameterSet::eraseOrSetUntrackedParameterSet, std::ref(proc_pset), _1));
397 
398  // drop the labels from @all_modules
399  vstring::iterator endAfterRemove =
400  std::remove_if(modulesInConfig.begin(),
401  modulesInConfig.end(),
402  std::bind(binary_search_string, std::ref(labelsToBeDropped), _1));
403  modulesInConfig.erase(endAfterRemove, modulesInConfig.end());
404  proc_pset.addParameter<vstring>(std::string("@all_modules"), modulesInConfig);
405 
406  // drop the labels from all end paths
407  vstring endPathsToBeDropped;
408  vstring labels;
409  for (vstring::const_iterator iEndPath = end_path_name_list.begin(), endEndPath = end_path_name_list.end();
410  iEndPath != endEndPath;
411  ++iEndPath) {
412  labels = proc_pset.getParameter<vstring>(*iEndPath);
413  vstring::iterator iSave = labels.begin();
414  vstring::iterator iBegin = labels.begin();
415 
416  for (vstring::iterator iLabel = labels.begin(), iEnd = labels.end(); iLabel != iEnd; ++iLabel) {
417  if (binary_search_string(labelsToBeDropped, *iLabel)) {
418  if (binary_search_string(outputModuleLabels, *iLabel)) {
419  outputModulePathPositions[*iLabel].emplace_back(*iEndPath, iSave - iBegin);
420  }
421  } else {
422  if (iSave != iLabel) {
423  iSave->swap(*iLabel);
424  }
425  ++iSave;
426  }
427  }
428  labels.erase(iSave, labels.end());
429  if (labels.empty()) {
430  // remove empty end paths and save their names
431  proc_pset.eraseSimpleParameter(*iEndPath);
432  endPathsToBeDropped.push_back(*iEndPath);
433  } else {
434  proc_pset.addParameter<vstring>(*iEndPath, labels);
435  }
436  }
437  sort_all(endPathsToBeDropped);
438 
439  // remove empty end paths from @paths
440  endAfterRemove = std::remove_if(scheduledPaths.begin(),
441  scheduledPaths.end(),
442  std::bind(binary_search_string, std::ref(endPathsToBeDropped), _1));
443  scheduledPaths.erase(endAfterRemove, scheduledPaths.end());
444  proc_pset.addParameter<vstring>(std::string("@paths"), scheduledPaths);
445 
446  // remove empty end paths from @end_paths
447  vstring scheduledEndPaths = proc_pset.getParameter<vstring>("@end_paths");
448  endAfterRemove = std::remove_if(scheduledEndPaths.begin(),
449  scheduledEndPaths.end(),
450  std::bind(binary_search_string, std::ref(endPathsToBeDropped), _1));
451  scheduledEndPaths.erase(endAfterRemove, scheduledEndPaths.end());
452  proc_pset.addParameter<vstring>(std::string("@end_paths"), scheduledEndPaths);
453  }
454 
455  class RngEDConsumer : public EDConsumerBase {
456  public:
457  explicit RngEDConsumer(std::set<TypeID>& typesConsumed) {
459  if (rng.isAvailable()) {
460  rng->consumes(consumesCollector());
461  for (auto const& consumesInfo : this->consumesInfo()) {
462  typesConsumed.emplace(consumesInfo.type());
463  }
464  }
465  }
466  };
467 
468  template <typename F>
469  auto doCleanup(F&& iF) {
470  auto wrapped = [f = std::move(iF)](std::exception_ptr const* iPtr, edm::WaitingTaskHolder iTask) {
471  CMS_SA_ALLOW try { f(); } catch (...) {
472  }
473  if (iPtr) {
474  iTask.doneWaiting(*iPtr);
475  }
476  };
477  return wrapped;
478  }
479  } // namespace
480  // -----------------------------
481 
482  typedef std::vector<std::string> vstring;
483 
484  // -----------------------------
485 
487  service::TriggerNamesService const& tns,
488  ProductRegistry& preg,
490  std::shared_ptr<ActivityRegistry> areg,
491  std::shared_ptr<ProcessConfiguration const> processConfiguration,
492  PreallocationConfiguration const& prealloc,
493  ProcessContext const* processContext,
494  ModuleTypeResolverMaker const* resolverMaker)
495  : //Only create a resultsInserter if there is a trigger path
496  resultsInserter_{tns.getTrigPaths().empty()
497  ? std::shared_ptr<TriggerResultInserter>{}
498  : makeInserter(proc_pset, prealloc, preg, actions, areg, processConfiguration)},
499  moduleRegistry_(std::make_shared<ModuleRegistry>(resolverMaker)),
500  all_output_communicators_(),
501  preallocConfig_(prealloc),
502  pathNames_(&tns.getTrigPaths()),
503  endPathNames_(&tns.getEndPaths()),
504  wantSummary_(tns.wantSummary()) {
505  makePathStatusInserters(pathStatusInserters_,
506  *pathNames_,
507  prealloc,
508  preg,
509  areg,
510  processConfiguration,
511  std::string("PathStatusInserter"));
512 
513  makePathStatusInserters(endPathStatusInserters_,
514  *endPathNames_,
515  prealloc,
516  preg,
517  areg,
518  processConfiguration,
519  std::string("EndPathStatusInserter"));
520 
521  assert(0 < prealloc.numberOfStreams());
522  streamSchedules_.reserve(prealloc.numberOfStreams());
523  for (unsigned int i = 0; i < prealloc.numberOfStreams(); ++i) {
524  streamSchedules_.emplace_back(make_shared_noexcept_false<StreamSchedule>(resultsInserter(),
525  pathStatusInserters_,
526  endPathStatusInserters_,
527  moduleRegistry(),
528  proc_pset,
529  tns,
530  prealloc,
531  preg,
532  actions,
533  areg,
534  processConfiguration,
535  StreamID{i},
536  processContext));
537  }
538 
539  //TriggerResults are injected automatically by StreamSchedules and are
540  // unknown to the ModuleRegistry
541  const std::string kTriggerResults("TriggerResults");
542  std::vector<std::string> modulesToUse;
543  modulesToUse.reserve(streamSchedules_[0]->allWorkers().size());
544  for (auto const& worker : streamSchedules_[0]->allWorkers()) {
545  if (worker->description()->moduleLabel() != kTriggerResults) {
546  modulesToUse.push_back(worker->description()->moduleLabel());
547  }
548  }
549  //The unscheduled modules are at the end of the list, but we want them at the front
550  unsigned int const nUnscheduledModules = streamSchedules_[0]->numberOfUnscheduledModules();
551  if (nUnscheduledModules > 0) {
552  std::vector<std::string> temp;
553  temp.reserve(modulesToUse.size());
554  auto itBeginUnscheduled = modulesToUse.begin() + modulesToUse.size() - nUnscheduledModules;
555  std::copy(itBeginUnscheduled, modulesToUse.end(), std::back_inserter(temp));
556  std::copy(modulesToUse.begin(), itBeginUnscheduled, std::back_inserter(temp));
557  temp.swap(modulesToUse);
558  }
559 
560  // propagate_const<T> has no reset() function
561  globalSchedule_ = std::make_unique<GlobalSchedule>(resultsInserter(),
562  pathStatusInserters_,
563  endPathStatusInserters_,
564  moduleRegistry(),
565  modulesToUse,
566  proc_pset,
567  preg,
568  prealloc,
569  actions,
570  areg,
571  processConfiguration,
572  processContext);
573  }
574 
576  service::TriggerNamesService const& tns,
577  ProductRegistry& preg,
578  BranchIDListHelper& branchIDListHelper,
579  ProcessBlockHelperBase& processBlockHelper,
580  ThinnedAssociationsHelper& thinnedAssociationsHelper,
581  SubProcessParentageHelper const* subProcessParentageHelper,
582  std::shared_ptr<ActivityRegistry> areg,
583  std::shared_ptr<ProcessConfiguration> processConfiguration,
584  bool hasSubprocesses,
585  PreallocationConfiguration const& prealloc,
586  ProcessContext const* processContext) {
587  //TriggerResults is not in the top level ParameterSet so the call to
588  // reduceParameterSet would fail to find it. Just remove it up front.
589  const std::string kTriggerResults("TriggerResults");
590 
591  std::set<std::string> usedModuleLabels;
592  for (auto const& worker : allWorkers()) {
593  if (worker->description()->moduleLabel() != kTriggerResults) {
594  usedModuleLabels.insert(worker->description()->moduleLabel());
595  }
596  }
597  std::vector<std::string> modulesInConfig(proc_pset.getParameter<std::vector<std::string>>("@all_modules"));
598  std::map<std::string, std::vector<std::pair<std::string, int>>> outputModulePathPositions;
599  reduceParameterSet(proc_pset, tns.getEndPaths(), modulesInConfig, usedModuleLabels, outputModulePathPositions);
600  {
601  std::vector<std::string> aliases = proc_pset.getParameter<std::vector<std::string>>("@all_aliases");
602  detail::processEDAliases(aliases, {}, proc_pset, processConfiguration->processName(), preg);
603  }
604 
605  // At this point all BranchDescriptions are created. Mark now the
606  // ones of unscheduled workers to be on-demand.
607  {
608  auto const& unsched = streamSchedules_[0]->unscheduledWorkers();
609  if (not unsched.empty()) {
610  std::set<std::string> unscheduledModules;
611  std::transform(unsched.begin(),
612  unsched.end(),
613  std::insert_iterator<std::set<std::string>>(unscheduledModules, unscheduledModules.begin()),
614  [](auto worker) { return worker->description()->moduleLabel(); });
615  preg.setUnscheduledProducts(unscheduledModules);
616  }
617  }
618 
619  processSwitchProducers(proc_pset, processConfiguration->processName(), preg);
620  proc_pset.registerIt();
621  processConfiguration->setParameterSetID(proc_pset.id());
622  processConfiguration->setProcessConfigurationID();
623 
624  // This is used for a little sanity-check to make sure no code
625  // modifications alter the number of workers at a later date.
626  size_t all_workers_count = allWorkers().size();
627 
628  moduleRegistry_->forAllModuleHolders([this](maker::ModuleHolder* iHolder) {
629  auto comm = iHolder->createOutputModuleCommunicator();
630  if (comm) {
631  all_output_communicators_.emplace_back(std::shared_ptr<OutputModuleCommunicator>{comm.release()});
632  }
633  });
634  // Now that the output workers are filled in, set any output limits or information.
635  limitOutput(proc_pset, branchIDListHelper.branchIDLists(), subProcessParentageHelper);
636 
637  // Sanity check: make sure nobody has added a worker after we've
638  // already relied on the WorkerManager being full.
639  assert(all_workers_count == allWorkers().size());
640 
641  branchIDListHelper.updateFromRegistry(preg);
642 
643  for (auto const& worker : streamSchedules_[0]->allWorkers()) {
644  worker->registerThinnedAssociations(preg, thinnedAssociationsHelper);
645  }
646 
647  processBlockHelper.updateForNewProcess(preg, processConfiguration->processName());
648 
649  // The output modules consume products in kept branches.
650  // So we must set this up before freezing.
651  for (auto& c : all_output_communicators_) {
652  c->selectProducts(preg, thinnedAssociationsHelper, processBlockHelper);
653  }
654 
655  for (auto& product : preg.productListUpdator()) {
656  setIsMergeable(product.second);
657  }
658 
659  {
660  // We now get a collection of types that may be consumed.
661  std::set<TypeID> productTypesConsumed;
662  std::set<TypeID> elementTypesConsumed;
663  // Loop over all modules
664  for (auto const& worker : allWorkers()) {
665  for (auto const& consumesInfo : worker->consumesInfo()) {
666  if (consumesInfo.kindOfType() == PRODUCT_TYPE) {
667  productTypesConsumed.emplace(consumesInfo.type());
668  } else {
669  elementTypesConsumed.emplace(consumesInfo.type());
670  }
671  }
672  }
673  // The SubProcess class is not a module, yet it may consume.
674  if (hasSubprocesses) {
675  productTypesConsumed.emplace(typeid(TriggerResults));
676  }
677  // The RandomNumberGeneratorService is not a module, yet it consumes.
678  { RngEDConsumer rngConsumer = RngEDConsumer(productTypesConsumed); }
679  preg.setFrozen(productTypesConsumed, elementTypesConsumed, processConfiguration->processName());
680  }
681 
682  for (auto& c : all_output_communicators_) {
683  c->setEventSelectionInfo(outputModulePathPositions, preg.anyProductProduced());
684  }
685 
686  if (wantSummary_) {
687  std::vector<const ModuleDescription*> modDesc;
688  const auto& workers = allWorkers();
689  modDesc.reserve(workers.size());
690 
691  std::transform(workers.begin(),
692  workers.end(),
693  std::back_inserter(modDesc),
694  [](const Worker* iWorker) -> const ModuleDescription* { return iWorker->description(); });
695 
696  // propagate_const<T> has no reset() function
697  summaryTimeKeeper_ = std::make_unique<SystemTimeKeeper>(prealloc.numberOfStreams(), modDesc, tns, processContext);
698  auto timeKeeperPtr = summaryTimeKeeper_.get();
699 
700  areg->watchPreModuleDestruction(timeKeeperPtr, &SystemTimeKeeper::removeModuleIfExists);
701 
702  areg->watchPreModuleEvent(timeKeeperPtr, &SystemTimeKeeper::startModuleEvent);
703  areg->watchPostModuleEvent(timeKeeperPtr, &SystemTimeKeeper::stopModuleEvent);
704  areg->watchPreModuleEventAcquire(timeKeeperPtr, &SystemTimeKeeper::restartModuleEvent);
705  areg->watchPostModuleEventAcquire(timeKeeperPtr, &SystemTimeKeeper::stopModuleEvent);
706  areg->watchPreModuleEventDelayedGet(timeKeeperPtr, &SystemTimeKeeper::pauseModuleEvent);
707  areg->watchPostModuleEventDelayedGet(timeKeeperPtr, &SystemTimeKeeper::restartModuleEvent);
708 
709  areg->watchPreSourceEvent(timeKeeperPtr, &SystemTimeKeeper::startEvent);
710  areg->watchPostEvent(timeKeeperPtr, &SystemTimeKeeper::stopEvent);
711 
712  areg->watchPrePathEvent(timeKeeperPtr, &SystemTimeKeeper::startPath);
713  areg->watchPostPathEvent(timeKeeperPtr, &SystemTimeKeeper::stopPath);
714 
715  areg->watchPostBeginJob(timeKeeperPtr, &SystemTimeKeeper::startProcessingLoop);
716  areg->watchPreEndJob(timeKeeperPtr, &SystemTimeKeeper::stopProcessingLoop);
717  //areg->preModuleEventSignal_.connect([timeKeeperPtr](StreamContext const& iContext, ModuleCallingContext const& iMod) {
718  //timeKeeperPtr->startModuleEvent(iContext,iMod);
719  //});
720  }
721 
722  } // Schedule::Schedule
723 
724  void Schedule::limitOutput(ParameterSet const& proc_pset,
725  BranchIDLists const& branchIDLists,
726  SubProcessParentageHelper const* subProcessParentageHelper) {
727  std::string const output("output");
728 
729  ParameterSet const& maxEventsPSet = proc_pset.getUntrackedParameterSet("maxEvents");
730  int maxEventSpecs = 0;
731  int maxEventsOut = -1;
732  ParameterSet const* vMaxEventsOut = nullptr;
733  std::vector<std::string> intNamesE = maxEventsPSet.getParameterNamesForType<int>(false);
734  if (search_all(intNamesE, output)) {
735  maxEventsOut = maxEventsPSet.getUntrackedParameter<int>(output);
736  ++maxEventSpecs;
737  }
738  std::vector<std::string> psetNamesE;
739  maxEventsPSet.getParameterSetNames(psetNamesE, false);
740  if (search_all(psetNamesE, output)) {
741  vMaxEventsOut = &maxEventsPSet.getUntrackedParameterSet(output);
742  ++maxEventSpecs;
743  }
744 
745  if (maxEventSpecs > 1) {
747  << "\nAt most, one form of 'output' may appear in the 'maxEvents' parameter set";
748  }
749 
750  for (auto& c : all_output_communicators_) {
751  OutputModuleDescription desc(branchIDLists, maxEventsOut, subProcessParentageHelper);
752  if (vMaxEventsOut != nullptr && !vMaxEventsOut->empty()) {
753  std::string const& moduleLabel = c->description().moduleLabel();
754  try {
755  desc.maxEvents_ = vMaxEventsOut->getUntrackedParameter<int>(moduleLabel);
756  } catch (Exception const&) {
758  << "\nNo entry in 'maxEvents' for output module label '" << moduleLabel << "'.\n";
759  }
760  }
761  c->configure(desc);
762  }
763  }
764 
765  bool Schedule::terminate() const {
766  if (all_output_communicators_.empty()) {
767  return false;
768  }
769  for (auto& c : all_output_communicators_) {
770  if (!c->limitReached()) {
771  // Found an output module that has not reached output event count.
772  return false;
773  }
774  }
775  LogInfo("SuccessfulTermination") << "The job is terminating successfully because each output module\n"
776  << "has reached its configured limit.\n";
777  return true;
778  }
779 
781  globalSchedule_->endJob(collector);
782  if (collector.hasThrown()) {
783  return;
784  }
785 
786  if (wantSummary_ == false)
787  return;
788  {
789  TriggerReport tr;
790  getTriggerReport(tr);
791 
792  // The trigger report (pass/fail etc.):
793 
794  LogFwkVerbatim("FwkSummary") << "";
795  if (streamSchedules_[0]->context().processContext()->isSubProcess()) {
796  LogFwkVerbatim("FwkSummary") << "TrigReport Process: "
797  << streamSchedules_[0]->context().processContext()->processName();
798  }
799  LogFwkVerbatim("FwkSummary") << "TrigReport "
800  << "---------- Event Summary ------------";
801  if (!tr.trigPathSummaries.empty()) {
802  LogFwkVerbatim("FwkSummary") << "TrigReport"
803  << " Events total = " << tr.eventSummary.totalEvents
804  << " passed = " << tr.eventSummary.totalEventsPassed
805  << " failed = " << tr.eventSummary.totalEventsFailed << "";
806  } else {
807  LogFwkVerbatim("FwkSummary") << "TrigReport"
808  << " Events total = " << tr.eventSummary.totalEvents
809  << " passed = " << tr.eventSummary.totalEvents << " failed = 0";
810  }
811 
812  LogFwkVerbatim("FwkSummary") << "";
813  LogFwkVerbatim("FwkSummary") << "TrigReport "
814  << "---------- Path Summary ------------";
815  LogFwkVerbatim("FwkSummary") << "TrigReport " << std::right << std::setw(10) << "Trig Bit#"
816  << " " << std::right << std::setw(10) << "Executed"
817  << " " << std::right << std::setw(10) << "Passed"
818  << " " << std::right << std::setw(10) << "Failed"
819  << " " << std::right << std::setw(10) << "Error"
820  << " "
821  << "Name"
822  << "";
823  for (auto const& p : tr.trigPathSummaries) {
824  LogFwkVerbatim("FwkSummary") << "TrigReport " << std::right << std::setw(5) << 1 << std::right << std::setw(5)
825  << p.bitPosition << " " << std::right << std::setw(10) << p.timesRun << " "
826  << std::right << std::setw(10) << p.timesPassed << " " << std::right
827  << std::setw(10) << p.timesFailed << " " << std::right << std::setw(10)
828  << p.timesExcept << " " << p.name << "";
829  }
830 
831  /*
832  std::vector<int>::const_iterator epi = empty_trig_paths_.begin();
833  std::vector<int>::const_iterator epe = empty_trig_paths_.end();
834  std::vector<std::string>::const_iterator epn = empty_trig_path_names_.begin();
835  for (; epi != epe; ++epi, ++epn) {
836 
837  LogFwkVerbatim("FwkSummary") << "TrigReport "
838  << std::right << std::setw(5) << 1
839  << std::right << std::setw(5) << *epi << " "
840  << std::right << std::setw(10) << totalEvents() << " "
841  << std::right << std::setw(10) << totalEvents() << " "
842  << std::right << std::setw(10) << 0 << " "
843  << std::right << std::setw(10) << 0 << " "
844  << *epn << "";
845  }
846  */
847 
848  LogFwkVerbatim("FwkSummary") << "";
849  LogFwkVerbatim("FwkSummary") << "TrigReport "
850  << "-------End-Path Summary ------------";
851  LogFwkVerbatim("FwkSummary") << "TrigReport " << std::right << std::setw(10) << "Trig Bit#"
852  << " " << std::right << std::setw(10) << "Executed"
853  << " " << std::right << std::setw(10) << "Passed"
854  << " " << std::right << std::setw(10) << "Failed"
855  << " " << std::right << std::setw(10) << "Error"
856  << " "
857  << "Name"
858  << "";
859  for (auto const& p : tr.endPathSummaries) {
860  LogFwkVerbatim("FwkSummary") << "TrigReport " << std::right << std::setw(5) << 0 << std::right << std::setw(5)
861  << p.bitPosition << " " << std::right << std::setw(10) << p.timesRun << " "
862  << std::right << std::setw(10) << p.timesPassed << " " << std::right
863  << std::setw(10) << p.timesFailed << " " << std::right << std::setw(10)
864  << p.timesExcept << " " << p.name << "";
865  }
866 
867  for (auto const& p : tr.trigPathSummaries) {
868  LogFwkVerbatim("FwkSummary") << "";
869  LogFwkVerbatim("FwkSummary") << "TrigReport "
870  << "---------- Modules in Path: " << p.name << " ------------";
871  LogFwkVerbatim("FwkSummary") << "TrigReport " << std::right << std::setw(10) << "Trig Bit#"
872  << " " << std::right << std::setw(10) << "Visited"
873  << " " << std::right << std::setw(10) << "Passed"
874  << " " << std::right << std::setw(10) << "Failed"
875  << " " << std::right << std::setw(10) << "Error"
876  << " "
877  << "Name"
878  << "";
879 
880  for (auto const& mod : p.moduleInPathSummaries) {
881  LogFwkVerbatim("FwkSummary") << "TrigReport " << std::right << std::setw(5) << 1 << std::right << std::setw(5)
882  << mod.bitPosition << " " << std::right << std::setw(10) << mod.timesVisited
883  << " " << std::right << std::setw(10) << mod.timesPassed << " " << std::right
884  << std::setw(10) << mod.timesFailed << " " << std::right << std::setw(10)
885  << mod.timesExcept << " " << mod.moduleLabel << "";
886  }
887  }
888 
889  for (auto const& p : tr.endPathSummaries) {
890  LogFwkVerbatim("FwkSummary") << "";
891  LogFwkVerbatim("FwkSummary") << "TrigReport "
892  << "------ Modules in End-Path: " << p.name << " ------------";
893  LogFwkVerbatim("FwkSummary") << "TrigReport " << std::right << std::setw(10) << "Trig Bit#"
894  << " " << std::right << std::setw(10) << "Visited"
895  << " " << std::right << std::setw(10) << "Passed"
896  << " " << std::right << std::setw(10) << "Failed"
897  << " " << std::right << std::setw(10) << "Error"
898  << " "
899  << "Name"
900  << "";
901 
902  unsigned int bitpos = 0;
903  for (auto const& mod : p.moduleInPathSummaries) {
904  LogFwkVerbatim("FwkSummary") << "TrigReport " << std::right << std::setw(5) << 0 << std::right << std::setw(5)
905  << bitpos << " " << std::right << std::setw(10) << mod.timesVisited << " "
906  << std::right << std::setw(10) << mod.timesPassed << " " << std::right
907  << std::setw(10) << mod.timesFailed << " " << std::right << std::setw(10)
908  << mod.timesExcept << " " << mod.moduleLabel << "";
909  ++bitpos;
910  }
911  }
912 
913  LogFwkVerbatim("FwkSummary") << "";
914  LogFwkVerbatim("FwkSummary") << "TrigReport "
915  << "---------- Module Summary ------------";
916  LogFwkVerbatim("FwkSummary") << "TrigReport " << std::right << std::setw(10) << "Visited"
917  << " " << std::right << std::setw(10) << "Executed"
918  << " " << std::right << std::setw(10) << "Passed"
919  << " " << std::right << std::setw(10) << "Failed"
920  << " " << std::right << std::setw(10) << "Error"
921  << " "
922  << "Name"
923  << "";
924  for (auto const& worker : tr.workerSummaries) {
925  LogFwkVerbatim("FwkSummary") << "TrigReport " << std::right << std::setw(10) << worker.timesVisited << " "
926  << std::right << std::setw(10) << worker.timesRun << " " << std::right
927  << std::setw(10) << worker.timesPassed << " " << std::right << std::setw(10)
928  << worker.timesFailed << " " << std::right << std::setw(10) << worker.timesExcept
929  << " " << worker.moduleLabel << "";
930  }
931  LogFwkVerbatim("FwkSummary") << "";
932  }
933  // The timing report (CPU and Real Time):
936 
937  const int totalEvents = std::max(1, tr.eventSummary.totalEvents);
938 
939  LogFwkVerbatim("FwkSummary") << "TimeReport "
940  << "---------- Event Summary ---[sec]----";
941  LogFwkVerbatim("FwkSummary") << "TimeReport" << std::setprecision(6) << std::fixed
942  << " event loop CPU/event = " << tr.eventSummary.cpuTime / totalEvents;
943  LogFwkVerbatim("FwkSummary") << "TimeReport" << std::setprecision(6) << std::fixed
944  << " event loop Real/event = " << tr.eventSummary.realTime / totalEvents;
945  LogFwkVerbatim("FwkSummary") << "TimeReport" << std::setprecision(6) << std::fixed
946  << " sum Streams Real/event = " << tr.eventSummary.sumStreamRealTime / totalEvents;
947  LogFwkVerbatim("FwkSummary") << "TimeReport" << std::setprecision(6) << std::fixed
948  << " efficiency CPU/Real/thread = "
951 
952  constexpr int kColumn1Size = 10;
953  constexpr int kColumn2Size = 12;
954  constexpr int kColumn3Size = 12;
955  LogFwkVerbatim("FwkSummary") << "";
956  LogFwkVerbatim("FwkSummary") << "TimeReport "
957  << "---------- Path Summary ---[Real sec]----";
958  LogFwkVerbatim("FwkSummary") << "TimeReport " << std::right << std::setw(kColumn1Size) << "per event"
959  << " " << std::right << std::setw(kColumn2Size) << "per exec"
960  << " Name";
961  for (auto const& p : tr.trigPathSummaries) {
962  const int timesRun = std::max(1, p.timesRun);
963  LogFwkVerbatim("FwkSummary") << "TimeReport " << std::setprecision(6) << std::fixed << std::right
964  << std::setw(kColumn1Size) << p.realTime / totalEvents << " " << std::right
965  << std::setw(kColumn2Size) << p.realTime / timesRun << " " << p.name << "";
966  }
967  LogFwkVerbatim("FwkSummary") << "TimeReport " << std::right << std::setw(kColumn1Size) << "per event"
968  << " " << std::right << std::setw(kColumn2Size) << "per exec"
969  << " Name"
970  << "";
971 
972  LogFwkVerbatim("FwkSummary") << "";
973  LogFwkVerbatim("FwkSummary") << "TimeReport "
974  << "-------End-Path Summary ---[Real sec]----";
975  LogFwkVerbatim("FwkSummary") << "TimeReport " << std::right << std::setw(kColumn1Size) << "per event"
976  << " " << std::right << std::setw(kColumn2Size) << "per exec"
977  << " Name"
978  << "";
979  for (auto const& p : tr.endPathSummaries) {
980  const int timesRun = std::max(1, p.timesRun);
981 
982  LogFwkVerbatim("FwkSummary") << "TimeReport " << std::setprecision(6) << std::fixed << std::right
983  << std::setw(kColumn1Size) << p.realTime / totalEvents << " " << std::right
984  << std::setw(kColumn2Size) << p.realTime / timesRun << " " << p.name << "";
985  }
986  LogFwkVerbatim("FwkSummary") << "TimeReport " << std::right << std::setw(kColumn1Size) << "per event"
987  << " " << std::right << std::setw(kColumn2Size) << "per exec"
988  << " Name"
989  << "";
990 
991  for (auto const& p : tr.trigPathSummaries) {
992  LogFwkVerbatim("FwkSummary") << "";
993  LogFwkVerbatim("FwkSummary") << "TimeReport "
994  << "---------- Modules in Path: " << p.name << " ---[Real sec]----";
995  LogFwkVerbatim("FwkSummary") << "TimeReport " << std::right << std::setw(kColumn1Size) << "per event"
996  << " " << std::right << std::setw(kColumn2Size) << "per visit"
997  << " Name"
998  << "";
999  for (auto const& mod : p.moduleInPathSummaries) {
1000  LogFwkVerbatim("FwkSummary") << "TimeReport " << std::setprecision(6) << std::fixed << std::right
1001  << std::setw(kColumn1Size) << mod.realTime / totalEvents << " " << std::right
1002  << std::setw(kColumn2Size) << mod.realTime / std::max(1, mod.timesVisited) << " "
1003  << mod.moduleLabel << "";
1004  }
1005  }
1006  if (not tr.trigPathSummaries.empty()) {
1007  LogFwkVerbatim("FwkSummary") << "TimeReport " << std::right << std::setw(kColumn1Size) << "per event"
1008  << " " << std::right << std::setw(kColumn2Size) << "per visit"
1009  << " Name"
1010  << "";
1011  }
1012  for (auto const& p : tr.endPathSummaries) {
1013  LogFwkVerbatim("FwkSummary") << "";
1014  LogFwkVerbatim("FwkSummary") << "TimeReport "
1015  << "------ Modules in End-Path: " << p.name << " ---[Real sec]----";
1016  LogFwkVerbatim("FwkSummary") << "TimeReport " << std::right << std::setw(kColumn1Size) << "per event"
1017  << " " << std::right << std::setw(kColumn2Size) << "per visit"
1018  << " Name"
1019  << "";
1020  for (auto const& mod : p.moduleInPathSummaries) {
1021  LogFwkVerbatim("FwkSummary") << "TimeReport " << std::setprecision(6) << std::fixed << std::right
1022  << std::setw(kColumn1Size) << mod.realTime / totalEvents << " " << std::right
1023  << std::setw(kColumn2Size) << mod.realTime / std::max(1, mod.timesVisited) << " "
1024  << mod.moduleLabel << "";
1025  }
1026  }
1027  if (not tr.endPathSummaries.empty()) {
1028  LogFwkVerbatim("FwkSummary") << "TimeReport " << std::right << std::setw(kColumn1Size) << "per event"
1029  << " " << std::right << std::setw(kColumn2Size) << "per visit"
1030  << " Name"
1031  << "";
1032  }
1033  LogFwkVerbatim("FwkSummary") << "";
1034  LogFwkVerbatim("FwkSummary") << "TimeReport "
1035  << "---------- Module Summary ---[Real sec]----";
1036  LogFwkVerbatim("FwkSummary") << "TimeReport " << std::right << std::setw(kColumn1Size) << "per event"
1037  << " " << std::right << std::setw(kColumn2Size) << "per exec"
1038  << " " << std::right << std::setw(kColumn3Size) << "per visit"
1039  << " Name"
1040  << "";
1041  for (auto const& worker : tr.workerSummaries) {
1042  LogFwkVerbatim("FwkSummary") << "TimeReport " << std::setprecision(6) << std::fixed << std::right
1043  << std::setw(kColumn1Size) << worker.realTime / totalEvents << " " << std::right
1044  << std::setw(kColumn2Size) << worker.realTime / std::max(1, worker.timesRun) << " "
1045  << std::right << std::setw(kColumn3Size)
1046  << worker.realTime / std::max(1, worker.timesVisited) << " " << worker.moduleLabel
1047  << "";
1048  }
1049  LogFwkVerbatim("FwkSummary") << "TimeReport " << std::right << std::setw(kColumn1Size) << "per event"
1050  << " " << std::right << std::setw(kColumn2Size) << "per exec"
1051  << " " << std::right << std::setw(kColumn3Size) << "per visit"
1052  << " Name"
1053  << "";
1054 
1055  LogFwkVerbatim("FwkSummary") << "";
1056  LogFwkVerbatim("FwkSummary") << "T---Report end!"
1057  << "";
1058  LogFwkVerbatim("FwkSummary") << "";
1059  }
1060 
1062  using std::placeholders::_1;
1064  for (auto& worker : allWorkers()) {
1065  worker->respondToCloseOutputFile();
1066  }
1067  }
1068 
1070  using std::placeholders::_1;
1071  for_all(all_output_communicators_, std::bind(&OutputModuleCommunicator::openFile, _1, std::cref(fb)));
1072  }
1073 
1075  RunPrincipal const& rp,
1076  ProcessContext const* processContext,
1077  ActivityRegistry* activityRegistry,
1078  MergeableRunProductMetadata const* mergeableRunProductMetadata) {
1081  LuminosityBlockID(rp.run(), 0),
1082  rp.index(),
1084  rp.endTime(),
1085  processContext);
1086 
1087  using namespace edm::waiting_task;
1088  chain::first([&](auto nextTask) {
1089  //services can depend on other services
1091 
1092  // Propagating the exception would be nontrivial, and signal actions are not supposed to throw exceptions
1093  CMS_SA_ALLOW try { activityRegistry->preGlobalWriteRunSignal_(globalContext); } catch (...) {
1094  }
1095  for (auto& c : all_output_communicators_) {
1096  c->writeRunAsync(nextTask, rp, processContext, activityRegistry, mergeableRunProductMetadata);
1097  }
1098  }) | chain::then(doCleanup([activityRegistry, globalContext, token]() {
1099  //services can depend on other services
1101 
1102  activityRegistry->postGlobalWriteRunSignal_(globalContext);
1103  })) |
1105  }
1106 
1108  ProcessBlockPrincipal const& pbp,
1109  ProcessContext const* processContext,
1110  ActivityRegistry* activityRegistry) {
1117  processContext);
1118 
1119  using namespace edm::waiting_task;
1120  chain::first([&](auto nextTask) {
1121  // Propagating the exception would be nontrivial, and signal actions are not supposed to throw exceptions
1123  CMS_SA_ALLOW try { activityRegistry->preWriteProcessBlockSignal_(globalContext); } catch (...) {
1124  }
1125  for (auto& c : all_output_communicators_) {
1126  c->writeProcessBlockAsync(nextTask, pbp, processContext, activityRegistry);
1127  }
1128  }) | chain::then(doCleanup([activityRegistry, globalContext, token]() {
1129  //services can depend on other services
1131 
1132  activityRegistry->postWriteProcessBlockSignal_(globalContext);
1133  })) |
1135  }
1136 
1138  LuminosityBlockPrincipal const& lbp,
1139  ProcessContext const* processContext,
1140  ActivityRegistry* activityRegistry) {
1143  lbp.id(),
1144  lbp.runPrincipal().index(),
1145  lbp.index(),
1146  lbp.beginTime(),
1147  processContext);
1148 
1149  using namespace edm::waiting_task;
1150  chain::first([&](auto nextTask) {
1152  CMS_SA_ALLOW try { activityRegistry->preGlobalWriteLumiSignal_(globalContext); } catch (...) {
1153  }
1154  for (auto& c : all_output_communicators_) {
1155  c->writeLumiAsync(nextTask, lbp, processContext, activityRegistry);
1156  }
1157  }) | chain::then(doCleanup([activityRegistry, globalContext, token]() {
1158  //services can depend on other services
1160 
1161  activityRegistry->postGlobalWriteLumiSignal_(globalContext);
1162  })) |
1164  }
1165 
1167  using std::placeholders::_1;
1168  // Return true iff at least one output module returns true.
1169  return (std::find_if(all_output_communicators_.begin(),
1173  }
1174 
1176  using std::placeholders::_1;
1177  for_all(allWorkers(), std::bind(&Worker::respondToOpenInputFile, _1, std::cref(fb)));
1178  }
1179 
1181  using std::placeholders::_1;
1182  for_all(allWorkers(), std::bind(&Worker::respondToCloseInputFile, _1, std::cref(fb)));
1183  }
1184 
1185  void Schedule::beginJob(ProductRegistry const& iRegistry,
1186  eventsetup::ESRecordsToProxyIndices const& iESIndices,
1187  ProcessBlockHelperBase const& processBlockHelperBase) {
1188  globalSchedule_->beginJob(iRegistry, iESIndices, processBlockHelperBase);
1189  }
1190 
1191  void Schedule::beginStream(unsigned int iStreamID) {
1192  assert(iStreamID < streamSchedules_.size());
1193  streamSchedules_[iStreamID]->beginStream();
1194  }
1195 
1196  void Schedule::endStream(unsigned int iStreamID) {
1197  assert(iStreamID < streamSchedules_.size());
1198  streamSchedules_[iStreamID]->endStream();
1199  }
1200 
1202  unsigned int iStreamID,
1204  ServiceToken const& token) {
1205  assert(iStreamID < streamSchedules_.size());
1206  streamSchedules_[iStreamID]->processOneEventAsync(std::move(iTask), info, token, pathStatusInserters_);
1207  }
1208 
1210  ParameterSet const& iPSet,
1211  const ProductRegistry& iRegistry,
1212  eventsetup::ESRecordsToProxyIndices const& iIndices) {
1213  Worker* found = nullptr;
1214  for (auto const& worker : allWorkers()) {
1215  if (worker->description()->moduleLabel() == iLabel) {
1216  found = worker;
1217  break;
1218  }
1219  }
1220  if (nullptr == found) {
1221  return false;
1222  }
1223 
1224  auto newMod = moduleRegistry_->replaceModule(iLabel, iPSet, preallocConfig_);
1225 
1226  globalSchedule_->replaceModule(newMod, iLabel);
1227 
1228  for (auto& s : streamSchedules_) {
1229  s->replaceModule(newMod, iLabel);
1230  }
1231 
1232  {
1233  //Need to updateLookup in order to make getByToken work
1234  auto const processBlockLookup = iRegistry.productLookup(InProcess);
1235  auto const runLookup = iRegistry.productLookup(InRun);
1236  auto const lumiLookup = iRegistry.productLookup(InLumi);
1237  auto const eventLookup = iRegistry.productLookup(InEvent);
1238  found->updateLookup(InProcess, *runLookup);
1239  found->updateLookup(InRun, *runLookup);
1240  found->updateLookup(InLumi, *lumiLookup);
1241  found->updateLookup(InEvent, *eventLookup);
1242  found->updateLookup(iIndices);
1243 
1244  auto const& processName = newMod->moduleDescription().processName();
1245  auto const& processBlockModuleToIndicies = processBlockLookup->indiciesForModulesInProcess(processName);
1246  auto const& runModuleToIndicies = runLookup->indiciesForModulesInProcess(processName);
1247  auto const& lumiModuleToIndicies = lumiLookup->indiciesForModulesInProcess(processName);
1248  auto const& eventModuleToIndicies = eventLookup->indiciesForModulesInProcess(processName);
1249  found->resolvePutIndicies(InProcess, processBlockModuleToIndicies);
1250  found->resolvePutIndicies(InRun, runModuleToIndicies);
1251  found->resolvePutIndicies(InLumi, lumiModuleToIndicies);
1252  found->resolvePutIndicies(InEvent, eventModuleToIndicies);
1253  }
1254 
1255  return true;
1256  }
1257 
1259  globalSchedule_->deleteModule(iLabel);
1260  for (auto& stream : streamSchedules_) {
1261  stream->deleteModule(iLabel);
1262  }
1263  moduleRegistry_->deleteModule(iLabel, areg->preModuleDestructionSignal_, areg->postModuleDestructionSignal_);
1264  }
1265 
1266  void Schedule::initializeEarlyDelete(std::vector<std::string> const& branchesToDeleteEarly,
1267  std::multimap<std::string, std::string> const& referencesToBranches,
1268  std::vector<std::string> const& modulesToSkip,
1269  edm::ProductRegistry const& preg) {
1270  for (auto& stream : streamSchedules_) {
1271  stream->initializeEarlyDelete(
1272  *moduleRegistry(), branchesToDeleteEarly, referencesToBranches, modulesToSkip, preg);
1273  }
1274  }
1275 
1276  std::vector<ModuleDescription const*> Schedule::getAllModuleDescriptions() const {
1277  std::vector<ModuleDescription const*> result;
1278  result.reserve(allWorkers().size());
1279 
1280  for (auto const& worker : allWorkers()) {
1281  ModuleDescription const* p = worker->description();
1282  result.push_back(p);
1283  }
1284  return result;
1285  }
1286 
1287  Schedule::AllWorkers const& Schedule::allWorkers() const { return globalSchedule_->allWorkers(); }
1288 
1290  for (auto const& worker : allWorkers()) {
1291  worker->convertCurrentProcessAlias(processName);
1292  }
1293  }
1294 
1295  void Schedule::availablePaths(std::vector<std::string>& oLabelsToFill) const {
1296  streamSchedules_[0]->availablePaths(oLabelsToFill);
1297  }
1298 
1299  void Schedule::triggerPaths(std::vector<std::string>& oLabelsToFill) const { oLabelsToFill = *pathNames_; }
1300 
1301  void Schedule::endPaths(std::vector<std::string>& oLabelsToFill) const { oLabelsToFill = *endPathNames_; }
1302 
1303  void Schedule::modulesInPath(std::string const& iPathLabel, std::vector<std::string>& oLabelsToFill) const {
1304  streamSchedules_[0]->modulesInPath(iPathLabel, oLabelsToFill);
1305  }
1306 
1308  std::vector<ModuleDescription const*>& descriptions,
1309  unsigned int hint) const {
1310  streamSchedules_[0]->moduleDescriptionsInPath(iPathLabel, descriptions, hint);
1311  }
1312 
1314  std::vector<ModuleDescription const*>& descriptions,
1315  unsigned int hint) const {
1316  streamSchedules_[0]->moduleDescriptionsInEndPath(iEndPathLabel, descriptions, hint);
1317  }
1318 
1320  std::vector<ModuleDescription const*>& allModuleDescriptions,
1321  std::vector<std::pair<unsigned int, unsigned int>>& moduleIDToIndex,
1322  std::array<std::vector<std::vector<ModuleDescription const*>>, NumBranchTypes>& modulesWhoseProductsAreConsumedBy,
1323  std::vector<std::vector<ModuleProcessName>>& modulesInPreviousProcessesWhoseProductsAreConsumedBy,
1324  ProductRegistry const& preg) const {
1325  allModuleDescriptions.clear();
1326  moduleIDToIndex.clear();
1327  for (auto iBranchType = 0U; iBranchType < NumBranchTypes; ++iBranchType) {
1328  modulesWhoseProductsAreConsumedBy[iBranchType].clear();
1329  }
1330  modulesInPreviousProcessesWhoseProductsAreConsumedBy.clear();
1331 
1332  allModuleDescriptions.reserve(allWorkers().size());
1333  moduleIDToIndex.reserve(allWorkers().size());
1334  for (auto iBranchType = 0U; iBranchType < NumBranchTypes; ++iBranchType) {
1335  modulesWhoseProductsAreConsumedBy[iBranchType].resize(allWorkers().size());
1336  }
1337  modulesInPreviousProcessesWhoseProductsAreConsumedBy.resize(allWorkers().size());
1338 
1339  std::map<std::string, ModuleDescription const*> labelToDesc;
1340  unsigned int i = 0;
1341  for (auto const& worker : allWorkers()) {
1342  ModuleDescription const* p = worker->description();
1343  allModuleDescriptions.push_back(p);
1344  moduleIDToIndex.push_back(std::pair<unsigned int, unsigned int>(p->id(), i));
1345  labelToDesc[p->moduleLabel()] = p;
1346  ++i;
1347  }
1348  sort_all(moduleIDToIndex);
1349 
1350  i = 0;
1351  for (auto const& worker : allWorkers()) {
1352  std::array<std::vector<ModuleDescription const*>*, NumBranchTypes> modules;
1353  for (auto iBranchType = 0U; iBranchType < NumBranchTypes; ++iBranchType) {
1354  modules[iBranchType] = &modulesWhoseProductsAreConsumedBy[iBranchType].at(i);
1355  }
1356 
1357  std::vector<ModuleProcessName>& modulesInPreviousProcesses =
1358  modulesInPreviousProcessesWhoseProductsAreConsumedBy.at(i);
1359  try {
1360  worker->modulesWhoseProductsAreConsumed(modules, modulesInPreviousProcesses, preg, labelToDesc);
1361  } catch (cms::Exception& ex) {
1362  ex.addContext("Calling Worker::modulesWhoseProductsAreConsumed() for module " +
1363  worker->description()->moduleLabel());
1364  throw;
1365  }
1366  ++i;
1367  }
1368  }
1369 
1371  rep.eventSummary.totalEvents = 0;
1372  rep.eventSummary.totalEventsPassed = 0;
1373  rep.eventSummary.totalEventsFailed = 0;
1374  for (auto& s : streamSchedules_) {
1375  s->getTriggerReport(rep);
1376  }
1377  sort_all(rep.workerSummaries);
1378  }
1379 
1381  rep.eventSummary.totalEvents = 0;
1382  rep.eventSummary.cpuTime = 0.;
1383  rep.eventSummary.realTime = 0.;
1384  summaryTimeKeeper_->fillTriggerTimingReport(rep);
1385  }
1386 
1388  int returnValue = 0;
1389  for (auto& s : streamSchedules_) {
1390  returnValue += s->totalEvents();
1391  }
1392  return returnValue;
1393  }
1394 
1396  int returnValue = 0;
1397  for (auto& s : streamSchedules_) {
1398  returnValue += s->totalEventsPassed();
1399  }
1400  return returnValue;
1401  }
1402 
1404  int returnValue = 0;
1405  for (auto& s : streamSchedules_) {
1406  returnValue += s->totalEventsFailed();
1407  }
1408  return returnValue;
1409  }
1410 
1412  for (auto& s : streamSchedules_) {
1413  s->clearCounters();
1414  }
1415  }
1416 } // namespace edm
size
Write out results.
void endPaths(std::vector< std::string > &oLabelsToFill) const
adds to oLabelsToFill the labels for all end paths in the process
Definition: Schedule.cc:1301
std::vector< PathSummary > endPathSummaries
Definition: TriggerReport.h:60
std::vector< PathTimingSummary > endPathSummaries
PostModuleDestruction postModuleDestructionSignal_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
static const TGPicture * info(bool iBackgroundIsBlack)
bool terminate() const
Return whether each output module has reached its maximum count.
Definition: Schedule.cc:765
#define CMS_SA_ALLOW
Timestamp const & endTime() const
Definition: RunPrincipal.h:69
void stopEvent(StreamContext const &)
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
virtual void openFile(FileBlock const &fb)=0
void getTriggerTimingReport(TriggerTimingReport &rep) const
Definition: Schedule.cc:1380
roAction_t actions[nactions]
Definition: GenABIO.cc:181
void writeProcessBlockAsync(WaitingTaskHolder iTask, ProcessBlockPrincipal const &, ProcessContext const *, ActivityRegistry *)
Definition: Schedule.cc:1107
static Timestamp invalidTimestamp()
Definition: Timestamp.h:75
void restartModuleEvent(StreamContext const &, ModuleCallingContext const &)
void respondToCloseInputFile(FileBlock const &fb)
Definition: Schedule.cc:1180
int totalEvents() const
Definition: Schedule.cc:1387
vector< string > vstring
Definition: ExoticaDQM.cc:7
void startModuleEvent(StreamContext const &, ModuleCallingContext const &)
std::vector< Worker * > AllWorkers
Definition: Schedule.h:127
RunPrincipal const & runPrincipal() const
void moduleDescriptionsInPath(std::string const &iPathLabel, std::vector< ModuleDescription const *> &descriptions, unsigned int hint) const
Definition: Schedule.cc:1307
void removeModuleIfExists(ModuleDescription const &module)
std::vector< std::string > const * pathNames_
Definition: Schedule.h:326
void getTriggerReport(TriggerReport &rep) const
Definition: Schedule.cc:1370
void convertCurrentProcessAlias(std::string const &processName)
Convert "@currentProcess" in InputTag process names to the actual current process name...
Definition: Schedule.cc:1289
RunNumber_t run() const
Definition: RunPrincipal.h:61
void endStream(unsigned int)
Definition: Schedule.cc:1196
BranchIDLists const & branchIDLists() const
ParameterSet getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
PostGlobalEndLumi postGlobalWriteLumiSignal_
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t stream
std::vector< WorkerSummary > workerSummaries
Definition: TriggerReport.h:61
edm::propagate_const< std::unique_ptr< SystemTimeKeeper > > summaryTimeKeeper_
Definition: Schedule.h:324
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
assert(be >=bs)
PreModuleDestruction preModuleDestructionSignal_
constexpr auto then(O &&iO)
Definition: chain_first.h:277
void processOneEventAsync(WaitingTaskHolder iTask, unsigned int iStreamID, EventTransitionInfo &, ServiceToken const &token)
Definition: Schedule.cc:1201
static unsigned int getUniqueID()
Returns a unique id each time called. Intended to be passed to ModuleDescription&#39;s constructor&#39;s modI...
void updateFromRegistry(ProductRegistry const &reg)
size_t getParameterSetNames(std::vector< std::string > &output, bool trackiness=true) const
edm::propagate_const< std::unique_ptr< GlobalSchedule > > globalSchedule_
Definition: Schedule.h:319
void eraseOrSetUntrackedParameterSet(std::string const &name)
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:14
bool anyProductProduced() const
T getUntrackedParameter(std::string const &, T const &) const
static RunIndex invalidRunIndex()
Definition: RunIndex.cc:9
void processEDAliases(std::vector< std::string > const &aliasNamesToProcess, std::unordered_set< std::string > const &aliasModulesToProcess, ParameterSet const &proc_pset, std::string const &processName, ProductRegistry &preg)
void deleteModule(std::string const &iLabel, ActivityRegistry *areg)
Deletes module with label iLabel.
Definition: Schedule.cc:1258
ParameterSetID id() const
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
Definition: Schedule.cc:1276
void updateForNewProcess(ProductRegistry const &, std::string const &processName)
ParameterSet const & registerIt()
std::vector< PathSummary > trigPathSummaries
Definition: TriggerReport.h:59
EventSummary eventSummary
Definition: TriggerReport.h:58
void beginJob(ProductRegistry const &, eventsetup::ESRecordsToProxyIndices const &, ProcessBlockHelperBase const &)
Definition: Schedule.cc:1185
auto runLast(edm::WaitingTaskHolder iTask)
Definition: chain_first.h:297
std::vector< edm::propagate_const< std::shared_ptr< PathStatusInserter > > > pathStatusInserters_
Definition: Schedule.h:314
void fillModuleAndConsumesInfo(std::vector< ModuleDescription const *> &allModuleDescriptions, std::vector< std::pair< unsigned int, unsigned int >> &moduleIDToIndex, std::array< std::vector< std::vector< ModuleDescription const *>>, NumBranchTypes > &modulesWhoseProductsAreConsumedBy, std::vector< std::vector< ModuleProcessName >> &modulesInPreviousProcessesWhoseProductsAreConsumedBy, ProductRegistry const &preg) const
Definition: Schedule.cc:1319
bool empty() const
Definition: ParameterSet.h:201
EventTimingSummary eventSummary
Strings const & getTrigPaths() const
Schedule(ParameterSet &proc_pset, service::TriggerNamesService const &tns, ProductRegistry &pregistry, ExceptionToActionTable const &actions, std::shared_ptr< ActivityRegistry > areg, std::shared_ptr< ProcessConfiguration const > processConfiguration, PreallocationConfiguration const &config, ProcessContext const *processContext, ModuleTypeResolverMaker const *resolverMaker)
Definition: Schedule.cc:486
void setUnscheduledProducts(std::set< std::string > const &unscheduledLabels)
void clearCounters()
Clear all the counters in the trigger report.
Definition: Schedule.cc:1411
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:179
PostGlobalWriteRun postGlobalWriteRunSignal_
static ServiceRegistry & instance()
std::vector< PathTimingSummary > trigPathSummaries
RunIndex index() const
Definition: RunPrincipal.h:56
double f[11][100]
void limitOutput(ParameterSet const &proc_pset, BranchIDLists const &branchIDLists, SubProcessParentageHelper const *subProcessParentageHelper)
Definition: Schedule.cc:724
void setFrozen(bool initializeLookupInfo=true)
void respondToOpenInputFile(FileBlock const &fb)
Definition: Schedule.cc:1175
edm::propagate_const< std::shared_ptr< ModuleRegistry > > moduleRegistry_
Definition: Schedule.h:316
Timestamp const & beginTime() const
rep
Definition: cuy.py:1189
void writeRunAsync(WaitingTaskHolder iTask, RunPrincipal const &rp, ProcessContext const *, ActivityRegistry *, MergeableRunProductMetadata const *)
Definition: Schedule.cc:1074
void stopPath(StreamContext const &, PathContext const &, HLTPathStatus const &)
int totalEventsPassed() const
Definition: Schedule.cc:1395
std::shared_ptr< ModuleRegistry const > moduleRegistry() const
Definition: Schedule.h:310
static LuminosityBlockIndex invalidLuminosityBlockIndex()
PreGlobalWriteRun preGlobalWriteRunSignal_
void stopModuleEvent(StreamContext const &, ModuleCallingContext const &)
virtual bool shouldWeCloseFile() const =0
void availablePaths(std::vector< std::string > &oLabelsToFill) const
adds to oLabelsToFill the labels for all paths in the process
Definition: Schedule.cc:1295
Log< level::Info, false > LogInfo
PreallocationConfiguration preallocConfig_
Definition: Schedule.h:322
Log< level::FwkInfo, true > LogFwkVerbatim
PreWriteProcessBlock preWriteProcessBlockSignal_
std::vector< edm::propagate_const< std::shared_ptr< StreamSchedule > > > streamSchedules_
Definition: Schedule.h:317
Strings const & getEndPaths() const
void sort_all(RandomAccessSequence &s)
wrappers for std::sort
Definition: Algorithms.h:92
AllWorkers const & allWorkers() const
returns the collection of pointers to workers
Definition: Schedule.cc:1287
std::shared_ptr< ProductResolverIndexHelper const > productLookup(BranchType branchType) const
void respondToOpenInputFile(FileBlock const &fb)
Definition: Worker.h:183
void startPath(StreamContext const &, PathContext const &)
bool search_all(ForwardSequence const &s, Datum const &d)
Definition: Algorithms.h:36
PostWriteProcessBlock postWriteProcessBlockSignal_
bool shouldWeCloseOutput() const
Definition: Schedule.cc:1166
ProductList & productListUpdator()
void addContext(std::string const &context)
Definition: Exception.cc:165
void moduleDescriptionsInEndPath(std::string const &iEndPathLabel, std::vector< ModuleDescription const *> &descriptions, unsigned int hint) const
Definition: Schedule.cc:1313
virtual std::unique_ptr< OutputModuleCommunicator > createOutputModuleCommunicator()=0
AllOutputModuleCommunicators all_output_communicators_
Definition: Schedule.h:321
void pauseModuleEvent(StreamContext const &, ModuleCallingContext const &)
PreGlobalEndLumi preGlobalWriteLumiSignal_
void beginStream(unsigned int)
Definition: Schedule.cc:1191
void respondToCloseInputFile(FileBlock const &fb)
Definition: Worker.h:184
bool wantSummary_
Definition: Schedule.h:328
std::vector< std::string > const * endPathNames_
Definition: Schedule.h:327
HLT enums.
void modulesInPath(std::string const &iPathLabel, std::vector< std::string > &oLabelsToFill) const
adds to oLabelsToFill in execution order the labels of all modules in path iPathLabel ...
Definition: Schedule.cc:1303
LuminosityBlockIndex index() const
void finishSetup(ParameterSet &proc_pset, service::TriggerNamesService const &tns, ProductRegistry &preg, BranchIDListHelper &branchIDListHelper, ProcessBlockHelperBase &processBlockHelper, ThinnedAssociationsHelper &thinnedAssociationsHelper, SubProcessParentageHelper const *subProcessParentageHelper, std::shared_ptr< ActivityRegistry > areg, std::shared_ptr< ProcessConfiguration > processConfiguration, bool hasSubprocesses, PreallocationConfiguration const &prealloc, ProcessContext const *processContext)
Definition: Schedule.cc:575
Definition: output.py:1
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
void openOutputFiles(FileBlock &fb)
Definition: Schedule.cc:1069
void writeLumiAsync(WaitingTaskHolder iTask, LuminosityBlockPrincipal const &lbp, ProcessContext const *, ActivityRegistry *)
Definition: Schedule.cc:1137
std::vector< WorkerTimingSummary > workerSummaries
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
void initializeEarlyDelete(std::vector< std::string > const &branchesToDeleteEarly, std::multimap< std::string, std::string > const &referencesToBranches, std::vector< std::string > const &modulesToSkip, edm::ProductRegistry const &preg)
Definition: Schedule.cc:1266
void endJob(ExceptionCollector &collector)
Definition: Schedule.cc:780
bool changeModule(std::string const &iLabel, ParameterSet const &iPSet, const ProductRegistry &iRegistry, eventsetup::ESRecordsToProxyIndices const &)
Definition: Schedule.cc:1209
std::vector< std::string > vstring
Definition: Schedule.cc:482
ServiceToken presentToken() const
void setIsMergeable(BranchDescription &)
std::vector< std::string > set_difference(std::vector< std::string > const &v1, std::vector< std::string > const &v2)
int totalEventsFailed() const
Definition: Schedule.cc:1403
def move(src, dest)
Definition: eostools.py:511
void closeOutputFiles()
Definition: Schedule.cc:1061
void triggerPaths(std::vector< std::string > &oLabelsToFill) const
Definition: Schedule.cc:1299
unsigned transform(const HcalDetId &id, unsigned transformCode)