CMS 3D CMS Logo

WorkerManager.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_WorkerManager_h
2 #define FWCore_Framework_WorkerManager_h
3 
4 /*
5 
6 */
7 
17 
18 #include <memory>
19 
20 #include <set>
21 #include <string>
22 #include <vector>
23 
24 namespace edm {
25  class EventTransitionInfo;
26  class ExceptionCollector;
27  class StreamID;
28  class StreamContext;
29  class ModuleRegistry;
30  class PreallocationConfiguration;
31  namespace eventsetup {
33  }
34  class WorkerManager {
35  public:
36  typedef std::vector<Worker*> AllWorkers;
37 
38  WorkerManager(std::shared_ptr<ActivityRegistry> actReg, ExceptionToActionTable const& actions);
39  WorkerManager(WorkerManager&&) = default;
40 
41  WorkerManager(std::shared_ptr<ModuleRegistry> modReg,
42  std::shared_ptr<ActivityRegistry> actReg,
45  ProductRegistry& preg,
46  PreallocationConfiguration const* prealloc,
47  std::shared_ptr<ProcessConfiguration> processConfiguration,
49  std::set<std::string>& unscheduledLabels,
50  std::vector<std::string>& shouldBeUsedLabels);
51 
52  template <typename T, typename U>
53  void processOneOccurrence(typename T::TransitionInfoType&,
54  StreamID,
55  typename T::Context const* topContext,
56  U const* context,
57  bool cleaningUpAfterException = false);
58  template <typename T, typename U>
60  typename T::TransitionInfoType&,
61  ServiceToken const&,
62  StreamID,
63  typename T::Context const* topContext,
64  U const* context);
65 
66  template <typename T>
68  typename T::TransitionInfoType const&,
69  ServiceToken const&,
70  StreamID,
71  ParentContext const&,
72  typename T::Context const*);
73 
74  void setupResolvers(Principal& principal);
76 
77  void beginJob(ProductRegistry const& iRegistry, eventsetup::ESRecordsToProxyIndices const&);
78  void endJob();
79  void endJob(ExceptionCollector& collector);
80 
81  void beginStream(StreamID iID, StreamContext& streamContext);
82  void endStream(StreamID iID, StreamContext& streamContext);
83 
84  AllWorkers const& allWorkers() const { return allWorkers_; }
85 
86  void addToAllWorkers(Worker* w);
87 
88  ExceptionToActionTable const& actionTable() const { return *actionTable_; }
89 
91  ProductRegistry& preg,
92  PreallocationConfiguration const* prealloc,
93  std::shared_ptr<ProcessConfiguration const> processConfiguration,
94  std::string const& label);
95 
96  void resetAll();
97 
98  private:
104  };
105 
106  template <typename T, typename U>
107  void WorkerManager::processOneOccurrence(typename T::TransitionInfoType& info,
108  StreamID streamID,
109  typename T::Context const* topContext,
110  U const* context,
111  bool cleaningUpAfterException) {
112  this->resetAll();
113 
114  auto waitTask = make_empty_waiting_task();
115  waitTask->increment_ref_count();
116  processOneOccurrenceAsync<T, U>(
117  waitTask.get(), info, ServiceRegistry::instance().presentToken(), streamID, topContext, context);
118  waitTask->wait_for_all();
119  if (waitTask->exceptionPtr() != nullptr) {
120  try {
121  convertException::wrap([&]() { std::rethrow_exception(*(waitTask->exceptionPtr())); });
122  } catch (cms::Exception& ex) {
123  if (ex.context().empty()) {
125  "Calling function WorkerManager::processOneOccurrence", ex, cleaningUpAfterException);
126  } else {
127  addContextAndPrintException("", ex, cleaningUpAfterException);
128  }
129  throw;
130  }
131  }
132  }
133 
134  template <typename T, typename U>
136  typename T::TransitionInfoType& info,
137  ServiceToken const& token,
138  StreamID streamID,
139  typename T::Context const* topContext,
140  U const* context) {
141  //make sure the unscheduled items see this run or lumi transition
142  unscheduled_.runNowAsync<T, U>(task, info, token, streamID, topContext, context);
143  }
144 
145  template <typename T>
147  typename T::TransitionInfoType const& info,
148  ServiceToken const& token,
149  StreamID streamID,
150  ParentContext const& parentContext,
151  typename T::Context const* context) {
152  unscheduled_.runAccumulatorsAsync<T>(task, info, token, streamID, parentContext, context);
153  }
154 } // namespace edm
155 
156 #endif
edm::EventTransitionInfo
Definition: TransitionInfoTypes.h:26
edm::StreamID
Definition: StreamID.h:30
edm::WorkerManager::addToAllWorkers
void addToAllWorkers(Worker *w)
Definition: WorkerManager.cc:123
edm::WorkerManager::AllWorkers
std::vector< Worker * > AllWorkers
Definition: WorkerManager.h:36
edm::UnscheduledCallProducer
Definition: UnscheduledCallProducer.h:37
ServiceRegistry.h
edm::UnscheduledCallProducer::runNowAsync
void runNowAsync(WaitingTask *task, typename T::TransitionInfoType const &info, ServiceToken const &token, StreamID streamID, typename T::Context const *topContext, U const *context) const
Definition: UnscheduledCallProducer.h:62
edm::eventsetup::ESRecordsToProxyIndices
Definition: ESRecordsToProxyIndices.h:35
edm::WorkerManager::resetAll
void resetAll()
Definition: WorkerManager.cc:121
edm
HLT enums.
Definition: AlignableModifier.h:19
UnscheduledCallProducer.h
edm::WorkerManager::addToUnscheduledWorkers
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)
Definition: WorkerManager.cc:42
edm::Principal
Definition: Principal.h:57
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
edm::WorkerManager::actionTable
ExceptionToActionTable const & actionTable() const
Definition: WorkerManager.h:88
edm::ProductRegistry
Definition: ProductRegistry.h:37
edm::WorkerManager::processOneOccurrenceAsync
void processOneOccurrenceAsync(WaitingTask *, typename T::TransitionInfoType &, ServiceToken const &, StreamID, typename T::Context const *topContext, U const *context)
Definition: WorkerManager.h:135
edm::ServiceToken
Definition: ServiceToken.h:40
edm::StreamContext
Definition: StreamContext.h:31
edm::ExceptionCollector
Definition: ExceptionCollector.h:33
w
const double w
Definition: UKUtility.cc:23
edm::convertException::wrap
auto wrap(F iFunc) -> decltype(iFunc())
Definition: ConvertException.h:19
edm::WorkerManager::unscheduled_
UnscheduledCallProducer unscheduled_
Definition: WorkerManager.h:102
TrackValidation_cff.task
task
Definition: TrackValidation_cff.py:252
edm::WorkerManager::allWorkers
AllWorkers const & allWorkers() const
Definition: WorkerManager.h:84
ConvertException.h
edm::Worker
Definition: Worker.h:88
edm::WorkerManager::actionTable_
ExceptionToActionTable const * actionTable_
Definition: WorkerManager.h:100
edm::WorkerManager::processOneOccurrence
void processOneOccurrence(typename T::TransitionInfoType &, StreamID, typename T::Context const *topContext, U const *context, bool cleaningUpAfterException=false)
Definition: WorkerManager.h:107
edm::WorkerManager::workerReg_
WorkerRegistry workerReg_
Definition: WorkerManager.h:99
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::WorkerManager::beginJob
void beginJob(ProductRegistry const &iRegistry, eventsetup::ESRecordsToProxyIndices const &)
Definition: WorkerManager.cc:81
edm::ParentContext
Definition: ParentContext.h:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::WorkerManager::beginStream
void beginStream(StreamID iID, StreamContext &streamContext)
Definition: WorkerManager.cc:109
edm::ParameterSet
Definition: ParameterSet.h:47
cms::Exception::context
std::list< std::string > const & context() const
Definition: Exception.cc:147
edm::WorkerManager::setupOnDemandSystem
void setupOnDemandSystem(EventTransitionInfo const &)
Definition: WorkerManager.cc:138
edm::ServiceRegistry::presentToken
ServiceToken presentToken() const
Definition: ServiceRegistry.cc:63
ESRecordsToProxyIndices
edm::addContextAndPrintException
void addContextAndPrintException(char const *context, cms::Exception &ex, bool disablePrint)
Definition: ExceptionHelpers.cc:11
edm::WorkerManager::allWorkers_
AllWorkers allWorkers_
Definition: WorkerManager.h:101
edm::WorkerManager::processAccumulatorsAsync
void processAccumulatorsAsync(WaitingTask *, typename T::TransitionInfoType const &, ServiceToken const &, StreamID, ParentContext const &, typename T::Context const *)
Definition: WorkerManager.h:146
edm::ExceptionToActionTable
Definition: ExceptionActions.h:16
edm::ServiceRegistry::instance
static ServiceRegistry & instance()
Definition: ServiceRegistry.cc:90
edm::make_empty_waiting_task
std::unique_ptr< edm::EmptyWaitingTask, waitingtask::TaskDestroyer > make_empty_waiting_task()
Create an EmptyWaitingTask which will properly be destroyed.
Definition: WaitingTaskList.h:96
edm::WorkerRegistry
The Registry of all workers that where requested Holds all instances of workers. In this implementati...
Definition: WorkerRegistry.h:38
edm::PreallocationConfiguration
Definition: PreallocationConfiguration.h:27
edm::WaitingTask
Definition: WaitingTask.h:36
ExceptionHelpers.h
Frameworkfwd.h
T
long double T
Definition: Basic3DVectorLD.h:48
edm::UnscheduledCallProducer::runAccumulatorsAsync
void runAccumulatorsAsync(WaitingTask *task, typename T::TransitionInfoType const &info, ServiceToken const &token, StreamID streamID, ParentContext const &parentContext, typename T::Context const *context)
Definition: UnscheduledCallProducer.h:84
Worker.h
WorkerRegistry.h
Exception.h
edm::WorkerManager::setupResolvers
void setupResolvers(Principal &principal)
Definition: WorkerManager.cc:129
edm::WorkerManager::endStream
void endStream(StreamID iID, StreamContext &streamContext)
Definition: WorkerManager.cc:115
edm::WorkerManager::getWorker
Worker * getWorker(ParameterSet &pset, ProductRegistry &preg, PreallocationConfiguration const *prealloc, std::shared_ptr< ProcessConfiguration const > processConfiguration, std::string const &label)
Definition: WorkerManager.cc:33
actions
roAction_t actions[nactions]
Definition: GenABIO.cc:181
cms::Exception
Definition: Exception.h:70
get_underlying_safe.h
edm::WorkerManager
Definition: WorkerManager.h:34
label
const char * label
Definition: PFTauDecayModeTools.cc:11
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
edm::WorkerManager::WorkerManager
WorkerManager(std::shared_ptr< ActivityRegistry > actReg, ExceptionToActionTable const &actions)
Definition: WorkerManager.cc:17
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:318
edm::WorkerManager::lastSetupEventPrincipal_
void const * lastSetupEventPrincipal_
Definition: WorkerManager.h:103
edm::WorkerManager::endJob
void endJob()
Definition: WorkerManager.cc:65