CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OutputModule.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_OutputModule_h
2 #define FWCore_Framework_OutputModule_h
3 
4 /*----------------------------------------------------------------------
5 
6 OutputModule: The base class of all "modules" that write Events to an
7 output stream.
8 
9 ----------------------------------------------------------------------*/
10 
17 
25 
26 #include <array>
27 #include <string>
28 #include <vector>
29 #include <map>
30 
31 namespace edm {
32 
33  class ModuleCallingContext;
34  class PreallocationConfiguration;
35 
36  namespace maker {
37  template<typename T> class ModuleHolderT;
38  }
39 
41 
42  class OutputModule : public EDConsumerBase {
43  public:
44  template <typename T> friend class maker::ModuleHolderT;
45  template <typename T> friend class WorkerT;
46  template <typename T> friend class OutputModuleCommunicatorT;
48 
49  explicit OutputModule(ParameterSet const& pset);
50  virtual ~OutputModule();
51 
52  OutputModule(OutputModule const&) = delete; // Disallow copying and moving
53  OutputModule& operator=(OutputModule const&) = delete; // Disallow copying and moving
54 
57  int maxEvents() const {return maxEvents_;}
58 
61  int remainingEvents() const {return remainingEvents_;}
62 
63  bool selected(BranchDescription const& desc) const;
64 
65  void selectProducts(ProductRegistry const& preg);
66  std::string const& processName() const {return process_name_;}
68  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
69 
70  static void fillDescription(ParameterSetDescription & desc);
71  static void fillDescriptions(ConfigurationDescriptions& descriptions);
72  static const std::string& baseType();
74 
76 
77  bool wantAllEvents() const {return wantAllEvents_;}
78 
79  BranchIDLists const* branchIDLists() const;
80 
81  protected:
82 
83  // This function is needed for compatibility with older code. We
84  // need to clean up the use of Event and EventPrincipal, to avoid
85  // creation of multiple Event objects when handling a single
86  // event.
88 
89  ModuleDescription const& description() const;
91  }
92 
94 
96 
97  void doBeginJob();
98  void doEndJob();
99  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
100  ModuleCallingContext const* mcc);
101  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
102  ModuleCallingContext const* mcc);
103  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
104  ModuleCallingContext const* mcc);
106  ModuleCallingContext const* mcc);
108  ModuleCallingContext const* mcc);
109 
110  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
111  bool anyProductProduced);
112 
113  void configure(OutputModuleDescription const& desc);
114 
115  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
117  }
118 
119  private:
120 
123 
124  // TODO: Give OutputModule
125  // an interface (protected?) that supplies client code with the
126  // needed functionality *without* giving away implementation
127  // details ... don't just return a reference to keptProducts_, because
128  // we are looking to have the flexibility to change the
129  // implementation of keptProducts_ without modifying clients. When this
130  // change is made, we'll have a one-time-only task of modifying
131  // clients (classes derived from OutputModule) to use the
132  // newly-introduced interface.
133  // TODO: Consider using shared pointers here?
134 
135  // keptProducts_ are pointers to the BranchDescription objects describing
136  // the branches we are to write.
137  //
138  // We do not own the BranchDescriptions to which we point.
140  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
141 
146 
149  // ID of the ParameterSet that configured the event selector
150  // subsystem.
152 
153  // needed because of possible EDAliases.
154  // filled in only if key and value are different.
155  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
156  std::unique_ptr<BranchIDLists> branchIDLists_;
158 
159  typedef std::map<BranchID, std::set<ParentageID> > BranchParents;
161 
163 
164  //------------------------------------------------------------------
165  // private member functions
166  //------------------------------------------------------------------
167  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const* mcc);
169  void doOpenFile(FileBlock const& fb);
173  void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren);
174 
175  std::string workerType() const {return "WorkerT<OutputModule>";}
176 
178  void doCloseFile();
179 
182  void maybeOpenFile();
183 
184 
185  // Do the end-of-file tasks; this is only called internally, after
186  // the appropriate tests have been done.
187  virtual void reallyCloseFile();
188 
190 
192  virtual bool shouldWeCloseFile() const {return false;}
193 
194  virtual void write(EventPrincipal const& e, ModuleCallingContext const*) = 0;
195  virtual void beginJob(){}
196  virtual void endJob(){}
197  virtual void beginRun(RunPrincipal const&, ModuleCallingContext const*){}
198  virtual void endRun(RunPrincipal const&, ModuleCallingContext const*){}
199  virtual void writeRun(RunPrincipal const&, ModuleCallingContext const*) = 0;
202  virtual void writeLuminosityBlock(LuminosityBlockPrincipal const&, ModuleCallingContext const*) = 0;
203  virtual void openFile(FileBlock const&) {}
204  virtual void respondToOpenInputFile(FileBlock const&) {}
205  virtual void respondToCloseInputFile(FileBlock const&) {}
206  virtual void preForkReleaseResources() {}
207  virtual void postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/) {}
208 
209  virtual bool isFileOpen() const { return true; }
210 
211  virtual void reallyOpenFile() {}
212 
214  moduleDescription_ = md;
215  }
216 
217  void updateBranchParents(EventPrincipal const& ep);
218  void fillDependencyGraph();
219 
220  bool limitReached() const {return remainingEvents_ == 0;}
221  };
222 }
223 #endif
void setModuleDescription(ModuleDescription const &md)
Definition: OutputModule.h:213
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: OutputModule.h:140
void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
Definition: OutputModule.h:155
friend class maker::ModuleHolderT
Definition: OutputModule.h:44
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
virtual void writeLuminosityBlock(LuminosityBlockPrincipal const &, ModuleCallingContext const *)=0
bool doEvent(EventPrincipal const &ep, EventSetup const &c, ModuleCallingContext const *mcc)
void selectProducts(ProductRegistry const &preg)
Definition: OutputModule.cc:68
virtual void write(EventPrincipal const &e, ModuleCallingContext const *)=0
ModuleDescription moduleDescription_
Definition: OutputModule.h:145
void doPreallocate(PreallocationConfiguration const &)
Definition: OutputModule.h:95
int remainingEvents() const
Definition: OutputModule.h:61
virtual void reallyCloseFile()
std::string const & processName() const
Definition: OutputModule.h:66
virtual void reallyOpenFile()
Definition: OutputModule.h:211
static const std::string & baseType()
std::map< BranchID, std::set< ParentageID > > BranchParents
Definition: OutputModule.h:159
void updateBranchParents(EventPrincipal const &ep)
void doWriteLuminosityBlock(LuminosityBlockPrincipal const &lbp, ModuleCallingContext const *mcc)
void doOpenFile(FileBlock const &fb)
bool selected(BranchDescription const &desc) const
BranchIDLists const * origBranchIDLists_
Definition: OutputModule.h:157
detail::TriggerResultsBasedEventSelector::handle_t Trig
Definition: OutputModule.h:40
SelectedProductsForBranchType const & keptProducts() const
Definition: OutputModule.h:67
void doCloseFile()
Tell the OutputModule that is must end the current file.
virtual void endLuminosityBlock(LuminosityBlockPrincipal const &, ModuleCallingContext const *)
Definition: OutputModule.h:201
bool wantAllEvents() const
Definition: OutputModule.h:77
void setEventSelectionInfo(std::map< std::string, std::vector< std::pair< std::string, int > > > const &outputModulePathPositions, bool anyProductProduced)
std::string process_name_
Definition: OutputModule.h:142
static void fillDescriptions(ConfigurationDescriptions &descriptions)
void doWriteRun(RunPrincipal const &rp, ModuleCallingContext const *mcc)
virtual void beginLuminosityBlock(LuminosityBlockPrincipal const &, ModuleCallingContext const *)
Definition: OutputModule.h:200
std::map< BranchID::value_type, BranchID::value_type > const & droppedBranchIDToKeptBranchID()
Definition: OutputModule.h:115
void doPreForkReleaseResources()
std::unique_ptr< BranchIDLists > branchIDLists_
Definition: OutputModule.h:156
bool doEndLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *mcc)
detail::TriggerResultsBasedEventSelector selectors_
Definition: OutputModule.h:148
virtual bool isFileOpen() const
Definition: OutputModule.h:209
virtual bool shouldWeCloseFile() const
Ask the OutputModule if we should end the current file.
Definition: OutputModule.h:192
void doRespondToCloseInputFile(FileBlock const &fb)
OutputModule & operator=(OutputModule const &)=delete
bool doBeginLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *mcc)
void fillDependencyGraph()
virtual void postForkReacquireResources(unsigned int, unsigned int)
Definition: OutputModule.h:207
static void prevalidate(ConfigurationDescriptions &)
BranchChildren const & branchChildren() const
Definition: OutputModule.h:75
boost::array< SelectedProducts, NumBranchTypes > SelectedProductsForBranchType
int maxEvents() const
Definition: OutputModule.h:57
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
Definition: OutputModule.h:68
virtual void beginRun(RunPrincipal const &, ModuleCallingContext const *)
Definition: OutputModule.h:197
virtual void respondToOpenInputFile(FileBlock const &)
Definition: OutputModule.h:204
static void fillDescription(ParameterSetDescription &desc)
bool limitReached() const
Definition: OutputModule.h:220
bool doEndRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *mcc)
OutputModule ModuleType
Definition: OutputModule.h:47
SelectedProductsForBranchType keptProducts_
Definition: OutputModule.h:139
ProductSelector productSelector_
Definition: OutputModule.h:144
BranchChildren branchChildren_
Definition: OutputModule.h:162
BranchIDLists const * branchIDLists() const
virtual void endJob()
Definition: OutputModule.h:196
ProductSelectorRules productSelectorRules_
Definition: OutputModule.h:143
virtual void beginJob()
Definition: OutputModule.h:195
std::string workerType() const
Definition: OutputModule.h:175
void doRespondToOpenInputFile(FileBlock const &fb)
virtual void respondToCloseInputFile(FileBlock const &)
Definition: OutputModule.h:205
virtual ~OutputModule()
bool doBeginRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *mcc)
void configure(OutputModuleDescription const &desc)
Definition: OutputModule.cc:63
virtual void openFile(FileBlock const &)
Definition: OutputModule.h:203
preg
Definition: Schedule.cc:362
ModuleDescription const & moduleDescription() const
Definition: OutputModule.h:90
virtual void writeRun(RunPrincipal const &, ModuleCallingContext const *)=0
virtual void endRun(RunPrincipal const &, ModuleCallingContext const *)
Definition: OutputModule.h:198
Trig getTriggerResults(EventPrincipal const &ep, ModuleCallingContext const *) const
ModuleDescription const & description() const
BranchParents branchParents_
Definition: OutputModule.h:160
virtual void preForkReleaseResources()
Definition: OutputModule.h:206
OutputModule(ParameterSet const &pset)
Definition: OutputModule.cc:28
ParameterSetID selectorConfig() const
Definition: OutputModule.h:93
void registerProductsAndCallbacks(OutputModule const *, ProductRegistry const *)
Definition: OutputModule.h:189
ParameterSetID selector_config_id_
Definition: OutputModule.h:151