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 
22 
24 
25 #include <map>
26 #include <memory>
27 #include <mutex>
28 #include <set>
29 #include <vector>
30 
31 namespace edm {
32  class ActivityRegistry;
33  class BranchDescription;
34  class BranchIDListHelper;
35  class EventPrincipal;
36  class EventSetupImpl;
37  class ExceptionCollector;
38  class HistoryAppender;
39  class LuminosityBlockPrincipal;
40  class LumiTransitionInfo;
41  class MergeableRunProductMetadata;
42  class ModuleTypeResolverMaker;
43  class ParameterSet;
44  class Principal;
45  class ProcessBlockTransitionInfo;
46  class ProductRegistry;
47  class PreallocationConfiguration;
48  class RunTransitionInfo;
49  class ThinnedAssociationsHelper;
50  class SubProcessParentageHelper;
51  class WaitingTaskHolder;
52 
53  namespace eventsetup {
54  class EventSetupsController;
55  }
56  class SubProcess : public EDConsumerBase {
57  public:
59  ParameterSet const& topLevelParameterSet,
60  std::shared_ptr<ProductRegistry const> parentProductRegistry,
61  std::shared_ptr<BranchIDListHelper const> parentBranchIDListHelper,
62  ProcessBlockHelperBase const& parentProcessBlockHelper,
63  ThinnedAssociationsHelper const& parentThinnedAssociationsHelper,
64  SubProcessParentageHelper const& parentSubProcessParentageHelper,
66  ActivityRegistry& parentActReg,
67  ServiceToken const& token,
69  PreallocationConfiguration const& preallocConfig,
70  ProcessContext const* parentProcessContext,
71  ModuleTypeResolverMaker const* typeResolverMaker);
72 
73  ~SubProcess() override;
74 
75  SubProcess(SubProcess const&) = delete; // Disallow copying
76  SubProcess& operator=(SubProcess const&) = delete; // Disallow copying
77  SubProcess(SubProcess&&) = default; // Allow Moving
78  SubProcess& operator=(SubProcess&&) = delete; // Move not supported by PrincipalCache
79 
80  //From OutputModule
81  void selectProducts(ProductRegistry const& preg,
82  ThinnedAssociationsHelper const& parentThinnedAssociationsHelper,
83  std::map<BranchID, bool>& keepAssociation);
84 
86 
87  // Returns the set of modules whose products may be consumed by
88  // modules in this SubProcess or its child SubProcesses
89  std::vector<ModuleProcessName> keepOnlyConsumedUnscheduledModules(bool deleteModules);
90 
91  void doBeginJob();
93 
94  void doEventAsync(WaitingTaskHolder iHolder,
95  EventPrincipal const& principal,
96  std::vector<std::shared_ptr<const EventSetupImpl>> const*);
97 
98  template <typename Traits>
100  ProcessBlockTransitionInfo const& iTransitionInfo,
101  bool cleaningUpAfterException);
102 
104  ProcessBlockTransitionInfo const& iTransitionInfo,
105  bool cleaningUpAfterException);
106 
107  void doBeginRunAsync(WaitingTaskHolder iHolder, RunTransitionInfo const& iTransitionInfo);
108 
109  void doEndRunAsync(WaitingTaskHolder iHolder,
110  RunTransitionInfo const& iTransitionInfo,
111  bool cleaningUpAfterException);
112 
113  void doBeginLuminosityBlockAsync(WaitingTaskHolder iHolder, LumiTransitionInfo const& iTransitionInfo);
114 
116  LumiTransitionInfo const& iTransitionInfo,
117  bool cleaningUpAfterException);
118 
119  void doBeginStream(unsigned int streamID);
120  void doEndStream(unsigned int streamID, ExceptionCollector& collector, std::mutex& collectorMutex) noexcept;
121  void doStreamBeginRunAsync(WaitingTaskHolder iHolder, unsigned int iID, RunTransitionInfo const&);
122 
124  unsigned int iID,
125  RunTransitionInfo const&,
126  bool cleaningUpAfterException);
127 
128  void doStreamBeginLuminosityBlockAsync(WaitingTaskHolder iHolder, unsigned int iID, LumiTransitionInfo const&);
129 
131  unsigned int iID,
132  LumiTransitionInfo const&,
133  bool cleaningUpAfterException);
134 
136 
138 
141 
143 
145 
147 
148  // Call closeFile() on all OutputModules.
151  schedule_->closeOutputFiles();
152  for_all(subProcesses_, [](auto& subProcess) { subProcess.closeOutputFiles(); });
153  }
154 
155  // Call openFiles() on all OutputModules
158  schedule_->openOutputFiles(fb);
159  for_all(subProcesses_, [&fb](auto& subProcess) { subProcess.openOutputFiles(fb); });
160  }
161 
163 
164  // Call respondToOpenInputFile() on all Modules
165  void respondToOpenInputFile(FileBlock const& fb);
166 
167  // Call respondToCloseInputFile() on all Modules
170  schedule_->respondToCloseInputFile(fb);
171  for_all(subProcesses_, [&fb](auto& subProcess) { subProcess.respondToCloseInputFile(fb); });
172  }
173 
174  // Call shouldWeCloseFile() on all OutputModules.
175  bool shouldWeCloseOutput() const {
177  if (schedule_->shouldWeCloseOutput()) {
178  return true;
179  }
180  for (auto const& subProcess : subProcesses_) {
181  if (subProcess.shouldWeCloseOutput()) {
182  return true;
183  }
184  }
185  return false;
186  }
187 
189 
193  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
194 
198  int totalEvents() const { return schedule_->totalEvents(); }
199 
201  int totalEventsPassed() const {
203  return schedule_->totalEventsPassed();
204  }
205 
208  int totalEventsFailed() const {
210  return schedule_->totalEventsFailed();
211  }
212 
217  schedule_->getTriggerReport(rep);
218  }
219 
222  bool terminate() const {
224  if (schedule_->terminate()) {
225  return true;
226  }
227  for (auto const& subProcess : subProcesses_) {
228  if (subProcess.terminate()) {
229  return true;
230  }
231  }
232  return false;
233  }
234 
236  void clearCounters() {
238  schedule_->clearCounters();
239  for_all(subProcesses_, [](auto& subProcess) { subProcess.clearCounters(); });
240  }
241 
242  private:
243  void beginJob();
244  void endJob(ExceptionCollector&);
245  void processAsync(WaitingTaskHolder iHolder,
246  EventPrincipal const& e,
247  std::vector<std::shared_ptr<const EventSetupImpl>> const*);
248 
249  void propagateProducts(BranchType type, Principal const& parentPrincipal, Principal& principal) const;
250  bool parentProducedProductIsKept(Principal const& parentPrincipal, Principal& principal) const;
252  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID);
254  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
255  std::set<BranchID>& keptProductsInEvent);
256 
257  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
259  }
260 
261  std::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {
263  }
264  std::shared_ptr<BranchIDListHelper>& branchIDListHelper() { return get_underlying_safe(branchIDListHelper_); }
265  std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper() const {
267  }
268  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper() {
270  }
271 
272  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
274  std::shared_ptr<ProductRegistry const> parentPreg_;
275  std::shared_ptr<ProductRegistry const> preg_;
280  std::unique_ptr<ExceptionToActionTable const> act_table_;
281  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
284  //We require 1 history for each Run, Lumi and Stream
285  // The vectors first hold Stream info, then Lumi then Run
286  unsigned int historyLumiOffset_;
287  unsigned int historyRunOffset_;
288  std::vector<ProcessHistoryRegistry> processHistoryRegistries_;
289  std::vector<HistoryAppender> historyAppenders_;
291  //vector index is principal's index value
292  std::vector<std::shared_ptr<RunPrincipal>> inUseRunPrincipals_;
293  std::vector<std::shared_ptr<LuminosityBlockPrincipal>> inUseLumiPrincipals_;
296  std::vector<SubProcess> subProcesses_;
298 
299  // keptProducts_ are pointers to the BranchDescription objects describing
300  // the branches we are to write.
301  //
302  // We do not own the BranchDescriptions to which we point.
306 
307  //EventSelection
311 
312  // needed because of possible EDAliases.
313  // filled in only if key and value are different.
314  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
315  };
316 
317  // free function
318  std::vector<ParameterSet> popSubProcessVParameterSet(ParameterSet& parameterSet);
319 } // namespace edm
320 #endif
unsigned int historyRunOffset_
Definition: SubProcess.h:287
void doStreamEndLuminosityBlockAsync(WaitingTaskHolder iHolder, unsigned int iID, LumiTransitionInfo const &, bool cleaningUpAfterException)
Definition: SubProcess.cc:778
unsigned int historyLumiOffset_
Definition: SubProcess.h:286
ParameterSetID selector_config_id_
Definition: SubProcess.h:309
std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper()
Definition: SubProcess.h:268
void endJob(ExceptionCollector &)
Definition: SubProcess.cc:332
void respondToOpenInputFile(FileBlock const &fb)
Definition: SubProcess.cc:830
SelectedProductsForBranchType const & keptProducts() const
Definition: SubProcess.h:85
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
void clearLumiPrincipal(LuminosityBlockPrincipal &)
Definition: SubProcess.cc:698
bool parentProducedProductIsKept(Principal const &parentPrincipal, Principal &principal) const
Definition: SubProcess.cc:805
std::vector< ProcessHistoryRegistry > processHistoryRegistries_
Definition: SubProcess.h:288
std::array< SelectedProducts, NumBranchTypes > SelectedProductsForBranchType
void clearProcessBlockPrincipal(ProcessBlockType)
Definition: SubProcess.cc:639
edm::propagate_const< std::shared_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
Definition: SubProcess.h:278
std::vector< SubProcess > subProcesses_
Definition: SubProcess.h:296
edm::propagate_const< std::shared_ptr< SubProcessBlockHelper > > processBlockHelper_
Definition: SubProcess.h:277
std::shared_ptr< BranchIDListHelper const > branchIDListHelper() const
Definition: SubProcess.h:261
void writeRunAsync(WaitingTaskHolder, RunPrincipal const &, MergeableRunProductMetadata const *)
Definition: SubProcess.cc:613
static std::mutex mutex
Definition: Proxy.cc:8
void doBeginProcessBlockAsync(WaitingTaskHolder iHolder, ProcessBlockTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
PathsAndConsumesOfModules pathsAndConsumesOfModules_
Definition: SubProcess.h:283
void doStreamEndRunAsync(WaitingTaskHolder iHolder, unsigned int iID, RunTransitionInfo const &, bool cleaningUpAfterException)
Definition: SubProcess.cc:751
void updateBranchIDListHelper(BranchIDLists const &)
Definition: SubProcess.cc:823
void doBeginStream(unsigned int streamID)
Definition: SubProcess.cc:708
void processAsync(WaitingTaskHolder iHolder, EventPrincipal const &e, std::vector< std::shared_ptr< const EventSetupImpl >> const *)
Definition: SubProcess.cc:439
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:156
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, ModuleTypeResolverMaker const *typeResolverMaker)
Definition: SubProcess.cc:53
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:257
edm::propagate_const< std::unique_ptr< Schedule > > schedule_
Definition: SubProcess.h:295
void doEndProcessBlockAsync(WaitingTaskHolder iHolder, ProcessBlockTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
Definition: SubProcess.cc:515
void getTriggerReport(TriggerReport &rep) const
Definition: SubProcess.h:215
BranchType
Definition: BranchType.h:11
int totalEventsFailed() const
Definition: SubProcess.h:208
std::vector< std::shared_ptr< RunPrincipal > > inUseRunPrincipals_
Definition: SubProcess.h:292
std::shared_ptr< ThinnedAssociationsHelper const > thinnedAssociationsHelper() const
Definition: SubProcess.h:265
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:423
ServiceToken serviceToken_
Definition: SubProcess.h:273
std::vector< std::shared_ptr< LuminosityBlockPrincipal > > inUseLumiPrincipals_
Definition: SubProcess.h:293
void doBeginLuminosityBlockAsync(WaitingTaskHolder iHolder, LumiTransitionInfo const &iTransitionInfo)
Definition: SubProcess.cc:647
int totalEventsPassed() const
Return the number of events which have been passed by one or more trigger paths.
Definition: SubProcess.h:201
~SubProcess() override
Definition: SubProcess.cc:240
SelectedProductsForBranchType keptProducts_
Definition: SubProcess.h:303
void selectProducts(ProductRegistry const &preg, ThinnedAssociationsHelper const &parentThinnedAssociationsHelper, std::map< BranchID, bool > &keepAssociation)
Definition: SubProcess.cc:344
ProductSelectorRules productSelectorRules_
Definition: SubProcess.h:304
void closeOutputFiles()
Definition: SubProcess.h:149
bool terminate() const
Definition: SubProcess.h:222
edm::propagate_const< std::shared_ptr< eventsetup::EventSetupProvider > > esp_
Definition: SubProcess.h:294
edm::propagate_const< std::unique_ptr< ParameterSet > > processParameterSet_
Definition: SubProcess.h:297
void propagateProducts(BranchType type, Principal const &parentPrincipal, Principal &principal) const
Definition: SubProcess.cc:790
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 doEndJob(ExceptionCollector &)
Definition: SubProcess.cc:299
void writeProcessBlockAsync(edm::WaitingTaskHolder task, ProcessBlockType)
Definition: SubProcess.cc:599
std::unique_ptr< ExceptionToActionTable const > act_table_
Definition: SubProcess.h:280
std::vector< ParameterSet > popSubProcessVParameterSet(ParameterSet &parameterSet)
Definition: SubProcess.cc:837
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
Definition: SubProcess.h:314
ProductSelector productSelector_
Definition: SubProcess.h:305
detail::TriggerResultsBasedEventSelector selectors_
Definition: SubProcess.h:310
void doStreamBeginLuminosityBlockAsync(WaitingTaskHolder iHolder, unsigned int iID, LumiTransitionInfo const &)
Definition: SubProcess.cc:766
void doStreamBeginRunAsync(WaitingTaskHolder iHolder, unsigned int iID, RunTransitionInfo const &)
Definition: SubProcess.cc:737
int totalEvents() const
Definition: SubProcess.h:198
void respondToCloseInputFile(FileBlock const &fb)
Definition: SubProcess.h:168
std::shared_ptr< ActivityRegistry > actReg_
Definition: SubProcess.h:272
void doEndRunAsync(WaitingTaskHolder iHolder, RunTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
Definition: SubProcess.cc:585
void doBeginRunAsync(WaitingTaskHolder iHolder, RunTransitionInfo const &iTransitionInfo)
Definition: SubProcess.cc:563
edm::propagate_const< std::shared_ptr< BranchIDListHelper > > branchIDListHelper_
Definition: SubProcess.h:276
void doEndStream(unsigned int streamID, ExceptionCollector &collector, std::mutex &collectorMutex) noexcept
Definition: SubProcess.cc:727
std::vector< HistoryAppender > historyAppenders_
Definition: SubProcess.h:289
HLT enums.
void clearRunPrincipal(RunPrincipal &)
Definition: SubProcess.cc:630
std::shared_ptr< ProductRegistry const > parentPreg_
Definition: SubProcess.h:274
void fixBranchIDListsForEDAliases(std::map< BranchID::value_type, BranchID::value_type > const &droppedBranchIDToKeptBranchID)
Definition: SubProcess.cc:405
std::shared_ptr< BranchIDListHelper > & branchIDListHelper()
Definition: SubProcess.h:264
ProcessContext processContext_
Definition: SubProcess.h:282
bool shouldWeCloseOutput() const
Definition: SubProcess.h:175
std::vector< ModuleProcessName > keepOnlyConsumedUnscheduledModules(bool deleteModules)
Definition: SubProcess.cc:242
void keepThisBranch(BranchDescription const &desc, std::map< BranchID, BranchDescription const *> &trueBranchIDToKeptBranchDesc, std::set< BranchID > &keptProductsInEvent)
Definition: SubProcess.cc:386
void clearCounters()
Clear all the counters in the trigger report.
Definition: SubProcess.h:236
void doEndLuminosityBlockAsync(WaitingTaskHolder iHolder, LumiTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
Definition: SubProcess.cc:669
void writeLumiAsync(WaitingTaskHolder, LuminosityBlockPrincipal &)
Definition: SubProcess.cc:683
std::shared_ptr< ProductRegistry const > preg_
Definition: SubProcess.h:275
PrincipalCache principalCache_
Definition: SubProcess.h:290
edm::propagate_const< std::shared_ptr< SubProcessParentageHelper > > subProcessParentageHelper_
Definition: SubProcess.h:279
std::shared_ptr< ProcessConfiguration const > processConfiguration_
Definition: SubProcess.h:281