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 
27 
28 #include <array>
29 #include <memory>
30 #include <string>
31 #include <vector>
32 #include <map>
33 #include <atomic>
34 #include <mutex>
35 
36 namespace edm {
37 
38  class ModuleCallingContext;
39  class PreallocationConfiguration;
40  class ActivityRegistry;
41  class ProductRegistry;
42  class ThinnedAssociationsHelper;
43 
44  namespace maker {
45  template<typename T> class ModuleHolderT;
46  }
47 
49 
50  class OutputModule : public EDConsumerBase {
51  public:
52  template <typename T> friend class maker::ModuleHolderT;
53  template <typename T> friend class WorkerT;
54  template <typename T> friend class OutputModuleCommunicatorT;
56 
57  explicit OutputModule(ParameterSet const& pset);
58  virtual ~OutputModule();
59 
60  OutputModule(OutputModule const&) = delete; // Disallow copying and moving
61  OutputModule& operator=(OutputModule const&) = delete; // Disallow copying and moving
62 
65  int maxEvents() const {return maxEvents_;}
66 
69  int remainingEvents() const {return remainingEvents_;}
70 
71  bool selected(BranchDescription const& desc) const;
72 
74  std::string const& processName() const {return process_name_;}
76  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
77 
78  static void fillDescription(ParameterSetDescription & desc);
79  static void fillDescriptions(ConfigurationDescriptions& descriptions);
80  static const std::string& baseType();
82 
84 
85  bool wantAllEvents() const {return wantAllEvents_;}
86 
87  BranchIDLists const* branchIDLists() const;
88 
90 
91  protected:
92 
93  // This function is needed for compatibility with older code. We
94  // need to clean up the use of Event and EventPrincipal, to avoid
95  // creation of multiple Event objects when handling a single
96  // event.
98 
99  ModuleDescription const& description() const;
101  }
102 
104 
106 
107  void doBeginJob();
108  void doEndJob();
109  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
110  ActivityRegistry* act,
111  ModuleCallingContext const* mcc);
112  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
113  ModuleCallingContext const* mcc);
114  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
115  ModuleCallingContext const* mcc);
117  ModuleCallingContext const* mcc);
119  ModuleCallingContext const* mcc);
120 
121  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
122  bool anyProductProduced);
123 
124  void configure(OutputModuleDescription const& desc);
125 
126  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
128  }
129 
130  private:
131 
133  std::atomic<int> remainingEvents_;
134 
135  // TODO: Give OutputModule
136  // an interface (protected?) that supplies client code with the
137  // needed functionality *without* giving away implementation
138  // details ... don't just return a reference to keptProducts_, because
139  // we are looking to have the flexibility to change the
140  // implementation of keptProducts_ without modifying clients. When this
141  // change is made, we'll have a one-time-only task of modifying
142  // clients (classes derived from OutputModule) to use the
143  // newly-introduced interface.
144  // TODO: Consider using shared pointers here?
145 
146  // keptProducts_ are pointers to the BranchDescription objects describing
147  // the branches we are to write.
148  //
149  // We do not own the BranchDescriptions to which we point.
151  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
152 
157 
160  // ID of the ParameterSet that configured the event selector
161  // subsystem.
163 
164  // needed because of possible EDAliases.
165  // filled in only if key and value are different.
166  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
167  std::unique_ptr<BranchIDLists> branchIDLists_;
169 
170  std::unique_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
171  std::map<BranchID, bool> keepAssociation_;
172 
173  typedef std::map<BranchID, std::set<ParentageID> > BranchParents;
175 
177 
180 
181  //------------------------------------------------------------------
182  // private member functions
183  //------------------------------------------------------------------
184  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const* mcc);
186  void doOpenFile(FileBlock const& fb);
190  void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren);
193 
194  std::string workerType() const {return "WorkerT<OutputModule>";}
195 
197  void doCloseFile();
198 
201  void maybeOpenFile();
202 
203 
204  // Do the end-of-file tasks; this is only called internally, after
205  // the appropriate tests have been done.
206  virtual void reallyCloseFile();
207 
209 
211  virtual bool shouldWeCloseFile() const {return false;}
212 
213  virtual void write(EventPrincipal const& e, ModuleCallingContext const*) = 0;
214  virtual void beginJob(){}
215  virtual void endJob(){}
216  virtual void beginRun(RunPrincipal const&, ModuleCallingContext const*){}
217  virtual void endRun(RunPrincipal const&, ModuleCallingContext const*){}
218  virtual void writeRun(RunPrincipal const&, ModuleCallingContext const*) = 0;
221  virtual void writeLuminosityBlock(LuminosityBlockPrincipal const&, ModuleCallingContext const*) = 0;
222  virtual void openFile(FileBlock const&) {}
223  virtual void respondToOpenInputFile(FileBlock const&) {}
224  virtual void respondToCloseInputFile(FileBlock const&) {}
225  virtual void preForkReleaseResources() {}
226  virtual void postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/) {}
227 
228  virtual bool isFileOpen() const { return true; }
229 
230  virtual void reallyOpenFile() {}
231 
232  void keepThisBranch(BranchDescription const& desc,
233  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
234  std::set<BranchID>& keptProductsInEvent);
235 
238  }
239 
240  void updateBranchParents(EventPrincipal const& ep);
241  void fillDependencyGraph();
242 
243  bool limitReached() const {return remainingEvents_ == 0;}
244  };
245 }
246 #endif
void setModuleDescription(ModuleDescription const &md)
Definition: OutputModule.h:236
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: OutputModule.h:151
void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
void keepThisBranch(BranchDescription const &desc, std::map< BranchID, BranchDescription const * > &trueBranchIDToKeptBranchDesc, std::set< BranchID > &keptProductsInEvent)
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
Definition: OutputModule.h:166
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
virtual void writeLuminosityBlock(LuminosityBlockPrincipal const &, ModuleCallingContext const *)=0
virtual void write(EventPrincipal const &e, ModuleCallingContext const *)=0
ModuleDescription moduleDescription_
Definition: OutputModule.h:156
std::map< BranchID, bool > keepAssociation_
Definition: OutputModule.h:171
static boost::mutex mutex
Definition: LHEProxy.cc:11
void doPreallocate(PreallocationConfiguration const &)
Definition: OutputModule.h:105
int remainingEvents() const
Definition: OutputModule.h:69
SharedResourcesAcquirer resourceAcquirer_
Definition: OutputModule.h:178
virtual void reallyCloseFile()
std::string const & processName() const
Definition: OutputModule.h:74
virtual void reallyOpenFile()
Definition: OutputModule.h:230
static const std::string & baseType()
std::map< BranchID, std::set< ParentageID > > BranchParents
Definition: OutputModule.h:173
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:168
detail::TriggerResultsBasedEventSelector::handle_t Trig
Definition: OutputModule.h:48
SelectedProductsForBranchType const & keptProducts() const
Definition: OutputModule.h:75
void doCloseFile()
Tell the OutputModule that is must end the current file.
virtual void endLuminosityBlock(LuminosityBlockPrincipal const &, ModuleCallingContext const *)
Definition: OutputModule.h:220
bool wantAllEvents() const
Definition: OutputModule.h:85
void setEventSelectionInfo(std::map< std::string, std::vector< std::pair< std::string, int > > > const &outputModulePathPositions, bool anyProductProduced)
std::string process_name_
Definition: OutputModule.h:153
static void fillDescriptions(ConfigurationDescriptions &descriptions)
std::mutex mutex_
Definition: OutputModule.h:179
void doWriteRun(RunPrincipal const &rp, ModuleCallingContext const *mcc)
virtual void beginLuminosityBlock(LuminosityBlockPrincipal const &, ModuleCallingContext const *)
Definition: OutputModule.h:219
std::map< BranchID::value_type, BranchID::value_type > const & droppedBranchIDToKeptBranchID()
Definition: OutputModule.h:126
bool doEvent(EventPrincipal const &ep, EventSetup const &c, ActivityRegistry *act, ModuleCallingContext const *mcc)
void doPreForkReleaseResources()
std::unique_ptr< BranchIDLists > branchIDLists_
Definition: OutputModule.h:167
bool doEndLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *mcc)
detail::TriggerResultsBasedEventSelector selectors_
Definition: OutputModule.h:159
virtual bool isFileOpen() const
Definition: OutputModule.h:228
virtual bool shouldWeCloseFile() const
Ask the OutputModule if we should end the current file.
Definition: OutputModule.h:211
void doRespondToCloseInputFile(FileBlock const &fb)
OutputModule & operator=(OutputModule const &)=delete
bool doBeginLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *mcc)
void fillDependencyGraph()
std::unique_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper_
Definition: OutputModule.h:170
virtual void postForkReacquireResources(unsigned int, unsigned int)
Definition: OutputModule.h:226
void selectProducts(ProductRegistry const &preg, ThinnedAssociationsHelper const &)
Definition: OutputModule.cc:77
static void prevalidate(ConfigurationDescriptions &)
BranchChildren const & branchChildren() const
Definition: OutputModule.h:83
boost::array< SelectedProducts, NumBranchTypes > SelectedProductsForBranchType
ThinnedAssociationsHelper const * thinnedAssociationsHelper() const
int maxEvents() const
Definition: OutputModule.h:65
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
Definition: OutputModule.h:76
virtual void beginRun(RunPrincipal const &, ModuleCallingContext const *)
Definition: OutputModule.h:216
virtual void respondToOpenInputFile(FileBlock const &)
Definition: OutputModule.h:223
static void fillDescription(ParameterSetDescription &desc)
bool limitReached() const
Definition: OutputModule.h:243
bool doEndRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *mcc)
OutputModule ModuleType
Definition: OutputModule.h:55
SelectedProductsForBranchType keptProducts_
Definition: OutputModule.h:150
ProductSelector productSelector_
Definition: OutputModule.h:155
BranchChildren branchChildren_
Definition: OutputModule.h:176
BranchIDLists const * branchIDLists() const
virtual void endJob()
Definition: OutputModule.h:215
ProductSelectorRules productSelectorRules_
Definition: OutputModule.h:154
virtual void beginJob()
Definition: OutputModule.h:214
std::string workerType() const
Definition: OutputModule.h:194
void doRespondToOpenInputFile(FileBlock const &fb)
virtual void respondToCloseInputFile(FileBlock const &)
Definition: OutputModule.h:224
virtual ~OutputModule()
bool doBeginRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *mcc)
void configure(OutputModuleDescription const &desc)
Definition: OutputModule.cc:72
virtual void openFile(FileBlock const &)
Definition: OutputModule.h:222
void doRegisterThinnedAssociations(ProductRegistry const &, ThinnedAssociationsHelper &)
Definition: OutputModule.h:191
preg
Definition: Schedule.cc:370
ModuleDescription const & moduleDescription() const
Definition: OutputModule.h:100
std::atomic< int > remainingEvents_
Definition: OutputModule.h:133
virtual void writeRun(RunPrincipal const &, ModuleCallingContext const *)=0
virtual void endRun(RunPrincipal const &, ModuleCallingContext const *)
Definition: OutputModule.h:217
Trig getTriggerResults(EventPrincipal const &ep, ModuleCallingContext const *) const
ModuleDescription const & description() const
BranchParents branchParents_
Definition: OutputModule.h:174
virtual void preForkReleaseResources()
Definition: OutputModule.h:225
OutputModule(ParameterSet const &pset)
Definition: OutputModule.cc:33
ParameterSetID selectorConfig() const
Definition: OutputModule.h:103
void registerProductsAndCallbacks(OutputModule const *, ProductRegistry const *)
Definition: OutputModule.h:208
ParameterSetID selector_config_id_
Definition: OutputModule.h:162