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 
16 
17 #include <memory>
18 
19 #include <set>
20 #include <string>
21 #include <vector>
22 
23 namespace edm {
24  class ExceptionCollector;
25  class StreamID;
26  class StreamContext;
27  class ModuleRegistry;
28  class PreallocationConfiguration;
29 
30  class WorkerManager {
31  public:
32  typedef std::vector<Worker*> AllWorkers;
33 
34  WorkerManager(std::shared_ptr<ActivityRegistry> actReg, ExceptionToActionTable const& actions);
35 
36  WorkerManager(std::shared_ptr<ModuleRegistry> modReg,
37  std::shared_ptr<ActivityRegistry> actReg,
40  ProductRegistry& preg,
41  PreallocationConfiguration const* prealloc,
42  std::shared_ptr<ProcessConfiguration> processConfiguration,
44  std::set<std::string>& unscheduledLabels,
45  std::vector<std::string>& shouldBeUsedLabels);
46 
47  void setOnDemandProducts(ProductRegistry& pregistry, std::set<std::string> const& unscheduledLabels) const;
48 
49  template <typename T, typename U>
50  void processOneOccurrence(typename T::MyPrincipal& principal,
51  EventSetup const& eventSetup,
52  StreamID streamID,
53  typename T::Context const* topContext,
54  U const* context,
55  bool cleaningUpAfterException = false);
56  template <typename T, typename U>
58  WaitingTask* task,
59  typename T::MyPrincipal& principal,
60  EventSetup const& eventSetup,
61  StreamID streamID,
62  typename T::Context const* topContext,
63  U const* context);
64 
65 
67 
68  void beginJob(ProductRegistry const& iRegistry);
69  void endJob();
70  void endJob(ExceptionCollector& collector);
71 
72  void beginStream(StreamID iID, StreamContext& streamContext);
73  void endStream(StreamID iID, StreamContext& streamContext);
74 
75  AllWorkers const& allWorkers() const {return allWorkers_;}
76 
77  void addToAllWorkers(Worker* w);
78 
80 
82  ProductRegistry& preg,
83  PreallocationConfiguration const* prealloc,
84  std::shared_ptr<ProcessConfiguration const> processConfiguration,
85  std::string const& label);
86 
87  void resetAll();
88 
89  private:
90 
93  AllWorkers allWorkers_;
96  };
97 
98  template <typename T, typename U>
99  void
100  WorkerManager::processOneOccurrence(typename T::MyPrincipal& ep,
101  EventSetup const& es,
102  StreamID streamID,
103  typename T::Context const* topContext,
104  U const* context,
105  bool cleaningUpAfterException) {
106  this->resetAll();
107 
108  auto waitTask = make_empty_waiting_task();
109  waitTask->increment_ref_count();
110  processOneOccurrenceAsync<T,U>(waitTask.get(), ep, es, streamID, topContext, context);
111  waitTask->wait_for_all();
112  if(waitTask->exceptionPtr() != nullptr) {
113  try{
114  convertException::wrap([&]() {
115  std::rethrow_exception(* (waitTask->exceptionPtr()) );
116  });
117  } catch(cms::Exception& ex) {
118  if (ex.context().empty()) {
119  addContextAndPrintException("Calling function WorkerManager::processOneOccurrence", ex, cleaningUpAfterException);
120  } else {
121  addContextAndPrintException("", ex, cleaningUpAfterException);
122  }
123  throw;
124  }
125  }
126  }
127 
128  template <typename T, typename U>
129  void
131  typename T::MyPrincipal& ep,
132  EventSetup const& es,
133  StreamID streamID,
134  typename T::Context const* topContext,
135  U const* context) {
136  //make sure the unscheduled items see this run or lumi transition
137  unscheduled_.runNowAsync<T,U>(task,ep, es,streamID, topContext, context);
138  }
139 
140 }
141 
142 #endif
roAction_t actions[nactions]
Definition: GenABIO.cc:187
void endStream(StreamID iID, StreamContext &streamContext)
const double w
Definition: UKUtility.cc:23
UnscheduledCallProducer unscheduled_
Definition: WorkerManager.h:94
void setOnDemandProducts(ProductRegistry &pregistry, std::set< std::string > const &unscheduledLabels) const
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)
AllWorkers allWorkers_
Definition: WorkerManager.h:93
void processOneOccurrence(typename T::MyPrincipal &principal, EventSetup const &eventSetup, StreamID streamID, typename T::Context const *topContext, U const *context, bool cleaningUpAfterException=false)
void addContextAndPrintException(char const *context, cms::Exception &ex, bool disablePrint)
void beginJob(ProductRegistry const &iRegistry)
ExceptionToActionTable const * actionTable_
Definition: WorkerManager.h:92
void const * lastSetupEventPrincipal_
Definition: WorkerManager.h:95
void processOneOccurrenceAsync(WaitingTask *task, typename T::MyPrincipal &principal, EventSetup const &eventSetup, StreamID streamID, typename T::Context const *topContext, U const *context)
std::vector< Worker * > AllWorkers
Definition: WorkerManager.h:32
def principal(options)
std::unique_ptr< edm::EmptyWaitingTask, waitingtask::TaskDestroyer > make_empty_waiting_task()
Create an EmptyWaitingTask which will properly be destroyed.
void runNowAsync(WaitingTask *task, typename T::MyPrincipal &p, EventSetup const &es, StreamID streamID, typename T::Context const *topContext, U const *context) const
std::list< std::string > const & context() const
Definition: Exception.cc:191
void beginStream(StreamID iID, StreamContext &streamContext)
AllWorkers const & allWorkers() const
Definition: WorkerManager.h:75
HLT enums.
WorkerRegistry workerReg_
Definition: WorkerManager.h:91
The Registry of all workers that where requested Holds all instances of workers. In this implementati...
auto wrap(F iFunc) -> decltype(iFunc())
WorkerManager(std::shared_ptr< ActivityRegistry > actReg, ExceptionToActionTable const &actions)
void setupOnDemandSystem(Principal &principal, EventSetup const &es)
long double T
Worker * getWorker(ParameterSet &pset, ProductRegistry &preg, PreallocationConfiguration const *prealloc, std::shared_ptr< ProcessConfiguration const > processConfiguration, std::string const &label)
ExceptionToActionTable const & actionTable() const
Definition: WorkerManager.h:79
void addToAllWorkers(Worker *w)