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 
81 
82 #include "boost/shared_ptr.hpp"
83 
84 #include <map>
85 #include <memory>
86 #include <set>
87 #include <string>
88 #include <vector>
89 #include <sstream>
90 
91 namespace edm {
92 
93  namespace service {
94  class TriggerNamesService;
95  }
96  class ActivityRegistry;
97  class BranchIDListHelper;
98  class EventSetup;
99  class ExceptionCollector;
100  class OutputModuleCommunicator;
101  class ProcessContext;
102  class PreallocationConfiguration;
103  class StreamSchedule;
104  class GlobalSchedule;
105  struct TriggerTimingReport;
106  class ModuleRegistry;
107  class TriggerResultInserter;
108 
109  class Schedule {
110  public:
111  typedef std::vector<std::string> vstring;
112  typedef boost::shared_ptr<Worker> WorkerPtr;
113  typedef std::vector<Worker*> AllWorkers;
114  typedef std::vector<boost::shared_ptr<OutputModuleCommunicator>> AllOutputModuleCommunicators;
115 
116  typedef std::vector<Worker*> Workers;
117 
118  Schedule(ParameterSet& proc_pset,
120  ProductRegistry& pregistry,
121  BranchIDListHelper& branchIDListHelper,
123  boost::shared_ptr<ActivityRegistry> areg,
124  boost::shared_ptr<ProcessConfiguration> processConfiguration,
125  const ParameterSet* subProcPSet,
127  ProcessContext const* processContext);
128 
129  template <typename T>
130  void processOneEvent(unsigned int iStreamID,
131  typename T::MyPrincipal& principal,
132  EventSetup const& eventSetup,
133  bool cleaningUpAfterException = false);
134 
135  template <typename T>
136  void processOneGlobal(typename T::MyPrincipal& principal,
137  EventSetup const& eventSetup,
138  bool cleaningUpAfterException = false);
139 
140  template <typename T>
141  void processOneStream(unsigned int iStreamID,
142  typename T::MyPrincipal& principal,
143  EventSetup const& eventSetup,
144  bool cleaningUpAfterException = false);
145 
146  void beginJob(ProductRegistry const&);
147  void endJob(ExceptionCollector & collector);
148 
149  void beginStream(unsigned int);
150  void endStream(unsigned int);
151 
152  // Write the luminosity block
153  void writeLumi(LuminosityBlockPrincipal const& lbp, ProcessContext const*);
154 
155  // Write the run
156  void writeRun(RunPrincipal const& rp, ProcessContext const*);
157 
158  // Call closeFile() on all OutputModules.
159  void closeOutputFiles();
160 
161  // Call openNewFileIfNeeded() on all OutputModules
163 
164  // Call openFiles() on all OutputModules
166 
167  // Call respondToOpenInputFile() on all Modules
168  void respondToOpenInputFile(FileBlock const& fb);
169 
170  // Call respondToCloseInputFile() on all Modules
171  void respondToCloseInputFile(FileBlock const& fb);
172 
173  // Call shouldWeCloseFile() on all OutputModules.
174  bool shouldWeCloseOutput() const;
175 
177  void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren);
178 
181 
185  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
186 
188  void availablePaths(std::vector<std::string>& oLabelsToFill) const;
189 
191  void modulesInPath(std::string const& iPathLabel,
192  std::vector<std::string>& oLabelsToFill) const;
193 
197  int totalEvents() const;
198 
201  int totalEventsPassed() const;
202 
205  int totalEventsFailed() const;
206 
209  void enableEndPaths(bool active);
210 
213  bool endPathsEnabled() const;
214 
217  void getTriggerReport(TriggerReport& rep) const;
218 
222 
224  bool terminate() const;
225 
227  void clearCounters();
228 
231  bool changeModule(std::string const& iLabel, ParameterSet const& iPSet, const ProductRegistry& iRegistry);
232 
234  AllWorkers const& allWorkers() const;
235 
236  private:
237 
239  void checkForCorrectness() const;
240 
241  void limitOutput(ParameterSet const& proc_pset, BranchIDLists const& branchIDLists);
242 
243  std::shared_ptr<TriggerResultInserter> resultsInserter_;
244  boost::shared_ptr<ModuleRegistry> moduleRegistry_;
245  std::vector<std::shared_ptr<StreamSchedule>> streamSchedules_;
246  //In the future, we will have one GlobalSchedule per simultaneous transition
247  std::unique_ptr<GlobalSchedule> globalSchedule_;
248 
251 
252 
254 
255  volatile bool endpathsAreActive_;
256  };
257 
258 
259  template <typename T>
260  void Schedule::processOneEvent(unsigned int iStreamID,
261  typename T::MyPrincipal& ep,
262  EventSetup const& es,
263  bool cleaningUpAfterException) {
264  assert(iStreamID<streamSchedules_.size());
265  streamSchedules_[iStreamID]->processOneEvent<T>(ep,es,cleaningUpAfterException);
266  }
267 
268  template <typename T>
269  void Schedule::processOneStream(unsigned int iStreamID,
270  typename T::MyPrincipal& ep,
271  EventSetup const& es,
272  bool cleaningUpAfterException) {
273  assert(iStreamID<streamSchedules_.size());
274  streamSchedules_[iStreamID]->processOneStream<T>(ep,es,cleaningUpAfterException);
275  }
276  template <typename T>
277  void
278  Schedule::processOneGlobal(typename T::MyPrincipal& ep,
279  EventSetup const& es,
280  bool cleaningUpAfterException) {
281  globalSchedule_->processOneGlobal<T>(ep,es,cleaningUpAfterException);
282  }
283 }
284 #endif
string rep
Definition: cuy.py:1188
std::vector< boost::shared_ptr< OutputModuleCommunicator > > AllOutputModuleCommunicators
Definition: Schedule.h:114
void checkForCorrectness() const
Check that the schedule is actually runable.
Definition: Schedule.cc:1239
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
AllWorkers const & allWorkers() const
returns the collection of pointers to workers
Definition: Schedule.cc:968
void availablePaths(std::vector< std::string > &oLabelsToFill) const
adds to oLabelsToFill the labels for all paths in the process
Definition: Schedule.cc:973
bool endPathsEnabled() const
Definition: Schedule.cc:992
void respondToCloseInputFile(FileBlock const &fb)
Definition: Schedule.cc:893
std::vector< Worker * > AllWorkers
Definition: Schedule.h:113
void writeRun(RunPrincipal const &rp, ProcessContext const *)
Definition: Schedule.cc:874
void endStream(unsigned int)
Definition: Schedule.cc:908
void processOneEvent(unsigned int iStreamID, typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
Definition: Schedule.h:260
void writeLumi(LuminosityBlockPrincipal const &lbp, ProcessContext const *)
Definition: Schedule.cc:878
void enableEndPaths(bool active)
Definition: Schedule.cc:984
processConfiguration
Definition: Schedule.cc:369
actions
Definition: Schedule.cc:369
int totalEventsFailed() const
Definition: Schedule.cc:1035
bool changeModule(std::string const &iLabel, ParameterSet const &iPSet, const ProductRegistry &iRegistry)
Definition: Schedule.cc:920
std::shared_ptr< TriggerResultInserter > resultsInserter_
Definition: Schedule.h:243
int totalEventsPassed() const
Definition: Schedule.cc:1026
void limitOutput(ParameterSet const &proc_pset, BranchIDLists const &branchIDLists)
Definition: Schedule.cc:459
int totalEvents() const
Definition: Schedule.cc:1017
void clearCounters()
Clear all the counters in the trigger report.
Definition: Schedule.cc:1045
boost::shared_ptr< ModuleRegistry > moduleRegistry_
Definition: Schedule.h:244
std::vector< std::shared_ptr< StreamSchedule > > streamSchedules_
Definition: Schedule.h:245
std::vector< std::string > vstring
Definition: Schedule.h:111
bool terminate() const
Return whether each output module has reached its maximum count.
Definition: Schedule.cc:498
void respondToOpenInputFile(FileBlock const &fb)
Definition: Schedule.cc:889
areg
Definition: Schedule.cc:369
std::vector< Worker * > Workers
Definition: Schedule.h:116
void getTriggerReport(TriggerReport &rep) const
Definition: Schedule.cc:997
void processOneGlobal(typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
Definition: Schedule.h:278
PreallocationConfiguration preallocConfig_
Definition: Schedule.h:250
boost::shared_ptr< Worker > WorkerPtr
Definition: Schedule.h:112
volatile bool endpathsAreActive_
Definition: Schedule.h:255
AllOutputModuleCommunicators all_output_communicators_
Definition: Schedule.h:249
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:978
Schedule(ParameterSet &proc_pset, service::TriggerNamesService &tns, ProductRegistry &pregistry, BranchIDListHelper &branchIDListHelper, ExceptionToActionTable const &actions, boost::shared_ptr< ActivityRegistry > areg, boost::shared_ptr< ProcessConfiguration > processConfiguration, const ParameterSet *subProcPSet, PreallocationConfiguration const &config, ProcessContext const *processContext)
Definition: Schedule.cc:358
void beginStream(unsigned int)
Definition: Schedule.cc:903
bool wantSummary_
Definition: Schedule.h:253
void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
Definition: Schedule.cc:916
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
Definition: Schedule.cc:956
std::unique_ptr< GlobalSchedule > globalSchedule_
Definition: Schedule.h:247
void processOneStream(unsigned int iStreamID, typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
Definition: Schedule.h:269
void beginJob(ProductRegistry const &)
Definition: Schedule.cc:897
void openNewOutputFilesIfNeeded()
Definition: Schedule.cc:866
void preForkReleaseResources()
Definition: Schedule.cc:913
void openOutputFiles(FileBlock &fb)
Definition: Schedule.cc:870
long double T
void endJob(ExceptionCollector &collector)
Definition: Schedule.cc:514
void getTriggerTimingReport(TriggerTimingReport &rep) const
Definition: Schedule.cc:1007
bool shouldWeCloseOutput() const
Definition: Schedule.cc:882
void closeOutputFiles()
Definition: Schedule.cc:862