CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OutputModuleBase.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_global_OutputModuleBase_h
2 #define FWCore_Framework_global_OutputModuleBase_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Framework
6 // Class : OutputModuleBase
7 //
16 //
17 //
18 
19 // system include files
20 #include <array>
21 #include <memory>
22 #include <string>
23 #include <vector>
24 #include <map>
25 #include <atomic>
26 #include <mutex>
27 
28 // user include files
33 
42 
43 // forward declarations
44 namespace edm {
45 
46  class ModuleCallingContext;
47  class PreallocationConfiguration;
48  class ActivityRegistry;
49  class ProductRegistry;
50  class ThinnedAssociationsHelper;
51 
52  template <typename T> class OutputModuleCommunicatorT;
53 
54  namespace maker {
55  template<typename T> class ModuleHolderT;
56  }
57 
58  namespace global {
59 
61  public:
62  template <typename U> friend class edm::maker::ModuleHolderT;
63  template <typename T> friend class ::edm::WorkerT;
64  template <typename T> friend class ::edm::OutputModuleCommunicatorT;
66 
67  explicit OutputModuleBase(ParameterSet const& pset);
68  virtual ~OutputModuleBase();
69 
70  OutputModuleBase(OutputModuleBase const&) = delete; // Disallow copying and moving
71  OutputModuleBase& operator=(OutputModuleBase const&) = delete; // Disallow copying and moving
72 
75  int maxEvents() const {return maxEvents_;}
76 
79  int remainingEvents() const {return remainingEvents_;}
80 
81  bool selected(BranchDescription const& desc) const;
82 
84  std::string const& processName() const {return process_name_;}
86  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
87 
88  static void fillDescription(ParameterSetDescription & desc);
89  static void fillDescriptions(ConfigurationDescriptions& descriptions);
90  static const std::string& baseType();
92 
93  bool wantAllEvents() const {return wantAllEvents_;}
94 
96 
98 
100  return moduleDescription_;
101  }
102  protected:
103 
104  ModuleDescription const& description() const;
105 
107 
109 
110  void doBeginJob();
111  void doEndJob();
112 
113  void doBeginStream(StreamID id);
114  void doEndStream(StreamID id);
115  void doStreamBeginRun(StreamID id,
116  RunPrincipal& ep,
117  EventSetup const& c,
118  ModuleCallingContext const*);
119  void doStreamEndRun(StreamID id,
120  RunPrincipal& ep,
121  EventSetup const& c,
122  ModuleCallingContext const*);
125  EventSetup const& c,
126  ModuleCallingContext const*);
129  EventSetup const& c,
130  ModuleCallingContext const*);
131 
132  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
134  ModuleCallingContext const*);
135  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
136  ModuleCallingContext const*);
137  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
138  ModuleCallingContext const*);
140  ModuleCallingContext const*);
142  ModuleCallingContext const*);
143 
144  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
145  bool anyProductProduced);
146 
147  void configure(OutputModuleDescription const& desc);
148 
149  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
151  }
152 
153  private:
154 
156  std::atomic<int> remainingEvents_;
157 
158  // TODO: Give OutputModule
159  // an interface (protected?) that supplies client code with the
160  // needed functionality *without* giving away implementation
161  // details ... don't just return a reference to keptProducts_, because
162  // we are looking to have the flexibility to change the
163  // implementation of keptProducts_ without modifying clients. When this
164  // change is made, we'll have a one-time-only task of modifying
165  // clients (classes derived from OutputModule) to use the
166  // newly-introduced interface.
167  // TODO: Consider using shared pointers here?
168 
169  // keptProducts_ are pointers to the BranchDescription objects describing
170  // the branches we are to write.
171  //
172  // We do not own the BranchDescriptions to which we point.
174  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
175 
180 
182  std::vector<detail::TriggerResultsBasedEventSelector> selectors_;
184  // ID of the ParameterSet that configured the event selector
185  // subsystem.
187 
188  // needed because of possible EDAliases.
189  // filled in only if key and value are different.
190  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
193 
195  std::map<BranchID, bool> keepAssociation_;
196 
197  //------------------------------------------------------------------
198  // private member functions
199  //------------------------------------------------------------------
200 
201  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const*);
203  void doOpenFile(FileBlock const& fb);
207  void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren);
210 
211  std::string workerType() const {return "WorkerT<edm::global::OutputModuleBase>";}
212 
214  void doCloseFile();
215 
218  void maybeOpenFile();
219 
221 
223 
224  // Do the end-of-file tasks; this is only called internally, after
225  // the appropriate tests have been done.
226  virtual void reallyCloseFile();
227 
228 
230  virtual bool shouldWeCloseFile() const {return false;}
231 
232  virtual void write(EventPrincipal const& e, ModuleCallingContext const*) = 0;
233  virtual void beginJob(){}
234  virtual void endJob(){}
235  virtual void writeLuminosityBlock(LuminosityBlockPrincipal const&, ModuleCallingContext const*) = 0;
236  virtual void writeRun(RunPrincipal const&, ModuleCallingContext const*) = 0;
237  virtual void openFile(FileBlock const&) {}
238  virtual bool isFileOpen() const { return true; }
239  virtual void reallyOpenFile() {}
240 
241  virtual void preForkReleaseResources();
242  virtual void postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/);
243 
244  virtual void preallocStreams(unsigned int){}
245  virtual void doBeginStream_(StreamID){}
246  virtual void doEndStream_(StreamID){}
247  virtual void doStreamBeginRun_(StreamID, Run const&, EventSetup const&){}
248  virtual void doStreamEndRun_(StreamID, Run const&, EventSetup const&){}
249  virtual void doStreamEndRunSummary_(StreamID, Run const&, EventSetup const&){}
253 
254  virtual void doBeginRun_(RunPrincipal const&, ModuleCallingContext const*){}
255  virtual void doBeginRunSummary_(Run const&, EventSetup const&){}
256  virtual void doEndRun_(RunPrincipal const&, ModuleCallingContext const*){}
257  virtual void doEndRunSummary_(Run const&, EventSetup const&){}
262  virtual void doRespondToOpenInputFile_(FileBlock const&) {}
263  virtual void doRespondToCloseInputFile_(FileBlock const&) {}
264 
265  void keepThisBranch(BranchDescription const& desc,
266  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
267  std::set<BranchID>& keptProductsInEvent);
268 
270  moduleDescription_ = md;
271  }
272 
273  bool limitReached() const {return remainingEvents_ == 0;}
274  };
275  }
276 }
277 #endif
void doStreamBeginLuminosityBlock(StreamID id, LuminosityBlockPrincipal &ep, EventSetup const &c, ModuleCallingContext const *)
virtual void doBeginRunSummary_(Run const &, EventSetup const &)
virtual void writeLuminosityBlock(LuminosityBlockPrincipal const &, ModuleCallingContext const *)=0
virtual void postForkReacquireResources(unsigned int, unsigned int)
void doCloseFile()
Tell the OutputModule that is must end the current file.
SelectedProductsForBranchType const & keptProducts() const
void keepThisBranch(BranchDescription const &desc, std::map< BranchID, BranchDescription const * > &trueBranchIDToKeptBranchDesc, std::set< BranchID > &keptProductsInEvent)
ModuleDescription const & description() const
BranchIDLists const * origBranchIDLists_
std::string workerType() const
void doRespondToOpenInputFile(FileBlock const &fb)
void selectProducts(ProductRegistry const &preg, ThinnedAssociationsHelper const &)
void setModuleDescription(ModuleDescription const &md)
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
virtual void preallocStreams(unsigned int)
void doStreamEndLuminosityBlock(StreamID id, LuminosityBlockPrincipal &ep, EventSetup const &c, ModuleCallingContext const *)
void doWriteLuminosityBlock(LuminosityBlockPrincipal const &lbp, ModuleCallingContext const *)
virtual bool isFileOpen() const
void doBeginStream(StreamID id)
OutputModuleBase(ParameterSet const &pset)
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
std::vector< detail::TriggerResultsBasedEventSelector > selectors_
virtual void openFile(FileBlock const &)
virtual void doBeginStream_(StreamID)
virtual void doRespondToOpenInputFile_(FileBlock const &)
std::string const & processName() const
SelectedProductsForBranchType keptProducts_
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
BranchIDLists const * branchIDLists()
void registerProductsAndCallbacks(OutputModuleBase const *, ProductRegistry const *)
bool doEvent(EventPrincipal const &ep, EventSetup const &c, ActivityRegistry *, ModuleCallingContext const *)
void doRegisterThinnedAssociations(ProductRegistry const &, ThinnedAssociationsHelper &)
OutputModuleBase & operator=(OutputModuleBase const &)=delete
ThinnedAssociationsHelper const * thinnedAssociationsHelper() const
ModuleDescription moduleDescription_
edm::propagate_const< std::unique_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
bool prePrefetchSelection(StreamID id, EventPrincipal const &, ModuleCallingContext const *)
virtual void doEndRun_(RunPrincipal const &, ModuleCallingContext const *)
virtual void doEndStream_(StreamID)
virtual void doStreamEndRun_(StreamID, Run const &, EventSetup const &)
void setEventSelectionInfo(std::map< std::string, std::vector< std::pair< std::string, int > > > const &outputModulePathPositions, bool anyProductProduced)
void doStreamEndRun(StreamID id, RunPrincipal &ep, EventSetup const &c, ModuleCallingContext const *)
void doPreallocate(PreallocationConfiguration const &)
std::map< BranchID, bool > keepAssociation_
bool selected(BranchDescription const &desc) const
virtual void doStreamEndRunSummary_(StreamID, Run const &, EventSetup const &)
const ModuleDescription & moduleDescription() const
virtual void doStreamBeginLuminosityBlock_(StreamID, LuminosityBlock const &, EventSetup const &)
edm::propagate_const< std::unique_ptr< BranchIDLists > > branchIDLists_
static void prevalidate(ConfigurationDescriptions &)
static const std::string & baseType()
void configure(OutputModuleDescription const &desc)
static void fillDescription(ParameterSetDescription &desc)
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
static void fillDescriptions(ConfigurationDescriptions &descriptions)
ParameterSetID selectorConfig() const
virtual void doBeginRun_(RunPrincipal const &, ModuleCallingContext const *)
ProductSelectorRules productSelectorRules_
boost::array< SelectedProducts, NumBranchTypes > SelectedProductsForBranchType
void doRespondToCloseInputFile(FileBlock const &fb)
std::atomic< int > remainingEvents_
virtual void write(EventPrincipal const &e, ModuleCallingContext const *)=0
bool doBeginRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *)
bool doEndRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *)
virtual bool shouldWeCloseFile() const
Ask the OutputModule if we should end the current file.
std::map< BranchID::value_type, BranchID::value_type > const & droppedBranchIDToKeptBranchID()
void doWriteRun(RunPrincipal const &rp, ModuleCallingContext const *)
bool doEndLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *)
virtual void doEndLuminosityBlockSummary_(LuminosityBlock const &, EventSetup const &)
void doEndStream(StreamID id)
virtual void doRespondToCloseInputFile_(FileBlock const &)
virtual void doStreamBeginRun_(StreamID, Run const &, EventSetup const &)
virtual void doEndRunSummary_(Run const &, EventSetup const &)
preg
Definition: Schedule.cc:374
bool doBeginLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *)
void doStreamBeginRun(StreamID id, RunPrincipal &ep, EventSetup const &c, ModuleCallingContext const *)
void doOpenFile(FileBlock const &fb)
virtual void doBeginLuminosityBlock_(LuminosityBlockPrincipal const &, ModuleCallingContext const *)
void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
virtual void writeRun(RunPrincipal const &, ModuleCallingContext const *)=0
virtual void doStreamEndLuminosityBlock_(StreamID, LuminosityBlock const &, EventSetup const &)
virtual void doStreamEndLuminosityBlockSummary_(StreamID, LuminosityBlock const &, EventSetup const &)
virtual void doBeginLuminosityBlockSummary_(LuminosityBlock const &, EventSetup const &)
Definition: Run.h:43
virtual void doEndLuminosityBlock_(LuminosityBlockPrincipal const &, ModuleCallingContext const *)