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::Context const* context) :
39  a_(a), context_(context),
40  allowThrow_(false) {
41  if (a_) T::preScheduleSignal(a_, context_);
42  }
43  ~GlobalScheduleSignalSentry() noexcept(false) {
44  try {
45  if (a_) T::postScheduleSignal(a_, 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::Context const* context_;
59  bool allowThrow_;
60  };
61  }
62 
63  class ActivityRegistry;
64  class EventSetup;
65  class ExceptionCollector;
66  class ProcessContext;
67  class PreallocationConfiguration;
68  class ModuleRegistry;
69  class TriggerResultInserter;
70 
72  public:
73  typedef std::vector<std::string> vstring;
74  typedef std::vector<Worker*> AllWorkers;
75  typedef boost::shared_ptr<Worker> WorkerPtr;
76  typedef std::vector<Worker*> Workers;
77 
79  boost::shared_ptr<ModuleRegistry> modReg,
80  std::vector<std::string> const& modulesToUse,
81  ParameterSet& proc_pset,
82  ProductRegistry& pregistry,
85  boost::shared_ptr<ActivityRegistry> areg,
86  boost::shared_ptr<ProcessConfiguration> processConfiguration,
87  ProcessContext const* processContext);
88  GlobalSchedule(GlobalSchedule const&) = delete;
89 
90  template <typename T>
91  void processOneGlobal(typename T::MyPrincipal& principal,
92  EventSetup const& eventSetup,
93  bool cleaningUpAfterException = false);
94 
95  void beginJob(ProductRegistry const&);
96  void endJob(ExceptionCollector & collector);
97 
100 
104  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
105 
108  void getTriggerReport(TriggerReport& rep) const;
109 
111  bool terminate() const;
112 
114  void replaceModule(maker::ModuleHolder* iMod, std::string const& iLabel);
115 
117  AllWorkers const& allWorkers() const {
118  return workerManager_.allWorkers();
119  }
120 
121  private:
122 
123  template<typename T>
124  void runNow(typename T::MyPrincipal& p, EventSetup const& es,
125  GlobalContext const* context);
126 
129  return workerManager_.actionTable();
130  }
131 
132  void addToAllWorkers(Worker* w);
133 
135  boost::shared_ptr<ActivityRegistry> actReg_;
137 
138 
140  };
141 
142 
143  template <typename T>
144  void
145  GlobalSchedule::processOneGlobal(typename T::MyPrincipal& ep,
146  EventSetup const& es,
147  bool cleaningUpAfterException) {
148  GlobalContext globalContext = T::makeGlobalContext(ep, processContext_);
149 
150  GlobalScheduleSignalSentry<T> sentry(actReg_.get(), &globalContext);
151 
152  // This call takes care of the unscheduled processing.
153  workerManager_.processOneOccurrence<T>(ep, es, StreamID::invalidStreamID(), &globalContext, &globalContext, cleaningUpAfterException);
154 
155  try {
156  convertException::wrap([&]() {
157  runNow<T>(ep,es,&globalContext);
158  });
159  }
160  catch(cms::Exception& ex) {
161  if (ex.context().empty()) {
162  addContextAndPrintException("Calling function GlobalSchedule::processOneGlobal", ex, cleaningUpAfterException);
163  } else {
164  addContextAndPrintException("", ex, cleaningUpAfterException);
165  }
166  throw;
167  }
168  //If we got here no other exception has happened so we can propogate any Service related exceptions
169  sentry.allowThrow();
170  }
171  template <typename T>
172  void
173  GlobalSchedule::runNow(typename T::MyPrincipal& p, EventSetup const& es,
174  GlobalContext const* context) {
175  //do nothing for event since we will run when requested
176  for(auto & worker: allWorkers()) {
177  try {
178  ParentContext parentContext(context);
179  worker->doWork<T>(p, es, nullptr,StreamID::invalidStreamID(), parentContext, context);
180  }
181  catch (cms::Exception & ex) {
182  std::ostringstream ost;
183  if (T::begin_ && T::branchType_ == InRun) {
184  ost << "Calling beginRun";
185  }
186  else if (T::begin_ && T::branchType_ == InLumi) {
187  ost << "Calling beginLuminosityBlock";
188  }
189  else if (!T::begin_ && T::branchType_ == InLumi) {
190  ost << "Calling endLuminosityBlock";
191  }
192  else if (!T::begin_ && T::branchType_ == InRun) {
193  ost << "Calling endRun";
194  }
195  else {
196  // It should be impossible to get here ...
197  ost << "Calling unknown function";
198  }
199  ost << " for unscheduled module " << worker->description().moduleName()
200  << "/'" << worker->description().moduleLabel() << "'";
201  ex.addContext(ost.str());
202  ost.str("");
203  ost << "Processing " << p.id();
204  ex.addContext(ost.str());
205  throw;
206  }
207  }
208  }
209 }
210 
211 #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:92
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 &)
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
boost::shared_ptr< ActivityRegistry > actReg_
void endJob(ExceptionCollector &collector)
areg
Definition: Schedule.cc:369
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
AllWorkers const & allWorkers() const
Definition: WorkerManager.h:64
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)
auto wrap(F iFunc) -> decltype(iFunc())
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:369