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