CMS 3D CMS Logo

OutputModuleBase.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_global_OutputModuleBase_h
2 #define FWCore_Framework_global_OutputModuleBase_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Framework
6 // Class : OutputModuleBase
7 //
16 //
17 //
18 
19 // system include files
20 #include <array>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 #include <map>
25 #include <atomic>
26 #include <mutex>
27 #include <set>
28 
29 // user include files
34 
43 
44 // forward declarations
45 namespace edm {
46 
47  class MergeableRunProductMetadata;
48  class ModuleCallingContext;
49  class PreallocationConfiguration;
50  class ActivityRegistry;
51  class ProductRegistry;
52  class ThinnedAssociationsHelper;
53  class WaitingTask;
54 
55  template <typename T>
57 
58  namespace maker {
59  template <typename T>
60  class ModuleHolderT;
61  }
62 
63  namespace global {
64 
66  public:
67  template <typename U>
69  template <typename T>
70  friend class ::edm::WorkerT;
71  template <typename T>
72  friend class ::edm::OutputModuleCommunicatorT;
74 
75  explicit OutputModuleBase(ParameterSet const& pset);
76  ~OutputModuleBase() override;
77 
78  OutputModuleBase(OutputModuleBase const&) = delete; // Disallow copying and moving
79  OutputModuleBase& operator=(OutputModuleBase const&) = delete; // Disallow copying and moving
80 
83  int maxEvents() const { return maxEvents_; }
84 
87  int remainingEvents() const { return remainingEvents_; }
88 
89  bool selected(BranchDescription const& desc) const;
90 
91  void selectProducts(ProductRegistry const& preg, ThinnedAssociationsHelper const&);
92  std::string const& processName() const { return process_name_; }
93  SelectedProductsForBranchType const& keptProducts() const { return keptProducts_; }
94  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const { return hasNewlyDroppedBranch_; }
95 
96  static void fillDescription(ParameterSetDescription& desc);
97  static void fillDescriptions(ConfigurationDescriptions& descriptions);
98  static const std::string& baseType();
99  static void prevalidate(ConfigurationDescriptions&);
100 
101  bool wantAllEvents() const { return wantAllEvents_; }
102 
103  BranchIDLists const* branchIDLists() const;
104 
105  ThinnedAssociationsHelper const* thinnedAssociationsHelper() const;
106 
107  const ModuleDescription& moduleDescription() const { return moduleDescription_; }
108 
109  //Output modules always need writeRun and writeLumi to be called
110  bool wantsGlobalRuns() const { return true; }
111  bool wantsGlobalLuminosityBlocks() const { return true; }
112 
113  virtual bool wantsStreamRuns() const = 0;
114  virtual bool wantsStreamLuminosityBlocks() const = 0;
115 
116  protected:
117  ModuleDescription const& description() const;
118 
119  ParameterSetID selectorConfig() const { return selector_config_id_; }
120 
121  void doPreallocate(PreallocationConfiguration const&);
122 
123  void doBeginJob();
124  void doEndJob();
125 
126  void doBeginStream(StreamID id);
127  void doEndStream(StreamID id);
128  void doStreamBeginRun(StreamID id, RunPrincipal& ep, EventSetupImpl const& c, ModuleCallingContext const*);
129  void doStreamEndRun(StreamID id, RunPrincipal& ep, EventSetupImpl const& c, ModuleCallingContext const*);
130  void doStreamBeginLuminosityBlock(StreamID id,
132  EventSetupImpl const& c,
133  ModuleCallingContext const*);
134  void doStreamEndLuminosityBlock(StreamID id,
136  EventSetupImpl const& c,
137  ModuleCallingContext const*);
138 
139  bool doEvent(EventPrincipal const& ep, EventSetupImpl const& c, ActivityRegistry*, ModuleCallingContext const*);
140  //For now this is a placeholder
141  /*virtual*/ void preActionBeforeRunEventAsync(WaitingTask* iTask,
142  ModuleCallingContext const& iModuleCallingContext,
143  Principal const& iPrincipal) const {}
144 
145  bool doBeginRun(RunPrincipal const& rp, EventSetupImpl const& c, ModuleCallingContext const*);
146  bool doEndRun(RunPrincipal const& rp, EventSetupImpl const& c, ModuleCallingContext const*);
147  bool doBeginLuminosityBlock(LuminosityBlockPrincipal const& lbp,
148  EventSetupImpl const& c,
149  ModuleCallingContext const*);
150  bool doEndLuminosityBlock(LuminosityBlockPrincipal const& lbp,
151  EventSetupImpl const& c,
152  ModuleCallingContext const*);
153 
154  void setEventSelectionInfo(
155  std::map<std::string, std::vector<std::pair<std::string, int>>> const& outputModulePathPositions,
156  bool anyProductProduced);
157 
158  void configure(OutputModuleDescription const& desc);
159 
160  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
161  return droppedBranchIDToKeptBranchID_;
162  }
163 
164  private:
166  std::atomic<int> remainingEvents_;
167 
168  // TODO: Give OutputModule
169  // an interface (protected?) that supplies client code with the
170  // needed functionality *without* giving away implementation
171  // details ... don't just return a reference to keptProducts_, because
172  // we are looking to have the flexibility to change the
173  // implementation of keptProducts_ without modifying clients. When this
174  // change is made, we'll have a one-time-only task of modifying
175  // clients (classes derived from OutputModule) to use the
176  // newly-introduced interface.
177  // TODO: Consider using shared pointers here?
178 
179  // keptProducts_ are pointers to the BranchDescription objects describing
180  // the branches we are to write.
181  //
182  // We do not own the BranchDescriptions to which we point.
184  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
185 
190 
192  std::vector<detail::TriggerResultsBasedEventSelector> selectors_;
194  // ID of the ParameterSet that configured the event selector
195  // subsystem.
197 
198  // needed because of possible EDAliases.
199  // filled in only if key and value are different.
200  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
203 
205  std::map<BranchID, bool> keepAssociation_;
206 
207  //------------------------------------------------------------------
208  // private member functions
209  //------------------------------------------------------------------
210 
211  void updateBranchIDListsWithKeptAliases();
212 
213  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const*, MergeableRunProductMetadata const*);
214  void doWriteLuminosityBlock(LuminosityBlockPrincipal const& lbp, ModuleCallingContext const*);
215  void doOpenFile(FileBlock const& fb);
216  void doRespondToOpenInputFile(FileBlock const& fb);
217  void doRespondToCloseInputFile(FileBlock const& fb);
219 
220  std::string workerType() const { return "WorkerT<edm::global::OutputModuleBase>"; }
221 
223  void doCloseFile();
224 
226 
227  bool needToRunSelection() const;
228  std::vector<ProductResolverIndexAndSkipBit> productsUsedBySelection() const;
229  bool prePrefetchSelection(StreamID id, EventPrincipal const&, ModuleCallingContext const*);
230 
231  // Do the end-of-file tasks; this is only called internally, after
232  // the appropriate tests have been done.
233  virtual void reallyCloseFile();
234 
236  virtual bool shouldWeCloseFile() const { return false; }
237 
238  virtual void write(EventForOutput const&) = 0;
239  virtual void beginJob() {}
240  virtual void endJob() {}
241  virtual void writeLuminosityBlock(LuminosityBlockForOutput const&) = 0;
242  virtual void writeRun(RunForOutput const&) = 0;
243  virtual void openFile(FileBlock const&) {}
244  virtual bool isFileOpen() const { return true; }
245 
246  virtual void preallocStreams(unsigned int) {}
247  virtual void preallocLumis(unsigned int) {}
248  virtual void preallocate(PreallocationConfiguration const&) {}
249  virtual void doBeginStream_(StreamID) {}
250  virtual void doEndStream_(StreamID) {}
251  virtual void doStreamBeginRun_(StreamID, RunForOutput const&, EventSetup const&) {}
252  virtual void doStreamEndRun_(StreamID, RunForOutput const&, EventSetup const&) {}
253  virtual void doStreamEndRunSummary_(StreamID, RunForOutput const&, EventSetup const&) {}
257 
258  virtual void doBeginRun_(RunForOutput const&) {}
259  virtual void doBeginRunSummary_(RunForOutput const&, EventSetup const&) {}
260  virtual void doEndRun_(RunForOutput const&) {}
261  virtual void doEndRunSummary_(RunForOutput const&, EventSetup const&) {}
266  virtual void doRespondToOpenInputFile_(FileBlock const&) {}
267  virtual void doRespondToCloseInputFile_(FileBlock const&) {}
268 
269  virtual void setProcessesWithSelectedMergeableRunProducts(std::set<std::string> const&) {}
270 
271  bool hasAcquire() const { return false; }
272  bool hasAccumulator() const { return false; }
273 
274  void keepThisBranch(BranchDescription const& desc,
275  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
276  std::set<BranchID>& keptProductsInEvent);
277 
278  void setModuleDescription(ModuleDescription const& md) { moduleDescription_ = md; }
279 
280  bool limitReached() const { return remainingEvents_ == 0; }
281  };
282  } // namespace global
283 } // namespace edm
284 #endif
virtual void doEndRunSummary_(RunForOutput const &, EventSetup const &)
virtual void preallocate(PreallocationConfiguration const &)
SelectedProductsForBranchType const & keptProducts() const
BranchIDLists const * origBranchIDLists_
std::string workerType() const
virtual void setProcessesWithSelectedMergeableRunProducts(std::set< std::string > const &)
virtual void doStreamEndRun_(StreamID, RunForOutput const &, EventSetup const &)
void setModuleDescription(ModuleDescription const &md)
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
virtual void preallocStreams(unsigned int)
virtual bool isFileOpen() const
std::array< SelectedProducts, NumBranchTypes > SelectedProductsForBranchType
virtual void doEndLuminosityBlockSummary_(LuminosityBlockForOutput const &, EventSetup const &)
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
std::vector< detail::TriggerResultsBasedEventSelector > selectors_
virtual void openFile(FileBlock const &)
virtual void doBeginStream_(StreamID)
virtual void doRespondToOpenInputFile_(FileBlock const &)
virtual void doStreamBeginRun_(StreamID, RunForOutput const &, EventSetup const &)
std::string const & processName() const
SelectedProductsForBranchType keptProducts_
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
void registerProductsAndCallbacks(OutputModuleBase const *, ProductRegistry const *)
void doRegisterThinnedAssociations(ProductRegistry const &, ThinnedAssociationsHelper &)
void preActionBeforeRunEventAsync(WaitingTask *iTask, ModuleCallingContext const &iModuleCallingContext, Principal const &iPrincipal) const
ModuleDescription moduleDescription_
edm::propagate_const< std::unique_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
virtual void doEndStream_(StreamID)
std::map< BranchID, bool > keepAssociation_
virtual void doBeginLuminosityBlock_(LuminosityBlockForOutput const &)
const ModuleDescription & moduleDescription() const
edm::propagate_const< std::unique_ptr< BranchIDLists > > branchIDLists_
virtual void doStreamEndLuminosityBlock_(StreamID, LuminosityBlockForOutput const &, EventSetup const &)
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
virtual void doStreamEndLuminosityBlockSummary_(StreamID, LuminosityBlockForOutput const &, EventSetup const &)
virtual void doEndRun_(RunForOutput const &)
virtual void preallocLumis(unsigned int)
ParameterSetID selectorConfig() const
ProductSelectorRules productSelectorRules_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::atomic< int > remainingEvents_
virtual void doEndLuminosityBlock_(LuminosityBlockForOutput const &)
virtual void doBeginRun_(RunForOutput const &)
HLT enums.
virtual bool shouldWeCloseFile() const
Ask the OutputModule if we should end the current file.
std::map< BranchID::value_type, BranchID::value_type > const & droppedBranchIDToKeptBranchID()
virtual void doStreamEndRunSummary_(StreamID, RunForOutput const &, EventSetup const &)
virtual void doRespondToCloseInputFile_(FileBlock const &)
virtual void doBeginRunSummary_(RunForOutput const &, EventSetup const &)
virtual void doBeginLuminosityBlockSummary_(LuminosityBlockForOutput const &, EventSetup const &)
virtual void doStreamBeginLuminosityBlock_(StreamID, LuminosityBlockForOutput const &, EventSetup const &)