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>
57  class OutputModuleCommunicatorT;
58 
59  namespace maker {
60  template <typename T>
61  class ModuleHolderT;
62  }
63 
64  namespace limited {
65 
67  public:
68  template <typename U>
70  template <typename T>
71  friend class ::edm::WorkerT;
72  template <typename T>
73  friend class ::edm::OutputModuleCommunicatorT;
75 
76  explicit OutputModuleBase(ParameterSet const& pset);
77  ~OutputModuleBase() override;
78 
79  OutputModuleBase(OutputModuleBase const&) = delete; // Disallow copying and moving
80  OutputModuleBase& operator=(OutputModuleBase const&) = delete; // Disallow copying and moving
81 
84  int maxEvents() const { return maxEvents_; }
85 
88  int remainingEvents() const { return remainingEvents_; }
89 
90  bool selected(BranchDescription const& desc) const;
91 
92  void selectProducts(ProductRegistry const& preg, ThinnedAssociationsHelper const&);
93  std::string const& processName() const { return process_name_; }
94  SelectedProductsForBranchType const& keptProducts() const { return keptProducts_; }
95  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const { return hasNewlyDroppedBranch_; }
96 
97  static void fillDescription(ParameterSetDescription& desc);
98  static void fillDescriptions(ConfigurationDescriptions& descriptions);
99  static const std::string& baseType();
100  static void prevalidate(ConfigurationDescriptions&);
101 
102  bool wantAllEvents() const { return wantAllEvents_; }
103 
104  BranchIDLists const* branchIDLists() const;
105 
106  ThinnedAssociationsHelper const* thinnedAssociationsHelper() const;
107 
108  const ModuleDescription& moduleDescription() const { return moduleDescription_; }
109 
110  //Output modules always need writeRun and writeLumi to be called
111  bool wantsGlobalRuns() const { return true; }
112  bool wantsGlobalLuminosityBlocks() const { return true; }
113  virtual bool wantsStreamRuns() const = 0;
114  virtual bool wantsStreamLuminosityBlocks() const = 0;
115 
116  unsigned int concurrencyLimit() const { return queue_.concurrencyLimit(); }
117 
118  LimitedTaskQueue& queue() { return queue_; }
119 
120  protected:
121  ModuleDescription const& description() const;
122 
123  ParameterSetID selectorConfig() const { return selector_config_id_; }
124 
125  void doPreallocate(PreallocationConfiguration const&);
126 
127  void doBeginJob();
128  void doEndJob();
129 
130  void doBeginStream(StreamID id);
131  void doEndStream(StreamID id);
132  void doStreamBeginRun(StreamID id, RunPrincipal& ep, EventSetupImpl const& c, ModuleCallingContext const*);
133  void doStreamEndRun(StreamID id, RunPrincipal& ep, EventSetupImpl const& c, ModuleCallingContext const*);
134  void doStreamBeginLuminosityBlock(StreamID id,
136  EventSetupImpl const& c,
137  ModuleCallingContext const*);
138  void doStreamEndLuminosityBlock(StreamID id,
140  EventSetupImpl const& c,
141  ModuleCallingContext const*);
142 
143  bool doEvent(EventPrincipal const& ep, EventSetupImpl const& c, ActivityRegistry*, ModuleCallingContext const*);
144  //For now this is a placeholder
145  /*virtual*/ void preActionBeforeRunEventAsync(WaitingTask* iTask,
146  ModuleCallingContext const& iModuleCallingContext,
147  Principal const& iPrincipal) const {}
148 
149  bool doBeginRun(RunPrincipal const& rp, EventSetupImpl const& c, ModuleCallingContext const*);
150  bool doEndRun(RunPrincipal const& rp, EventSetupImpl const& c, ModuleCallingContext const*);
151  bool doBeginLuminosityBlock(LuminosityBlockPrincipal const& lbp,
152  EventSetupImpl const& c,
153  ModuleCallingContext const*);
154  bool doEndLuminosityBlock(LuminosityBlockPrincipal const& lbp,
155  EventSetupImpl const& c,
156  ModuleCallingContext const*);
157 
158  void setEventSelectionInfo(
159  std::map<std::string, std::vector<std::pair<std::string, int>>> const& outputModulePathPositions,
160  bool anyProductProduced);
161 
162  void configure(OutputModuleDescription const& desc);
163 
164  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
165  return droppedBranchIDToKeptBranchID_;
166  }
167 
168  private:
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_;
211 
212  //------------------------------------------------------------------
213  // private member functions
214  //------------------------------------------------------------------
215 
216  void updateBranchIDListsWithKeptAliases();
217 
218  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const*, MergeableRunProductMetadata const*);
219  void doWriteLuminosityBlock(LuminosityBlockPrincipal const& lbp, ModuleCallingContext const*);
220  void doOpenFile(FileBlock const& fb);
221  void doRespondToOpenInputFile(FileBlock const& fb);
222  void doRespondToCloseInputFile(FileBlock const& fb);
224 
225  std::string workerType() const { return "WorkerT<edm::limited::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 
241  virtual bool shouldWeCloseFile() const { return false; }
242 
243  virtual void write(EventForOutput const&) = 0;
244  virtual void beginJob() {}
245  virtual void endJob() {}
246  virtual void writeLuminosityBlock(LuminosityBlockForOutput const&) = 0;
247  virtual void writeRun(RunForOutput const&) = 0;
248  virtual void openFile(FileBlock const&) const {}
249  virtual bool isFileOpen() const { return true; }
250 
251  virtual void preallocStreams(unsigned int) {}
252  virtual void preallocLumis(unsigned int) {}
253  virtual void preallocate(PreallocationConfiguration const&) {}
254  virtual void doBeginStream_(StreamID) {}
255  virtual void doEndStream_(StreamID) {}
256  virtual void doStreamBeginRun_(StreamID, RunForOutput const&, EventSetup const&) {}
257  virtual void doStreamEndRun_(StreamID, RunForOutput const&, EventSetup const&) {}
258  virtual void doStreamEndRunSummary_(StreamID, RunForOutput const&, EventSetup const&) {}
262 
263  virtual void doBeginRun_(RunForOutput const&) {}
264  virtual void doBeginRunSummary_(RunForOutput const&, EventSetup const&) {}
265  virtual void doEndRun_(RunForOutput const&) {}
266  virtual void doEndRunSummary_(RunForOutput const&, EventSetup const&) {}
271  virtual void doRespondToOpenInputFile_(FileBlock const&) {}
272  virtual void doRespondToCloseInputFile_(FileBlock const&) {}
273 
274  virtual void setProcessesWithSelectedMergeableRunProducts(std::set<std::string> const&) {}
275 
276  bool hasAcquire() const { return false; }
277  bool hasAccumulator() const { return false; }
278 
279  void keepThisBranch(BranchDescription const& desc,
280  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
281  std::set<BranchID>& keptProductsInEvent);
282 
283  void setModuleDescription(ModuleDescription const& md) { moduleDescription_ = md; }
284 
285  bool limitReached() const { return remainingEvents_ == 0; }
286  };
287  } // namespace limited
288 } // namespace edm
289 #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 *)