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> class OutputModuleCommunicatorT;
59 
60  namespace maker {
61  template<typename T> class ModuleHolderT;
62  }
63 
64  namespace one {
65 
67  public:
68  template <typename U> friend class edm::maker::ModuleHolderT;
69  template <typename T> friend class ::edm::WorkerT;
70  template <typename T> friend class ::edm::OutputModuleCommunicatorT;
72 
73  explicit OutputModuleBase(ParameterSet const& pset);
74  ~OutputModuleBase() override;
75 
76  OutputModuleBase(OutputModuleBase const&) = delete; // Disallow copying and moving
77  OutputModuleBase& operator=(OutputModuleBase const&) = delete; // Disallow copying and moving
78 
81  int maxEvents() const {return maxEvents_;}
82 
85  int remainingEvents() const {return remainingEvents_;}
86 
87  bool selected(BranchDescription const& desc) const;
88 
89  void selectProducts(ProductRegistry const& preg, ThinnedAssociationsHelper const&);
90  std::string const& processName() const {return process_name_;}
91  SelectedProductsForBranchType const& keptProducts() const {return keptProducts_;}
92  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
93 
94  static void fillDescription(ParameterSetDescription & desc);
95  static void fillDescriptions(ConfigurationDescriptions& descriptions);
96  static const std::string& baseType();
97  static void prevalidate(ConfigurationDescriptions& );
98 
99  //Output modules always need writeRun and writeLumi to be called
100  virtual bool wantsGlobalRuns() const = 0;
101  virtual bool wantsGlobalLuminosityBlocks() const = 0;
102  bool wantsStreamRuns() const {return false;}
103  bool wantsStreamLuminosityBlocks() const {return false;};
104 
105  SerialTaskQueue* globalRunsQueue() { return &runQueue_;}
106  SerialTaskQueue* globalLuminosityBlocksQueue() { return &luminosityBlockQueue_;}
108  return resourcesAcquirer_;
109  }
110 
111  bool wantAllEvents() const {return wantAllEvents_;}
112 
113  BranchIDLists const* branchIDLists();
114 
115  ThinnedAssociationsHelper const* thinnedAssociationsHelper() const;
116 
118  return subProcessParentageHelper_;
119  }
120 
122  return moduleDescription_;
123  }
124  protected:
125 
126  ModuleDescription const& description() const;
127 
128  ParameterSetID selectorConfig() const { return selector_config_id_; }
129 
130  void doPreallocate(PreallocationConfiguration const&);
131 
132  void doBeginJob();
133  void doEndJob();
134  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
136  ModuleCallingContext const*);
137  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
138  ModuleCallingContext const*);
139  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
140  ModuleCallingContext const*);
141  bool doBeginLuminosityBlock(LuminosityBlockPrincipal const& lbp, EventSetup const& c,
142  ModuleCallingContext const*);
143  bool doEndLuminosityBlock(LuminosityBlockPrincipal const& lbp, EventSetup const& c,
144  ModuleCallingContext const*);
145 
146  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
147  bool anyProductProduced);
148 
149  void configure(OutputModuleDescription const& desc);
150 
151  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
152  return droppedBranchIDToKeptBranchID_;
153  }
154 
155  private:
156 
158  std::atomic<int> remainingEvents_;
159 
160  // TODO: Give OutputModule
161  // an interface (protected?) that supplies client code with the
162  // needed functionality *without* giving away implementation
163  // details ... don't just return a reference to keptProducts_, because
164  // we are looking to have the flexibility to change the
165  // implementation of keptProducts_ without modifying clients. When this
166  // change is made, we'll have a one-time-only task of modifying
167  // clients (classes derived from OutputModule) to use the
168  // newly-introduced interface.
169  // TODO: Consider using shared pointers here?
170 
171  // keptProducts_ are pointers to the BranchDescription objects describing
172  // the branches we are to write.
173  //
174  // We do not own the BranchDescriptions to which we point.
176  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
177 
182 
184  std::vector<detail::TriggerResultsBasedEventSelector> selectors_;
186  // ID of the ParameterSet that configured the event selector
187  // subsystem.
189 
190  // needed because of possible EDAliases.
191  // filled in only if key and value are different.
192  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
195 
197 
199  std::map<BranchID, bool> keepAssociation_;
200 
204 
205  //------------------------------------------------------------------
206  // private member functions
207  //------------------------------------------------------------------
208 
209  virtual SharedResourcesAcquirer createAcquirer();
210 
211  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const*, MergeableRunProductMetadata const*);
212  void doWriteLuminosityBlock(LuminosityBlockPrincipal const& lbp, ModuleCallingContext const*);
213  void doOpenFile(FileBlock const& fb);
214  void doRespondToOpenInputFile(FileBlock const& fb);
215  void doRespondToCloseInputFile(FileBlock const& fb);
218 
219  std::string workerType() const {return "WorkerT<edm::one::OutputModuleBase>";}
220 
222  void doCloseFile();
223 
225 
226  bool needToRunSelection() const;
227  std::vector<ProductResolverIndexAndSkipBit> productsUsedBySelection() const;
228  bool prePrefetchSelection(StreamID id, EventPrincipal const&, ModuleCallingContext const*);
229 
230  // Do the end-of-file tasks; this is only called internally, after
231  // the appropriate tests have been done.
232  virtual void reallyCloseFile();
233 
234 
236  virtual bool shouldWeCloseFile() const {return false;}
237 
238  virtual void write(EventForOutput const&) = 0;
239  virtual void preActionBeforeRunEventAsync(WaitingTask* iTask, ModuleCallingContext const& iModuleCallingContext, Principal const& iPrincipal) const {}
240 
241  virtual void beginJob(){}
242  virtual void endJob(){}
243  virtual void writeLuminosityBlock(LuminosityBlockForOutput const&) = 0;
244  virtual void writeRun(RunForOutput const&) = 0;
245  virtual void openFile(FileBlock const&) {}
246  virtual bool isFileOpen() const { return true; }
247 
248  virtual void doBeginRun_(RunForOutput const&){}
249  virtual void doEndRun_(RunForOutput const& ){}
252  virtual void doRespondToOpenInputFile_(FileBlock const&) {}
253  virtual void doRespondToCloseInputFile_(FileBlock const&) {}
254 
255  virtual void setProcessesWithSelectedMergeableRunProducts(std::set<std::string> const&) {}
256 
257  bool hasAcquire() const { return false; }
258  bool hasAccumulator() const { return false; }
259 
260  void keepThisBranch(BranchDescription const& desc,
261  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
262  std::set<BranchID>& keptProductsInEvent);
263 
265  moduleDescription_ = md;
266  }
267 
268  bool limitReached() const {return remainingEvents_ == 0;}
269  };
270  }
271 }
272 #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 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
SerialTaskQueue * globalRunsQueue()
std::string workerType() const
edm::propagate_const< std::unique_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
SharedResourcesAcquirer resourcesAcquirer_
SerialTaskQueue * globalLuminosityBlocksQueue()
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
std::vector< detail::TriggerResultsBasedEventSelector > selectors_
void setModuleDescription(ModuleDescription const &md)
const ModuleDescription & moduleDescription() const
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_