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 "boost/shared_ptr.hpp"
24 
25 #include <map>
26 #include <memory>
27 #include <set>
28 #include <string>
29 #include <vector>
30 #include <sstream>
31 
32 namespace edm {
33 
34  namespace {
35  template <typename T>
36  class GlobalScheduleSignalSentry {
37  public:
38  GlobalScheduleSignalSentry(ActivityRegistry* a, typename T::MyPrincipal* principal, EventSetup const* es, typename T::Context const* context) :
39  a_(a), principal_(principal), es_(es), context_(context),
40  allowThrow_(false) {
41  if (a_) T::preScheduleSignal(a_, principal_, context_);
42  }
43  ~GlobalScheduleSignalSentry() noexcept(false) {
44  try {
45  if (a_) if (principal_) T::postScheduleSignal(a_, principal_, es_, context_);
46  } catch(...) {
47  if(allowThrow_) {throw;}
48  }
49  }
50 
51  void allowThrow() {
52  allowThrow_ = true;
53  }
54 
55  private:
56  // We own none of these resources.
57  ActivityRegistry* a_;
58  typename T::MyPrincipal* principal_;
59  EventSetup const* es_;
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 
74  public:
75  typedef std::vector<std::string> vstring;
76  typedef std::vector<Worker*> AllWorkers;
77  typedef boost::shared_ptr<Worker> WorkerPtr;
78  typedef std::vector<Worker*> Workers;
79 
81  boost::shared_ptr<ModuleRegistry> modReg,
82  std::vector<std::string> const& modulesToUse,
83  ParameterSet& proc_pset,
84  ProductRegistry& pregistry,
87  boost::shared_ptr<ActivityRegistry> areg,
88  boost::shared_ptr<ProcessConfiguration> processConfiguration,
89  ProcessContext const* processContext);
90  GlobalSchedule(GlobalSchedule const&) = delete;
91 
92  template <typename T>
93  void processOneGlobal(typename T::MyPrincipal& principal,
94  EventSetup const& eventSetup,
95  bool cleaningUpAfterException = false);
96 
97  void beginJob(ProductRegistry const&);
98  void endJob(ExceptionCollector & collector);
99 
102 
106  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
107 
110  void getTriggerReport(TriggerReport& rep) const;
111 
113  bool terminate() const;
114 
116  void replaceModule(maker::ModuleHolder* iMod, std::string const& iLabel);
117 
119  AllWorkers const& allWorkers() const {
120  return workerManager_.allWorkers();
121  }
122 
123  private:
124 
125  template<typename T>
126  void runNow(typename T::MyPrincipal& p, EventSetup const& es,
127  GlobalContext const* context);
128 
131  return workerManager_.actionTable();
132  }
133 
134  void addToAllWorkers(Worker* w);
135 
137  boost::shared_ptr<ActivityRegistry> actReg_;
139 
140 
142  };
143 
144 
145  template <typename T>
146  void
147  GlobalSchedule::processOneGlobal(typename T::MyPrincipal& ep,
148  EventSetup const& es,
149  bool cleaningUpAfterException) {
150  GlobalContext globalContext = T::makeGlobalContext(ep, processContext_);
151 
152  GlobalScheduleSignalSentry<T> sentry(actReg_.get(), &ep, &es, &globalContext);
153 
154  // This call takes care of the unscheduled processing.
155  workerManager_.processOneOccurrence<T>(ep, es, StreamID::invalidStreamID(), &globalContext, &globalContext, cleaningUpAfterException);
156 
157  try {
158  try {
159  runNow<T>(ep,es,&globalContext);
160  }
161  catch (cms::Exception& e) { throw; }
162  catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
163  catch (std::exception& e) { convertException::stdToEDM(e); }
165  catch(char const* c) { convertException::charPtrToEDM(c); }
166  catch (...) { convertException::unknownToEDM(); }
167  }
168  catch(cms::Exception& ex) {
169  if (ex.context().empty()) {
170  addContextAndPrintException("Calling function GlobalSchedule::processOneGlobal", ex, cleaningUpAfterException);
171  } else {
172  addContextAndPrintException("", ex, cleaningUpAfterException);
173  }
174  throw;
175  }
176  //If we got here no other exception has happened so we can propogate any Service related exceptions
177  sentry.allowThrow();
178  }
179  template <typename T>
180  void
181  GlobalSchedule::runNow(typename T::MyPrincipal& p, EventSetup const& es,
182  GlobalContext const* context) {
183  //do nothing for event since we will run when requested
184  for(auto & worker: allWorkers()) {
185  try {
186  ParentContext parentContext(context);
187  worker->doWork<T>(p, es, nullptr,StreamID::invalidStreamID(), parentContext, context);
188  }
189  catch (cms::Exception & ex) {
190  std::ostringstream ost;
191  if (T::begin_ && T::branchType_ == InRun) {
192  ost << "Calling beginRun";
193  }
194  else if (T::begin_ && T::branchType_ == InLumi) {
195  ost << "Calling beginLuminosityBlock";
196  }
197  else if (!T::begin_ && T::branchType_ == InLumi) {
198  ost << "Calling endLuminosityBlock";
199  }
200  else if (!T::begin_ && T::branchType_ == InRun) {
201  ost << "Calling endRun";
202  }
203  else {
204  // It should be impossible to get here ...
205  ost << "Calling unknown function";
206  }
207  ost << " for unscheduled module " << worker->description().moduleName()
208  << "/'" << worker->description().moduleLabel() << "'";
209  ex.addContext(ost.str());
210  ost.str("");
211  ost << "Processing " << p.id();
212  ex.addContext(ost.str());
213  throw;
214  }
215  }
216  }
217 }
218 
219 #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)
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:92
std::vector< Worker * > AllWorkers
void addContextAndPrintException(char const *context, cms::Exception &ex, bool disablePrint)
processConfiguration
Definition: Schedule.cc:362
void addToAllWorkers(Worker *w)
static StreamID invalidStreamID()
Definition: StreamID.h:48
actions
Definition: Schedule.cc:362
bool terminate() const
Return whether each output module has reached its maximum count.
void beginJob(ProductRegistry const &)
std::vector< Worker * > Workers
void stdToEDM(std::exception const &e)
AllWorkers const & allWorkers() const
returns the collection of pointers to workers
std::list< std::string > const & context() const
Definition: Exception.cc:191
boost::shared_ptr< ActivityRegistry > actReg_
void endJob(ExceptionCollector &collector)
areg
Definition: Schedule.cc:362
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
#define noexcept
AllWorkers const & allWorkers() const
Definition: WorkerManager.h:64
void charPtrToEDM(char const *c)
void stringToEDM(std::string &s)
void addContext(std::string const &context)
Definition: Exception.cc:227
ExceptionToActionTable const & actionTable() const
returns the action table
double a
Definition: hdecay.h:121
GlobalSchedule(TriggerResultInserter *inserter, boost::shared_ptr< ModuleRegistry > modReg, std::vector< std::string > const &modulesToUse, ParameterSet &proc_pset, ProductRegistry &pregistry, PreallocationConfiguration const &prealloc, ExceptionToActionTable const &actions, boost::shared_ptr< ActivityRegistry > areg, boost::shared_ptr< ProcessConfiguration > processConfiguration, ProcessContext const *processContext)
T w() const
volatile std::atomic< bool > shutdown_flag false
ProcessContext const * processContext_
WorkerPtr results_inserter_
WorkerManager workerManager_
long double T
boost::shared_ptr< Worker > WorkerPtr
ExceptionToActionTable const & actionTable() const
Definition: WorkerManager.h:68
prealloc
Definition: Schedule.cc:362