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 
15 
23 
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 
83  bool wantAllEvents() const {return wantAllEvents_;}
84 
86 
88 
89  protected:
90 
91  // This function is needed for compatibility with older code. We
92  // need to clean up the use of Event and EventPrincipal, to avoid
93  // creation of multiple Event objects when handling a single
94  // event.
96 
97  ModuleDescription const& description() const;
99  }
100 
102 
104 
105  void doBeginJob();
106  void doEndJob();
107  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
108  ActivityRegistry* act,
109  ModuleCallingContext const* mcc);
110  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
111  ModuleCallingContext const* mcc);
112  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
113  ModuleCallingContext const* mcc);
115  ModuleCallingContext const* mcc);
117  ModuleCallingContext const* mcc);
118 
119  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
120  bool anyProductProduced);
121 
122  void configure(OutputModuleDescription const& desc);
123 
124  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
126  }
127 
128  private:
129 
131  std::atomic<int> remainingEvents_;
132 
133  // TODO: Give OutputModule
134  // an interface (protected?) that supplies client code with the
135  // needed functionality *without* giving away implementation
136  // details ... don't just return a reference to keptProducts_, because
137  // we are looking to have the flexibility to change the
138  // implementation of keptProducts_ without modifying clients. When this
139  // change is made, we'll have a one-time-only task of modifying
140  // clients (classes derived from OutputModule) to use the
141  // newly-introduced interface.
142  // TODO: Consider using shared pointers here?
143 
144  // keptProducts_ are pointers to the BranchDescription objects describing
145  // the branches we are to write.
146  //
147  // We do not own the BranchDescriptions to which we point.
149  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
150 
155 
157  std::vector<detail::TriggerResultsBasedEventSelector> selectors_;
158  // ID of the ParameterSet that configured the event selector
159  // subsystem.
162 
163  // needed because of possible EDAliases.
164  // filled in only if key and value are different.
165  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
166  std::unique_ptr<BranchIDLists> branchIDLists_;
168 
169  std::unique_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
170  std::map<BranchID, bool> keepAssociation_;
171 
174 
175  //------------------------------------------------------------------
176  // private member functions
177  //------------------------------------------------------------------
178  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const* mcc);
180  void doOpenFile(FileBlock const& fb);
184  void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren);
187 
188  std::string workerType() const {return "WorkerT<OutputModule>";}
189 
191  void doCloseFile();
192 
195  void maybeOpenFile();
196 
197 
198  // Do the end-of-file tasks; this is only called internally, after
199  // the appropriate tests have been done.
200  virtual void reallyCloseFile();
201 
203 
205 
207  virtual bool shouldWeCloseFile() const {return false;}
208 
209  virtual void write(EventPrincipal const& e, ModuleCallingContext const*) = 0;
210  virtual void beginJob(){}
211  virtual void endJob(){}
212  virtual void beginRun(RunPrincipal const&, ModuleCallingContext const*){}
213  virtual void endRun(RunPrincipal const&, ModuleCallingContext const*){}
214  virtual void writeRun(RunPrincipal const&, ModuleCallingContext const*) = 0;
217  virtual void writeLuminosityBlock(LuminosityBlockPrincipal const&, ModuleCallingContext const*) = 0;
218  virtual void openFile(FileBlock const&) {}
219  virtual void respondToOpenInputFile(FileBlock const&) {}
220  virtual void respondToCloseInputFile(FileBlock const&) {}
221  virtual void preForkReleaseResources() {}
222  virtual void postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/) {}
223 
224  virtual bool isFileOpen() const { return true; }
225 
226  virtual void reallyOpenFile() {}
227 
228  void keepThisBranch(BranchDescription const& desc,
229  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
230  std::set<BranchID>& keptProductsInEvent);
231 
234  }
235 
236  bool limitReached() const {return remainingEvents_ == 0;}
237  };
238 }
239 #endif
void setModuleDescription(ModuleDescription const &md)
Definition: OutputModule.h:232
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
Definition: OutputModule.h:149
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:165
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
virtual void writeLuminosityBlock(LuminosityBlockPrincipal const &, ModuleCallingContext const *)=0
ParameterSet selectEvents_
Definition: OutputModule.h:160
virtual void write(EventPrincipal const &e, ModuleCallingContext const *)=0
ModuleDescription moduleDescription_
Definition: OutputModule.h:154
std::map< BranchID, bool > keepAssociation_
Definition: OutputModule.h:170
static boost::mutex mutex
Definition: LHEProxy.cc:11
BranchIDLists const * branchIDLists()
void doPreallocate(PreallocationConfiguration const &)
int remainingEvents() const
Definition: OutputModule.h:69
SharedResourcesAcquirer resourceAcquirer_
Definition: OutputModule.h:172
virtual void reallyCloseFile()
std::string const & processName() const
Definition: OutputModule.h:74
bool prePrefetchSelection(StreamID id, EventPrincipal const &, ModuleCallingContext const *)
virtual void reallyOpenFile()
Definition: OutputModule.h:226
static const std::string & baseType()
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:167
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:216
bool wantAllEvents() const
Definition: OutputModule.h:83
void setEventSelectionInfo(std::map< std::string, std::vector< std::pair< std::string, int > > > const &outputModulePathPositions, bool anyProductProduced)
std::string process_name_
Definition: OutputModule.h:151
static void fillDescriptions(ConfigurationDescriptions &descriptions)
std::mutex mutex_
Definition: OutputModule.h:173
void doWriteRun(RunPrincipal const &rp, ModuleCallingContext const *mcc)
virtual void beginLuminosityBlock(LuminosityBlockPrincipal const &, ModuleCallingContext const *)
Definition: OutputModule.h:215
std::map< BranchID::value_type, BranchID::value_type > const & droppedBranchIDToKeptBranchID()
Definition: OutputModule.h:124
bool doEvent(EventPrincipal const &ep, EventSetup const &c, ActivityRegistry *act, ModuleCallingContext const *mcc)
void doPreForkReleaseResources()
std::unique_ptr< BranchIDLists > branchIDLists_
Definition: OutputModule.h:166
bool doEndLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *mcc)
virtual bool isFileOpen() const
Definition: OutputModule.h:224
virtual bool shouldWeCloseFile() const
Ask the OutputModule if we should end the current file.
Definition: OutputModule.h:207
void doRespondToCloseInputFile(FileBlock const &fb)
OutputModule & operator=(OutputModule const &)=delete
bool doBeginLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *mcc)
std::unique_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper_
Definition: OutputModule.h:169
virtual void postForkReacquireResources(unsigned int, unsigned int)
Definition: OutputModule.h:222
void selectProducts(ProductRegistry const &preg, ThinnedAssociationsHelper const &)
Definition: OutputModule.cc:80
static void prevalidate(ConfigurationDescriptions &)
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:212
virtual void respondToOpenInputFile(FileBlock const &)
Definition: OutputModule.h:219
static void fillDescription(ParameterSetDescription &desc)
bool limitReached() const
Definition: OutputModule.h:236
bool doEndRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *mcc)
OutputModule ModuleType
Definition: OutputModule.h:55
std::vector< detail::TriggerResultsBasedEventSelector > selectors_
Definition: OutputModule.h:157
SelectedProductsForBranchType keptProducts_
Definition: OutputModule.h:148
ProductSelector productSelector_
Definition: OutputModule.h:153
virtual void endJob()
Definition: OutputModule.h:211
ProductSelectorRules productSelectorRules_
Definition: OutputModule.h:152
Trig getTriggerResults(EDGetTokenT< TriggerResults > const &token, EventPrincipal const &ep, ModuleCallingContext const *) const
virtual void beginJob()
Definition: OutputModule.h:210
std::string workerType() const
Definition: OutputModule.h:188
void doRespondToOpenInputFile(FileBlock const &fb)
virtual void respondToCloseInputFile(FileBlock const &)
Definition: OutputModule.h:220
virtual ~OutputModule()
bool doBeginRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *mcc)
void configure(OutputModuleDescription const &desc)
Definition: OutputModule.cc:75
virtual void openFile(FileBlock const &)
Definition: OutputModule.h:218
void doRegisterThinnedAssociations(ProductRegistry const &, ThinnedAssociationsHelper &)
Definition: OutputModule.h:185
preg
Definition: Schedule.cc:369
ModuleDescription const & moduleDescription() const
Definition: OutputModule.h:98
std::atomic< int > remainingEvents_
Definition: OutputModule.h:131
virtual void writeRun(RunPrincipal const &, ModuleCallingContext const *)=0
virtual void endRun(RunPrincipal const &, ModuleCallingContext const *)
Definition: OutputModule.h:213
ModuleDescription const & description() const
virtual void preForkReleaseResources()
Definition: OutputModule.h:221
OutputModule(ParameterSet const &pset)
Definition: OutputModule.cc:34
ParameterSetID selectorConfig() const
Definition: OutputModule.h:101
void registerProductsAndCallbacks(OutputModule const *, ProductRegistry const *)
Definition: OutputModule.h:202
ParameterSetID selector_config_id_
Definition: OutputModule.h:161