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