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