test
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 
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,
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_) {
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  // This call takes care of the unscheduled processing.
176  workerManager_.processOneOccurrence<T>(ep, es, StreamID::invalidStreamID(), &globalContext, &globalContext, cleaningUpAfterException);
177 
178  try {
179  convertException::wrap([&]() {
180  runNow<T>(ep,es,&globalContext);
181  });
182  }
183  catch(cms::Exception& ex) {
184  if (ex.context().empty()) {
185  addContextAndPrintException("Calling function GlobalSchedule::processOneGlobal", ex, cleaningUpAfterException);
186  } else {
187  addContextAndPrintException("", ex, cleaningUpAfterException);
188  }
189  throw;
190  }
191  terminationSentry.completedSuccessfully();
192 
193  //If we got here no other exception has happened so we can propogate any Service related exceptions
194  sentry.allowThrow();
195  }
196  template <typename T>
197  void
198  GlobalSchedule::runNow(typename T::MyPrincipal const& p, EventSetup const& es,
199  GlobalContext const* context) {
200  //do nothing for event since we will run when requested
201  for(auto & worker: allWorkers()) {
202  try {
203  ParentContext parentContext(context);
204  worker->doWork<T>(p, es,StreamID::invalidStreamID(), parentContext, context);
205  }
206  catch (cms::Exception & ex) {
207  std::ostringstream ost;
208  if (T::begin_ && T::branchType_ == InRun) {
209  ost << "Calling global beginRun";
210  }
211  else if (T::begin_ && T::branchType_ == InLumi) {
212  ost << "Calling global beginLuminosityBlock";
213  }
214  else if (!T::begin_ && T::branchType_ == InLumi) {
215  ost << "Calling global endLuminosityBlock";
216  }
217  else if (!T::begin_ && T::branchType_ == InRun) {
218  ost << "Calling global endRun";
219  }
220  else {
221  // It should be impossible to get here ...
222  ost << "Calling unknown function";
223  }
224  ost << " for module " << worker->description().moduleName()
225  << "/'" << worker->description().moduleLabel() << "'";
226  ex.addContext(ost.str());
227  ost.str("");
228  ost << "Processing " << p.id();
229  ex.addContext(ost.str());
230  throw;
231  }
232  }
233  }
234 }
235 
236 #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
edm::propagate_const< WorkerPtr > results_inserter_
void replaceModule(maker::ModuleHolder *iMod, std::string const &iLabel)
clone the type of module with label iLabel but configure with iPSet.
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:95
std::vector< Worker * > AllWorkers
#define noexcept
void addContextAndPrintException(char const *context, cms::Exception &ex, bool disablePrint)
processConfiguration
Definition: Schedule.cc:374
void runNow(typename T::MyPrincipal const &p, EventSetup const &es, GlobalContext const *context)
void addToAllWorkers(Worker *w)
static StreamID invalidStreamID()
Definition: StreamID.h:48
actions
Definition: Schedule.cc:374
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:374
std::shared_ptr< ActivityRegistry > actReg_
PreGlobalEarlyTermination preGlobalEarlyTerminationSignal_
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
AllWorkers const & allWorkers() const
Definition: WorkerManager.h:64
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_
WorkerManager workerManager_
long double T
ExceptionToActionTable const & actionTable() const
Definition: WorkerManager.h:68
prealloc
Definition: Schedule.cc:374