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  class 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);
232 
234  AllWorkers const& allWorkers() const;
235 
236  private:
237 
238  void limitOutput(ParameterSet const& proc_pset, BranchIDLists const& branchIDLists);
239 
240  std::shared_ptr<TriggerResultInserter> resultsInserter_;
241  boost::shared_ptr<ModuleRegistry> moduleRegistry_;
242  std::vector<std::shared_ptr<StreamSchedule>> streamSchedules_;
243  //In the future, we will have one GlobalSchedule per simultaneous transition
244  std::unique_ptr<GlobalSchedule> globalSchedule_;
245 
248 
249 
251 
252  volatile bool endpathsAreActive_;
253  };
254 
255 
256  template <typename T>
257  void Schedule::processOneEvent(unsigned int iStreamID,
258  typename T::MyPrincipal& ep,
259  EventSetup const& es,
260  bool cleaningUpAfterException) {
261  assert(iStreamID<streamSchedules_.size());
262  streamSchedules_[iStreamID]->processOneEvent<T>(ep,es,cleaningUpAfterException);
263  }
264 
265  template <typename T>
266  void Schedule::processOneStream(unsigned int iStreamID,
267  typename T::MyPrincipal& ep,
268  EventSetup const& es,
269  bool cleaningUpAfterException) {
270  assert(iStreamID<streamSchedules_.size());
271  streamSchedules_[iStreamID]->processOneStream<T>(ep,es,cleaningUpAfterException);
272  }
273  template <typename T>
274  void
275  Schedule::processOneGlobal(typename T::MyPrincipal& ep,
276  EventSetup const& es,
277  bool cleaningUpAfterException) {
278  globalSchedule_->processOneGlobal<T>(ep,es,cleaningUpAfterException);
279  }
280 }
281 #endif
string rep
Definition: cuy.py:1188
std::vector< boost::shared_ptr< OutputModuleCommunicator > > AllOutputModuleCommunicators
Definition: Schedule.h:114
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
AllWorkers const & allWorkers() const
returns the collection of pointers to workers
Definition: Schedule.cc:947
void availablePaths(std::vector< std::string > &oLabelsToFill) const
adds to oLabelsToFill the labels for all paths in the process
Definition: Schedule.cc:952
bool endPathsEnabled() const
Definition: Schedule.cc:971
void respondToCloseInputFile(FileBlock const &fb)
Definition: Schedule.cc:886
bool changeModule(std::string const &iLabel, ParameterSet const &iPSet)
Definition: Schedule.cc:911
std::vector< Worker * > AllWorkers
Definition: Schedule.h:113
void writeRun(RunPrincipal const &rp, ProcessContext const *)
Definition: Schedule.cc:867
void endStream(unsigned int)
Definition: Schedule.cc:899
void processOneEvent(unsigned int iStreamID, typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
Definition: Schedule.h:257
void writeLumi(LuminosityBlockPrincipal const &lbp, ProcessContext const *)
Definition: Schedule.cc:871
void enableEndPaths(bool active)
Definition: Schedule.cc:963
processConfiguration
Definition: Schedule.cc:362
actions
Definition: Schedule.cc:362
int totalEventsFailed() const
Definition: Schedule.cc:1014
std::shared_ptr< TriggerResultInserter > resultsInserter_
Definition: Schedule.h:240
int totalEventsPassed() const
Definition: Schedule.cc:1005
void limitOutput(ParameterSet const &proc_pset, BranchIDLists const &branchIDLists)
Definition: Schedule.cc:452
int totalEvents() const
Definition: Schedule.cc:996
void clearCounters()
Clear all the counters in the trigger report.
Definition: Schedule.cc:1024
boost::shared_ptr< ModuleRegistry > moduleRegistry_
Definition: Schedule.h:241
std::vector< std::shared_ptr< StreamSchedule > > streamSchedules_
Definition: Schedule.h:242
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:491
void respondToOpenInputFile(FileBlock const &fb)
Definition: Schedule.cc:882
areg
Definition: Schedule.cc:362
std::vector< Worker * > Workers
Definition: Schedule.h:116
void getTriggerReport(TriggerReport &rep) const
Definition: Schedule.cc:976
void processOneGlobal(typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
Definition: Schedule.h:275
PreallocationConfiguration preallocConfig_
Definition: Schedule.h:247
boost::shared_ptr< Worker > WorkerPtr
Definition: Schedule.h:112
volatile bool endpathsAreActive_
Definition: Schedule.h:252
AllOutputModuleCommunicators all_output_communicators_
Definition: Schedule.h:246
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:957
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:351
void beginStream(unsigned int)
Definition: Schedule.cc:894
bool wantSummary_
Definition: Schedule.h:250
void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
Definition: Schedule.cc:907
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
Definition: Schedule.cc:935
std::unique_ptr< GlobalSchedule > globalSchedule_
Definition: Schedule.h:244
void processOneStream(unsigned int iStreamID, typename T::MyPrincipal &principal, EventSetup const &eventSetup, bool cleaningUpAfterException=false)
Definition: Schedule.h:266
void beginJob(ProductRegistry const &)
Definition: Schedule.cc:890
void openNewOutputFilesIfNeeded()
Definition: Schedule.cc:859
void preForkReleaseResources()
Definition: Schedule.cc:904
void openOutputFiles(FileBlock &fb)
Definition: Schedule.cc:863
long double T
void endJob(ExceptionCollector &collector)
Definition: Schedule.cc:507
void getTriggerTimingReport(TriggerTimingReport &rep) const
Definition: Schedule.cc:986
bool shouldWeCloseOutput() const
Definition: Schedule.cc:875
void closeOutputFiles()
Definition: Schedule.cc:855