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 #include <utility>
92 
93 namespace edm {
94 
95  namespace service {
96  class TriggerNamesService;
97  }
98  class ActivityRegistry;
99  class BranchIDListHelper;
100  class EventSetup;
101  class ExceptionCollector;
102  class OutputModuleCommunicator;
103  class ProcessContext;
104  class ProductRegistry;
105  class PreallocationConfiguration;
106  class StreamSchedule;
107  class GlobalSchedule;
108  struct TriggerTimingReport;
109  class ModuleRegistry;
110  class ThinnedAssociationsHelper;
111  class TriggerResultInserter;
112 
113  class Schedule {
114  public:
115  typedef std::vector<std::string> vstring;
116  typedef std::shared_ptr<Worker> WorkerPtr;
117  typedef std::vector<Worker*> AllWorkers;
118  typedef std::vector<std::shared_ptr<OutputModuleCommunicator> > AllOutputModuleCommunicators;
119 
120  typedef std::vector<Worker*> Workers;
121 
122  Schedule(ParameterSet& proc_pset,
124  ProductRegistry& pregistry,
125  BranchIDListHelper& branchIDListHelper,
126  ThinnedAssociationsHelper& thinnedAssociationsHelper,
128  std::shared_ptr<ActivityRegistry> areg,
129  std::shared_ptr<ProcessConfiguration> processConfiguration,
130  const ParameterSet* subProcPSet,
132  ProcessContext const* processContext);
133 
134  template <typename T>
135  void processOneEvent(unsigned int iStreamID,
136  typename T::MyPrincipal& principal,
137  EventSetup const& eventSetup,
138  bool cleaningUpAfterException = false);
139 
140  template <typename T>
141  void processOneGlobal(typename T::MyPrincipal& principal,
142  EventSetup const& eventSetup,
143  bool cleaningUpAfterException = false);
144 
145  template <typename T>
146  void processOneStream(unsigned int iStreamID,
147  typename T::MyPrincipal& principal,
148  EventSetup const& eventSetup,
149  bool cleaningUpAfterException = false);
150 
151  void beginJob(ProductRegistry const&);
152  void endJob(ExceptionCollector & collector);
153 
154  void beginStream(unsigned int);
155  void endStream(unsigned int);
156 
157  // Write the luminosity block
158  void writeLumi(LuminosityBlockPrincipal const& lbp, ProcessContext const*);
159 
160  // Write the run
161  void writeRun(RunPrincipal const& rp, ProcessContext const*);
162 
163  // Call closeFile() on all OutputModules.
164  void closeOutputFiles();
165 
166  // Call openNewFileIfNeeded() on all OutputModules
168 
169  // Call openFiles() on all OutputModules
171 
172  // Call respondToOpenInputFile() on all Modules
173  void respondToOpenInputFile(FileBlock const& fb);
174 
175  // Call respondToCloseInputFile() on all Modules
176  void respondToCloseInputFile(FileBlock const& fb);
177 
178  // Call shouldWeCloseFile() on all OutputModules.
179  bool shouldWeCloseOutput() const;
180 
182  void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren);
183 
186 
190  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
191 
193  void availablePaths(std::vector<std::string>& oLabelsToFill) const;
194 
198  void triggerPaths(std::vector<std::string>& oLabelsToFill) const;
199 
201  void endPaths(std::vector<std::string>& oLabelsToFill) const;
202 
204  void modulesInPath(std::string const& iPathLabel,
205  std::vector<std::string>& oLabelsToFill) const;
206 
209  void moduleDescriptionsInPath(std::string const& iPathLabel,
210  std::vector<ModuleDescription const*>& descriptions,
211  unsigned int hint) const;
212 
215  void moduleDescriptionsInEndPath(std::string const& iEndPathLabel,
216  std::vector<ModuleDescription const*>& descriptions,
217  unsigned int hint) const;
218 
219  void fillModuleAndConsumesInfo(std::vector<ModuleDescription const*>& allModuleDescriptions,
220  std::vector<std::pair<unsigned int, unsigned int> >& moduleIDToIndex,
221  std::vector<std::vector<ModuleDescription const*> >& modulesWhoseProductsAreConsumedBy,
222  ProductRegistry const& preg) const;
223 
227  int totalEvents() const;
228 
231  int totalEventsPassed() const;
232 
235  int totalEventsFailed() const;
236 
239  void enableEndPaths(bool active);
240 
243  bool endPathsEnabled() const;
244 
247  void getTriggerReport(TriggerReport& rep) const;
248 
252 
254  bool terminate() const;
255 
257  void clearCounters();
258 
261  bool changeModule(std::string const& iLabel, ParameterSet const& iPSet, const ProductRegistry& iRegistry);
262 
264  AllWorkers const& allWorkers() const;
265 
266  private:
267 
269  void checkForCorrectness() const;
270 
271  void limitOutput(ParameterSet const& proc_pset, BranchIDLists const& branchIDLists);
272 
273  std::shared_ptr<TriggerResultInserter> resultsInserter_;
274  std::shared_ptr<ModuleRegistry> moduleRegistry_;
275  std::vector<std::shared_ptr<StreamSchedule>> streamSchedules_;
276  //In the future, we will have one GlobalSchedule per simultaneous transition
277  std::unique_ptr<GlobalSchedule> globalSchedule_;
278 
281 
282  std::unique_ptr<SystemTimeKeeper> summaryTimeKeeper_;
283 
285 
286  volatile bool endpathsAreActive_;
287  };
288 
289 
290  template <typename T>
291  void Schedule::processOneEvent(unsigned int iStreamID,
292  typename T::MyPrincipal& ep,
293  EventSetup const& es,
294  bool cleaningUpAfterException) {
295  assert(iStreamID<streamSchedules_.size());
296  streamSchedules_[iStreamID]->processOneEvent<T>(ep,es,cleaningUpAfterException);
297  }
298 
299  template <typename T>
300  void Schedule::processOneStream(unsigned int iStreamID,
301  typename T::MyPrincipal& ep,
302  EventSetup const& es,
303  bool cleaningUpAfterException) {
304  assert(iStreamID<streamSchedules_.size());
305  streamSchedules_[iStreamID]->processOneStream<T>(ep,es,cleaningUpAfterException);
306  }
307  template <typename T>
308  void
309  Schedule::processOneGlobal(typename T::MyPrincipal& ep,
310  EventSetup const& es,
311  bool cleaningUpAfterException) {
312  globalSchedule_->processOneGlobal<T>(ep,es,cleaningUpAfterException);
313  }
314 }
315 #endif
string rep
Definition: cuy.py:1188
void checkForCorrectness() const
Check that the schedule is actually runable.
Definition: Schedule.cc:1280
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
void fillModuleAndConsumesInfo(std::vector< ModuleDescription const * > &allModuleDescriptions, std::vector< std::pair< unsigned int, unsigned int > > &moduleIDToIndex, std::vector< std::vector< ModuleDescription const * > > &modulesWhoseProductsAreConsumedBy, ProductRegistry const &preg) const
Definition: Schedule.cc:995
AllWorkers const & allWorkers() const
returns the collection of pointers to workers
Definition: Schedule.cc:955
void availablePaths(std::vector< std::string > &oLabelsToFill) const
adds to oLabelsToFill the labels for all paths in the process
Definition: Schedule.cc:960
bool endPathsEnabled() const
Definition: Schedule.cc:1035
void respondToCloseInputFile(FileBlock const &fb)
Definition: Schedule.cc:877
std::vector< Worker * > AllWorkers
Definition: Schedule.h:117
assert(m_qm.get())
void writeRun(RunPrincipal const &rp, ProcessContext const *)
Definition: Schedule.cc:854
void endStream(unsigned int)
Definition: Schedule.cc:893
void processOneEvent(unsigned int iStreamID, typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
Definition: Schedule.h:291
void writeLumi(LuminosityBlockPrincipal const &lbp, ProcessContext const *)
Definition: Schedule.cc:859
std::shared_ptr< Worker > WorkerPtr
Definition: Schedule.h:116
void enableEndPaths(bool active)
Definition: Schedule.cc:1027
processConfiguration
Definition: Schedule.cc:370
std::shared_ptr< ModuleRegistry > moduleRegistry_
Definition: Schedule.h:274
void moduleDescriptionsInEndPath(std::string const &iEndPathLabel, std::vector< ModuleDescription const * > &descriptions, unsigned int hint) const
Definition: Schedule.cc:988
actions
Definition: Schedule.cc:370
int totalEventsFailed() const
Definition: Schedule.cc:1076
bool changeModule(std::string const &iLabel, ParameterSet const &iPSet, const ProductRegistry &iRegistry)
Definition: Schedule.cc:907
std::shared_ptr< TriggerResultInserter > resultsInserter_
Definition: Schedule.h:273
int totalEventsPassed() const
Definition: Schedule.cc:1067
void triggerPaths(std::vector< std::string > &oLabelsToFill) const
Definition: Schedule.cc:965
void limitOutput(ParameterSet const &proc_pset, BranchIDLists const &branchIDLists)
Definition: Schedule.cc:499
int totalEvents() const
Definition: Schedule.cc:1058
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:1086
std::vector< std::shared_ptr< StreamSchedule > > streamSchedules_
Definition: Schedule.h:275
std::vector< std::string > vstring
Definition: Schedule.h:115
std::vector< std::shared_ptr< OutputModuleCommunicator > > AllOutputModuleCommunicators
Definition: Schedule.h:118
bool terminate() const
Return whether each output module has reached its maximum count.
Definition: Schedule.cc:538
void respondToOpenInputFile(FileBlock const &fb)
Definition: Schedule.cc:872
areg
Definition: Schedule.cc:370
std::vector< Worker * > Workers
Definition: Schedule.h:120
void getTriggerReport(TriggerReport &rep) const
Definition: Schedule.cc:1040
void processOneGlobal(typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
Definition: Schedule.h:309
PreallocationConfiguration preallocConfig_
Definition: Schedule.h:280
volatile bool endpathsAreActive_
Definition: Schedule.h:286
std::unique_ptr< SystemTimeKeeper > summaryTimeKeeper_
Definition: Schedule.h:282
AllOutputModuleCommunicators all_output_communicators_
Definition: Schedule.h:279
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:975
void beginStream(unsigned int)
Definition: Schedule.cc:888
bool wantSummary_
Definition: Schedule.h:284
void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
Definition: Schedule.cc:902
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
Definition: Schedule.cc:943
std::unique_ptr< GlobalSchedule > globalSchedule_
Definition: Schedule.h:277
void processOneStream(unsigned int iStreamID, typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
Definition: Schedule.h:300
void beginJob(ProductRegistry const &)
Definition: Schedule.cc:882
void openNewOutputFilesIfNeeded()
Definition: Schedule.cc:844
void preForkReleaseResources()
Definition: Schedule.cc:898
void openOutputFiles(FileBlock &fb)
Definition: Schedule.cc:849
preg
Definition: Schedule.cc:370
long double T
void endJob(ExceptionCollector &collector)
Definition: Schedule.cc:554
void getTriggerTimingReport(TriggerTimingReport &rep) const
Definition: Schedule.cc:1050
bool shouldWeCloseOutput() const
Definition: Schedule.cc:864
void closeOutputFiles()
Definition: Schedule.cc:839
void endPaths(std::vector< std::string > &oLabelsToFill) const
adds to oLabelsToFill the labels for all end paths in the process
Definition: Schedule.cc:970
void moduleDescriptionsInPath(std::string const &iPathLabel, std::vector< ModuleDescription const * > &descriptions, unsigned int hint) const
Definition: Schedule.cc:981