CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Schedule.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_Schedule_h
2 #define FWCore_Framework_Schedule_h
3 
4 /*
5  Author: Jim Kowalkowski 28-01-06
6 
7  A class for creating a schedule based on paths in the configuration file.
8  The schedule is maintained as a sequence of paths.
9  After construction, events can be fed to the object and passed through
10  all the modules in the schedule. All accounting about processing
11  of events by modules and paths is contained here or in object held
12  by containment.
13 
14  The trigger results producer and product are generated and managed here.
15  This class also manages endpaths and calls to endjob and beginjob.
16  Endpaths are just treated as a simple list of modules that need to
17  do processing of the event and do not participate in trigger path
18  activities.
19 
20  This class requires the high-level process pset. It uses @process_name.
21  If the high-level pset contains an "options" pset, then the
22  following optional parameter can be present:
23  bool wantSummary = true/false # default false
24 
25  wantSummary indicates whether or not the pass/fail/error stats
26  for modules and paths should be printed at the end-of-job.
27 
28  A TriggerResults object will always be inserted into the event
29  for any schedule. The producer of the TriggerResults EDProduct
30  is always the first module in the endpath. The TriggerResultInserter
31  is given a fixed label of "TriggerResults".
32 
33  Processing of an event happens by pushing the event through the Paths.
34  The scheduler performs the reset() on each of the workers independent
35  of the Path objects.
36 
37  ------------------------
38 
39  About Paths:
40  Paths fit into two categories:
41  1) trigger paths that contribute directly to saved trigger bits
42  2) end paths
43  The Schedule holds these paths in two data structures:
44  1) main path list
45  2) end path list
46 
47  Trigger path processing always precedes endpath processing.
48  The order of the paths from the input configuration is
49  preserved in the main paths list.
50 
51  ------------------------
52 
53  The Schedule uses the TriggerNamesService to get the names of the
54  trigger paths and end paths. When a TriggerResults object is created
55  the results are stored in the same order as the trigger names from
56  TriggerNamesService.
57 
58 */
59 
74 
75 #include "boost/shared_ptr.hpp"
76 
77 #include <map>
78 #include <memory>
79 #include <set>
80 #include <string>
81 #include <vector>
82 
83 namespace edm {
84  namespace service {
85  class TriggerNamesService;
86  }
87  class ActivityRegistry;
88  class EventSetup;
89  class OutputWorker;
90  class RunStopwatch;
91  class UnscheduledCallProducer;
92  class WorkerInPath;
93  class Schedule {
94  public:
95  typedef std::vector<std::string> vstring;
96  typedef std::vector<Path> TrigPaths;
97  typedef std::vector<Path> NonTrigPaths;
98  typedef boost::shared_ptr<HLTGlobalStatus> TrigResPtr;
99  typedef boost::shared_ptr<Worker> WorkerPtr;
100  typedef std::vector<Worker*> AllWorkers;
101  typedef std::vector<OutputWorker*> AllOutputWorkers;
102 
103  typedef std::vector<Worker*> Workers;
104 
105  typedef std::vector<WorkerInPath> PathWorkers;
106 
107  Schedule(ParameterSet& proc_pset,
109  ProductRegistry& pregistry,
110  ActionTable const& actions,
111  boost::shared_ptr<ActivityRegistry> areg,
112  boost::shared_ptr<ProcessConfiguration> processConfiguration);
113 
114  enum State { Ready = 0, Running, Latched };
115 
116  template <typename T>
117  void processOneOccurrence(typename T::MyPrincipal& principal, EventSetup const& eventSetup);
118 
119  void beginJob();
120  void endJob();
121 
122  // Write the luminosity block
123  void writeLumi(LuminosityBlockPrincipal const& lbp);
124 
125  // Write the run
126  void writeRun(RunPrincipal const& rp);
127 
128  // Call closeFile() on all OutputModules.
129  void closeOutputFiles();
130 
131  // Call openNewFileIfNeeded() on all OutputModules
133 
134  // Call openFiles() on all OutputModules
136 
137  // Call respondToOpenInputFile() on all Modules
138  void respondToOpenInputFile(FileBlock const& fb);
139 
140  // Call respondToCloseInputFile() on all Modules
141  void respondToCloseInputFile(FileBlock const& fb);
142 
143  // Call respondToOpenOutputFiles() on all Modules
145 
146  // Call respondToCloseOutputFiles() on all Modules
148 
149  // Call shouldWeCloseFile() on all OutputModules.
150  bool shouldWeCloseOutput() const;
151 
153  void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren);
154 
155  std::pair<double, double> timeCpuReal() const {
156  return std::pair<double, double>(stopwatch_->cpuTime(), stopwatch_->realTime());
157  }
158 
161 
165  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
166 
168  void availablePaths(std::vector<std::string>& oLabelsToFill) const;
169 
171  void modulesInPath(std::string const& iPathLabel,
172  std::vector<std::string>& oLabelsToFill) const;
173 
177  int totalEvents() const {
178  return total_events_;
179  }
180 
183  int totalEventsPassed() const {
184  return total_passed_;
185  }
186 
189  int totalEventsFailed() const {
190  return totalEvents() - totalEventsPassed();
191  }
192 
195  void enableEndPaths(bool active);
196 
199  bool endPathsEnabled() const;
200 
203  void getTriggerReport(TriggerReport& rep) const;
204 
206  bool const terminate() const;
207 
209  void clearCounters();
210 
213  bool changeModule(std::string const& iLabel, ParameterSet const& iPSet);
214 
215  private:
216 
217  AllWorkers::const_iterator workersBegin() const {
218  return all_workers_.begin();
219  }
220 
221  AllWorkers::const_iterator workersEnd() const {
222  return all_workers_.end();
223  }
224 
225  AllWorkers::iterator workersBegin() {
226  return all_workers_.begin();
227  }
228 
229  AllWorkers::iterator workersEnd() {
230  return all_workers_.end();
231  }
232 
233  void resetAll();
234 
235  template <typename T>
236  bool runTriggerPaths(typename T::MyPrincipal&, EventSetup const&);
237 
238  template <typename T>
239  void runEndPaths(typename T::MyPrincipal&, EventSetup const&);
240 
242 
243  void reportSkipped(EventPrincipal const& ep) const;
245  void reportSkipped(RunPrincipal const&) const {}
246 
247  void fillWorkers(ParameterSet& proc_pset,
248  ProductRegistry& preg,
249  boost::shared_ptr<ProcessConfiguration const> processConfiguration,
250  std::string const& name, bool ignoreFilters, PathWorkers& out);
251  void fillTrigPath(ParameterSet& proc_pset,
252  ProductRegistry& preg,
253  boost::shared_ptr<ProcessConfiguration const> processConfiguration,
254  int bitpos, std::string const& name, TrigResPtr);
255  void fillEndPath(ParameterSet& proc_pset,
256  ProductRegistry& preg,
257  boost::shared_ptr<ProcessConfiguration const> processConfiguration,
258  int bitpos, std::string const& name);
259 
260  void limitOutput(ParameterSet const& proc_pset);
261 
262  void addToAllWorkers(Worker* w);
263 
266  boost::shared_ptr<ActivityRegistry> actReg_;
267 
271 
274 
280 
285 
286  boost::shared_ptr<UnscheduledCallProducer> unscheduled_;
287 
288  volatile bool endpathsAreActive_;
289  };
290 
291  // -----------------------------
292  // ProcessOneOccurrence is a functor that has bound a specific
293  // Principal and Event Setup, and can be called with a Path, to
294  // execute Path::processOneOccurrence for that event
295 
296  template <typename T>
298  public:
299  typedef void result_type;
300  ProcessOneOccurrence(typename T::MyPrincipal& principal, EventSetup const& setup) :
301  ep(principal), es(setup) {};
302 
304 
305  private:
306  typename T::MyPrincipal& ep;
307  EventSetup const& es;
308  };
309 
311  public:
313  void addWorker(Worker* aWorker) {
314  assert(0 != aWorker);
315  labelToWorkers_[aWorker->description().moduleLabel()] = aWorker;
316  }
317 
318  template <typename T>
319  void runNow(typename T::MyPrincipal& p, EventSetup const& es) {
320  //do nothing for event since we will run when requested
321  if(!T::isEvent_) {
322  for(std::map<std::string, Worker*>::iterator it = labelToWorkers_.begin(), itEnd=labelToWorkers_.end();
323  it != itEnd;
324  ++it) {
325  CPUTimer timer;
326  it->second->doWork<T>(p, es, 0, &timer);
327  }
328  }
329  }
330 
331  private:
332  virtual bool tryToFillImpl(std::string const& moduleLabel,
334  EventSetup const& eventSetup,
335  CurrentProcessingContext const* iContext) {
336  std::map<std::string, Worker*>::const_iterator itFound =
337  labelToWorkers_.find(moduleLabel);
338  if(itFound != labelToWorkers_.end()) {
339  CPUTimer timer;
340  itFound->second->doWork<OccurrenceTraits<EventPrincipal, BranchActionBegin> >(event, eventSetup, iContext, &timer);
341  return true;
342  }
343  return false;
344  }
345  std::map<std::string, Worker*> labelToWorkers_;
346  };
347 
348  void
349  inline
351  Service<JobReport> reportSvc;
352  reportSvc->reportSkippedEvent(ep.id().run(), ep.id().event());
353  }
354 
355  template <typename T>
356  void
357  Schedule::processOneOccurrence(typename T::MyPrincipal& ep, EventSetup const& es) {
358  this->resetAll();
359  state_ = Running;
360 
361  // A RunStopwatch, but only if we are processing an event.
362  RunStopwatch stopwatch(T::isEvent_ ? stopwatch_ : RunStopwatch::StopwatchPointer());
363 
364  if (T::isEvent_) {
365  ++total_events_;
366  setupOnDemandSystem(dynamic_cast<EventPrincipal&>(ep), es);
367  }
368  try {
369  try {
370  //make sure the unscheduled items see this transition [Event will be a no-op]
371  unscheduled_->runNow<T>(ep, es);
372  if (runTriggerPaths<T>(ep, es)) {
373  if (T::isEvent_) ++total_passed_;
374  }
375  state_ = Latched;
376  }
377  catch(cms::Exception& e) {
379  assert (action != actions::IgnoreCompletely);
380  assert (action != actions::FailPath);
381  assert (action != actions::FailModule);
382  if (action == actions::SkipEvent) {
383  LogWarning(e.category())
384  << "an exception occurred and all paths for the event are being skipped: \n"
385  << e.what();
386  } else {
387  throw;
388  }
389  }
390 
391  try {
392  CPUTimer timer;
393  if (results_inserter_.get()) results_inserter_->doWork<T>(ep, es, 0, &timer);
394  }
395  catch (cms::Exception& e) {
396  e << "EventProcessingStopped\n";
397  e << "Attempt to insert TriggerResults into event failed.\n";
398  throw;
399  }
400 
401  if (endpathsAreActive_) runEndPaths<T>(ep, es);
402  }
403  catch(cms::Exception& e) {
405  assert (action != actions::SkipEvent);
406  assert (action != actions::FailPath);
407  assert (action != actions::FailModule);
408  switch(action) {
410  LogWarning(e.category())
411  << "exception being ignored for current event:\n"
412  << e.what();
413  break;
414  }
415  default: {
416  state_ = Ready;
417  e << "EventProcessingStopped\n";
418  e << "an exception occurred during current event processing\n";
419  throw;
420  }
421  }
422  }
423  catch(...) {
424  LogError("PassingThrough")
425  << "an exception occurred during current event processing\n";
426  state_ = Ready;
427  throw;
428  }
429 
430  // next thing probably is not needed, the product insertion code clears it
431  state_ = Ready;
432 
433  }
434 
435  template <typename T>
436  bool
437  Schedule::runTriggerPaths(typename T::MyPrincipal& ep, EventSetup const& es) {
439  return results_->accept();
440  }
441 
442  template <typename T>
443  void
444  Schedule::runEndPaths(typename T::MyPrincipal& ep, EventSetup const& es) {
445  // Note there is no state-checking safety controlling the
446  // activation/deactivation of endpaths.
448 
449  // We could get rid of the functor ProcessOneOccurrence if we used
450  // boost::lambda, but the use of lambda with member functions
451  // which take multiple arguments, by both non-const and const
452  // reference, seems much more obscure...
453  //
454  // using namespace boost::lambda;
455  // for_all(end_paths_,
456  // bind(&Path::processOneOccurrence,
457  // boost::lambda::_1, // qualification to avoid ambiguity
458  // var(ep), // pass by reference (not copy)
459  // constant_ref(es))); // pass by const-reference (not copy)
460  }
461 }
462 
463 #endif
RunNumber_t run() const
Definition: EventID.h:42
State state_
Definition: Schedule.h:268
virtual char const * what() const
Definition: Exception.cc:97
std::vector< Path > NonTrigPaths
Definition: Schedule.h:97
EventNumber_t event() const
Definition: EventID.h:44
std::pair< double, double > timeCpuReal() const
Definition: Schedule.h:155
ModuleDescription const & description() const
Definition: Worker.h:63
roAction_t actions[nactions]
Definition: GenABIO.cc:200
void availablePaths(std::vector< std::string > &oLabelsToFill) const
adds to oLabelsToFill the labels for all paths in the process
Definition: Schedule.cc:916
void limitOutput(ParameterSet const &proc_pset)
Definition: Schedule.cc:307
AllOutputWorkers all_output_workers_
Definition: Schedule.h:277
WorkerPtr results_inserter_
Definition: Schedule.h:275
bool endPathsEnabled() const
Definition: Schedule.cc:947
std::string rootCause() const
Definition: Exception.cc:78
void respondToCloseInputFile(FileBlock const &fb)
Definition: Schedule.cc:857
std::vector< OutputWorker * > AllOutputWorkers
Definition: Schedule.h:101
bool changeModule(std::string const &iLabel, ParameterSet const &iPSet)
Definition: Schedule.cc:880
void writeLumi(LuminosityBlockPrincipal const &lbp)
Definition: Schedule.cc:842
std::vector< Worker * > AllWorkers
Definition: Schedule.h:100
void processOneOccurrence(typename T::MyPrincipal &principal, EventSetup const &eventSetup)
Definition: Schedule.h:357
WorkerRegistry worker_reg_
Definition: Schedule.h:264
std::vector< WorkerInPath > PathWorkers
Definition: Schedule.h:105
void reportSkipped(LuminosityBlockPrincipal const &) const
Definition: Schedule.h:244
EventID const & id() const
TrigPaths trig_paths_
Definition: Schedule.h:278
void enableEndPaths(bool active)
Definition: Schedule.cc:942
TrigResPtr endpath_results_
Definition: Schedule.h:273
int total_passed_
Definition: Schedule.h:283
std::string const & moduleLabel() const
boost::shared_ptr< HLTGlobalStatus > TrigResPtr
Definition: Schedule.h:98
int totalEventsFailed() const
Definition: Schedule.h:189
void resetAll()
Definition: Schedule.cc:1018
void fillEndPath(ParameterSet &proc_pset, ProductRegistry &preg, boost::shared_ptr< ProcessConfiguration const > processConfiguration, int bitpos, std::string const &name)
Definition: Schedule.cc:449
RunStopwatch::StopwatchPointer stopwatch_
Definition: Schedule.h:284
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:16
void runEndPaths(typename T::MyPrincipal &, EventSetup const &)
Definition: Schedule.h:444
void addWorker(Worker *aWorker)
Definition: Schedule.h:313
int totalEventsPassed() const
Definition: Schedule.h:183
void operator()(Path &p)
Definition: Schedule.h:303
void processOneOccurrence(typename T::MyPrincipal &, EventSetup const &)
Definition: Path.h:129
boost::shared_ptr< CPUTimer > StopwatchPointer
Definition: RunStopwatch.h:23
void runNow(typename T::MyPrincipal &p, EventSetup const &es)
Definition: Schedule.h:319
void fillWorkers(ParameterSet &proc_pset, ProductRegistry &preg, boost::shared_ptr< ProcessConfiguration const > processConfiguration, std::string const &name, bool ignoreFilters, PathWorkers &out)
Definition: Schedule.cc:369
int totalEvents() const
Definition: Schedule.h:177
AllWorkers::iterator workersBegin()
Definition: Schedule.h:225
Definition: Path.h:29
void clearCounters()
Clear all the counters in the trigger report.
Definition: Schedule.cc:1010
T::MyPrincipal & ep
Definition: Schedule.h:306
bool runTriggerPaths(typename T::MyPrincipal &, EventSetup const &)
Definition: Schedule.h:437
void respondToCloseOutputFiles(FileBlock const &fb)
Definition: Schedule.cc:865
std::vector< std::string > vstring
Definition: Schedule.h:95
void respondToOpenInputFile(FileBlock const &fb)
Definition: Schedule.cc:853
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
vstring trig_name_list_
Definition: Schedule.h:269
virtual bool tryToFillImpl(std::string const &moduleLabel, EventPrincipal &event, EventSetup const &eventSetup, CurrentProcessingContext const *iContext)
Definition: Schedule.h:332
EventSetup const & es
Definition: Schedule.h:307
ActionTable const * act_table_
Definition: Schedule.h:265
std::vector< Worker * > Workers
Definition: Schedule.h:103
AllWorkers::const_iterator workersBegin() const
Definition: Schedule.h:217
void getTriggerReport(TriggerReport &rep) const
Definition: Schedule.cc:999
tuple out
Definition: dbtoconf.py:99
boost::shared_ptr< Worker > WorkerPtr
Definition: Schedule.h:99
void respondToOpenOutputFiles(FileBlock const &fb)
Definition: Schedule.cc:861
volatile bool endpathsAreActive_
Definition: Schedule.h:288
TrigResPtr results_
Definition: Schedule.h:272
void reportSkipped(RunPrincipal const &) const
Definition: Schedule.h:245
int total_events_
Definition: Schedule.h:282
void modulesInPath(std::string const &iPathLabel, std::vector< std::string > &oLabelsToFill) const
adds to oLabelsToFill in execution order the labels of all modules in path iPathLabel ...
Definition: Schedule.cc:925
TrigPaths end_paths_
Definition: Schedule.h:279
void reportSkipped(EventPrincipal const &ep) const
Definition: Schedule.h:350
bool wantSummary_
Definition: Schedule.h:281
void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
Definition: Schedule.cc:876
author Stefano ARGIRO author Bill Tanenbaum
bool const terminate() const
Return whether each output module has reached its maximum count.
Definition: Schedule.cc:351
void endJob()
Definition: Schedule.cc:471
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
Definition: Schedule.cc:901
actions::ActionCodes find(const std::string &category) const
Definition: Actions.cc:95
std::vector< Path > TrigPaths
Definition: Schedule.h:96
void openNewOutputFilesIfNeeded()
Definition: Schedule.cc:830
void preForkReleaseResources()
Definition: Schedule.cc:873
void openOutputFiles(FileBlock &fb)
Definition: Schedule.cc:834
void writeRun(RunPrincipal const &rp)
Definition: Schedule.cc:838
ProcessOneOccurrence(typename T::MyPrincipal &principal, EventSetup const &setup)
Definition: Schedule.h:300
Schedule(ParameterSet &proc_pset, service::TriggerNamesService &tns, ProductRegistry &pregistry, ActionTable const &actions, boost::shared_ptr< ActivityRegistry > areg, boost::shared_ptr< ProcessConfiguration > processConfiguration)
Definition: Schedule.cc:140
AllWorkers::iterator workersEnd()
Definition: Schedule.h:229
bool shouldWeCloseOutput() const
Definition: Schedule.cc:846
void setupOnDemandSystem(EventPrincipal &principal, EventSetup const &es)
Definition: Schedule.cc:1035
void beginJob()
Definition: Schedule.cc:869
std::map< std::string, Worker * > labelToWorkers_
Definition: Schedule.h:345
vstring end_path_name_list_
Definition: Schedule.h:270
void closeOutputFiles()
Definition: Schedule.cc:826
AllWorkers::const_iterator workersEnd() const
Definition: Schedule.h:221
void addToAllWorkers(Worker *w)
Definition: Schedule.cc:1025
const std::string * moduleLabel() const
Definition: HLTadd.h:40
boost::shared_ptr< ActivityRegistry > actReg_
Definition: Schedule.h:266
AllWorkers all_workers_
Definition: Schedule.h:276
void fillTrigPath(ParameterSet &proc_pset, ProductRegistry &preg, boost::shared_ptr< ProcessConfiguration const > processConfiguration, int bitpos, std::string const &name, TrigResPtr)
Definition: Schedule.cc:425
boost::shared_ptr< UnscheduledCallProducer > unscheduled_
Definition: Schedule.h:286
std::string category() const
Definition: Exception.cc:74