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 
21 
23 
24 #include <map>
25 #include <memory>
26 #include <set>
27 #include <vector>
28 
29 namespace edm {
30  class ActivityRegistry;
31  class BranchDescription;
32  class BranchIDListHelper;
33  class EventPrincipal;
34  class EventSetupImpl;
35  class HistoryAppender;
36  class LuminosityBlockPrincipal;
37  class LumiTransitionInfo;
38  class MergeableRunProductMetadata;
39  class ParameterSet;
40  class Principal;
41  class ProcessBlockTransitionInfo;
42  class ProductRegistry;
43  class PreallocationConfiguration;
44  class RunTransitionInfo;
45  class ThinnedAssociationsHelper;
46  class SubProcessParentageHelper;
47  class WaitingTaskHolder;
48 
49  namespace eventsetup {
50  class EventSetupsController;
51  }
52  class SubProcess : public EDConsumerBase {
53  public:
55  ParameterSet const& topLevelParameterSet,
56  std::shared_ptr<ProductRegistry const> parentProductRegistry,
57  std::shared_ptr<BranchIDListHelper const> parentBranchIDListHelper,
58  ProcessBlockHelperBase const& parentProcessBlockHelper,
59  ThinnedAssociationsHelper const& parentThinnedAssociationsHelper,
60  SubProcessParentageHelper const& parentSubProcessParentageHelper,
62  ActivityRegistry& parentActReg,
63  ServiceToken const& token,
65  PreallocationConfiguration const& preallocConfig,
66  ProcessContext const* parentProcessContext);
67 
68  ~SubProcess() override;
69 
70  SubProcess(SubProcess const&) = delete; // Disallow copying
71  SubProcess& operator=(SubProcess const&) = delete; // Disallow copying
72  SubProcess(SubProcess&&) = default; // Allow Moving
73  SubProcess& operator=(SubProcess&&) = delete; // Move not supported by PrincipalCache
74 
75  //From OutputModule
76  void selectProducts(ProductRegistry const& preg,
77  ThinnedAssociationsHelper const& parentThinnedAssociationsHelper,
78  std::map<BranchID, bool>& keepAssociation);
79 
81 
82  // Returns the set of modules whose products may be consumed by
83  // modules in this SubProcess or its child SubProcesses
84  std::vector<ModuleProcessName> keepOnlyConsumedUnscheduledModules(bool deleteModules);
85 
86  void doBeginJob();
87  void doEndJob();
88 
89  void doEventAsync(WaitingTaskHolder iHolder,
90  EventPrincipal const& principal,
91  std::vector<std::shared_ptr<const EventSetupImpl>> const*);
92 
93  template <typename Traits>
95  ProcessBlockTransitionInfo const& iTransitionInfo,
96  bool cleaningUpAfterException);
97 
99  ProcessBlockTransitionInfo const& iTransitionInfo,
100  bool cleaningUpAfterException);
101 
102  void doBeginRunAsync(WaitingTaskHolder iHolder, RunTransitionInfo const& iTransitionInfo);
103 
104  void doEndRunAsync(WaitingTaskHolder iHolder,
105  RunTransitionInfo const& iTransitionInfo,
106  bool cleaningUpAfterException);
107 
108  void doBeginLuminosityBlockAsync(WaitingTaskHolder iHolder, LumiTransitionInfo const& iTransitionInfo);
109 
111  LumiTransitionInfo const& iTransitionInfo,
112  bool cleaningUpAfterException);
113 
114  void doBeginStream(unsigned int);
115  void doEndStream(unsigned int);
116  void doStreamBeginRunAsync(WaitingTaskHolder iHolder, unsigned int iID, RunTransitionInfo const&);
117 
119  unsigned int iID,
120  RunTransitionInfo const&,
121  bool cleaningUpAfterException);
122 
123  void doStreamBeginLuminosityBlockAsync(WaitingTaskHolder iHolder, unsigned int iID, LumiTransitionInfo const&);
124 
126  unsigned int iID,
127  LumiTransitionInfo const&,
128  bool cleaningUpAfterException);
129 
131 
133 
136 
138 
140 
142 
143  // Call closeFile() on all OutputModules.
146  schedule_->closeOutputFiles();
147  for_all(subProcesses_, [](auto& subProcess) { subProcess.closeOutputFiles(); });
148  }
149 
150  // Call openFiles() on all OutputModules
153  schedule_->openOutputFiles(fb);
154  for_all(subProcesses_, [&fb](auto& subProcess) { subProcess.openOutputFiles(fb); });
155  }
156 
158 
159  // Call respondToOpenInputFile() on all Modules
160  void respondToOpenInputFile(FileBlock const& fb);
161 
162  // Call respondToCloseInputFile() on all Modules
165  schedule_->respondToCloseInputFile(fb);
166  for_all(subProcesses_, [&fb](auto& subProcess) { subProcess.respondToCloseInputFile(fb); });
167  }
168 
169  // Call shouldWeCloseFile() on all OutputModules.
170  bool shouldWeCloseOutput() const {
172  if (schedule_->shouldWeCloseOutput()) {
173  return true;
174  }
175  for (auto const& subProcess : subProcesses_) {
176  if (subProcess.shouldWeCloseOutput()) {
177  return true;
178  }
179  }
180  return false;
181  }
182 
184 
188  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
189 
193  int totalEvents() const { return schedule_->totalEvents(); }
194 
196  int totalEventsPassed() const {
198  return schedule_->totalEventsPassed();
199  }
200 
203  int totalEventsFailed() const {
205  return schedule_->totalEventsFailed();
206  }
207 
212  schedule_->getTriggerReport(rep);
213  }
214 
217  bool terminate() const {
219  if (schedule_->terminate()) {
220  return true;
221  }
222  for (auto const& subProcess : subProcesses_) {
223  if (subProcess.terminate()) {
224  return true;
225  }
226  }
227  return false;
228  }
229 
231  void clearCounters() {
233  schedule_->clearCounters();
234  for_all(subProcesses_, [](auto& subProcess) { subProcess.clearCounters(); });
235  }
236 
237  private:
238  void beginJob();
239  void endJob();
240  void processAsync(WaitingTaskHolder iHolder,
241  EventPrincipal const& e,
242  std::vector<std::shared_ptr<const EventSetupImpl>> const*);
243 
244  void propagateProducts(BranchType type, Principal const& parentPrincipal, Principal& principal) const;
245  bool parentProducedProductIsKept(Principal const& parentPrincipal, Principal& principal) const;
247  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID);
249  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
250  std::set<BranchID>& keptProductsInEvent);
251 
252  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
254  }
255 
256  std::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {
258  }
259  std::shared_ptr<BranchIDListHelper>& branchIDListHelper() { return get_underlying_safe(branchIDListHelper_); }
260  std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper() const {
262  }
263  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper() {
265  }
266 
267  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
269  std::shared_ptr<ProductRegistry const> parentPreg_;
270  std::shared_ptr<ProductRegistry const> preg_;
275  std::unique_ptr<ExceptionToActionTable const> act_table_;
276  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
279  //We require 1 history for each Run, Lumi and Stream
280  // The vectors first hold Stream info, then Lumi then Run
281  unsigned int historyLumiOffset_;
282  unsigned int historyRunOffset_;
283  std::vector<ProcessHistoryRegistry> processHistoryRegistries_;
284  std::vector<HistoryAppender> historyAppenders_;
286  //vector index is principal's index value
287  std::vector<std::shared_ptr<RunPrincipal>> inUseRunPrincipals_;
288  std::vector<std::shared_ptr<LuminosityBlockPrincipal>> inUseLumiPrincipals_;
291  std::vector<SubProcess> subProcesses_;
293 
294  // keptProducts_ are pointers to the BranchDescription objects describing
295  // the branches we are to write.
296  //
297  // We do not own the BranchDescriptions to which we point.
301 
302  //EventSelection
306 
307  // needed because of possible EDAliases.
308  // filled in only if key and value are different.
309  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
310  };
311 
312  // free function
313  std::vector<ParameterSet> popSubProcessVParameterSet(ParameterSet& parameterSet);
314 } // namespace edm
315 #endif
unsigned int historyRunOffset_
Definition: SubProcess.h:282
void doStreamEndLuminosityBlockAsync(WaitingTaskHolder iHolder, unsigned int iID, LumiTransitionInfo const &, bool cleaningUpAfterException)
Definition: SubProcess.cc:739
unsigned int historyLumiOffset_
Definition: SubProcess.h:281
ParameterSetID selector_config_id_
Definition: SubProcess.h:304
std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper()
Definition: SubProcess.h:263
void respondToOpenInputFile(FileBlock const &fb)
Definition: SubProcess.cc:791
SelectedProductsForBranchType const & keptProducts() const
Definition: SubProcess.h:80
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
void clearLumiPrincipal(LuminosityBlockPrincipal &)
Definition: SubProcess.cc:676
bool parentProducedProductIsKept(Principal const &parentPrincipal, Principal &principal) const
Definition: SubProcess.cc:766
std::vector< ProcessHistoryRegistry > processHistoryRegistries_
Definition: SubProcess.h:283
std::array< SelectedProducts, NumBranchTypes > SelectedProductsForBranchType
void clearProcessBlockPrincipal(ProcessBlockType)
Definition: SubProcess.cc:617
edm::propagate_const< std::shared_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
Definition: SubProcess.h:273
std::vector< SubProcess > subProcesses_
Definition: SubProcess.h:291
edm::propagate_const< std::shared_ptr< SubProcessBlockHelper > > processBlockHelper_
Definition: SubProcess.h:272
std::shared_ptr< BranchIDListHelper const > branchIDListHelper() const
Definition: SubProcess.h:256
void writeRunAsync(WaitingTaskHolder, RunPrincipal const &, MergeableRunProductMetadata const *)
Definition: SubProcess.cc:591
void doBeginProcessBlockAsync(WaitingTaskHolder iHolder, ProcessBlockTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
PathsAndConsumesOfModules pathsAndConsumesOfModules_
Definition: SubProcess.h:278
void doStreamEndRunAsync(WaitingTaskHolder iHolder, unsigned int iID, RunTransitionInfo const &, bool cleaningUpAfterException)
Definition: SubProcess.cc:712
void updateBranchIDListHelper(BranchIDLists const &)
Definition: SubProcess.cc:784
void processAsync(WaitingTaskHolder iHolder, EventPrincipal const &e, std::vector< std::shared_ptr< const EventSetupImpl >> const *)
Definition: SubProcess.cc:417
void doEndStream(unsigned int)
Definition: SubProcess.cc:692
SubProcess & operator=(SubProcess const &)=delete
constexpr std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
void openOutputFiles(FileBlock &fb)
Definition: SubProcess.h:151
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
std::map< BranchID::value_type, BranchID::value_type > const & droppedBranchIDToKeptBranchID()
Definition: SubProcess.h:252
edm::propagate_const< std::unique_ptr< Schedule > > schedule_
Definition: SubProcess.h:290
void doEndProcessBlockAsync(WaitingTaskHolder iHolder, ProcessBlockTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
Definition: SubProcess.cc:493
void getTriggerReport(TriggerReport &rep) const
Definition: SubProcess.h:210
BranchType
Definition: BranchType.h:11
int totalEventsFailed() const
Definition: SubProcess.h:203
std::vector< std::shared_ptr< RunPrincipal > > inUseRunPrincipals_
Definition: SubProcess.h:287
std::shared_ptr< ThinnedAssociationsHelper const > thinnedAssociationsHelper() const
Definition: SubProcess.h:260
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:14
void doEventAsync(WaitingTaskHolder iHolder, EventPrincipal const &principal, std::vector< std::shared_ptr< const EventSetupImpl >> const *)
Definition: SubProcess.cc:401
ServiceToken serviceToken_
Definition: SubProcess.h:268
std::vector< std::shared_ptr< LuminosityBlockPrincipal > > inUseLumiPrincipals_
Definition: SubProcess.h:288
void doBeginLuminosityBlockAsync(WaitingTaskHolder iHolder, LumiTransitionInfo const &iTransitionInfo)
Definition: SubProcess.cc:625
int totalEventsPassed() const
Return the number of events which have been passed by one or more trigger paths.
Definition: SubProcess.h:196
~SubProcess() override
Definition: SubProcess.cc:232
SelectedProductsForBranchType keptProducts_
Definition: SubProcess.h:298
void selectProducts(ProductRegistry const &preg, ThinnedAssociationsHelper const &parentThinnedAssociationsHelper, std::map< BranchID, bool > &keepAssociation)
Definition: SubProcess.cc:322
ProductSelectorRules productSelectorRules_
Definition: SubProcess.h:299
void closeOutputFiles()
Definition: SubProcess.h:144
bool terminate() const
Definition: SubProcess.h:217
edm::propagate_const< std::shared_ptr< eventsetup::EventSetupProvider > > esp_
Definition: SubProcess.h:289
edm::propagate_const< std::unique_ptr< ParameterSet > > processParameterSet_
Definition: SubProcess.h:292
void propagateProducts(BranchType type, Principal const &parentPrincipal, Principal &principal) const
Definition: SubProcess.cc:751
std::vector< ModuleDescription const * > getAllModuleDescriptions() const
Return a vector allowing const access to all the ModuleDescriptions for this SubProcess.
rep
Definition: cuy.py:1189
void writeProcessBlockAsync(edm::WaitingTaskHolder task, ProcessBlockType)
Definition: SubProcess.cc:577
std::unique_ptr< ExceptionToActionTable const > act_table_
Definition: SubProcess.h:275
SubProcess(ParameterSet &parameterSet, ParameterSet const &topLevelParameterSet, std::shared_ptr< ProductRegistry const > parentProductRegistry, std::shared_ptr< BranchIDListHelper const > parentBranchIDListHelper, ProcessBlockHelperBase const &parentProcessBlockHelper, ThinnedAssociationsHelper const &parentThinnedAssociationsHelper, SubProcessParentageHelper const &parentSubProcessParentageHelper, eventsetup::EventSetupsController &esController, ActivityRegistry &parentActReg, ServiceToken const &token, serviceregistry::ServiceLegacy iLegacy, PreallocationConfiguration const &preallocConfig, ProcessContext const *parentProcessContext)
Definition: SubProcess.cc:51
std::vector< ParameterSet > popSubProcessVParameterSet(ParameterSet &parameterSet)
Definition: SubProcess.cc:798
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
Definition: SubProcess.h:309
ProductSelector productSelector_
Definition: SubProcess.h:300
detail::TriggerResultsBasedEventSelector selectors_
Definition: SubProcess.h:305
void doStreamBeginLuminosityBlockAsync(WaitingTaskHolder iHolder, unsigned int iID, LumiTransitionInfo const &)
Definition: SubProcess.cc:727
void doStreamBeginRunAsync(WaitingTaskHolder iHolder, unsigned int iID, RunTransitionInfo const &)
Definition: SubProcess.cc:698
int totalEvents() const
Definition: SubProcess.h:193
void respondToCloseInputFile(FileBlock const &fb)
Definition: SubProcess.h:163
std::shared_ptr< ActivityRegistry > actReg_
Definition: SubProcess.h:267
void doEndRunAsync(WaitingTaskHolder iHolder, RunTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
Definition: SubProcess.cc:563
void doBeginRunAsync(WaitingTaskHolder iHolder, RunTransitionInfo const &iTransitionInfo)
Definition: SubProcess.cc:541
edm::propagate_const< std::shared_ptr< BranchIDListHelper > > branchIDListHelper_
Definition: SubProcess.h:271
std::vector< HistoryAppender > historyAppenders_
Definition: SubProcess.h:284
HLT enums.
void clearRunPrincipal(RunPrincipal &)
Definition: SubProcess.cc:608
void doBeginStream(unsigned int)
Definition: SubProcess.cc:686
std::shared_ptr< ProductRegistry const > parentPreg_
Definition: SubProcess.h:269
void fixBranchIDListsForEDAliases(std::map< BranchID::value_type, BranchID::value_type > const &droppedBranchIDToKeptBranchID)
Definition: SubProcess.cc:383
std::shared_ptr< BranchIDListHelper > & branchIDListHelper()
Definition: SubProcess.h:259
ProcessContext processContext_
Definition: SubProcess.h:277
bool shouldWeCloseOutput() const
Definition: SubProcess.h:170
std::vector< ModuleProcessName > keepOnlyConsumedUnscheduledModules(bool deleteModules)
Definition: SubProcess.cc:234
void keepThisBranch(BranchDescription const &desc, std::map< BranchID, BranchDescription const *> &trueBranchIDToKeptBranchDesc, std::set< BranchID > &keptProductsInEvent)
Definition: SubProcess.cc:364
void clearCounters()
Clear all the counters in the trigger report.
Definition: SubProcess.h:231
void doEndLuminosityBlockAsync(WaitingTaskHolder iHolder, LumiTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
Definition: SubProcess.cc:647
void writeLumiAsync(WaitingTaskHolder, LuminosityBlockPrincipal &)
Definition: SubProcess.cc:661
std::shared_ptr< ProductRegistry const > preg_
Definition: SubProcess.h:270
PrincipalCache principalCache_
Definition: SubProcess.h:285
edm::propagate_const< std::shared_ptr< SubProcessParentageHelper > > subProcessParentageHelper_
Definition: SubProcess.h:274
std::shared_ptr< ProcessConfiguration const > processConfiguration_
Definition: SubProcess.h:276