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  ProcessHistoryID const& parentPhID,
139  int runNumber,
141 
142  void deleteRunFromCache(ProcessHistoryID const& parentPhID, int runNumber);
143 
145 
146  // Call closeFile() on all OutputModules.
149  schedule_->closeOutputFiles();
150  for_all(subProcesses_, [](auto& subProcess) { subProcess.closeOutputFiles(); });
151  }
152 
153  // Call openFiles() on all OutputModules
156  schedule_->openOutputFiles(fb);
157  for_all(subProcesses_, [&fb](auto& subProcess) { subProcess.openOutputFiles(fb); });
158  }
159 
161 
162  // Call respondToOpenInputFile() on all Modules
163  void respondToOpenInputFile(FileBlock const& fb);
164 
165  // Call respondToCloseInputFile() on all Modules
168  schedule_->respondToCloseInputFile(fb);
169  for_all(subProcesses_, [&fb](auto& subProcess) { subProcess.respondToCloseInputFile(fb); });
170  }
171 
172  // Call shouldWeCloseFile() on all OutputModules.
173  bool shouldWeCloseOutput() const {
175  if (schedule_->shouldWeCloseOutput()) {
176  return true;
177  }
178  for (auto const& subProcess : subProcesses_) {
179  if (subProcess.shouldWeCloseOutput()) {
180  return true;
181  }
182  }
183  return false;
184  }
185 
187 
191  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
192 
196  int totalEvents() const { return schedule_->totalEvents(); }
197 
199  int totalEventsPassed() const {
201  return schedule_->totalEventsPassed();
202  }
203 
206  int totalEventsFailed() const {
208  return schedule_->totalEventsFailed();
209  }
210 
215  schedule_->getTriggerReport(rep);
216  }
217 
220  bool terminate() const {
222  if (schedule_->terminate()) {
223  return true;
224  }
225  for (auto const& subProcess : subProcesses_) {
226  if (subProcess.terminate()) {
227  return true;
228  }
229  }
230  return false;
231  }
232 
234  void clearCounters() {
236  schedule_->clearCounters();
237  for_all(subProcesses_, [](auto& subProcess) { subProcess.clearCounters(); });
238  }
239 
240  private:
241  void beginJob();
242  void endJob();
243  void processAsync(WaitingTaskHolder iHolder,
244  EventPrincipal const& e,
245  std::vector<std::shared_ptr<const EventSetupImpl>> const*);
246 
247  void propagateProducts(BranchType type, Principal const& parentPrincipal, Principal& principal) const;
248  bool parentProducedProductIsKept(Principal const& parentPrincipal, Principal& principal) const;
250  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID);
252  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
253  std::set<BranchID>& keptProductsInEvent);
254 
255  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
257  }
258 
259  std::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {
261  }
262  std::shared_ptr<BranchIDListHelper>& branchIDListHelper() { return get_underlying_safe(branchIDListHelper_); }
263  std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper() const {
265  }
266  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper() {
268  }
269 
270  std::shared_ptr<ActivityRegistry> actReg_; // We do not use propagate_const because the registry itself is mutable.
272  std::shared_ptr<ProductRegistry const> parentPreg_;
273  std::shared_ptr<ProductRegistry const> preg_;
278  std::unique_ptr<ExceptionToActionTable const> act_table_;
279  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
282  //We require 1 history for each Run, Lumi and Stream
283  // The vectors first hold Stream info, then Lumi then Run
284  unsigned int historyLumiOffset_;
285  unsigned int historyRunOffset_;
286  std::vector<ProcessHistoryRegistry> processHistoryRegistries_;
287  std::vector<HistoryAppender> historyAppenders_;
289  //vector index is principal lumi's index value
290  std::vector<std::shared_ptr<LuminosityBlockPrincipal>> inUseLumiPrincipals_;
293  std::map<ProcessHistoryID, ProcessHistoryID> parentToChildPhID_;
294  std::vector<SubProcess> subProcesses_;
296 
297  // keptProducts_ are pointers to the BranchDescription objects describing
298  // the branches we are to write.
299  //
300  // We do not own the BranchDescriptions to which we point.
304 
305  //EventSelection
309 
310  // needed because of possible EDAliases.
311  // filled in only if key and value are different.
312  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
313  };
314 
315  // free function
316  std::vector<ParameterSet> popSubProcessVParameterSet(ParameterSet& parameterSet);
317 } // namespace edm
318 #endif
unsigned int historyRunOffset_
Definition: SubProcess.h:285
void doStreamEndLuminosityBlockAsync(WaitingTaskHolder iHolder, unsigned int iID, LumiTransitionInfo const &, bool cleaningUpAfterException)
Definition: SubProcess.cc:747
unsigned int historyLumiOffset_
Definition: SubProcess.h:284
ParameterSetID selector_config_id_
Definition: SubProcess.h:307
std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper()
Definition: SubProcess.h:266
void respondToOpenInputFile(FileBlock const &fb)
Definition: SubProcess.cc:799
SelectedProductsForBranchType const & keptProducts() const
Definition: SubProcess.h:80
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
bool parentProducedProductIsKept(Principal const &parentPrincipal, Principal &principal) const
Definition: SubProcess.cc:774
std::vector< ProcessHistoryRegistry > processHistoryRegistries_
Definition: SubProcess.h:286
std::array< SelectedProducts, NumBranchTypes > SelectedProductsForBranchType
void clearProcessBlockPrincipal(ProcessBlockType)
Definition: SubProcess.cc:633
edm::propagate_const< std::shared_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
Definition: SubProcess.h:276
std::vector< SubProcess > subProcesses_
Definition: SubProcess.h:294
Definition: Hash.h:43
edm::propagate_const< std::shared_ptr< SubProcessBlockHelper > > processBlockHelper_
Definition: SubProcess.h:275
std::shared_ptr< BranchIDListHelper const > branchIDListHelper() const
Definition: SubProcess.h:259
void doBeginProcessBlockAsync(WaitingTaskHolder iHolder, ProcessBlockTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
PathsAndConsumesOfModules pathsAndConsumesOfModules_
Definition: SubProcess.h:281
void doStreamEndRunAsync(WaitingTaskHolder iHolder, unsigned int iID, RunTransitionInfo const &, bool cleaningUpAfterException)
Definition: SubProcess.cc:723
void updateBranchIDListHelper(BranchIDLists const &)
Definition: SubProcess.cc:792
void processAsync(WaitingTaskHolder iHolder, EventPrincipal const &e, std::vector< std::shared_ptr< const EventSetupImpl >> const *)
Definition: SubProcess.cc:415
void doEndStream(unsigned int)
Definition: SubProcess.cc:707
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:154
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:255
edm::propagate_const< std::unique_ptr< Schedule > > schedule_
Definition: SubProcess.h:292
void doEndProcessBlockAsync(WaitingTaskHolder iHolder, ProcessBlockTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
Definition: SubProcess.cc:491
void getTriggerReport(TriggerReport &rep) const
Definition: SubProcess.h:213
BranchType
Definition: BranchType.h:11
int totalEventsFailed() const
Definition: SubProcess.h:206
std::shared_ptr< ThinnedAssociationsHelper const > thinnedAssociationsHelper() const
Definition: SubProcess.h:263
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:399
ServiceToken serviceToken_
Definition: SubProcess.h:271
void deleteRunFromCache(ProcessHistoryID const &parentPhID, int runNumber)
Definition: SubProcess.cc:624
std::vector< std::shared_ptr< LuminosityBlockPrincipal > > inUseLumiPrincipals_
Definition: SubProcess.h:290
void doBeginLuminosityBlockAsync(WaitingTaskHolder iHolder, LumiTransitionInfo const &iTransitionInfo)
Definition: SubProcess.cc:641
int totalEventsPassed() const
Return the number of events which have been passed by one or more trigger paths.
Definition: SubProcess.h:199
~SubProcess() override
Definition: SubProcess.cc:230
SelectedProductsForBranchType keptProducts_
Definition: SubProcess.h:301
void selectProducts(ProductRegistry const &preg, ThinnedAssociationsHelper const &parentThinnedAssociationsHelper, std::map< BranchID, bool > &keepAssociation)
Definition: SubProcess.cc:320
void deleteLumiFromCache(LuminosityBlockPrincipal &)
Definition: SubProcess.cc:692
ProductSelectorRules productSelectorRules_
Definition: SubProcess.h:302
void closeOutputFiles()
Definition: SubProcess.h:147
bool terminate() const
Definition: SubProcess.h:220
edm::propagate_const< std::shared_ptr< eventsetup::EventSetupProvider > > esp_
Definition: SubProcess.h:291
edm::propagate_const< std::unique_ptr< ParameterSet > > processParameterSet_
Definition: SubProcess.h:295
void propagateProducts(BranchType type, Principal const &parentPrincipal, Principal &principal) const
Definition: SubProcess.cc:759
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:582
std::unique_ptr< ExceptionToActionTable const > act_table_
Definition: SubProcess.h:278
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:806
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
Definition: SubProcess.h:312
void writeRunAsync(WaitingTaskHolder, ProcessHistoryID const &parentPhID, int runNumber, MergeableRunProductMetadata const *)
Definition: SubProcess.cc:596
ProductSelector productSelector_
Definition: SubProcess.h:303
detail::TriggerResultsBasedEventSelector selectors_
Definition: SubProcess.h:308
void doStreamBeginLuminosityBlockAsync(WaitingTaskHolder iHolder, unsigned int iID, LumiTransitionInfo const &)
Definition: SubProcess.cc:735
void doStreamBeginRunAsync(WaitingTaskHolder iHolder, unsigned int iID, RunTransitionInfo const &)
Definition: SubProcess.cc:713
int totalEvents() const
Definition: SubProcess.h:196
std::map< ProcessHistoryID, ProcessHistoryID > parentToChildPhID_
Definition: SubProcess.h:293
void respondToCloseInputFile(FileBlock const &fb)
Definition: SubProcess.h:166
std::shared_ptr< ActivityRegistry > actReg_
Definition: SubProcess.h:270
void doEndRunAsync(WaitingTaskHolder iHolder, RunTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
Definition: SubProcess.cc:569
void doBeginRunAsync(WaitingTaskHolder iHolder, RunTransitionInfo const &iTransitionInfo)
Definition: SubProcess.cc:539
edm::propagate_const< std::shared_ptr< BranchIDListHelper > > branchIDListHelper_
Definition: SubProcess.h:274
std::vector< HistoryAppender > historyAppenders_
Definition: SubProcess.h:287
HLT enums.
void doBeginStream(unsigned int)
Definition: SubProcess.cc:701
std::shared_ptr< ProductRegistry const > parentPreg_
Definition: SubProcess.h:272
void fixBranchIDListsForEDAliases(std::map< BranchID::value_type, BranchID::value_type > const &droppedBranchIDToKeptBranchID)
Definition: SubProcess.cc:381
std::shared_ptr< BranchIDListHelper > & branchIDListHelper()
Definition: SubProcess.h:262
ProcessContext processContext_
Definition: SubProcess.h:280
bool shouldWeCloseOutput() const
Definition: SubProcess.h:173
std::vector< ModuleProcessName > keepOnlyConsumedUnscheduledModules(bool deleteModules)
Definition: SubProcess.cc:232
void keepThisBranch(BranchDescription const &desc, std::map< BranchID, BranchDescription const *> &trueBranchIDToKeptBranchDesc, std::set< BranchID > &keptProductsInEvent)
Definition: SubProcess.cc:362
void clearCounters()
Clear all the counters in the trigger report.
Definition: SubProcess.h:234
void doEndLuminosityBlockAsync(WaitingTaskHolder iHolder, LumiTransitionInfo const &iTransitionInfo, bool cleaningUpAfterException)
Definition: SubProcess.cc:663
void writeLumiAsync(WaitingTaskHolder, LuminosityBlockPrincipal &)
Definition: SubProcess.cc:677
std::shared_ptr< ProductRegistry const > preg_
Definition: SubProcess.h:273
PrincipalCache principalCache_
Definition: SubProcess.h:288
edm::propagate_const< std::shared_ptr< SubProcessParentageHelper > > subProcessParentageHelper_
Definition: SubProcess.h:277
std::shared_ptr< ProcessConfiguration const > processConfiguration_
Definition: SubProcess.h:279