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 ThinnedAssociationsHelper;
109  class TriggerResultInserter;
110 
111  class Schedule {
112  public:
113  typedef std::vector<std::string> vstring;
114  typedef std::shared_ptr<Worker> WorkerPtr;
115  typedef std::vector<Worker*> AllWorkers;
116  typedef std::vector<std::shared_ptr<OutputModuleCommunicator> > AllOutputModuleCommunicators;
117 
118  typedef std::vector<Worker*> Workers;
119 
120  Schedule(ParameterSet& proc_pset,
122  ProductRegistry& pregistry,
123  BranchIDListHelper& branchIDListHelper,
124  ThinnedAssociationsHelper& thinnedAssociationsHelper,
126  std::shared_ptr<ActivityRegistry> areg,
127  std::shared_ptr<ProcessConfiguration> processConfiguration,
128  const ParameterSet* subProcPSet,
130  ProcessContext const* processContext);
131 
132  template <typename T>
133  void processOneEvent(unsigned int iStreamID,
134  typename T::MyPrincipal& principal,
135  EventSetup const& eventSetup,
136  bool cleaningUpAfterException = false);
137 
138  template <typename T>
139  void processOneGlobal(typename T::MyPrincipal& principal,
140  EventSetup const& eventSetup,
141  bool cleaningUpAfterException = false);
142 
143  template <typename T>
144  void processOneStream(unsigned int iStreamID,
145  typename T::MyPrincipal& principal,
146  EventSetup const& eventSetup,
147  bool cleaningUpAfterException = false);
148 
149  void beginJob(ProductRegistry const&);
150  void endJob(ExceptionCollector & collector);
151 
152  void beginStream(unsigned int);
153  void endStream(unsigned int);
154 
155  // Write the luminosity block
156  void writeLumi(LuminosityBlockPrincipal const& lbp, ProcessContext const*);
157 
158  // Write the run
159  void writeRun(RunPrincipal const& rp, ProcessContext const*);
160 
161  // Call closeFile() on all OutputModules.
162  void closeOutputFiles();
163 
164  // Call openNewFileIfNeeded() on all OutputModules
166 
167  // Call openFiles() on all OutputModules
169 
170  // Call respondToOpenInputFile() on all Modules
171  void respondToOpenInputFile(FileBlock const& fb);
172 
173  // Call respondToCloseInputFile() on all Modules
174  void respondToCloseInputFile(FileBlock const& fb);
175 
176  // Call shouldWeCloseFile() on all OutputModules.
177  bool shouldWeCloseOutput() const;
178 
180  void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren);
181 
184 
188  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
189 
191  void availablePaths(std::vector<std::string>& oLabelsToFill) const;
192 
194  void modulesInPath(std::string const& iPathLabel,
195  std::vector<std::string>& oLabelsToFill) const;
196 
200  int totalEvents() const;
201 
204  int totalEventsPassed() const;
205 
208  int totalEventsFailed() const;
209 
212  void enableEndPaths(bool active);
213 
216  bool endPathsEnabled() const;
217 
220  void getTriggerReport(TriggerReport& rep) const;
221 
225 
227  bool terminate() const;
228 
230  void clearCounters();
231 
234  bool changeModule(std::string const& iLabel, ParameterSet const& iPSet, const ProductRegistry& iRegistry);
235 
237  AllWorkers const& allWorkers() const;
238 
239  private:
240 
242  void checkForCorrectness() const;
243 
244  void limitOutput(ParameterSet const& proc_pset, BranchIDLists const& branchIDLists);
245 
246  std::shared_ptr<TriggerResultInserter> resultsInserter_;
247  std::shared_ptr<ModuleRegistry> moduleRegistry_;
248  std::vector<std::shared_ptr<StreamSchedule>> streamSchedules_;
249  //In the future, we will have one GlobalSchedule per simultaneous transition
250  std::unique_ptr<GlobalSchedule> globalSchedule_;
251 
254 
255  std::unique_ptr<SystemTimeKeeper> summaryTimeKeeper_;
256 
258 
259  volatile bool endpathsAreActive_;
260  };
261 
262 
263  template <typename T>
264  void Schedule::processOneEvent(unsigned int iStreamID,
265  typename T::MyPrincipal& ep,
266  EventSetup const& es,
267  bool cleaningUpAfterException) {
268  assert(iStreamID<streamSchedules_.size());
269  streamSchedules_[iStreamID]->processOneEvent<T>(ep,es,cleaningUpAfterException);
270  }
271 
272  template <typename T>
273  void Schedule::processOneStream(unsigned int iStreamID,
274  typename T::MyPrincipal& ep,
275  EventSetup const& es,
276  bool cleaningUpAfterException) {
277  assert(iStreamID<streamSchedules_.size());
278  streamSchedules_[iStreamID]->processOneStream<T>(ep,es,cleaningUpAfterException);
279  }
280  template <typename T>
281  void
282  Schedule::processOneGlobal(typename T::MyPrincipal& ep,
283  EventSetup const& es,
284  bool cleaningUpAfterException) {
285  globalSchedule_->processOneGlobal<T>(ep,es,cleaningUpAfterException);
286  }
287 }
288 #endif
string rep
Definition: cuy.py:1188
void checkForCorrectness() const
Check that the schedule is actually runable.
Definition: Schedule.cc:1284
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
AllWorkers const & allWorkers() const
returns the collection of pointers to workers
Definition: Schedule.cc:1015
void availablePaths(std::vector< std::string > &oLabelsToFill) const
adds to oLabelsToFill the labels for all paths in the process
Definition: Schedule.cc:1020
bool endPathsEnabled() const
Definition: Schedule.cc:1039
void respondToCloseInputFile(FileBlock const &fb)
Definition: Schedule.cc:937
std::vector< Worker * > AllWorkers
Definition: Schedule.h:115
void writeRun(RunPrincipal const &rp, ProcessContext const *)
Definition: Schedule.cc:914
void endStream(unsigned int)
Definition: Schedule.cc:953
void processOneEvent(unsigned int iStreamID, typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
Definition: Schedule.h:264
void writeLumi(LuminosityBlockPrincipal const &lbp, ProcessContext const *)
Definition: Schedule.cc:919
std::shared_ptr< Worker > WorkerPtr
Definition: Schedule.h:114
void enableEndPaths(bool active)
Definition: Schedule.cc:1031
processConfiguration
Definition: Schedule.cc:370
std::shared_ptr< ModuleRegistry > moduleRegistry_
Definition: Schedule.h:247
actions
Definition: Schedule.cc:370
int totalEventsFailed() const
Definition: Schedule.cc:1080
bool changeModule(std::string const &iLabel, ParameterSet const &iPSet, const ProductRegistry &iRegistry)
Definition: Schedule.cc:967
std::shared_ptr< TriggerResultInserter > resultsInserter_
Definition: Schedule.h:246
int totalEventsPassed() const
Definition: Schedule.cc:1071
void limitOutput(ParameterSet const &proc_pset, BranchIDLists const &branchIDLists)
Definition: Schedule.cc:496
int totalEvents() const
Definition: Schedule.cc:1062
Schedule(ParameterSet &proc_pset, service::TriggerNamesService &tns, ProductRegistry &pregistry, BranchIDListHelper &branchIDListHelper, ThinnedAssociationsHelper &thinnedAssociationsHelper, 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:358
void clearCounters()
Clear all the counters in the trigger report.
Definition: Schedule.cc:1090
std::vector< std::shared_ptr< StreamSchedule > > streamSchedules_
Definition: Schedule.h:248
std::vector< std::string > vstring
Definition: Schedule.h:113
std::vector< std::shared_ptr< OutputModuleCommunicator > > AllOutputModuleCommunicators
Definition: Schedule.h:116
bool terminate() const
Return whether each output module has reached its maximum count.
Definition: Schedule.cc:535
void respondToOpenInputFile(FileBlock const &fb)
Definition: Schedule.cc:932
areg
Definition: Schedule.cc:370
std::vector< Worker * > Workers
Definition: Schedule.h:118
void getTriggerReport(TriggerReport &rep) const
Definition: Schedule.cc:1044
void processOneGlobal(typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
Definition: Schedule.h:282
PreallocationConfiguration preallocConfig_
Definition: Schedule.h:253
volatile bool endpathsAreActive_
Definition: Schedule.h:259
std::unique_ptr< SystemTimeKeeper > summaryTimeKeeper_
Definition: Schedule.h:255
AllOutputModuleCommunicators all_output_communicators_
Definition: Schedule.h:252
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:1025
void beginStream(unsigned int)
Definition: Schedule.cc:948
bool wantSummary_
Definition: Schedule.h:257
void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
Definition: Schedule.cc:962
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
Definition: Schedule.cc:1003
std::unique_ptr< GlobalSchedule > globalSchedule_
Definition: Schedule.h:250
void processOneStream(unsigned int iStreamID, typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
Definition: Schedule.h:273
void beginJob(ProductRegistry const &)
Definition: Schedule.cc:942
void openNewOutputFilesIfNeeded()
Definition: Schedule.cc:904
void preForkReleaseResources()
Definition: Schedule.cc:958
void openOutputFiles(FileBlock &fb)
Definition: Schedule.cc:909
long double T
void endJob(ExceptionCollector &collector)
Definition: Schedule.cc:551
void getTriggerTimingReport(TriggerTimingReport &rep) const
Definition: Schedule.cc:1054
bool shouldWeCloseOutput() const
Definition: Schedule.cc:924
void closeOutputFiles()
Definition: Schedule.cc:899