CMS 3D CMS Logo

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