CMS 3D CMS Logo

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