CMS 3D CMS Logo

SubProcess.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_SubProcess_h
2 #define FWCore_Framework_SubProcess_h
3 
20 
22 
23 #include <map>
24 #include <memory>
25 #include <set>
26 
27 namespace edm {
28  class ActivityRegistry;
29  class BranchDescription;
30  class BranchIDListHelper;
31  class HistoryAppender;
32  class IOVSyncValue;
33  class ParameterSet;
34  class ProductRegistry;
35  class PreallocationConfiguration;
36  class ThinnedAssociationsHelper;
37  class SubProcessParentageHelper;
38  class WaitingTaskHolder;
39 
40  namespace eventsetup {
41  class EventSetupsController;
42  }
43  class SubProcess : public EDConsumerBase {
44  public:
46  ParameterSet const& topLevelParameterSet,
47  std::shared_ptr<ProductRegistry const> parentProductRegistry,
48  std::shared_ptr<BranchIDListHelper const> parentBranchIDListHelper,
49  ThinnedAssociationsHelper const& parentThinnedAssociationsHelper,
50  SubProcessParentageHelper const& parentSubProcessParentageHelper,
52  ActivityRegistry& parentActReg,
53  ServiceToken const& token,
55  PreallocationConfiguration const& preallocConfig,
56  ProcessContext const* parentProcessContext);
57 
58  virtual ~SubProcess();
59 
60  SubProcess(SubProcess const&) = delete; // Disallow copying
61  SubProcess& operator=(SubProcess const&) = delete; // Disallow copying
62  SubProcess(SubProcess&&) = default; // Allow Moving
63  SubProcess& operator=(SubProcess&&) = default; // Allow moving
64 
65  //From OutputModule
66  void selectProducts(ProductRegistry const& preg,
67  ThinnedAssociationsHelper const& parentThinnedAssociationsHelper,
68  std::map<BranchID, bool>& keepAssociation);
69 
70  SelectedProductsForBranchType const& keptProducts() const {return keptProducts_;}
71 
72  void doBeginJob();
73  void doEndJob();
74 
75  void doEventAsync(WaitingTaskHolder iHolder,
76  EventPrincipal const& principal);
77 
78  void doBeginRun(RunPrincipal const& principal, IOVSyncValue const& ts);
79  void doBeginRunAsync(WaitingTaskHolder iHolder, RunPrincipal const& principal, IOVSyncValue const& ts);
80 
81  void doEndRun(RunPrincipal const& principal, IOVSyncValue const& ts, bool cleaningUpAfterException);
82  void doEndRunAsync(WaitingTaskHolder iHolder, RunPrincipal const& principal, IOVSyncValue const& ts, bool cleaningUpAfterException);
83 
84  void doBeginLuminosityBlock(LuminosityBlockPrincipal const& principal, IOVSyncValue const& ts);
85  void doBeginLuminosityBlockAsync(WaitingTaskHolder iHolder, LuminosityBlockPrincipal const& principal, IOVSyncValue const& ts);
86 
87  void doEndLuminosityBlock(LuminosityBlockPrincipal const& principal, IOVSyncValue const& ts, bool cleaningUpAfterException);
88  void doEndLuminosityBlockAsync(WaitingTaskHolder iHolder, LuminosityBlockPrincipal const& principal, IOVSyncValue const& ts, bool cleaningUpAfterException);
89 
90 
91  void doBeginStream(unsigned int);
92  void doEndStream(unsigned int);
93  void doStreamBeginRun(unsigned int iID, RunPrincipal const& principal, IOVSyncValue const& ts);
94  void doStreamBeginRunAsync(WaitingTaskHolder iHolder,
95  unsigned int iID,
96  RunPrincipal const& principal,
97  IOVSyncValue const& ts);
98 
99  void doStreamEndRun(unsigned int iID, RunPrincipal const& principal, IOVSyncValue const& ts, bool cleaningUpAfterException);
100  void doStreamEndRunAsync(WaitingTaskHolder iHolder,
101  unsigned int iID, RunPrincipal const& principal,
102  IOVSyncValue const& ts,
103  bool cleaningUpAfterException);
104 
105  void doStreamBeginLuminosityBlock(unsigned int iID, LuminosityBlockPrincipal const& principal, IOVSyncValue const& ts);
106  void doStreamBeginLuminosityBlockAsync(WaitingTaskHolder iHolder,
107  unsigned int iID,
108  LuminosityBlockPrincipal const& principal,
109  IOVSyncValue const& ts);
110 
111  void doStreamEndLuminosityBlock(unsigned int iID, LuminosityBlockPrincipal const& principal, IOVSyncValue const& ts, bool cleaningUpAfterException);
112  void doStreamEndLuminosityBlockAsync(WaitingTaskHolder iHolder,
113  unsigned int iID,
114  LuminosityBlockPrincipal const& principal,
115  IOVSyncValue const& ts,
116  bool cleaningUpAfterException);
117 
118 
119  // Write the luminosity block
120  void writeLumi(ProcessHistoryID const& parentPhID, int runNumber, int lumiNumber);
121 
122  void deleteLumiFromCache(ProcessHistoryID const& parentPhID, int runNumber, int lumiNumber);
123 
124  // Write the run
125  void writeRun(ProcessHistoryID const& parentPhID, int runNumber);
126 
127  void deleteRunFromCache(ProcessHistoryID const& parentPhID, int runNumber);
128 
129  // Call closeFile() on all OutputModules.
131  ServiceRegistry::Operate operate(serviceToken_);
132  schedule_->closeOutputFiles();
133  for_all(subProcesses_, [](auto& subProcess) { subProcess.closeOutputFiles(); });
134  }
135 
136  // Call openFiles() on all OutputModules
138  ServiceRegistry::Operate operate(serviceToken_);
139  schedule_->openOutputFiles(fb);
140  for_all(subProcesses_, [&fb](auto& subProcess) { subProcess.openOutputFiles(fb); });
141  }
142 
143  void updateBranchIDListHelper(BranchIDLists const&);
144 
145  // Call respondToOpenInputFile() on all Modules
146  void respondToOpenInputFile(FileBlock const& fb);
147 
148  // Call respondToCloseInputFile() on all Modules
150  ServiceRegistry::Operate operate(serviceToken_);
151  schedule_->respondToCloseInputFile(fb);
152  for_all(subProcesses_, [&fb](auto& subProcess) { subProcess.respondToCloseInputFile(fb); });
153  }
154 
155  // Call shouldWeCloseFile() on all OutputModules.
156  bool shouldWeCloseOutput() const {
157  ServiceRegistry::Operate operate(serviceToken_);
158  if(schedule_->shouldWeCloseOutput()) {
159  return true;
160  }
161  for(auto const& subProcess : subProcesses_) {
162  if(subProcess.shouldWeCloseOutput()) {
163  return true;
164  }
165  }
166  return false;
167  }
168 
170 
174  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
175 
179  int totalEvents() const {
180  return schedule_->totalEvents();
181  }
182 
184  int totalEventsPassed() const {
185  ServiceRegistry::Operate operate(serviceToken_);
186  return schedule_->totalEventsPassed();
187  }
188 
191  int totalEventsFailed() const {
192  ServiceRegistry::Operate operate(serviceToken_);
193  return schedule_->totalEventsFailed();
194  }
195 
198  void enableEndPaths(bool active) {
199  ServiceRegistry::Operate operate(serviceToken_);
200  schedule_->enableEndPaths(active);
201  for_all(subProcesses_, [active](auto& subProcess){ subProcess.enableEndPaths(active); });
202  }
203 
205  bool endPathsEnabled() const {
206  ServiceRegistry::Operate operate(serviceToken_);
207  return schedule_->endPathsEnabled();
208  }
209 
213  ServiceRegistry::Operate operate(serviceToken_);
214  schedule_->getTriggerReport(rep);
215  }
216 
219  bool terminate() const {
220  ServiceRegistry::Operate operate(serviceToken_);
221  if(schedule_->terminate()) {
222  return true;
223  }
224  for(auto const& subProcess : subProcesses_) {
225  if(subProcess.terminate()) {
226  return true;
227  }
228  }
229  return false;
230  }
231 
233  void clearCounters() {
234  ServiceRegistry::Operate operate(serviceToken_);
235  schedule_->clearCounters();
236  for_all(subProcesses_, [](auto& subProcess){ subProcess.clearCounters(); });
237  }
238 
239  private:
240  void beginJob();
241  void endJob();
242  void processAsync(WaitingTaskHolder iHolder, EventPrincipal const& e);
243  void beginRun(RunPrincipal const& r, IOVSyncValue const& ts);
244  void endRun(RunPrincipal const& r, IOVSyncValue const& ts, bool cleaningUpAfterException);
245  void beginLuminosityBlock(LuminosityBlockPrincipal const& lb, IOVSyncValue const& ts);
246  void endLuminosityBlock(LuminosityBlockPrincipal const& lb, IOVSyncValue const& ts, bool cleaningUpAfterException);
247 
248  void propagateProducts(BranchType type, Principal const& parentPrincipal, Principal& principal) const;
249  void fixBranchIDListsForEDAliases(std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID);
250  void keepThisBranch(BranchDescription const& desc,
251  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
252  std::set<BranchID>& keptProductsInEvent);
253 
254  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
255  return droppedBranchIDToKeptBranchID_;
256  }
257 
258  std::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {return get_underlying_safe(branchIDListHelper_);}
259  std::shared_ptr<BranchIDListHelper>& branchIDListHelper() {return get_underlying_safe(branchIDListHelper_);}
260  std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper() const {return get_underlying_safe(thinnedAssociationsHelper_);}
261  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper() {return get_underlying_safe(thinnedAssociationsHelper_);}
262 
263  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
265  std::shared_ptr<ProductRegistry const> parentPreg_;
266  std::shared_ptr<ProductRegistry const> preg_;
270  std::unique_ptr<ExceptionToActionTable const> act_table_;
271  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
274  //We require 1 history for each Run, Lumi and Stream
275  // The vectors first hold Stream info, then Lumi then Run
276  unsigned int historyLumiOffset_;
277  unsigned int historyRunOffset_;
278  std::vector<ProcessHistoryRegistry> processHistoryRegistries_;
279  std::vector<HistoryAppender> historyAppenders_;
283  std::map<ProcessHistoryID, ProcessHistoryID> parentToChildPhID_;
284  std::vector<SubProcess> subProcesses_;
286 
287  // keptProducts_ are pointers to the BranchDescription objects describing
288  // the branches we are to write.
289  //
290  // We do not own the BranchDescriptions to which we point.
294 
295  //EventSelection
299 
300  // needed because of possible EDAliases.
301  // filled in only if key and value are different.
302  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
303 
304  };
305 
306  // free function
307  std::vector<ParameterSet> popSubProcessVParameterSet(ParameterSet& parameterSet);
308 }
309 #endif
unsigned int historyRunOffset_
Definition: SubProcess.h:277
unsigned int historyLumiOffset_
Definition: SubProcess.h:276
ParameterSetID selector_config_id_
Definition: SubProcess.h:297
std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper()
Definition: SubProcess.h:261
type
Definition: HCALResponse.h:21
void enableEndPaths(bool active)
Definition: SubProcess.h:198
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
int totalEventsFailed() const
Definition: SubProcess.h:191
std::shared_ptr< BranchIDListHelper const > branchIDListHelper() const
Definition: SubProcess.h:258
std::vector< ProcessHistoryRegistry > processHistoryRegistries_
Definition: SubProcess.h:278
int totalEvents() const
Definition: SubProcess.h:179
std::array< SelectedProducts, NumBranchTypes > SelectedProductsForBranchType
edm::propagate_const< std::shared_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
Definition: SubProcess.h:268
std::vector< SubProcess > subProcesses_
Definition: SubProcess.h:284
Definition: Hash.h:43
PathsAndConsumesOfModules pathsAndConsumesOfModules_
Definition: SubProcess.h:273
SelectedProductsForBranchType const & keptProducts() const
Definition: SubProcess.h:70
bool terminate() const
Definition: SubProcess.h:219
void openOutputFiles(FileBlock &fb)
Definition: SubProcess.h:137
std::map< BranchID::value_type, BranchID::value_type > const & droppedBranchIDToKeptBranchID()
Definition: SubProcess.h:254
edm::propagate_const< std::unique_ptr< Schedule > > schedule_
Definition: SubProcess.h:282
int totalEventsPassed() const
Return the number of events which have been passed by one or more trigger paths.
Definition: SubProcess.h:184
bool endPathsEnabled() const
Return true if end_paths are active, and false if they are inactive.
Definition: SubProcess.h:205
BranchType
Definition: BranchType.h:11
void beginJob()
Definition: Breakpoints.cc:15
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:16
ServiceToken serviceToken_
Definition: SubProcess.h:264
def principal(options)
bool shouldWeCloseOutput() const
Definition: SubProcess.h:156
SelectedProductsForBranchType keptProducts_
Definition: SubProcess.h:291
ProductSelectorRules productSelectorRules_
Definition: SubProcess.h:292
void closeOutputFiles()
Definition: SubProcess.h:130
edm::propagate_const< std::shared_ptr< eventsetup::EventSetupProvider > > esp_
Definition: SubProcess.h:281
edm::propagate_const< std::unique_ptr< ParameterSet > > processParameterSet_
Definition: SubProcess.h:285
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
rep
Definition: cuy.py:1188
std::unique_ptr< ExceptionToActionTable const > act_table_
Definition: SubProcess.h:270
std::vector< ParameterSet > popSubProcessVParameterSet(ParameterSet &parameterSet)
Definition: SubProcess.cc:784
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
Definition: SubProcess.h:302
ProductSelector productSelector_
Definition: SubProcess.h:293
detail::TriggerResultsBasedEventSelector selectors_
Definition: SubProcess.h:298
std::map< ProcessHistoryID, ProcessHistoryID > parentToChildPhID_
Definition: SubProcess.h:283
void respondToCloseInputFile(FileBlock const &fb)
Definition: SubProcess.h:149
std::shared_ptr< ActivityRegistry > actReg_
Definition: SubProcess.h:263
edm::propagate_const< std::shared_ptr< BranchIDListHelper > > branchIDListHelper_
Definition: SubProcess.h:267
void getTriggerReport(TriggerReport &rep) const
Definition: SubProcess.h:212
std::vector< HistoryAppender > historyAppenders_
Definition: SubProcess.h:279
HLT enums.
std::shared_ptr< ProductRegistry const > parentPreg_
Definition: SubProcess.h:265
std::shared_ptr< BranchIDListHelper > & branchIDListHelper()
Definition: SubProcess.h:259
ProcessContext processContext_
Definition: SubProcess.h:272
std::shared_ptr< ThinnedAssociationsHelper const > thinnedAssociationsHelper() const
Definition: SubProcess.h:260
void clearCounters()
Clear all the counters in the trigger report.
Definition: SubProcess.h:233
std::shared_ptr< ProductRegistry const > preg_
Definition: SubProcess.h:266
PrincipalCache principalCache_
Definition: SubProcess.h:280
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
edm::propagate_const< std::shared_ptr< SubProcessParentageHelper > > subProcessParentageHelper_
Definition: SubProcess.h:269
std::shared_ptr< ProcessConfiguration const > processConfiguration_
Definition: SubProcess.h:271
def operate(timelog, memlog, json_f, num)