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  virtual ~OutputModuleBase();
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();
97 
98  ThinnedAssociationsHelper const* thinnedAssociationsHelper() const;
99 
101  return moduleDescription_;
102  }
103  protected:
104 
105  ModuleDescription const& description() const;
106 
107  ParameterSetID selectorConfig() const { return selector_config_id_; }
108 
109  void doPreallocate(PreallocationConfiguration const&);
110 
111  void doBeginJob();
112  void doEndJob();
113 
114  void doBeginStream(StreamID id);
115  void doEndStream(StreamID id);
116  void doStreamBeginRun(StreamID id,
117  RunPrincipal& ep,
118  EventSetup const& c,
119  ModuleCallingContext const*);
120  void doStreamEndRun(StreamID id,
121  RunPrincipal& ep,
122  EventSetup const& c,
123  ModuleCallingContext const*);
124  void doStreamBeginLuminosityBlock(StreamID id,
126  EventSetup const& c,
127  ModuleCallingContext const*);
128  void doStreamEndLuminosityBlock(StreamID id,
130  EventSetup const& c,
131  ModuleCallingContext const*);
132 
133  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
135  ModuleCallingContext const*);
136  //For now this is a placeholder
137  /*virtual*/ void preActionBeforeRunEventAsync(WaitingTask* iTask, ModuleCallingContext const& iModuleCallingContext, Principal const& iPrincipal) const {}
138 
139  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
140  ModuleCallingContext const*);
141  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
142  ModuleCallingContext const*);
143  bool doBeginLuminosityBlock(LuminosityBlockPrincipal const& lbp, EventSetup const& c,
144  ModuleCallingContext const*);
145  bool doEndLuminosityBlock(LuminosityBlockPrincipal const& lbp, EventSetup const& c,
146  ModuleCallingContext const*);
147 
148  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
149  bool anyProductProduced);
150 
151  void configure(OutputModuleDescription const& desc);
152 
153  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
154  return droppedBranchIDToKeptBranchID_;
155  }
156 
157  private:
158 
160  std::atomic<int> remainingEvents_;
161 
162  // TODO: Give OutputModule
163  // an interface (protected?) that supplies client code with the
164  // needed functionality *without* giving away implementation
165  // details ... don't just return a reference to keptProducts_, because
166  // we are looking to have the flexibility to change the
167  // implementation of keptProducts_ without modifying clients. When this
168  // change is made, we'll have a one-time-only task of modifying
169  // clients (classes derived from OutputModule) to use the
170  // newly-introduced interface.
171  // TODO: Consider using shared pointers here?
172 
173  // keptProducts_ are pointers to the BranchDescription objects describing
174  // the branches we are to write.
175  //
176  // We do not own the BranchDescriptions to which we point.
178  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
179 
184 
186  std::vector<detail::TriggerResultsBasedEventSelector> selectors_;
188  // ID of the ParameterSet that configured the event selector
189  // subsystem.
191 
192  // needed because of possible EDAliases.
193  // filled in only if key and value are different.
194  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
197 
199  std::map<BranchID, bool> keepAssociation_;
200 
201  //------------------------------------------------------------------
202  // private member functions
203  //------------------------------------------------------------------
204 
205  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const*);
206  void doWriteLuminosityBlock(LuminosityBlockPrincipal const& lbp, ModuleCallingContext const*);
207  void doOpenFile(FileBlock const& fb);
208  void doRespondToOpenInputFile(FileBlock const& fb);
209  void doRespondToCloseInputFile(FileBlock const& fb);
212 
213  std::string workerType() const {return "WorkerT<edm::global::OutputModuleBase>";}
214 
216  void doCloseFile();
217 
219 
220  bool prePrefetchSelection(StreamID id, EventPrincipal const&, ModuleCallingContext const*);
221 
222  // Do the end-of-file tasks; this is only called internally, after
223  // the appropriate tests have been done.
224  virtual void reallyCloseFile();
225 
226 
228  virtual bool shouldWeCloseFile() const {return false;}
229 
230  virtual void write(EventForOutput const&) = 0;
231  virtual void beginJob(){}
232  virtual void endJob(){}
233  virtual void writeLuminosityBlock(LuminosityBlockForOutput const&) = 0;
234  virtual void writeRun(RunForOutput const&) = 0;
235  virtual void openFile(FileBlock const&) {}
236  virtual bool isFileOpen() const { return true; }
237 
238  virtual void preallocStreams(unsigned int){}
239  virtual void doBeginStream_(StreamID){}
240  virtual void doEndStream_(StreamID){}
241  virtual void doStreamBeginRun_(StreamID, RunForOutput const&, EventSetup const&){}
242  virtual void doStreamEndRun_(StreamID, RunForOutput const&, EventSetup const&){}
243  virtual void doStreamEndRunSummary_(StreamID, RunForOutput const&, EventSetup const&){}
247 
248  virtual void doBeginRun_(RunForOutput const&){}
249  virtual void doBeginRunSummary_(RunForOutput const&, EventSetup const&){}
250  virtual void doEndRun_(RunForOutput const& ){}
251  virtual void doEndRunSummary_(RunForOutput const&, EventSetup const&){}
256  virtual void doRespondToOpenInputFile_(FileBlock const&) {}
257  virtual void doRespondToCloseInputFile_(FileBlock const&) {}
258 
259  void keepThisBranch(BranchDescription const& desc,
260  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
261  std::set<BranchID>& keptProductsInEvent);
262 
264  moduleDescription_ = md;
265  }
266 
267  bool limitReached() const {return remainingEvents_ == 0;}
268  };
269  }
270 }
271 #endif
virtual void doEndRunSummary_(RunForOutput const &, EventSetup 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 &)