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 
23 
24 #include <map>
25 #include <memory>
26 #include <set>
27 #include <string>
28 #include <vector>
29 #include <sstream>
30 
31 namespace edm {
32 
33  namespace {
34  template <typename T>
35  class GlobalScheduleSignalSentry {
36  public:
37  GlobalScheduleSignalSentry(ActivityRegistry* a, typename T::Context const* context) :
38  a_(a), context_(context),
39  allowThrow_(false) {
40  if (a_) T::preScheduleSignal(a_, context_);
41  }
42  ~GlobalScheduleSignalSentry() noexcept(false) {
43  try {
44  if (a_) T::postScheduleSignal(a_, context_);
45  } catch(...) {
46  if(allowThrow_) {throw;}
47  }
48  }
49 
50  void allowThrow() {
51  allowThrow_ = true;
52  }
53 
54  private:
55  // We own none of these resources.
56  ActivityRegistry* a_; // We do not use propagate_const because the registry itself is mutable.
57  typename T::Context const* context_;
58  bool allowThrow_;
59  };
60  }
61 
62  class ActivityRegistry;
63  class EventSetup;
64  class ExceptionCollector;
65  class ProcessContext;
66  class PreallocationConfiguration;
67  class ModuleRegistry;
68  class TriggerResultInserter;
69 
71  public:
72  typedef std::vector<std::string> vstring;
73  typedef std::vector<Worker*> AllWorkers;
74  typedef std::shared_ptr<Worker> WorkerPtr;
75  typedef std::vector<Worker*> Workers;
76 
77  GlobalSchedule(std::shared_ptr<TriggerResultInserter> inserter,
78  std::shared_ptr<ModuleRegistry> modReg,
79  std::vector<std::string> const& modulesToUse,
80  ParameterSet& proc_pset,
81  ProductRegistry& pregistry,
82  PreallocationConfiguration const& prealloc,
84  std::shared_ptr<ActivityRegistry> areg,
85  std::shared_ptr<ProcessConfiguration> processConfiguration,
86  ProcessContext const* processContext);
87  GlobalSchedule(GlobalSchedule const&) = delete;
88 
89  template <typename T>
90  void processOneGlobal(typename T::MyPrincipal& principal,
91  EventSetup const& eventSetup,
92  bool cleaningUpAfterException = false);
93 
94  void beginJob(ProductRegistry const&);
95  void endJob(ExceptionCollector & collector);
96 
99 
103  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
104 
107  void getTriggerReport(TriggerReport& rep) const;
108 
110  bool terminate() const;
111 
113  void replaceModule(maker::ModuleHolder* iMod, std::string const& iLabel);
114 
116  AllWorkers const& allWorkers() const {
117  return workerManager_.allWorkers();
118  }
119 
120  private:
121  //Sentry class to only send a signal if an
122  // exception occurs. An exception is identified
123  // by the destructor being called without first
124  // calling completedSuccessfully().
126  public:
128  reg_(iReg),
129  context_(iContext){}
131  if(reg_) {
132  reg_->preGlobalEarlyTerminationSignal_(*context_,TerminationOrigin::ExceptionFromThisContext);
133  }
134  }
136  reg_ = nullptr;
137  }
138  private:
139  edm::ActivityRegistry* reg_; // We do not use propagate_const because the registry itself is mutable.
141  };
142 
143 
144  template<typename T>
145  void runNow(typename T::MyPrincipal const& p, EventSetup const& es,
146  GlobalContext const* context);
147 
150  return workerManager_.actionTable();
151  }
152 
153  void addToAllWorkers(Worker* w);
154 
156  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
158 
159 
161  };
162 
163 
164  template <typename T>
165  void
166  GlobalSchedule::processOneGlobal(typename T::MyPrincipal& ep,
167  EventSetup const& es,
168  bool cleaningUpAfterException) {
169  GlobalContext globalContext = T::makeGlobalContext(ep, processContext_);
170 
171  GlobalScheduleSignalSentry<T> sentry(actReg_.get(), &globalContext);
172 
173  SendTerminationSignalIfException terminationSentry(actReg_.get(), &globalContext);
174 
175  //If we are in an end transition, we need to reset failed items since they might
176  // be set this time around
177  if( not T::begin_) {
178  ep.resetFailedFromThisProcess();
179  }
180  // This call takes care of the unscheduled processing.
181  workerManager_.processOneOccurrence<T>(ep, es, StreamID::invalidStreamID(), &globalContext, &globalContext, cleaningUpAfterException);
182 
183  try {
184  convertException::wrap([&]() {
185  runNow<T>(ep,es,&globalContext);
186  });
187  }
188  catch(cms::Exception& ex) {
189  if (ex.context().empty()) {
190  addContextAndPrintException("Calling function GlobalSchedule::processOneGlobal", ex, cleaningUpAfterException);
191  } else {
192  addContextAndPrintException("", ex, cleaningUpAfterException);
193  }
194  throw;
195  }
196  terminationSentry.completedSuccessfully();
197 
198  //If we got here no other exception has happened so we can propogate any Service related exceptions
199  sentry.allowThrow();
200  }
201  template <typename T>
202  void
203  GlobalSchedule::runNow(typename T::MyPrincipal const& p, EventSetup const& es,
204  GlobalContext const* context) {
205  //do nothing for event since we will run when requested
206  for(auto & worker: allWorkers()) {
207  try {
208  ParentContext parentContext(context);
209  worker->doWork<T>(p, es,StreamID::invalidStreamID(), parentContext, context);
210  }
211  catch (cms::Exception & ex) {
212  if(ex.context().empty()) {
213  std::ostringstream ost;
214  ost << "Processing " <<T::transitionName()<<" "<< p.id();
215  ex.addContext(ost.str());
216  }
217  throw;
218  }
219  }
220  }
221 }
222 
223 #endif
void processOneGlobal(typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
std::vector< std::string > vstring
edm::propagate_const< WorkerPtr > results_inserter_
roAction_t actions[nactions]
Definition: GenABIO.cc:187
const double w
Definition: UKUtility.cc:23
std::vector< Worker * > AllWorkers
#define noexcept
void addContextAndPrintException(char const *context, cms::Exception &ex, bool disablePrint)
void runNow(typename T::MyPrincipal const &p, EventSetup const &es, GlobalContext const *context)
static StreamID invalidStreamID()
Definition: StreamID.h:48
void beginJob()
Definition: Breakpoints.cc:15
def principal(options)
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:1188
std::shared_ptr< ActivityRegistry > actReg_
void addContext(std::string const &context)
Definition: Exception.cc:227
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_
WorkerManager workerManager_
long double T