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> class OutputModuleCommunicatorT;
56 
57  namespace maker {
58  template<typename T> class ModuleHolderT;
59  }
60 
61  namespace global {
62 
64  public:
65  template <typename U> friend class edm::maker::ModuleHolderT;
66  template <typename T> friend class ::edm::WorkerT;
67  template <typename T> friend class ::edm::OutputModuleCommunicatorT;
69 
70  explicit OutputModuleBase(ParameterSet const& pset);
71  ~OutputModuleBase() override;
72 
73  OutputModuleBase(OutputModuleBase const&) = delete; // Disallow copying and moving
74  OutputModuleBase& operator=(OutputModuleBase const&) = delete; // Disallow copying and moving
75 
78  int maxEvents() const {return maxEvents_;}
79 
82  int remainingEvents() const {return remainingEvents_;}
83 
84  bool selected(BranchDescription const& desc) const;
85 
86  void selectProducts(ProductRegistry const& preg, ThinnedAssociationsHelper const&);
87  std::string const& processName() const {return process_name_;}
88  SelectedProductsForBranchType const& keptProducts() const {return keptProducts_;}
89  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
90 
91  static void fillDescription(ParameterSetDescription & desc);
92  static void fillDescriptions(ConfigurationDescriptions& descriptions);
93  static const std::string& baseType();
94  static void prevalidate(ConfigurationDescriptions& );
95 
96  bool wantAllEvents() const {return wantAllEvents_;}
97 
98  BranchIDLists const* branchIDLists() const;
99 
100  ThinnedAssociationsHelper const* thinnedAssociationsHelper() const;
101 
103  return moduleDescription_;
104  }
105 
106  //Output modules always need writeRun and writeLumi to be called
107  bool wantsGlobalRuns() const {return true;}
108  bool wantsGlobalLuminosityBlocks() const {return true;}
109 
110  virtual bool wantsStreamRuns() const =0;
111  virtual bool wantsStreamLuminosityBlocks() const =0;
112 
113  protected:
114 
115  ModuleDescription const& description() const;
116 
117  ParameterSetID selectorConfig() const { return selector_config_id_; }
118 
119  void doPreallocate(PreallocationConfiguration const&);
120 
121  void doBeginJob();
122  void doEndJob();
123 
124  void doBeginStream(StreamID id);
125  void doEndStream(StreamID id);
126  void doStreamBeginRun(StreamID id,
127  RunPrincipal& ep,
128  EventSetup const& c,
129  ModuleCallingContext const*);
130  void doStreamEndRun(StreamID id,
131  RunPrincipal& ep,
132  EventSetup const& c,
133  ModuleCallingContext const*);
134  void doStreamBeginLuminosityBlock(StreamID id,
136  EventSetup const& c,
137  ModuleCallingContext const*);
138  void doStreamEndLuminosityBlock(StreamID id,
140  EventSetup const& c,
141  ModuleCallingContext const*);
142 
143  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
145  ModuleCallingContext const*);
146  //For now this is a placeholder
147  /*virtual*/ void preActionBeforeRunEventAsync(WaitingTask* iTask, ModuleCallingContext const& iModuleCallingContext, Principal const& iPrincipal) const {}
148 
149  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
150  ModuleCallingContext const*);
151  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
152  ModuleCallingContext const*);
153  bool doBeginLuminosityBlock(LuminosityBlockPrincipal const& lbp, EventSetup const& c,
154  ModuleCallingContext const*);
155  bool doEndLuminosityBlock(LuminosityBlockPrincipal const& lbp, EventSetup const& c,
156  ModuleCallingContext const*);
157 
158  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
159  bool anyProductProduced);
160 
161  void configure(OutputModuleDescription const& desc);
162 
163  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
164  return droppedBranchIDToKeptBranchID_;
165  }
166 
167  private:
168 
170  std::atomic<int> remainingEvents_;
171 
172  // TODO: Give OutputModule
173  // an interface (protected?) that supplies client code with the
174  // needed functionality *without* giving away implementation
175  // details ... don't just return a reference to keptProducts_, because
176  // we are looking to have the flexibility to change the
177  // implementation of keptProducts_ without modifying clients. When this
178  // change is made, we'll have a one-time-only task of modifying
179  // clients (classes derived from OutputModule) to use the
180  // newly-introduced interface.
181  // TODO: Consider using shared pointers here?
182 
183  // keptProducts_ are pointers to the BranchDescription objects describing
184  // the branches we are to write.
185  //
186  // We do not own the BranchDescriptions to which we point.
188  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
189 
194 
196  std::vector<detail::TriggerResultsBasedEventSelector> selectors_;
198  // ID of the ParameterSet that configured the event selector
199  // subsystem.
201 
202  // needed because of possible EDAliases.
203  // filled in only if key and value are different.
204  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
207 
209  std::map<BranchID, bool> keepAssociation_;
210 
211  //------------------------------------------------------------------
212  // private member functions
213  //------------------------------------------------------------------
214 
215  void updateBranchIDListsWithKeptAliases();
216 
217  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const*, MergeableRunProductMetadata const*);
218  void doWriteLuminosityBlock(LuminosityBlockPrincipal const& lbp, ModuleCallingContext const*);
219  void doOpenFile(FileBlock const& fb);
220  void doRespondToOpenInputFile(FileBlock const& fb);
221  void doRespondToCloseInputFile(FileBlock const& fb);
224 
225  std::string workerType() const {return "WorkerT<edm::global::OutputModuleBase>";}
226 
228  void doCloseFile();
229 
231 
232  bool needToRunSelection() const;
233  std::vector<ProductResolverIndexAndSkipBit> productsUsedBySelection() const;
234  bool prePrefetchSelection(StreamID id, EventPrincipal const&, ModuleCallingContext const*);
235 
236  // Do the end-of-file tasks; this is only called internally, after
237  // the appropriate tests have been done.
238  virtual void reallyCloseFile();
239 
240 
242  virtual bool shouldWeCloseFile() const {return false;}
243 
244  virtual void write(EventForOutput const&) = 0;
245  virtual void beginJob(){}
246  virtual void endJob(){}
247  virtual void writeLuminosityBlock(LuminosityBlockForOutput const&) = 0;
248  virtual void writeRun(RunForOutput const&) = 0;
249  virtual void openFile(FileBlock const&) {}
250  virtual bool isFileOpen() const { return true; }
251 
252  virtual void preallocStreams(unsigned int){}
253  virtual void preallocLumis(unsigned int){}
255  virtual void doBeginStream_(StreamID){}
256  virtual void doEndStream_(StreamID){}
257  virtual void doStreamBeginRun_(StreamID, RunForOutput const&, EventSetup const&){}
258  virtual void doStreamEndRun_(StreamID, RunForOutput const&, EventSetup const&){}
259  virtual void doStreamEndRunSummary_(StreamID, RunForOutput const&, EventSetup const&){}
263 
264  virtual void doBeginRun_(RunForOutput const&){}
265  virtual void doBeginRunSummary_(RunForOutput const&, EventSetup const&){}
266  virtual void doEndRun_(RunForOutput const& ){}
267  virtual void doEndRunSummary_(RunForOutput const&, EventSetup const&){}
272  virtual void doRespondToOpenInputFile_(FileBlock const&) {}
273  virtual void doRespondToCloseInputFile_(FileBlock const&) {}
274 
275  virtual void setProcessesWithSelectedMergeableRunProducts(std::set<std::string> const&) {}
276 
277  bool hasAcquire() const { return false; }
278  bool hasAccumulator() const { return false; }
279 
280  void keepThisBranch(BranchDescription const& desc,
281  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
282  std::set<BranchID>& keptProductsInEvent);
283 
285  moduleDescription_ = md;
286  }
287 
288  bool limitReached() const {return remainingEvents_ == 0;}
289  };
290  }
291 }
292 #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 &)
def write(self, setup)
virtual void doBeginRunSummary_(RunForOutput const &, EventSetup const &)
virtual void doBeginLuminosityBlockSummary_(LuminosityBlockForOutput const &, EventSetup const &)
virtual void doStreamBeginLuminosityBlock_(StreamID, LuminosityBlockForOutput const &, EventSetup const &)