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