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 
24 
25 #include <array>
26 #include <string>
27 #include <vector>
28 #include <map>
29 
30 namespace edm {
31 
33 
34  std::vector<std::string> const& getAllTriggerNames();
35 
36  class OutputModule : public EDConsumerBase {
37  public:
38  template <typename T> friend class WorkerT;
39  friend class OutputWorker;
42 
43  explicit OutputModule(ParameterSet const& pset);
44  virtual ~OutputModule();
45 
46  OutputModule(OutputModule const&) = delete; // Disallow copying and moving
47  OutputModule& operator=(OutputModule const&) = delete; // Disallow copying and moving
48 
51  int maxEvents() const {return maxEvents_;}
52 
55  int remainingEvents() const {return remainingEvents_;}
56 
57  bool selected(BranchDescription const& desc) const;
58 
59  void selectProducts(ProductRegistry const& preg);
60  std::string const& processName() const {return process_name_;}
61  SelectionsArray const& keptProducts() const {return keptProducts_;}
62  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
63 
64  static void fillDescription(ParameterSetDescription & desc);
65  static void fillDescriptions(ConfigurationDescriptions& descriptions);
66  static const std::string& baseType();
68 
70 
71  bool wantAllEvents() const {return wantAllEvents_;}
72 
73  BranchIDLists const* branchIDLists() const;
74 
75  protected:
76 
77  //Trig const& getTriggerResults(Event const& ep) const;
78  Trig getTriggerResults(Event const& ep) const;
79 
80  // This function is needed for compatibility with older code. We
81  // need to clean up the use of Event and EventPrincipal, to avoid
82  // creation of multiple Event objects when handling a single
83  // event.
84  Trig getTriggerResults(EventPrincipal const& ep) const;
85 
86  // The returned pointer will be null unless the this is currently
87  // executing its event loop function ('write').
89 
90  ModuleDescription const& description() const;
91 
93 
94  void doBeginJob();
95  void doEndJob();
96  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
97  CurrentProcessingContext const* cpc);
98  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
99  CurrentProcessingContext const* cpc);
100  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
101  CurrentProcessingContext const* cpc);
103  CurrentProcessingContext const* cpc);
105  CurrentProcessingContext const* cpc);
106 
107  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
108  bool anyProductProduced);
109 
110  void configure(OutputModuleDescription const& desc);
111 
112  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
114  }
115 
116  private:
117 
120 
121  // TODO: Give OutputModule
122  // an interface (protected?) that supplies client code with the
123  // needed functionality *without* giving away implementation
124  // details ... don't just return a reference to keptProducts_, because
125  // we are looking to have the flexibility to change the
126  // implementation of keptProducts_ without modifying clients. When this
127  // change is made, we'll have a one-time-only task of modifying
128  // clients (classes derived from OutputModule) to use the
129  // newly-introduced interface.
130  // TODO: Consider using shared pointers here?
131 
132  // keptProducts_ are pointers to the BranchDescription objects describing
133  // the branches we are to write.
134  //
135  // We do not own the BranchDescriptions to which we point.
137  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
138 
143 
144  // We do not own the pointed-to CurrentProcessingContext.
146 
147  //This will store TriggerResults objects for the current event.
148  // mutable std::vector<Trig> prods_;
149  mutable bool prodsValid_;
150 
153  // ID of the ParameterSet that configured the event selector
154  // subsystem.
156 
157  // needed because of possible EDAliases.
158  // filled in only if key and value are different.
159  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
160  std::unique_ptr<BranchIDLists> branchIDLists_;
162 
163  typedef std::map<BranchID, std::set<ParentageID> > BranchParents;
165 
167 
168  //------------------------------------------------------------------
169  // private member functions
170  //------------------------------------------------------------------
171  void doWriteRun(RunPrincipal const& rp);
173  void doOpenFile(FileBlock const& fb);
179  void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren);
180 
181  std::string workerType() const {return "OutputWorker";}
182 
184  void doCloseFile();
185 
188  void maybeOpenFile();
189 
190 
191  // Do the end-of-file tasks; this is only called internally, after
192  // the appropriate tests have been done.
193  void reallyCloseFile();
194 
196 
198  virtual bool shouldWeCloseFile() const {return false;}
199 
200  virtual void write(EventPrincipal const& e) = 0;
201  virtual void beginJob(){}
202  virtual void endJob(){}
203  virtual void beginRun(RunPrincipal const&){}
204  virtual void endRun(RunPrincipal const&){}
205  virtual void writeRun(RunPrincipal const&) = 0;
208  virtual void writeLuminosityBlock(LuminosityBlockPrincipal const&) = 0;
209  virtual void openFile(FileBlock const&) {}
210  virtual void respondToOpenInputFile(FileBlock const&) {}
211  virtual void respondToCloseInputFile(FileBlock const&) {}
212  virtual void respondToOpenOutputFiles(FileBlock const&) {}
213  virtual void respondToCloseOutputFiles(FileBlock const&) {}
214  virtual void preForkReleaseResources() {}
215  virtual void postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/) {}
216 
217  virtual bool isFileOpen() const { return true; }
218 
219  virtual void doOpenFile() { }
220 
222  moduleDescription_ = md;
223  }
224 
225  void updateBranchParents(EventPrincipal const& ep);
226  void fillDependencyGraph();
227 
228  bool limitReached() const {return remainingEvents_ == 0;}
229 
230  // The following member functions are part of the Template Method
231  // pattern, used for implementing doCloseFile() and maybeEndFile().
232 
233  virtual void startEndFile() {}
234  virtual void writeFileFormatVersion() {}
235  virtual void writeFileIdentifier() {}
236  virtual void writeIndexIntoFile() {}
238  virtual void writeProcessHistoryRegistry() {}
239  virtual void writeParameterSetRegistry() {}
240  virtual void writeBranchIDListRegistry() {}
241  virtual void writeParentageRegistry() {}
243  virtual void writeProductDependencies() {}
244  virtual void writeBranchMapper() {}
245  virtual void finishEndFile() {}
246  };
247 }
248 
249 //this is included after the class definition since this header also needs to know about OutputModule
250 // we put this here since all OutputModules need this header to create their plugin
252 
253 #endif
void setModuleDescription(ModuleDescription const &md)
Definition: OutputModule.h:221
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: OutputModule.h:137
void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
virtual void doOpenFile()
Definition: OutputModule.h:219
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
Definition: OutputModule.h:159
virtual void writeProductDependencies()
Definition: OutputModule.h:243
virtual void respondToCloseOutputFiles(FileBlock const &)
Definition: OutputModule.h:213
SelectionsArray const & keptProducts() const
Definition: OutputModule.h:61
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
void selectProducts(ProductRegistry const &preg)
ModuleDescription moduleDescription_
Definition: OutputModule.h:142
virtual void writeFileFormatVersion()
Definition: OutputModule.h:234
bool doEndLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, CurrentProcessingContext const *cpc)
CurrentProcessingContext const * current_context_
Definition: OutputModule.h:145
virtual void respondToOpenOutputFiles(FileBlock const &)
Definition: OutputModule.h:212
detail::CachedProducts selectors_
Definition: OutputModule.h:152
detail::CachedProducts::handle_t Trig
Definition: OutputModule.h:32
virtual void writeIndexIntoFile()
Definition: OutputModule.h:236
int remainingEvents() const
Definition: OutputModule.h:55
virtual void endRun(RunPrincipal const &)
Definition: OutputModule.h:204
std::string const & processName() const
Definition: OutputModule.h:60
static const std::string & baseType()
std::map< BranchID, std::set< ParentageID > > BranchParents
Definition: OutputModule.h:163
void updateBranchParents(EventPrincipal const &ep)
virtual void beginRun(RunPrincipal const &)
Definition: OutputModule.h:203
virtual void finishEndFile()
Definition: OutputModule.h:245
bool selected(BranchDescription const &desc) const
BranchIDLists const * origBranchIDLists_
Definition: OutputModule.h:161
virtual void writeParentageRegistry()
Definition: OutputModule.h:241
dictionary map
Definition: Association.py:205
void doCloseFile()
Tell the OutputModule that is must end the current file.
bool wantAllEvents() const
Definition: OutputModule.h:71
void setEventSelectionInfo(std::map< std::string, std::vector< std::pair< std::string, int > > > const &outputModulePathPositions, bool anyProductProduced)
std::string process_name_
Definition: OutputModule.h:139
virtual void endLuminosityBlock(LuminosityBlockPrincipal const &)
Definition: OutputModule.h:207
virtual void writeProcessConfigurationRegistry()
Definition: OutputModule.h:237
static void fillDescriptions(ConfigurationDescriptions &descriptions)
bool doEvent(EventPrincipal const &ep, EventSetup const &c, CurrentProcessingContext const *cpc)
OutputWorker WorkerType
Definition: OutputModule.h:41
boost::array< Selections, NumBranchTypes > SelectionsArray
Definition: Selections.h:12
std::map< BranchID::value_type, BranchID::value_type > const & droppedBranchIDToKeptBranchID()
Definition: OutputModule.h:112
SelectionsArray keptProducts_
Definition: OutputModule.h:136
void doWriteLuminosityBlock(LuminosityBlockPrincipal const &lbp)
void doPreForkReleaseResources()
std::unique_ptr< BranchIDLists > branchIDLists_
Definition: OutputModule.h:160
virtual void beginLuminosityBlock(LuminosityBlockPrincipal const &)
Definition: OutputModule.h:206
void doRespondToCloseOutputFiles(FileBlock const &fb)
virtual void write(EventPrincipal const &e)=0
virtual bool isFileOpen() const
Definition: OutputModule.h:217
virtual bool shouldWeCloseFile() const
Ask the OutputModule if we should end the current file.
Definition: OutputModule.h:198
void doRespondToCloseInputFile(FileBlock const &fb)
OutputModule & operator=(OutputModule const &)=delete
virtual void writeFileIdentifier()
Definition: OutputModule.h:235
void fillDependencyGraph()
virtual void postForkReacquireResources(unsigned int, unsigned int)
Definition: OutputModule.h:215
static void prevalidate(ConfigurationDescriptions &)
BranchChildren const & branchChildren() const
Definition: OutputModule.h:69
CurrentProcessingContext const * currentContext() const
virtual void writeRun(RunPrincipal const &)=0
int maxEvents() const
Definition: OutputModule.h:51
void doWriteRun(RunPrincipal const &rp)
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
Definition: OutputModule.h:62
virtual void respondToOpenInputFile(FileBlock const &)
Definition: OutputModule.h:210
static void fillDescription(ParameterSetDescription &desc)
bool limitReached() const
Definition: OutputModule.h:228
OutputModule ModuleType
Definition: OutputModule.h:40
bool doBeginLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, CurrentProcessingContext const *cpc)
ProductSelector productSelector_
Definition: OutputModule.h:141
std::vector< std::string > const & getAllTriggerNames()
Definition: OutputModule.cc:28
BranchChildren branchChildren_
Definition: OutputModule.h:166
Trig getTriggerResults(Event const &ep) const
virtual void writeParameterSetRegistry()
Definition: OutputModule.h:239
BranchIDLists const * branchIDLists() const
virtual void endJob()
Definition: OutputModule.h:202
ProductSelectorRules productSelectorRules_
Definition: OutputModule.h:140
virtual void beginJob()
Definition: OutputModule.h:201
std::string workerType() const
Definition: OutputModule.h:181
void doRespondToOpenInputFile(FileBlock const &fb)
virtual void respondToCloseInputFile(FileBlock const &)
Definition: OutputModule.h:211
virtual ~OutputModule()
bool doEndRun(RunPrincipal const &rp, EventSetup const &c, CurrentProcessingContext const *cpc)
void configure(OutputModuleDescription const &desc)
virtual void openFile(FileBlock const &)
Definition: OutputModule.h:209
bool doBeginRun(RunPrincipal const &rp, EventSetup const &c, CurrentProcessingContext const *cpc)
virtual void startEndFile()
Definition: OutputModule.h:233
virtual void writeBranchMapper()
Definition: OutputModule.h:244
virtual void writeLuminosityBlock(LuminosityBlockPrincipal const &)=0
ModuleDescription const & description() const
BranchParents branchParents_
Definition: OutputModule.h:164
virtual void preForkReleaseResources()
Definition: OutputModule.h:214
OutputModule(ParameterSet const &pset)
virtual void writeBranchIDListRegistry()
Definition: OutputModule.h:240
virtual void writeProcessHistoryRegistry()
Definition: OutputModule.h:238
void doRespondToOpenOutputFiles(FileBlock const &fb)
ParameterSetID selectorConfig() const
Definition: OutputModule.h:92
virtual void writeProductDescriptionRegistry()
Definition: OutputModule.h:242
void registerProductsAndCallbacks(OutputModule const *, ProductRegistry const *)
Definition: OutputModule.h:195
ParameterSetID selector_config_id_
Definition: OutputModule.h:155