CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
22 
23 #include <map>
24 #include <memory>
25 #include <set>
26 #include <string>
27 #include <vector>
28 #include <sstream>
29 
30 namespace edm {
31 
32  namespace {
33  template <typename T>
34  class GlobalScheduleSignalSentry {
35  public:
36  GlobalScheduleSignalSentry(ActivityRegistry* a, typename T::Context const* context) :
37  a_(a), context_(context),
38  allowThrow_(false) {
39  if (a_) T::preScheduleSignal(a_, context_);
40  }
41  ~GlobalScheduleSignalSentry() noexcept(false) {
42  try {
43  if (a_) T::postScheduleSignal(a_, context_);
44  } catch(...) {
45  if(allowThrow_) {throw;}
46  }
47  }
48 
49  void allowThrow() {
50  allowThrow_ = true;
51  }
52 
53  private:
54  // We own none of these resources.
55  ActivityRegistry* a_;
56  typename T::Context const* context_;
57  bool allowThrow_;
58  };
59  }
60 
61  class ActivityRegistry;
62  class EventSetup;
63  class ExceptionCollector;
64  class ProcessContext;
65  class PreallocationConfiguration;
66  class ModuleRegistry;
67  class TriggerResultInserter;
68 
70  public:
71  typedef std::vector<std::string> vstring;
72  typedef std::vector<Worker*> AllWorkers;
73  typedef std::shared_ptr<Worker> WorkerPtr;
74  typedef std::vector<Worker*> Workers;
75 
76  GlobalSchedule(std::shared_ptr<TriggerResultInserter> inserter,
77  std::shared_ptr<ModuleRegistry> modReg,
78  std::vector<std::string> const& modulesToUse,
79  ParameterSet& proc_pset,
80  ProductRegistry& pregistry,
83  std::shared_ptr<ActivityRegistry> areg,
84  std::shared_ptr<ProcessConfiguration> processConfiguration,
85  ProcessContext const* processContext);
86  GlobalSchedule(GlobalSchedule const&) = delete;
87 
88  template <typename T>
89  void processOneGlobal(typename T::MyPrincipal& principal,
90  EventSetup const& eventSetup,
91  bool cleaningUpAfterException = false);
92 
93  void beginJob(ProductRegistry const&);
94  void endJob(ExceptionCollector & collector);
95 
98 
102  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
103 
106  void getTriggerReport(TriggerReport& rep) const;
107 
109  bool terminate() const;
110 
112  void replaceModule(maker::ModuleHolder* iMod, std::string const& iLabel);
113 
115  AllWorkers const& allWorkers() const {
116  return workerManager_.allWorkers();
117  }
118 
119  private:
120  //Sentry class to only send a signal if an
121  // exception occurs. An exception is identified
122  // by the destructor being called without first
123  // calling completedSuccessfully().
125  public:
127  reg_(iReg),
128  context_(iContext){}
130  if(reg_) {
132  }
133  }
135  reg_ = nullptr;
136  }
137  private:
140  };
141 
142 
143  template<typename T>
144  void runNow(typename T::MyPrincipal& p, EventSetup const& es,
145  GlobalContext const* context);
146 
149  return workerManager_.actionTable();
150  }
151 
152  void addToAllWorkers(Worker* w);
153 
155  std::shared_ptr<ActivityRegistry> actReg_;
157 
158 
160  };
161 
162 
163  template <typename T>
164  void
165  GlobalSchedule::processOneGlobal(typename T::MyPrincipal& ep,
166  EventSetup const& es,
167  bool cleaningUpAfterException) {
168  GlobalContext globalContext = T::makeGlobalContext(ep, processContext_);
169 
170  GlobalScheduleSignalSentry<T> sentry(actReg_.get(), &globalContext);
171 
172  SendTerminationSignalIfException terminationSentry(actReg_.get(), &globalContext);
173 
174  // This call takes care of the unscheduled processing.
175  workerManager_.processOneOccurrence<T>(ep, es, StreamID::invalidStreamID(), &globalContext, &globalContext, cleaningUpAfterException);
176 
177  try {
178  convertException::wrap([&]() {
179  runNow<T>(ep,es,&globalContext);
180  });
181  }
182  catch(cms::Exception& ex) {
183  if (ex.context().empty()) {
184  addContextAndPrintException("Calling function GlobalSchedule::processOneGlobal", ex, cleaningUpAfterException);
185  } else {
186  addContextAndPrintException("", ex, cleaningUpAfterException);
187  }
188  throw;
189  }
190  terminationSentry.completedSuccessfully();
191 
192  //If we got here no other exception has happened so we can propogate any Service related exceptions
193  sentry.allowThrow();
194  }
195  template <typename T>
196  void
197  GlobalSchedule::runNow(typename T::MyPrincipal& p, EventSetup const& es,
198  GlobalContext const* context) {
199  //do nothing for event since we will run when requested
200  for(auto & worker: allWorkers()) {
201  try {
202  ParentContext parentContext(context);
203  worker->doWork<T>(p, es,StreamID::invalidStreamID(), parentContext, context);
204  }
205  catch (cms::Exception & ex) {
206  std::ostringstream ost;
207  if (T::begin_ && T::branchType_ == InRun) {
208  ost << "Calling global beginRun";
209  }
210  else if (T::begin_ && T::branchType_ == InLumi) {
211  ost << "Calling global beginLuminosityBlock";
212  }
213  else if (!T::begin_ && T::branchType_ == InLumi) {
214  ost << "Calling global endLuminosityBlock";
215  }
216  else if (!T::begin_ && T::branchType_ == InRun) {
217  ost << "Calling global endRun";
218  }
219  else {
220  // It should be impossible to get here ...
221  ost << "Calling unknown function";
222  }
223  ost << " for module " << worker->description().moduleName()
224  << "/'" << worker->description().moduleLabel() << "'";
225  ex.addContext(ost.str());
226  ost.str("");
227  ost << "Processing " << p.id();
228  ex.addContext(ost.str());
229  throw;
230  }
231  }
232  }
233 }
234 
235 #endif
void getTriggerReport(TriggerReport &rep) const
string rep
Definition: cuy.py:1188
void processOneGlobal(typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
std::vector< std::string > vstring
void replaceModule(maker::ModuleHolder *iMod, std::string const &iLabel)
clone the type of module with label iLabel but configure with iPSet.
void runNow(typename T::MyPrincipal &p, EventSetup const &es, GlobalContext const *context)
const double w
Definition: UKUtility.cc:23
void processOneOccurrence(typename T::MyPrincipal &principal, EventSetup const &eventSetup, StreamID streamID, typename T::Context const *topContext, U const *context, bool cleaningUpAfterException=false)
Definition: WorkerManager.h:91
std::vector< Worker * > AllWorkers
#define noexcept
void addContextAndPrintException(char const *context, cms::Exception &ex, bool disablePrint)
processConfiguration
Definition: Schedule.cc:369
void addToAllWorkers(Worker *w)
static StreamID invalidStreamID()
Definition: StreamID.h:48
actions
Definition: Schedule.cc:369
bool terminate() const
Return whether each output module has reached its maximum count.
void beginJob(ProductRegistry const &)
GlobalSchedule(std::shared_ptr< TriggerResultInserter > inserter, std::shared_ptr< ModuleRegistry > modReg, std::vector< std::string > const &modulesToUse, ParameterSet &proc_pset, ProductRegistry &pregistry, PreallocationConfiguration const &prealloc, ExceptionToActionTable const &actions, std::shared_ptr< ActivityRegistry > areg, std::shared_ptr< ProcessConfiguration > processConfiguration, ProcessContext const *processContext)
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
void endJob(ExceptionCollector &collector)
areg
Definition: Schedule.cc:369
std::shared_ptr< ActivityRegistry > actReg_
PreGlobalEarlyTermination preGlobalEarlyTerminationSignal_
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
AllWorkers const & allWorkers() const
Definition: WorkerManager.h:63
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
double a
Definition: hdecay.h:121
auto wrap(F iFunc) -> decltype(iFunc())
volatile std::atomic< bool > shutdown_flag false
ProcessContext const * processContext_
WorkerPtr results_inserter_
WorkerManager workerManager_
long double T
ExceptionToActionTable const & actionTable() const
Definition: WorkerManager.h:67
prealloc
Definition: Schedule.cc:369