CMS 3D CMS Logo

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