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