CMS 3D CMS Logo

SecondaryEventProvider.cc
Go to the documentation of this file.
11 #include "oneapi/tbb/task_arena.h"
12 
13 namespace {
14  template <typename T, typename U>
15  void processOneOccurrence(edm::WorkerManager& manager,
16  typename T::TransitionInfoType& info,
17  edm::StreamID streamID,
18  typename T::Context const* topContext,
19  U const* context,
20  bool cleaningUpAfterException = false) {
21  manager.resetAll();
22 
23  if (manager.allWorkers().empty())
24  return;
25 
27  //we need the arena to guarantee that the syncWait will return to this thread
28  // and not cause this callstack to possibly be moved to a new thread
29  tbb::task_arena localArena{tbb::this_task_arena::max_concurrency()};
30  std::exception_ptr exceptPtr = localArena.execute([&]() {
31  return edm::syncWait([&](edm::WaitingTaskHolder&& iHolder) {
32  manager.processOneOccurrenceAsync<T, U>(std::move(iHolder), info, token, streamID, topContext, context);
33  });
34  });
35 
36  if (exceptPtr) {
37  try {
38  edm::convertException::wrap([&]() { std::rethrow_exception(exceptPtr); });
39  } catch (cms::Exception& ex) {
40  if (ex.context().empty()) {
41  edm::addContextAndPrintException("Calling SecondaryEventProvider", ex, cleaningUpAfterException);
42  } else {
43  edm::addContextAndPrintException("", ex, cleaningUpAfterException);
44  }
45  throw;
46  }
47  }
48  }
49 } // namespace
50 
51 namespace edm {
52  SecondaryEventProvider::SecondaryEventProvider(std::vector<ParameterSet>& psets,
53  ProductRegistry& preg,
54  std::shared_ptr<ProcessConfiguration> processConfiguration)
55  : exceptionToActionTable_(new ExceptionToActionTable),
56  // no type resolver for modules in SecondaryEventProvider for now
57  workerManager_(std::make_shared<ActivityRegistry>(), *exceptionToActionTable_, nullptr) {
58  std::vector<std::string> shouldBeUsedLabels;
59  std::set<std::string> unscheduledLabels;
60  const PreallocationConfiguration preallocConfig;
61  for (auto& pset : psets) {
62  std::string label = pset.getParameter<std::string>("@module_label");
64  pset, preg, &preallocConfig, processConfiguration, label, unscheduledLabels, shouldBeUsedLabels);
65  }
66  if (!unscheduledLabels.empty()) {
67  preg.setUnscheduledProducts(unscheduledLabels);
68  }
69  } // SecondaryEventProvider::SecondaryEventProvider
70 
73  ProcessBlockHelper dummyProcessBlockHelper;
74  workerManager_.beginJob(iRegistry, iIndices, dummyProcessBlockHelper);
75  }
76 
77  //NOTE: When the Stream interfaces are propagated to the modules, this code must be updated
78  // to also send the stream based transitions
80  const EventSetupImpl& setup,
81  ModuleCallingContext const* mcc,
82  StreamContext& sContext) {
84  processOneOccurrence<OccurrenceTraits<RunPrincipal, BranchActionGlobalBegin>>(
86  processOneOccurrence<OccurrenceTraits<RunPrincipal, BranchActionStreamBegin>>(
87  workerManager_, info, sContext.streamID(), &sContext, mcc);
88  }
89 
91  const EventSetupImpl& setup,
92  ModuleCallingContext const* mcc,
93  StreamContext& sContext) {
95  processOneOccurrence<OccurrenceTraits<LuminosityBlockPrincipal, BranchActionGlobalBegin>>(
97  processOneOccurrence<OccurrenceTraits<LuminosityBlockPrincipal, BranchActionStreamBegin>>(
98  workerManager_, info, sContext.streamID(), &sContext, mcc);
99  }
100 
102  const EventSetupImpl& setup,
103  ModuleCallingContext const* mcc,
104  StreamContext& sContext) {
106  processOneOccurrence<OccurrenceTraits<RunPrincipal, BranchActionStreamEnd>>(
107  workerManager_, info, sContext.streamID(), &sContext, mcc);
108  processOneOccurrence<OccurrenceTraits<RunPrincipal, BranchActionGlobalEnd>>(
109  workerManager_, info, StreamID::invalidStreamID(), nullptr, mcc);
110  }
111 
113  const EventSetupImpl& setup,
114  ModuleCallingContext const* mcc,
115  StreamContext& sContext) {
117  processOneOccurrence<OccurrenceTraits<LuminosityBlockPrincipal, BranchActionStreamEnd>>(
118  workerManager_, info, sContext.streamID(), &sContext, mcc);
119  processOneOccurrence<OccurrenceTraits<LuminosityBlockPrincipal, BranchActionGlobalEnd>>(
120  workerManager_, info, StreamID::invalidStreamID(), nullptr, mcc);
121  }
122 
124  const EventSetupImpl& setup,
125  StreamContext& sContext) {
129 
130  if (workerManager_.unscheduledWorkers().empty()) {
131  return;
132  }
134  //we need the arena to guarantee that the syncWait will return to this thread
135  // and not cause this callstack to possibly be moved to a new thread
136  ParentContext pc(&sContext);
137  std::exception_ptr exceptPtr = tbb::this_task_arena::isolate([&]() {
138  return edm::syncWait([&](edm::WaitingTaskHolder&& iHolder) {
139  for (auto& worker : workerManager_.unscheduledWorkers()) {
141  iHolder, info, token, sContext.streamID(), pc, &sContext);
142  }
143  });
144  });
145  if (exceptPtr) {
146  try {
147  edm::convertException::wrap([&]() { std::rethrow_exception(exceptPtr); });
148  } catch (cms::Exception& ex) {
149  if (ex.context().empty()) {
150  edm::addContextAndPrintException("Calling SecondaryEventProvider", ex, false);
151  } else {
152  edm::addContextAndPrintException("", ex, false);
153  }
154  throw;
155  }
156  }
157  }
158 
160  workerManager_.beginStream(iID, sContext);
161  }
162 
164  workerManager_.endStream(iID, sContext);
165  }
166 } // namespace edm
void endStream(edm::StreamID iID, StreamContext &sContext)
static const TGPicture * info(bool iBackgroundIsBlack)
void setupPileUpEvent(EventPrincipal &ep, const EventSetupImpl &setup, StreamContext &sContext)
std::exception_ptr syncWait(F &&iFunc)
void endStream(StreamID iID, StreamContext &streamContext)
void beginJob(ProductRegistry const &iRegistry, eventsetup::ESRecordsToProductResolverIndices const &, ProcessBlockHelperBase const &)
void setupOnDemandSystem(EventTransitionInfo const &)
void addContextAndPrintException(char const *context, cms::Exception &ex, bool disablePrint)
AllWorkers const & unscheduledWorkers() const
Definition: WorkerManager.h:81
static StreamID invalidStreamID()
Definition: StreamID.h:45
char const * label
void setUnscheduledProducts(std::set< std::string > const &unscheduledLabels)
void processOneOccurrenceAsync(WaitingTaskHolder, typename T::TransitionInfoType &, ServiceToken const &, StreamID, typename T::Context const *topContext, U const *context) noexcept
StreamID const & streamID() const
Definition: StreamContext.h:55
void beginRun(RunPrincipal &run, const edm::EventSetupImpl &setup, ModuleCallingContext const *, StreamContext &sContext)
static ServiceRegistry & instance()
AllWorkers const & allWorkers() const
Definition: WorkerManager.h:80
void endLuminosityBlock(LuminosityBlockPrincipal &lumi, const edm::EventSetupImpl &setup, ModuleCallingContext const *, StreamContext &sContext)
void endRun(RunPrincipal &run, const edm::EventSetupImpl &setup, ModuleCallingContext const *, StreamContext &sContext)
void beginStream(edm::StreamID iID, StreamContext &sContext)
void beginStream(StreamID iID, StreamContext &streamContext)
void addToUnscheduledWorkers(ParameterSet &pset, ProductRegistry &preg, PreallocationConfiguration const *prealloc, std::shared_ptr< ProcessConfiguration const > processConfiguration, std::string label, std::set< std::string > &unscheduledLabels, std::vector< std::string > &shouldBeUsedLabels)
SecondaryEventProvider(std::vector< ParameterSet > &psets, ProductRegistry &pregistry, std::shared_ptr< ProcessConfiguration > processConfiguration)
void beginJob(ProductRegistry const &iRegistry, eventsetup::ESRecordsToProductResolverIndices const &)
HLT enums.
void setupResolvers(Principal &principal)
auto wrap(F iFunc) -> decltype(iFunc())
void beginLuminosityBlock(LuminosityBlockPrincipal &lumi, const edm::EventSetupImpl &setup, ModuleCallingContext const *, StreamContext &sContext)
std::list< std::string > const & context() const
Definition: Exception.cc:151
long double T
ServiceToken presentToken() const
def move(src, dest)
Definition: eostools.py:511