CMS 3D CMS Logo

OutputModuleBase.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_one_OutputModuleBase_h
2 #define FWCore_Framework_one_OutputModuleBase_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Framework
6 // Class : OutputModuleBase
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Wed, 31 Jul 2013 15:37:16 GMT
19 //
20 
21 // system include files
22 #include <array>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 #include <map>
27 #include <atomic>
28 #include <set>
29 
30 // user include files
35 
45 
46 // forward declarations
47 namespace edm {
48 
49  class MergeableRunProductMetadata;
50  class ModuleCallingContext;
51  class PreallocationConfiguration;
52  class ActivityRegistry;
53  class ProductRegistry;
54  class ThinnedAssociationsHelper;
55  class SubProcessParentageHelper;
56  class WaitingTask;
57 
58  template <typename T>
59  class OutputModuleCommunicatorT;
60 
61  namespace maker {
62  template <typename T>
63  class ModuleHolderT;
64  }
65 
66  namespace one {
67 
69  public:
70  template <typename U>
72  template <typename T>
73  friend class ::edm::WorkerT;
74  template <typename T>
75  friend class ::edm::OutputModuleCommunicatorT;
77 
78  explicit OutputModuleBase(ParameterSet const& pset);
79  ~OutputModuleBase() override;
80 
81  OutputModuleBase(OutputModuleBase const&) = delete; // Disallow copying and moving
82  OutputModuleBase& operator=(OutputModuleBase const&) = delete; // Disallow copying and moving
83 
86  int maxEvents() const { return maxEvents_; }
87 
90  int remainingEvents() const { return remainingEvents_; }
91 
92  bool selected(BranchDescription const& desc) const;
93 
94  void selectProducts(ProductRegistry const& preg, ThinnedAssociationsHelper const&);
95  std::string const& processName() const { return process_name_; }
96  SelectedProductsForBranchType const& keptProducts() const { return keptProducts_; }
97  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const { return hasNewlyDroppedBranch_; }
98 
99  static void fillDescription(ParameterSetDescription& desc);
100  static void fillDescriptions(ConfigurationDescriptions& descriptions);
101  static const std::string& baseType();
102  static void prevalidate(ConfigurationDescriptions&);
103 
104  //Output modules always need writeRun and writeLumi to be called
105  virtual bool wantsGlobalRuns() const = 0;
106  virtual bool wantsGlobalLuminosityBlocks() const = 0;
107  bool wantsStreamRuns() const { return false; }
108  bool wantsStreamLuminosityBlocks() const { return false; };
109 
110  virtual SerialTaskQueue* globalRunsQueue() { return nullptr; }
111  virtual SerialTaskQueue* globalLuminosityBlocksQueue() { return nullptr; }
112  SharedResourcesAcquirer& sharedResourcesAcquirer() { return resourcesAcquirer_; }
113 
114  bool wantAllEvents() const { return wantAllEvents_; }
115 
116  BranchIDLists const* branchIDLists();
117 
118  ThinnedAssociationsHelper const* thinnedAssociationsHelper() const;
119 
120  SubProcessParentageHelper const* subProcessParentageHelper() const { return subProcessParentageHelper_; }
121 
122  const ModuleDescription& moduleDescription() const { return moduleDescription_; }
123 
124  protected:
125  ModuleDescription const& description() const;
126 
127  ParameterSetID selectorConfig() const { return selector_config_id_; }
128 
129  void doPreallocate(PreallocationConfiguration const&);
130  virtual void preallocLumis(unsigned int);
131 
132  void doBeginJob();
133  void doEndJob();
134  bool doEvent(EventPrincipal const& ep, EventSetupImpl const& c, ActivityRegistry*, ModuleCallingContext const*);
135  bool doBeginRun(RunPrincipal const& rp, EventSetupImpl const& c, ModuleCallingContext const*);
136  bool doEndRun(RunPrincipal const& rp, EventSetupImpl const& c, ModuleCallingContext const*);
137  bool doBeginLuminosityBlock(LuminosityBlockPrincipal const& lbp,
138  EventSetupImpl const& c,
139  ModuleCallingContext const*);
140  bool doEndLuminosityBlock(LuminosityBlockPrincipal const& lbp,
141  EventSetupImpl const& c,
142  ModuleCallingContext const*);
143 
144  void setEventSelectionInfo(
145  std::map<std::string, std::vector<std::pair<std::string, int>>> const& outputModulePathPositions,
146  bool anyProductProduced);
147 
148  void configure(OutputModuleDescription const& desc);
149 
150  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
151  return droppedBranchIDToKeptBranchID_;
152  }
153 
154  private:
156  std::atomic<int> remainingEvents_;
157 
158  // TODO: Give OutputModule
159  // an interface (protected?) that supplies client code with the
160  // needed functionality *without* giving away implementation
161  // details ... don't just return a reference to keptProducts_, because
162  // we are looking to have the flexibility to change the
163  // implementation of keptProducts_ without modifying clients. When this
164  // change is made, we'll have a one-time-only task of modifying
165  // clients (classes derived from OutputModule) to use the
166  // newly-introduced interface.
167  // TODO: Consider using shared pointers here?
168 
169  // keptProducts_ are pointers to the BranchDescription objects describing
170  // the branches we are to write.
171  //
172  // We do not own the BranchDescriptions to which we point.
174  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
175 
180 
182  std::vector<detail::TriggerResultsBasedEventSelector> selectors_;
184  // ID of the ParameterSet that configured the event selector
185  // subsystem.
187 
188  // needed because of possible EDAliases.
189  // filled in only if key and value are different.
190  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
193 
195 
197  std::map<BranchID, bool> keepAssociation_;
198 
202 
203  //------------------------------------------------------------------
204  // private member functions
205  //------------------------------------------------------------------
206 
207  virtual SharedResourcesAcquirer createAcquirer();
208 
209  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const*, MergeableRunProductMetadata const*);
210  void doWriteLuminosityBlock(LuminosityBlockPrincipal const& lbp, ModuleCallingContext const*);
211  void doOpenFile(FileBlock const& fb);
212  void doRespondToOpenInputFile(FileBlock const& fb);
213  void doRespondToCloseInputFile(FileBlock const& fb);
215 
216  std::string workerType() const { return "WorkerT<edm::one::OutputModuleBase>"; }
217 
219  void doCloseFile();
220 
222 
223  bool needToRunSelection() const;
224  std::vector<ProductResolverIndexAndSkipBit> productsUsedBySelection() const;
225  bool prePrefetchSelection(StreamID id, EventPrincipal const&, ModuleCallingContext const*);
226 
227  // Do the end-of-file tasks; this is only called internally, after
228  // the appropriate tests have been done.
229  virtual void reallyCloseFile();
230 
232  virtual bool shouldWeCloseFile() const { return false; }
233 
234  virtual void write(EventForOutput const&) = 0;
236  ModuleCallingContext const& iModuleCallingContext,
237  Principal const& iPrincipal) const {}
238 
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 doBeginRun_(RunForOutput const&) {}
247  virtual void doEndRun_(RunForOutput const&) {}
250  virtual void doRespondToOpenInputFile_(FileBlock const&) {}
251  virtual void doRespondToCloseInputFile_(FileBlock const&) {}
252 
253  virtual void setProcessesWithSelectedMergeableRunProducts(std::set<std::string> const&) {}
254 
255  bool hasAcquire() const { return false; }
256  bool hasAccumulator() const { return false; }
257 
258  void keepThisBranch(BranchDescription const& desc,
259  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
260  std::set<BranchID>& keptProductsInEvent);
261 
262  void setModuleDescription(ModuleDescription const& md) { moduleDescription_ = md; }
263 
264  bool limitReached() const { return remainingEvents_ == 0; }
265  };
266  } // namespace one
267 } // namespace edm
268 #endif
SubProcessParentageHelper const * subProcessParentageHelper() const
SharedResourcesAcquirer & sharedResourcesAcquirer()
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
SelectedProductsForBranchType keptProducts_
ModuleDescription moduleDescription_
std::array< SelectedProducts, NumBranchTypes > SelectedProductsForBranchType
SubProcessParentageHelper const * subProcessParentageHelper_
virtual void preActionBeforeRunEventAsync(WaitingTask *iTask, ModuleCallingContext const &iModuleCallingContext, Principal const &iPrincipal) const
void registerProductsAndCallbacks(OutputModuleBase const *, ProductRegistry const *)
SerialTaskQueue luminosityBlockQueue_
ParameterSetID selectorConfig() const
virtual void doBeginLuminosityBlock_(LuminosityBlockForOutput const &)
ProductSelectorRules productSelectorRules_
virtual SerialTaskQueue * globalLuminosityBlocksQueue()
virtual void doRespondToCloseInputFile_(FileBlock const &)
virtual void doRespondToOpenInputFile_(FileBlock const &)
virtual void openFile(FileBlock const &)
virtual void doEndRun_(RunForOutput const &)
std::atomic< int > remainingEvents_
bool wantsStreamLuminosityBlocks() const
std::map< BranchID::value_type, BranchID::value_type > const & droppedBranchIDToKeptBranchID()
SelectedProductsForBranchType const & keptProducts() const
std::string workerType() const
edm::propagate_const< std::unique_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
SharedResourcesAcquirer resourcesAcquirer_
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
std::vector< detail::TriggerResultsBasedEventSelector > selectors_
void setModuleDescription(ModuleDescription const &md)
const ModuleDescription & moduleDescription() const
virtual SerialTaskQueue * globalRunsQueue()
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void doEndLuminosityBlock_(LuminosityBlockForOutput const &)
void doRegisterThinnedAssociations(ProductRegistry const &, ThinnedAssociationsHelper &)
std::string const & processName() const
virtual void doBeginRun_(RunForOutput const &)
HLT enums.
BranchIDLists const * origBranchIDLists_
virtual void setProcessesWithSelectedMergeableRunProducts(std::set< std::string > const &)
virtual bool shouldWeCloseFile() const
Ask the OutputModule if we should end the current file.
def write(self, setup)
virtual bool isFileOpen() const
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
ProductSelector productSelector_
ParameterSetID selector_config_id_
edm::propagate_const< std::unique_ptr< BranchIDLists > > branchIDLists_
std::map< BranchID, bool > keepAssociation_