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