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 MergeableRunProductMetadata;
34  class ParameterSet;
35  class ProductRegistry;
36  class PreallocationConfiguration;
37  class ThinnedAssociationsHelper;
38  class SubProcessParentageHelper;
39  class WaitingTaskHolder;
40 
41  namespace eventsetup {
42  class EventSetupsController;
43  }
44  class SubProcess : public EDConsumerBase {
45  public:
47  ParameterSet const& topLevelParameterSet,
48  std::shared_ptr<ProductRegistry const> parentProductRegistry,
49  std::shared_ptr<BranchIDListHelper const> parentBranchIDListHelper,
50  ThinnedAssociationsHelper const& parentThinnedAssociationsHelper,
51  SubProcessParentageHelper const& parentSubProcessParentageHelper,
53  ActivityRegistry& parentActReg,
54  ServiceToken const& token,
56  PreallocationConfiguration const& preallocConfig,
57  ProcessContext const* parentProcessContext);
58 
59  ~SubProcess() override;
60 
61  SubProcess(SubProcess const&) = delete; // Disallow copying
62  SubProcess& operator=(SubProcess const&) = delete; // Disallow copying
63  SubProcess(SubProcess&&) = default; // Allow Moving
64  SubProcess& operator=(SubProcess&&) = default; // Allow moving
65 
66  //From OutputModule
67  void selectProducts(ProductRegistry const& preg,
68  ThinnedAssociationsHelper const& parentThinnedAssociationsHelper,
69  std::map<BranchID, bool>& keepAssociation);
70 
71  SelectedProductsForBranchType const& keptProducts() const { return keptProducts_; }
72 
73  void doBeginJob();
74  void doEndJob();
75 
76  void doEventAsync(WaitingTaskHolder iHolder, EventPrincipal const& principal);
77 
78  void doBeginRunAsync(WaitingTaskHolder iHolder, RunPrincipal const& principal, IOVSyncValue const& ts);
79 
80  void doEndRunAsync(WaitingTaskHolder iHolder,
81  RunPrincipal const& principal,
82  IOVSyncValue const& ts,
83  bool cleaningUpAfterException);
84 
85  void doBeginLuminosityBlockAsync(WaitingTaskHolder iHolder,
86  LuminosityBlockPrincipal const& principal,
87  IOVSyncValue const& ts);
88 
89  void doEndLuminosityBlockAsync(WaitingTaskHolder iHolder,
90  LuminosityBlockPrincipal const& principal,
91  IOVSyncValue const& ts,
92  bool cleaningUpAfterException);
93 
94  void doBeginStream(unsigned int);
95  void doEndStream(unsigned int);
96  void doStreamBeginRunAsync(WaitingTaskHolder iHolder,
97  unsigned int iID,
98  RunPrincipal const& principal,
99  IOVSyncValue const& ts);
100 
101  void doStreamEndRunAsync(WaitingTaskHolder iHolder,
102  unsigned int iID,
103  RunPrincipal const& principal,
104  IOVSyncValue const& ts,
105  bool cleaningUpAfterException);
106 
107  void doStreamBeginLuminosityBlockAsync(WaitingTaskHolder iHolder,
108  unsigned int iID,
109  LuminosityBlockPrincipal const& principal,
110  IOVSyncValue const& ts);
111 
112  void doStreamEndLuminosityBlockAsync(WaitingTaskHolder iHolder,
113  unsigned int iID,
114  LuminosityBlockPrincipal const& principal,
115  IOVSyncValue const& ts,
116  bool cleaningUpAfterException);
117 
118  // Write the luminosity block
119  void writeLumiAsync(WaitingTaskHolder, LuminosityBlockPrincipal&);
120 
121  void deleteLumiFromCache(LuminosityBlockPrincipal&);
122 
123  // Write the run
124  void writeRunAsync(WaitingTaskHolder,
125  ProcessHistoryID const& parentPhID,
126  int runNumber,
128 
129  void deleteRunFromCache(ProcessHistoryID const& parentPhID, int runNumber);
130 
131  // Call closeFile() on all OutputModules.
133  ServiceRegistry::Operate operate(serviceToken_);
134  schedule_->closeOutputFiles();
135  for_all(subProcesses_, [](auto& subProcess) { subProcess.closeOutputFiles(); });
136  }
137 
138  // Call openFiles() on all OutputModules
140  ServiceRegistry::Operate operate(serviceToken_);
141  schedule_->openOutputFiles(fb);
142  for_all(subProcesses_, [&fb](auto& subProcess) { subProcess.openOutputFiles(fb); });
143  }
144 
145  void updateBranchIDListHelper(BranchIDLists const&);
146 
147  // Call respondToOpenInputFile() on all Modules
148  void respondToOpenInputFile(FileBlock const& fb);
149 
150  // Call respondToCloseInputFile() on all Modules
152  ServiceRegistry::Operate operate(serviceToken_);
153  schedule_->respondToCloseInputFile(fb);
154  for_all(subProcesses_, [&fb](auto& subProcess) { subProcess.respondToCloseInputFile(fb); });
155  }
156 
157  // Call shouldWeCloseFile() on all OutputModules.
158  bool shouldWeCloseOutput() const {
159  ServiceRegistry::Operate operate(serviceToken_);
160  if (schedule_->shouldWeCloseOutput()) {
161  return true;
162  }
163  for (auto const& subProcess : subProcesses_) {
164  if (subProcess.shouldWeCloseOutput()) {
165  return true;
166  }
167  }
168  return false;
169  }
170 
172 
176  std::vector<ModuleDescription const*> getAllModuleDescriptions() const;
177 
181  int totalEvents() const { return schedule_->totalEvents(); }
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(
250  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID);
251  void keepThisBranch(BranchDescription const& desc,
252  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
253  std::set<BranchID>& keptProductsInEvent);
254 
255  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
256  return droppedBranchIDToKeptBranchID_;
257  }
258 
259  std::shared_ptr<BranchIDListHelper const> branchIDListHelper() const {
260  return get_underlying_safe(branchIDListHelper_);
261  }
262  std::shared_ptr<BranchIDListHelper>& branchIDListHelper() { return get_underlying_safe(branchIDListHelper_); }
263  std::shared_ptr<ThinnedAssociationsHelper const> thinnedAssociationsHelper() const {
264  return get_underlying_safe(thinnedAssociationsHelper_);
265  }
266  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper() {
267  return get_underlying_safe(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_;
277  std::unique_ptr<ExceptionToActionTable const> act_table_;
278  std::shared_ptr<ProcessConfiguration const> processConfiguration_;
281  //We require 1 history for each Run, Lumi and Stream
282  // The vectors first hold Stream info, then Lumi then Run
283  unsigned int historyLumiOffset_;
284  unsigned int historyRunOffset_;
285  std::vector<ProcessHistoryRegistry> processHistoryRegistries_;
286  std::vector<HistoryAppender> historyAppenders_;
288  //vector index is principal lumi's index value
289  std::vector<std::shared_ptr<LuminosityBlockPrincipal>> inUseLumiPrincipals_;
292  std::map<ProcessHistoryID, ProcessHistoryID> parentToChildPhID_;
293  std::vector<SubProcess> subProcesses_;
295 
296  // keptProducts_ are pointers to the BranchDescription objects describing
297  // the branches we are to write.
298  //
299  // We do not own the BranchDescriptions to which we point.
303 
304  //EventSelection
308 
309  // needed because of possible EDAliases.
310  // filled in only if key and value are different.
311  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
312  };
313 
314  // free function
315  std::vector<ParameterSet> popSubProcessVParameterSet(ParameterSet& parameterSet);
316 } // namespace edm
317 #endif
unsigned int historyRunOffset_
Definition: SubProcess.h:284
unsigned int historyLumiOffset_
Definition: SubProcess.h:283
ParameterSetID selector_config_id_
Definition: SubProcess.h:306
std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper()
Definition: SubProcess.h:266
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:259
std::vector< ProcessHistoryRegistry > processHistoryRegistries_
Definition: SubProcess.h:285
int totalEvents() const
Definition: SubProcess.h:181
std::array< SelectedProducts, NumBranchTypes > SelectedProductsForBranchType
edm::propagate_const< std::shared_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
Definition: SubProcess.h:275
std::vector< SubProcess > subProcesses_
Definition: SubProcess.h:293
Definition: Hash.h:43
PathsAndConsumesOfModules pathsAndConsumesOfModules_
Definition: SubProcess.h:280
SelectedProductsForBranchType const & keptProducts() const
Definition: SubProcess.h:71
bool terminate() const
Definition: SubProcess.h:219
void openOutputFiles(FileBlock &fb)
Definition: SubProcess.h:139
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:291
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:14
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:14
ServiceToken serviceToken_
Definition: SubProcess.h:271
def principal(options)
bool shouldWeCloseOutput() const
Definition: SubProcess.h:158
std::vector< std::shared_ptr< LuminosityBlockPrincipal > > inUseLumiPrincipals_
Definition: SubProcess.h:289
SelectedProductsForBranchType keptProducts_
Definition: SubProcess.h:300
ProductSelectorRules productSelectorRules_
Definition: SubProcess.h:301
void closeOutputFiles()
Definition: SubProcess.h:132
edm::propagate_const< std::shared_ptr< eventsetup::EventSetupProvider > > esp_
Definition: SubProcess.h:290
edm::propagate_const< std::unique_ptr< ParameterSet > > processParameterSet_
Definition: SubProcess.h:294
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:277
std::vector< ParameterSet > popSubProcessVParameterSet(ParameterSet &parameterSet)
Definition: SubProcess.cc:648
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
Definition: SubProcess.h:311
ProductSelector productSelector_
Definition: SubProcess.h:302
detail::TriggerResultsBasedEventSelector selectors_
Definition: SubProcess.h:307
std::map< ProcessHistoryID, ProcessHistoryID > parentToChildPhID_
Definition: SubProcess.h:292
void respondToCloseInputFile(FileBlock const &fb)
Definition: SubProcess.h:151
std::shared_ptr< ActivityRegistry > actReg_
Definition: SubProcess.h:270
edm::propagate_const< std::shared_ptr< BranchIDListHelper > > branchIDListHelper_
Definition: SubProcess.h:274
void getTriggerReport(TriggerReport &rep) const
Definition: SubProcess.h:212
std::vector< HistoryAppender > historyAppenders_
Definition: SubProcess.h:286
HLT enums.
std::shared_ptr< ProductRegistry const > parentPreg_
Definition: SubProcess.h:272
std::shared_ptr< BranchIDListHelper > & branchIDListHelper()
Definition: SubProcess.h:262
ProcessContext processContext_
Definition: SubProcess.h:279
std::shared_ptr< ThinnedAssociationsHelper const > thinnedAssociationsHelper() const
Definition: SubProcess.h:263
void clearCounters()
Clear all the counters in the trigger report.
Definition: SubProcess.h:233
std::shared_ptr< ProductRegistry const > preg_
Definition: SubProcess.h:273
PrincipalCache principalCache_
Definition: SubProcess.h:287
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
edm::propagate_const< std::shared_ptr< SubProcessParentageHelper > > subProcessParentageHelper_
Definition: SubProcess.h:276
std::shared_ptr< ProcessConfiguration const > processConfiguration_
Definition: SubProcess.h:278
def operate(timelog, memlog, json_f, num)