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();
98 
99  ThinnedAssociationsHelper const* thinnedAssociationsHelper() const;
100 
102  return moduleDescription_;
103  }
104 
105  unsigned int concurrencyLimit() const { return queue_.concurrencyLimit(); }
106 
108  return queue_;
109  }
110  protected:
111 
112  ModuleDescription const& description() const;
113 
114  ParameterSetID selectorConfig() const { return selector_config_id_; }
115 
116  void doPreallocate(PreallocationConfiguration const&);
117 
118  void doBeginJob();
119  void doEndJob();
120 
121  void doBeginStream(StreamID id);
122  void doEndStream(StreamID id);
123  void doStreamBeginRun(StreamID id,
124  RunPrincipal& ep,
125  EventSetup const& c,
126  ModuleCallingContext const*);
127  void doStreamEndRun(StreamID id,
128  RunPrincipal& ep,
129  EventSetup const& c,
130  ModuleCallingContext const*);
131  void doStreamBeginLuminosityBlock(StreamID id,
133  EventSetup const& c,
134  ModuleCallingContext const*);
135  void doStreamEndLuminosityBlock(StreamID id,
137  EventSetup const& c,
138  ModuleCallingContext const*);
139 
140  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
142  ModuleCallingContext const*);
143  //For now this is a placeholder
144  /*virtual*/ void preActionBeforeRunEventAsync(WaitingTask* iTask, ModuleCallingContext const& iModuleCallingContext, Principal const& iPrincipal) const {}
145 
146  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
147  ModuleCallingContext const*);
148  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
149  ModuleCallingContext const*);
150  bool doBeginLuminosityBlock(LuminosityBlockPrincipal const& lbp, EventSetup const& c,
151  ModuleCallingContext const*);
152  bool doEndLuminosityBlock(LuminosityBlockPrincipal const& lbp, EventSetup const& c,
153  ModuleCallingContext const*);
154 
155  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
156  bool anyProductProduced);
157 
158  void configure(OutputModuleDescription const& desc);
159 
160  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
161  return droppedBranchIDToKeptBranchID_;
162  }
163 
164  private:
165 
167  std::atomic<int> remainingEvents_;
168 
169  // TODO: Give OutputModule
170  // an interface (protected?) that supplies client code with the
171  // needed functionality *without* giving away implementation
172  // details ... don't just return a reference to keptProducts_, because
173  // we are looking to have the flexibility to change the
174  // implementation of keptProducts_ without modifying clients. When this
175  // change is made, we'll have a one-time-only task of modifying
176  // clients (classes derived from OutputModule) to use the
177  // newly-introduced interface.
178  // TODO: Consider using shared pointers here?
179 
180  // keptProducts_ are pointers to the BranchDescription objects describing
181  // the branches we are to write.
182  //
183  // We do not own the BranchDescriptions to which we point.
185  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
186 
191 
193  std::vector<detail::TriggerResultsBasedEventSelector> selectors_;
195  // ID of the ParameterSet that configured the event selector
196  // subsystem.
198 
199  // needed because of possible EDAliases.
200  // filled in only if key and value are different.
201  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
204 
206  std::map<BranchID, bool> keepAssociation_;
208 
209  //------------------------------------------------------------------
210  // private member functions
211  //------------------------------------------------------------------
212 
213  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const*);
214  void doWriteLuminosityBlock(LuminosityBlockPrincipal const& lbp, ModuleCallingContext const*);
215  void doOpenFile(FileBlock const& fb);
216  void doRespondToOpenInputFile(FileBlock const& fb);
217  void doRespondToCloseInputFile(FileBlock const& fb);
220 
221  std::string workerType() const {return "WorkerT<edm::limited::OutputModuleBase>";}
222 
224  void doCloseFile();
225 
227 
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 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&) const {}
244  virtual bool isFileOpen() const { return true; }
245 
246  virtual void preallocStreams(unsigned int){}
247  virtual void doBeginStream_(StreamID){}
248  virtual void doEndStream_(StreamID){}
249  virtual void doStreamBeginRun_(StreamID, RunForOutput const&, EventSetup const&){}
250  virtual void doStreamEndRun_(StreamID, RunForOutput const&, EventSetup const&){}
251  virtual void doStreamEndRunSummary_(StreamID, RunForOutput const&, EventSetup const&){}
255 
256  virtual void doBeginRun_(RunForOutput const&){}
257  virtual void doBeginRunSummary_(RunForOutput const&, EventSetup const&){}
258  virtual void doEndRun_(RunForOutput const& ){}
259  virtual void doEndRunSummary_(RunForOutput const&, EventSetup const&){}
264  virtual void doRespondToOpenInputFile_(FileBlock const&) {}
265  virtual void doRespondToCloseInputFile_(FileBlock const&) {}
266 
267  void keepThisBranch(BranchDescription const& desc,
268  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
269  std::set<BranchID>& keptProductsInEvent);
270 
272  moduleDescription_ = md;
273  }
274 
275  bool limitReached() const {return remainingEvents_ == 0;}
276  };
277  }
278 }
279 #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 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_
std::map< BranchID::value_type, BranchID::value_type > const & droppedBranchIDToKeptBranchID()
SelectedProductsForBranchType keptProducts_
def write(self, setup)
void registerProductsAndCallbacks(OutputModuleBase const *, ProductRegistry const *)