CMS 3D CMS Logo

GlobalSchedule.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_GlobalSchedule_h
2 #define FWCore_Framework_GlobalSchedule_h
3 
4 /*
5 */
6 
24 
25 #include <map>
26 #include <memory>
27 #include <set>
28 #include <string>
29 #include <vector>
30 #include <sstream>
31 #include "boost/range/adaptor/reversed.hpp"
32 
33 
34 namespace edm {
35 
36  namespace {
37  template <typename T>
38  class GlobalScheduleSignalSentry {
39  public:
40  GlobalScheduleSignalSentry(ActivityRegistry* a, typename T::Context const* context) :
41  a_(a), context_(context),
42  allowThrow_(false) {
43  if (a_) T::preScheduleSignal(a_, context_);
44  }
45  ~GlobalScheduleSignalSentry() noexcept(false) {
46  try {
47  if (a_) T::postScheduleSignal(a_, context_);
48  } catch(...) {
49  if(allowThrow_) {throw;}
50  }
51  }
52 
53  void allowThrow() {
54  allowThrow_ = true;
55  }
56 
57  private:
58  // We own none of these resources.
59  ActivityRegistry* a_; // We do not use propagate_const because the registry itself is mutable.
60  typename T::Context const* context_;
61  bool allowThrow_;
62  };
63  }
64 
65  class ActivityRegistry;
66  class EventSetup;
67  class ExceptionCollector;
68  class ProcessContext;
69  class PreallocationConfiguration;
70  class ModuleRegistry;
71  class TriggerResultInserter;
72  class PathStatusInserter;
73  class EndPathStatusInserter;
74 
76  public:
77  typedef std::vector<std::string> vstring;
78  typedef std::vector<Worker*> AllWorkers;
79  typedef std::shared_ptr<Worker> WorkerPtr;
80  typedef std::vector<Worker*> Workers;
81 
82  GlobalSchedule(std::shared_ptr<TriggerResultInserter> inserter,
83  std::vector<edm::propagate_const<std::shared_ptr<PathStatusInserter>>>& pathStatusInserters,
84  std::vector<edm::propagate_const<std::shared_ptr<EndPathStatusInserter>>>& endPathStatusInserters,
85  std::shared_ptr<ModuleRegistry> modReg,
86  std::vector<std::string> const& modulesToUse,
87  ParameterSet& proc_pset,
88  ProductRegistry& pregistry,
89  PreallocationConfiguration const& prealloc,
91  std::shared_ptr<ActivityRegistry> areg,
92  std::shared_ptr<ProcessConfiguration> processConfiguration,
93  ProcessContext const* processContext);
94  GlobalSchedule(GlobalSchedule const&) = delete;
95 
96  template <typename T>
97  void processOneGlobalAsync(WaitingTaskHolder holder,
98  typename T::MyPrincipal& principal,
99  EventSetup const& eventSetup,
100  ServiceToken const& token,
101  bool cleaningUpAfterException = false);
102 
103  void beginJob(ProductRegistry const&);
104  void endJob(ExceptionCollector & collector);
105 
108 
112  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
113 
116  void getTriggerReport(TriggerReport& rep) const;
117 
119  bool terminate() const;
120 
122  void replaceModule(maker::ModuleHolder* iMod, std::string const& iLabel);
123 
125  AllWorkers const& allWorkers() const {
126  return workerManagers_[0].allWorkers();
127  }
128 
129  private:
130  //Sentry class to only send a signal if an
131  // exception occurs. An exception is identified
132  // by the destructor being called without first
133  // calling completedSuccessfully().
135  public:
137  reg_(iReg),
138  context_(iContext){}
140  if(reg_) {
141  reg_->preGlobalEarlyTerminationSignal_(*context_,TerminationOrigin::ExceptionFromThisContext);
142  }
143  }
145  reg_ = nullptr;
146  }
147  private:
148  edm::ActivityRegistry* reg_; // We do not use propagate_const because the registry itself is mutable.
150  };
151 
154  return workerManagers_[0].actionTable();
155  }
156 
157  std::vector<WorkerManager> workerManagers_;
158  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
159  std::vector<edm::propagate_const<WorkerPtr>> extraWorkers_;
161  };
162 
163 
164  template <typename T>
165  void
167  typename T::MyPrincipal& ep,
168  EventSetup const& es,
169  ServiceToken const& token,
170  bool cleaningUpAfterException) {
171  try {
172  //need the doneTask to own the memory
173  auto globalContext = std::make_shared<GlobalContext>(T::makeGlobalContext(ep, processContext_));
174 
175  if(actReg_) {
176  //Services may depend upon each other
177  ServiceRegistry::Operate op(token);
178  T::preScheduleSignal(actReg_.get(), globalContext.get());
179  }
180 
181  auto doneTask = make_waiting_task(tbb::task::allocate_root(),
182  [this,iHolder, cleaningUpAfterException, globalContext, token](std::exception_ptr const* iPtr) mutable
183  {
184  std::exception_ptr excpt;
185  if(iPtr) {
186  excpt = *iPtr;
187  //add context information to the exception and print message
188  try {
189  convertException::wrap([&]() {
190  std::rethrow_exception(excpt);
191  });
192  } catch(cms::Exception& ex) {
193  //TODO: should add the transition type info
194  std::ostringstream ost;
195  if(ex.context().empty()) {
196  ost<<"Processing "<<T::transitionName()<<" ";
197  }
198  ServiceRegistry::Operate op(token);
199  addContextAndPrintException(ost.str().c_str(), ex, cleaningUpAfterException);
200  excpt = std::current_exception();
201  }
202  if(actReg_) {
203  ServiceRegistry::Operate op(token);
204  actReg_->preGlobalEarlyTerminationSignal_(*globalContext,TerminationOrigin::ExceptionFromThisContext);
205  }
206  }
207  if(actReg_) {
208  try {
209  ServiceRegistry::Operate op(token);
210  T::postScheduleSignal(actReg_.get(), globalContext.get());
211  } catch(...) {
212  if(not excpt) {
213  excpt = std::current_exception();
214  }
215  }
216  }
217  iHolder.doneWaiting(excpt);
218 
219  });
220  workerManagers_[ep.index()].resetAll();
221 
222  ParentContext parentContext(globalContext.get());
223  //make sure the ProductResolvers know about their
224  // workers to allow proper data dependency handling
225  workerManagers_[ep.index()].setupOnDemandSystem(ep,es);
226 
227  //make sure the task doesn't get run until all workers have beens started
228  WaitingTaskHolder holdForLoop(doneTask);
229  auto& aw = workerManagers_[ep.index()].allWorkers();
230  for(Worker* worker: boost::adaptors::reverse(aw) ) {
231  worker->doWorkAsync<T>(doneTask,ep,es,token, StreamID::invalidStreamID(),parentContext,globalContext.get());
232  }
233  } catch(...) {
234  iHolder.doneWaiting(std::current_exception());
235  }
236  }
237 }
238 
239 #endif
std::vector< std::string > vstring
std::vector< WorkerManager > workerManagers_
roAction_t actions[nactions]
Definition: GenABIO.cc:187
std::vector< Worker * > AllWorkers
#define noexcept
void addContextAndPrintException(char const *context, cms::Exception &ex, bool disablePrint)
static StreamID invalidStreamID()
Definition: StreamID.h:48
void beginJob()
Definition: Breakpoints.cc:15
def principal(options)
void doneWaiting(std::exception_ptr iExcept)
std::vector< Worker * > Workers
AllWorkers const & allWorkers() const
returns the collection of pointers to workers
std::list< std::string > const & context() const
Definition: Exception.cc:191
std::shared_ptr< Worker > WorkerPtr
rep
Definition: cuy.py:1189
std::shared_ptr< ActivityRegistry > actReg_
void processOneGlobalAsync(WaitingTaskHolder holder, typename T::MyPrincipal &principal, EventSetup const &eventSetup, ServiceToken const &token, bool cleaningUpAfterException=false)
FunctorWaitingTask< F > * make_waiting_task(ALLOC &&iAlloc, F f)
Definition: WaitingTask.h:92
SendTerminationSignalIfException(edm::ActivityRegistry *iReg, edm::GlobalContext const *iContext)
ExceptionToActionTable const & actionTable() const
returns the action table
HLT enums.
double a
Definition: hdecay.h:121
auto wrap(F iFunc) -> decltype(iFunc())
ProcessContext const * processContext_
long double T
std::vector< edm::propagate_const< WorkerPtr > > extraWorkers_