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 ExceptionCollector;
26  class StreamID;
27  class StreamContext;
28  class ModuleRegistry;
29  class PreallocationConfiguration;
30  namespace eventsetup {
32  }
33  class WorkerManager {
34  public:
35  typedef std::vector<Worker*> AllWorkers;
36 
37  WorkerManager(std::shared_ptr<ActivityRegistry> actReg, ExceptionToActionTable const& actions);
38  WorkerManager(WorkerManager&&) = default;
39 
40  WorkerManager(std::shared_ptr<ModuleRegistry> modReg,
41  std::shared_ptr<ActivityRegistry> actReg,
44  ProductRegistry& preg,
45  PreallocationConfiguration const* prealloc,
46  std::shared_ptr<ProcessConfiguration> processConfiguration,
48  std::set<std::string>& unscheduledLabels,
49  std::vector<std::string>& shouldBeUsedLabels);
50 
51  template <typename T, typename U>
52  void processOneOccurrence(typename T::MyPrincipal& principal,
54  StreamID streamID,
55  typename T::Context const* topContext,
56  U const* context,
57  bool cleaningUpAfterException = false);
58  template <typename T, typename U>
60  typename T::MyPrincipal& principal,
62  ServiceToken const& token,
63  StreamID streamID,
64  typename T::Context const* topContext,
65  U const* context);
66 
67  template <typename T>
69  typename T::MyPrincipal const& ep,
70  EventSetupImpl const& es,
71  ServiceToken const& token,
72  StreamID streamID,
73  ParentContext const& parentContext,
74  typename T::Context const* context);
75 
76  void setupOnDemandSystem(Principal& principal, EventSetupImpl const& es);
77 
78  void beginJob(ProductRegistry const& iRegistry, eventsetup::ESRecordsToProxyIndices const&);
79  void endJob();
80  void endJob(ExceptionCollector& collector);
81 
82  void beginStream(StreamID iID, StreamContext& streamContext);
83  void endStream(StreamID iID, StreamContext& streamContext);
84 
85  AllWorkers const& allWorkers() const { return allWorkers_; }
86 
87  void addToAllWorkers(Worker* w);
88 
89  ExceptionToActionTable const& actionTable() const { return *actionTable_; }
90 
92  ProductRegistry& preg,
93  PreallocationConfiguration const* prealloc,
94  std::shared_ptr<ProcessConfiguration const> processConfiguration,
95  std::string const& label);
96 
97  void resetAll();
98 
99  private:
105  };
106 
107  template <typename T, typename U>
108  void WorkerManager::processOneOccurrence(typename T::MyPrincipal& ep,
109  EventSetupImpl const& es,
110  StreamID streamID,
111  typename T::Context const* topContext,
112  U const* context,
113  bool cleaningUpAfterException) {
114  this->resetAll();
115 
116  auto waitTask = make_empty_waiting_task();
117  waitTask->increment_ref_count();
118  processOneOccurrenceAsync<T, U>(
119  waitTask.get(), ep, es, ServiceRegistry::instance().presentToken(), streamID, topContext, context);
120  waitTask->wait_for_all();
121  if (waitTask->exceptionPtr() != nullptr) {
122  try {
123  convertException::wrap([&]() { std::rethrow_exception(*(waitTask->exceptionPtr())); });
124  } catch (cms::Exception& ex) {
125  if (ex.context().empty()) {
127  "Calling function WorkerManager::processOneOccurrence", ex, cleaningUpAfterException);
128  } else {
129  addContextAndPrintException("", ex, cleaningUpAfterException);
130  }
131  throw;
132  }
133  }
134  }
135 
136  template <typename T, typename U>
138  typename T::MyPrincipal& ep,
139  EventSetupImpl const& es,
140  ServiceToken const& token,
141  StreamID streamID,
142  typename T::Context const* topContext,
143  U const* context) {
144  //make sure the unscheduled items see this run or lumi transition
145  unscheduled_.runNowAsync<T, U>(task, ep, es, token, streamID, topContext, context);
146  }
147 
148  template <typename T>
150  typename T::MyPrincipal const& ep,
151  EventSetupImpl const& es,
152  ServiceToken const& token,
153  StreamID streamID,
154  ParentContext const& parentContext,
155  typename T::Context const* context) {
156  unscheduled_.runAccumulatorsAsync<T>(task, ep, es, token, streamID, parentContext, context);
157  }
158 } // namespace edm
159 
160 #endif
edm::StreamID
Definition: StreamID.h:30
edm::WorkerManager::addToAllWorkers
void addToAllWorkers(Worker *w)
Definition: WorkerManager.cc:119
edm::WorkerManager::AllWorkers
std::vector< Worker * > AllWorkers
Definition: WorkerManager.h:35
edm::UnscheduledCallProducer
Definition: UnscheduledCallProducer.h:35
ServiceRegistry.h
edm::eventsetup::ESRecordsToProxyIndices
Definition: ESRecordsToProxyIndices.h:35
edm::EventSetupImpl
Definition: EventSetupImpl.h:44
edm::WorkerManager::resetAll
void resetAll()
Definition: WorkerManager.cc:117
edm
HLT enums.
Definition: AlignableModifier.h:19
UnscheduledCallProducer.h
edm::WorkerManager::processOneOccurrenceAsync
void processOneOccurrenceAsync(WaitingTask *task, typename T::MyPrincipal &principal, EventSetupImpl const &eventSetup, ServiceToken const &token, StreamID streamID, typename T::Context const *topContext, U const *context)
Definition: WorkerManager.h:137
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
edm::WorkerManager::actionTable
ExceptionToActionTable const & actionTable() const
Definition: WorkerManager.h:89
edm::ProductRegistry
Definition: ProductRegistry.h:34
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:103
TrackValidation_cff.task
task
Definition: TrackValidation_cff.py:252
edm::WorkerManager::allWorkers
AllWorkers const & allWorkers() const
Definition: WorkerManager.h:85
ConvertException.h
edm::Worker
Definition: Worker.h:83
edm::WorkerManager::actionTable_
ExceptionToActionTable const * actionTable_
Definition: WorkerManager.h:101
edm::WorkerManager::workerReg_
WorkerRegistry workerReg_
Definition: WorkerManager.h:100
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:105
edm::ParameterSet
Definition: ParameterSet.h:36
cms::Exception::context
std::list< std::string > const & context() const
Definition: Exception.cc:147
edm::ServiceRegistry::presentToken
ServiceToken presentToken() const
Definition: ServiceRegistry.cc:63
ESRecordsToProxyIndices
edm::WorkerManager::processOneOccurrence
void processOneOccurrence(typename T::MyPrincipal &principal, EventSetupImpl const &eventSetup, StreamID streamID, typename T::Context const *topContext, U const *context, bool cleaningUpAfterException=false)
Definition: WorkerManager.h:108
edm::addContextAndPrintException
void addContextAndPrintException(char const *context, cms::Exception &ex, bool disablePrint)
Definition: ExceptionHelpers.cc:11
edm::WorkerManager::processAccumulatorsAsync
void processAccumulatorsAsync(WaitingTask *task, typename T::MyPrincipal const &ep, EventSetupImpl const &es, ServiceToken const &token, StreamID streamID, ParentContext const &parentContext, typename T::Context const *context)
Definition: WorkerManager.h:149
edm::WorkerManager::allWorkers_
AllWorkers allWorkers_
Definition: WorkerManager.h:102
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
Worker.h
edm::UnscheduledCallProducer::runNowAsync
void runNowAsync(WaitingTask *task, typename T::MyPrincipal &p, EventSetupImpl const &es, ServiceToken const &token, StreamID streamID, typename T::Context const *topContext, U const *context) const
Definition: UnscheduledCallProducer.h:60
options_cfi.eventSetup
eventSetup
Definition: options_cfi.py:12
WorkerRegistry.h
edm::WorkerManager::setupOnDemandSystem
void setupOnDemandSystem(Principal &principal, EventSetupImpl const &es)
Definition: WorkerManager.cc:125
Exception.h
edm::WorkerManager::endStream
void endStream(StreamID iID, StreamContext &streamContext)
Definition: WorkerManager.cc:111
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:33
SiStripBadComponentsDQMServiceTemplate_cfg.ep
ep
Definition: SiStripBadComponentsDQMServiceTemplate_cfg.py:86
label
const char * label
Definition: PFTauDecayModeTools.cc:11
edm::UnscheduledCallProducer::runAccumulatorsAsync
void runAccumulatorsAsync(WaitingTask *task, typename T::MyPrincipal const &ep, EventSetupImpl const &es, ServiceToken const &token, StreamID streamID, ParentContext const &parentContext, typename T::Context const *context)
Definition: UnscheduledCallProducer.h:83
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:316
edm::WorkerManager::lastSetupEventPrincipal_
void const * lastSetupEventPrincipal_
Definition: WorkerManager.h:104
edm::WorkerManager::endJob
void endJob()
Definition: WorkerManager.cc:65