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