CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <string>
24 #include <vector>
25 #include <map>
26 
27 
28 // user include files
35 
43 
44 // forward declarations
45 namespace edm {
46 
47  class ModuleCallingContext;
48  class PreallocationConfiguration;
49  template <typename T> class OutputModuleCommunicatorT;
50 
51  namespace maker {
52  template<typename T> class ModuleHolderT;
53  }
54 
55  namespace one {
56 
58 
60  public:
61  template <typename U> friend class edm::maker::ModuleHolderT;
62  template <typename T> friend class ::edm::WorkerT;
63  template <typename T> friend class ::edm::OutputModuleCommunicatorT;
65 
66  explicit OutputModuleBase(ParameterSet const& pset);
67  virtual ~OutputModuleBase();
68 
69  OutputModuleBase(OutputModuleBase const&) = delete; // Disallow copying and moving
70  OutputModuleBase& operator=(OutputModuleBase const&) = delete; // Disallow copying and moving
71 
74  int maxEvents() const {return maxEvents_;}
75 
78  int remainingEvents() const {return remainingEvents_;}
79 
80  bool selected(BranchDescription const& desc) const;
81 
82  void selectProducts(ProductRegistry const& preg);
83  std::string const& processName() const {return process_name_;}
85  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
86 
87  static void fillDescription(ParameterSetDescription & desc);
88  static void fillDescriptions(ConfigurationDescriptions& descriptions);
89  static const std::string& baseType();
91 
93 
94  bool wantAllEvents() const {return wantAllEvents_;}
95 
96  BranchIDLists const* branchIDLists() const;
97 
99  return moduleDescription_;
100  }
101  protected:
102 
104 
105  ModuleDescription const& description() const;
106 
108 
110 
111  void doBeginJob();
112  void doEndJob();
113  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
114  ModuleCallingContext const*);
115  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
116  ModuleCallingContext const*);
117  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
118  ModuleCallingContext const*);
120  ModuleCallingContext const*);
122  ModuleCallingContext const*);
123 
124  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
125  bool anyProductProduced);
126 
127  void configure(OutputModuleDescription const& desc);
128 
129  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
131  }
132 
133  private:
134 
137 
138  // TODO: Give OutputModule
139  // an interface (protected?) that supplies client code with the
140  // needed functionality *without* giving away implementation
141  // details ... don't just return a reference to keptProducts_, because
142  // we are looking to have the flexibility to change the
143  // implementation of keptProducts_ without modifying clients. When this
144  // change is made, we'll have a one-time-only task of modifying
145  // clients (classes derived from OutputModule) to use the
146  // newly-introduced interface.
147  // TODO: Consider using shared pointers here?
148 
149  // keptProducts_ are pointers to the BranchDescription objects describing
150  // the branches we are to write.
151  //
152  // We do not own the BranchDescriptions to which we point.
154  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
155 
160 
163  // ID of the ParameterSet that configured the event selector
164  // subsystem.
166 
167  // needed because of possible EDAliases.
168  // filled in only if key and value are different.
169  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
170  std::unique_ptr<BranchIDLists> branchIDLists_;
172 
173  typedef std::map<BranchID, std::set<ParentageID> > BranchParents;
175 
177 
178  //------------------------------------------------------------------
179  // private member functions
180  //------------------------------------------------------------------
181  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const*);
183  void doOpenFile(FileBlock const& fb);
187  void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren);
188 
189  std::string workerType() const {return "WorkerT<edm::one::OutputModuleBase>";}
190 
192  void doCloseFile();
193 
196  void maybeOpenFile();
197 
199 
200 
201  // Do the end-of-file tasks; this is only called internally, after
202  // the appropriate tests have been done.
203  virtual void reallyCloseFile();
204 
205 
207  virtual bool shouldWeCloseFile() const {return false;}
208 
209  virtual void write(EventPrincipal const& e, ModuleCallingContext const*) = 0;
210  virtual void beginJob(){}
211  virtual void endJob(){}
212  virtual void writeLuminosityBlock(LuminosityBlockPrincipal const&, ModuleCallingContext const*) = 0;
213  virtual void writeRun(RunPrincipal const&, ModuleCallingContext const*) = 0;
214  virtual void openFile(FileBlock const&) {}
215  virtual bool isFileOpen() const { return true; }
216  virtual void reallyOpenFile() {}
217 
218  virtual void preForkReleaseResources();
219  virtual void postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/);
220 
221  virtual void doBeginRun_(RunPrincipal const&, ModuleCallingContext const*){}
222  virtual void doEndRun_(RunPrincipal const&, ModuleCallingContext const*){}
225  virtual void doRespondToOpenInputFile_(FileBlock const&) {}
226  virtual void doRespondToCloseInputFile_(FileBlock const&) {}
227 
229  moduleDescription_ = md;
230  }
231 
232  void updateBranchParents(EventPrincipal const& ep);
233  void fillDependencyGraph();
234 
235  bool limitReached() const {return remainingEvents_ == 0;}
236  };
237  }
238 }
239 #endif
BranchIDLists const * branchIDLists() const
std::unique_ptr< BranchIDLists > branchIDLists_
ModuleDescription const & description() const
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
SelectedProductsForBranchType keptProducts_
void doWriteLuminosityBlock(LuminosityBlockPrincipal const &lbp, ModuleCallingContext const *)
ModuleDescription moduleDescription_
void doWriteRun(RunPrincipal const &rp, ModuleCallingContext const *)
static void prevalidate(ConfigurationDescriptions &)
detail::TriggerResultsBasedEventSelector::handle_t Trig
void configure(OutputModuleDescription const &desc)
void registerProductsAndCallbacks(OutputModuleBase const *, ProductRegistry const *)
virtual void doEndRun_(RunPrincipal const &, ModuleCallingContext const *)
bool doBeginRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *)
void selectProducts(ProductRegistry const &preg)
ParameterSetID selectorConfig() const
ProductSelectorRules productSelectorRules_
virtual void doBeginRun_(RunPrincipal const &, ModuleCallingContext const *)
Trig getTriggerResults(EventPrincipal const &ep, ModuleCallingContext const *) const
virtual void doRespondToCloseInputFile_(FileBlock const &)
virtual void doRespondToOpenInputFile_(FileBlock const &)
bool doEvent(EventPrincipal const &ep, EventSetup const &c, ModuleCallingContext const *)
virtual void openFile(FileBlock const &)
bool selected(BranchDescription const &desc) const
std::map< BranchID::value_type, BranchID::value_type > const & droppedBranchIDToKeptBranchID()
void doPreallocate(PreallocationConfiguration const &)
void setEventSelectionInfo(std::map< std::string, std::vector< std::pair< std::string, int > > > const &outputModulePathPositions, bool anyProductProduced)
virtual void writeRun(RunPrincipal const &, ModuleCallingContext const *)=0
SelectedProductsForBranchType const & keptProducts() const
virtual void preForkReleaseResources()
std::string workerType() const
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
virtual void doBeginLuminosityBlock_(LuminosityBlockPrincipal const &, ModuleCallingContext const *)
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
OutputModuleBase(ParameterSet const &pset)
virtual void doEndLuminosityBlock_(LuminosityBlockPrincipal const &, ModuleCallingContext const *)
void setModuleDescription(ModuleDescription const &md)
const ModuleDescription & moduleDescription() const
void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
boost::array< SelectedProducts, NumBranchTypes > SelectedProductsForBranchType
BranchChildren const & branchChildren() const
void doRespondToCloseInputFile(FileBlock const &fb)
void doRespondToOpenInputFile(FileBlock const &fb)
std::string const & processName() const
static void fillDescriptions(ConfigurationDescriptions &descriptions)
virtual void write(EventPrincipal const &e, ModuleCallingContext const *)=0
bool doEndRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *)
OutputModuleBase & operator=(OutputModuleBase const &)=delete
static const std::string & baseType()
void doOpenFile(FileBlock const &fb)
virtual void writeLuminosityBlock(LuminosityBlockPrincipal const &, ModuleCallingContext const *)=0
virtual void postForkReacquireResources(unsigned int, unsigned int)
BranchIDLists const * origBranchIDLists_
bool doBeginLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *)
virtual bool shouldWeCloseFile() const
Ask the OutputModule if we should end the current file.
void doCloseFile()
Tell the OutputModule that is must end the current file.
static void fillDescription(ParameterSetDescription &desc)
virtual bool isFileOpen() const
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
preg
Definition: Schedule.cc:362
void updateBranchParents(EventPrincipal const &ep)
ProductSelector productSelector_
detail::TriggerResultsBasedEventSelector selectors_
ParameterSetID selector_config_id_
bool doEndLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *)
std::map< BranchID, std::set< ParentageID > > BranchParents