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 
82 
83 #include "boost/shared_ptr.hpp"
84 
85 #include <map>
86 #include <memory>
87 #include <set>
88 #include <string>
89 #include <vector>
90 #include <sstream>
91 
92 namespace edm {
93 
94  namespace service {
95  class TriggerNamesService;
96  }
97  class ActivityRegistry;
98  class BranchIDListHelper;
99  class EventSetup;
100  class ExceptionCollector;
101  class OutputModuleCommunicator;
102  class ProcessContext;
103  class PreallocationConfiguration;
104  class StreamSchedule;
105  class GlobalSchedule;
106  struct TriggerTimingReport;
107  class ModuleRegistry;
108  class TriggerResultInserter;
109 
110  class Schedule {
111  public:
112  typedef std::vector<std::string> vstring;
113  typedef std::shared_ptr<Worker> WorkerPtr;
114  typedef std::vector<Worker*> AllWorkers;
115  typedef std::vector<std::shared_ptr<OutputModuleCommunicator> > AllOutputModuleCommunicators;
116 
117  typedef std::vector<Worker*> Workers;
118 
119  Schedule(ParameterSet& proc_pset,
121  ProductRegistry& pregistry,
122  BranchIDListHelper& branchIDListHelper,
124  std::shared_ptr<ActivityRegistry> areg,
125  std::shared_ptr<ProcessConfiguration> processConfiguration,
126  const ParameterSet* subProcPSet,
128  ProcessContext const* processContext);
129 
130  template <typename T>
131  void processOneEvent(unsigned int iStreamID,
132  typename T::MyPrincipal& principal,
133  EventSetup const& eventSetup,
134  bool cleaningUpAfterException = false);
135 
136  template <typename T>
137  void processOneGlobal(typename T::MyPrincipal& principal,
138  EventSetup const& eventSetup,
139  bool cleaningUpAfterException = false);
140 
141  template <typename T>
142  void processOneStream(unsigned int iStreamID,
143  typename T::MyPrincipal& principal,
144  EventSetup const& eventSetup,
145  bool cleaningUpAfterException = false);
146 
147  void beginJob(ProductRegistry const&);
148  void endJob(ExceptionCollector & collector);
149 
150  void beginStream(unsigned int);
151  void endStream(unsigned int);
152 
153  // Write the luminosity block
154  void writeLumi(LuminosityBlockPrincipal const& lbp, ProcessContext const*);
155 
156  // Write the run
157  void writeRun(RunPrincipal const& rp, ProcessContext const*);
158 
159  // Call closeFile() on all OutputModules.
160  void closeOutputFiles();
161 
162  // Call openNewFileIfNeeded() on all OutputModules
164 
165  // Call openFiles() on all OutputModules
167 
168  // Call respondToOpenInputFile() on all Modules
169  void respondToOpenInputFile(FileBlock const& fb);
170 
171  // Call respondToCloseInputFile() on all Modules
172  void respondToCloseInputFile(FileBlock const& fb);
173 
174  // Call shouldWeCloseFile() on all OutputModules.
175  bool shouldWeCloseOutput() const;
176 
178  void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren);
179 
182 
186  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
187 
189  void availablePaths(std::vector<std::string>& oLabelsToFill) const;
190 
192  void modulesInPath(std::string const& iPathLabel,
193  std::vector<std::string>& oLabelsToFill) const;
194 
198  int totalEvents() const;
199 
202  int totalEventsPassed() const;
203 
206  int totalEventsFailed() const;
207 
210  void enableEndPaths(bool active);
211 
214  bool endPathsEnabled() const;
215 
218  void getTriggerReport(TriggerReport& rep) const;
219 
223 
225  bool terminate() const;
226 
228  void clearCounters();
229 
232  bool changeModule(std::string const& iLabel, ParameterSet const& iPSet, const ProductRegistry& iRegistry);
233 
235  AllWorkers const& allWorkers() const;
236 
237  private:
238 
240  void checkForCorrectness() const;
241 
242  void limitOutput(ParameterSet const& proc_pset, BranchIDLists const& branchIDLists);
243 
244  std::shared_ptr<TriggerResultInserter> resultsInserter_;
245  std::shared_ptr<ModuleRegistry> moduleRegistry_;
246  std::vector<std::shared_ptr<StreamSchedule>> streamSchedules_;
247  //In the future, we will have one GlobalSchedule per simultaneous transition
248  std::unique_ptr<GlobalSchedule> globalSchedule_;
249 
252 
253  std::unique_ptr<SystemTimeKeeper> summaryTimeKeeper_;
254 
256 
257  volatile bool endpathsAreActive_;
258  };
259 
260 
261  template <typename T>
262  void Schedule::processOneEvent(unsigned int iStreamID,
263  typename T::MyPrincipal& ep,
264  EventSetup const& es,
265  bool cleaningUpAfterException) {
266  assert(iStreamID<streamSchedules_.size());
267  streamSchedules_[iStreamID]->processOneEvent<T>(ep,es,cleaningUpAfterException);
268  }
269 
270  template <typename T>
271  void Schedule::processOneStream(unsigned int iStreamID,
272  typename T::MyPrincipal& ep,
273  EventSetup const& es,
274  bool cleaningUpAfterException) {
275  assert(iStreamID<streamSchedules_.size());
276  streamSchedules_[iStreamID]->processOneStream<T>(ep,es,cleaningUpAfterException);
277  }
278  template <typename T>
279  void
280  Schedule::processOneGlobal(typename T::MyPrincipal& ep,
281  EventSetup const& es,
282  bool cleaningUpAfterException) {
283  globalSchedule_->processOneGlobal<T>(ep,es,cleaningUpAfterException);
284  }
285 }
286 #endif
string rep
Definition: cuy.py:1188
void checkForCorrectness() const
Check that the schedule is actually runable.
Definition: Schedule.cc:1277
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
AllWorkers const & allWorkers() const
returns the collection of pointers to workers
Definition: Schedule.cc:1008
void availablePaths(std::vector< std::string > &oLabelsToFill) const
adds to oLabelsToFill the labels for all paths in the process
Definition: Schedule.cc:1013
bool endPathsEnabled() const
Definition: Schedule.cc:1032
Schedule(ParameterSet &proc_pset, service::TriggerNamesService &tns, ProductRegistry &pregistry, BranchIDListHelper &branchIDListHelper, ExceptionToActionTable const &actions, std::shared_ptr< ActivityRegistry > areg, std::shared_ptr< ProcessConfiguration > processConfiguration, const ParameterSet *subProcPSet, PreallocationConfiguration const &config, ProcessContext const *processContext)
Definition: Schedule.cc:357
void respondToCloseInputFile(FileBlock const &fb)
Definition: Schedule.cc:930
std::vector< Worker * > AllWorkers
Definition: Schedule.h:114
void writeRun(RunPrincipal const &rp, ProcessContext const *)
Definition: Schedule.cc:907
void endStream(unsigned int)
Definition: Schedule.cc:946
void processOneEvent(unsigned int iStreamID, typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
Definition: Schedule.h:262
void writeLumi(LuminosityBlockPrincipal const &lbp, ProcessContext const *)
Definition: Schedule.cc:912
std::shared_ptr< Worker > WorkerPtr
Definition: Schedule.h:113
void enableEndPaths(bool active)
Definition: Schedule.cc:1024
processConfiguration
Definition: Schedule.cc:368
std::shared_ptr< ModuleRegistry > moduleRegistry_
Definition: Schedule.h:245
actions
Definition: Schedule.cc:368
int totalEventsFailed() const
Definition: Schedule.cc:1073
bool changeModule(std::string const &iLabel, ParameterSet const &iPSet, const ProductRegistry &iRegistry)
Definition: Schedule.cc:960
std::shared_ptr< TriggerResultInserter > resultsInserter_
Definition: Schedule.h:244
int totalEventsPassed() const
Definition: Schedule.cc:1064
void limitOutput(ParameterSet const &proc_pset, BranchIDLists const &branchIDLists)
Definition: Schedule.cc:489
int totalEvents() const
Definition: Schedule.cc:1055
void clearCounters()
Clear all the counters in the trigger report.
Definition: Schedule.cc:1083
std::vector< std::shared_ptr< StreamSchedule > > streamSchedules_
Definition: Schedule.h:246
std::vector< std::string > vstring
Definition: Schedule.h:112
std::vector< std::shared_ptr< OutputModuleCommunicator > > AllOutputModuleCommunicators
Definition: Schedule.h:115
bool terminate() const
Return whether each output module has reached its maximum count.
Definition: Schedule.cc:528
void respondToOpenInputFile(FileBlock const &fb)
Definition: Schedule.cc:925
areg
Definition: Schedule.cc:368
std::vector< Worker * > Workers
Definition: Schedule.h:117
void getTriggerReport(TriggerReport &rep) const
Definition: Schedule.cc:1037
void processOneGlobal(typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
Definition: Schedule.h:280
PreallocationConfiguration preallocConfig_
Definition: Schedule.h:251
volatile bool endpathsAreActive_
Definition: Schedule.h:257
std::unique_ptr< SystemTimeKeeper > summaryTimeKeeper_
Definition: Schedule.h:253
AllOutputModuleCommunicators all_output_communicators_
Definition: Schedule.h:250
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:1018
void beginStream(unsigned int)
Definition: Schedule.cc:941
bool wantSummary_
Definition: Schedule.h:255
void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
Definition: Schedule.cc:955
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
Definition: Schedule.cc:996
std::unique_ptr< GlobalSchedule > globalSchedule_
Definition: Schedule.h:248
void processOneStream(unsigned int iStreamID, typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
Definition: Schedule.h:271
void beginJob(ProductRegistry const &)
Definition: Schedule.cc:935
void openNewOutputFilesIfNeeded()
Definition: Schedule.cc:897
void preForkReleaseResources()
Definition: Schedule.cc:951
void openOutputFiles(FileBlock &fb)
Definition: Schedule.cc:902
long double T
void endJob(ExceptionCollector &collector)
Definition: Schedule.cc:544
void getTriggerTimingReport(TriggerTimingReport &rep) const
Definition: Schedule.cc:1047
bool shouldWeCloseOutput() const
Definition: Schedule.cc:917
void closeOutputFiles()
Definition: Schedule.cc:892