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