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_one_OutputModuleBase_h
2 #define FWCore_Framework_one_OutputModuleBase_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Framework
6 // Class : OutputModuleBase
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Wed, 31 Jul 2013 15:37:16 GMT
19 //
20 
21 // system include files
22 #include <array>
23 #include <string>
24 #include <vector>
25 #include <map>
26 #include <atomic>
27 #include <mutex>
28 
29 // user include files
36 
45 
46 // forward declarations
47 namespace edm {
48 
49  class ModuleCallingContext;
50  class PreallocationConfiguration;
51  class ActivityRegistry;
52  template <typename T> class OutputModuleCommunicatorT;
53 
54  namespace maker {
55  template<typename T> class ModuleHolderT;
56  }
57 
58  namespace one {
59 
61 
63  public:
64  template <typename U> friend class edm::maker::ModuleHolderT;
65  template <typename T> friend class ::edm::WorkerT;
66  template <typename T> friend class ::edm::OutputModuleCommunicatorT;
68 
69  explicit OutputModuleBase(ParameterSet const& pset);
70  virtual ~OutputModuleBase();
71 
72  OutputModuleBase(OutputModuleBase const&) = delete; // Disallow copying and moving
73  OutputModuleBase& operator=(OutputModuleBase const&) = delete; // Disallow copying and moving
74 
77  int maxEvents() const {return maxEvents_;}
78 
81  int remainingEvents() const {return remainingEvents_;}
82 
83  bool selected(BranchDescription const& desc) const;
84 
85  void selectProducts(ProductRegistry const& preg);
86  std::string const& processName() const {return process_name_;}
88  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
89 
90  static void fillDescription(ParameterSetDescription & desc);
91  static void fillDescriptions(ConfigurationDescriptions& descriptions);
92  static const std::string& baseType();
94 
96 
97  bool wantAllEvents() const {return wantAllEvents_;}
98 
99  BranchIDLists const* branchIDLists() const;
100 
102  return moduleDescription_;
103  }
104  protected:
105 
107 
108  ModuleDescription const& description() const;
109 
111 
113 
114  void doBeginJob();
115  void doEndJob();
116  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
118  ModuleCallingContext const*);
119  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
120  ModuleCallingContext const*);
121  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
122  ModuleCallingContext const*);
124  ModuleCallingContext const*);
126  ModuleCallingContext const*);
127 
128  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
129  bool anyProductProduced);
130 
131  void configure(OutputModuleDescription const& desc);
132 
133  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
135  }
136 
137  private:
138 
140  std::atomic<int> remainingEvents_;
141 
142  // TODO: Give OutputModule
143  // an interface (protected?) that supplies client code with the
144  // needed functionality *without* giving away implementation
145  // details ... don't just return a reference to keptProducts_, because
146  // we are looking to have the flexibility to change the
147  // implementation of keptProducts_ without modifying clients. When this
148  // change is made, we'll have a one-time-only task of modifying
149  // clients (classes derived from OutputModule) to use the
150  // newly-introduced interface.
151  // TODO: Consider using shared pointers here?
152 
153  // keptProducts_ are pointers to the BranchDescription objects describing
154  // the branches we are to write.
155  //
156  // We do not own the BranchDescriptions to which we point.
158  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
159 
164 
167  // ID of the ParameterSet that configured the event selector
168  // subsystem.
170 
171  // needed because of possible EDAliases.
172  // filled in only if key and value are different.
173  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
174  std::unique_ptr<BranchIDLists> branchIDLists_;
176 
177  typedef std::map<BranchID, std::set<ParentageID> > BranchParents;
179 
181 
184  //------------------------------------------------------------------
185  // private member functions
186  //------------------------------------------------------------------
187 
189 
190  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const*);
192  void doOpenFile(FileBlock const& fb);
196  void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren);
197 
198  std::string workerType() const {return "WorkerT<edm::one::OutputModuleBase>";}
199 
201  void doCloseFile();
202 
205  void maybeOpenFile();
206 
208 
209 
210  // Do the end-of-file tasks; this is only called internally, after
211  // the appropriate tests have been done.
212  virtual void reallyCloseFile();
213 
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 writeLuminosityBlock(LuminosityBlockPrincipal const&, ModuleCallingContext const*) = 0;
222  virtual void writeRun(RunPrincipal const&, ModuleCallingContext const*) = 0;
223  virtual void openFile(FileBlock const&) {}
224  virtual bool isFileOpen() const { return true; }
225  virtual void reallyOpenFile() {}
226 
227  virtual void preForkReleaseResources();
228  virtual void postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/);
229 
230  virtual void doBeginRun_(RunPrincipal const&, ModuleCallingContext const*){}
231  virtual void doEndRun_(RunPrincipal const&, ModuleCallingContext const*){}
234  virtual void doRespondToOpenInputFile_(FileBlock const&) {}
235  virtual void doRespondToCloseInputFile_(FileBlock const&) {}
236 
238  moduleDescription_ = md;
239  }
240 
241  void updateBranchParents(EventPrincipal const& ep);
242  void fillDependencyGraph();
243 
244  bool limitReached() const {return remainingEvents_ == 0;}
245  };
246  }
247 }
248 #endif
BranchIDLists const * branchIDLists() const
std::unique_ptr< BranchIDLists > branchIDLists_
ModuleDescription const & description() const
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
SelectedProductsForBranchType keptProducts_
void doWriteLuminosityBlock(LuminosityBlockPrincipal const &lbp, ModuleCallingContext const *)
ModuleDescription moduleDescription_
void doWriteRun(RunPrincipal const &rp, ModuleCallingContext const *)
static boost::mutex mutex
Definition: LHEProxy.cc:11
static void prevalidate(ConfigurationDescriptions &)
bool doEvent(EventPrincipal const &ep, EventSetup const &c, ActivityRegistry *, ModuleCallingContext const *)
detail::TriggerResultsBasedEventSelector::handle_t Trig
void configure(OutputModuleDescription const &desc)
void registerProductsAndCallbacks(OutputModuleBase const *, ProductRegistry const *)
virtual void doEndRun_(RunPrincipal const &, ModuleCallingContext const *)
bool doBeginRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *)
void selectProducts(ProductRegistry const &preg)
ParameterSetID selectorConfig() const
ProductSelectorRules productSelectorRules_
virtual void doBeginRun_(RunPrincipal const &, ModuleCallingContext const *)
Trig getTriggerResults(EventPrincipal const &ep, ModuleCallingContext const *) const
virtual void doRespondToCloseInputFile_(FileBlock const &)
virtual void doRespondToOpenInputFile_(FileBlock const &)
virtual void openFile(FileBlock const &)
std::atomic< int > remainingEvents_
bool selected(BranchDescription const &desc) const
std::map< BranchID::value_type, BranchID::value_type > const & droppedBranchIDToKeptBranchID()
void doPreallocate(PreallocationConfiguration const &)
void setEventSelectionInfo(std::map< std::string, std::vector< std::pair< std::string, int > > > const &outputModulePathPositions, bool anyProductProduced)
virtual void writeRun(RunPrincipal const &, ModuleCallingContext const *)=0
SelectedProductsForBranchType const & keptProducts() const
virtual void preForkReleaseResources()
std::string workerType() const
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
SharedResourcesAcquirer resourcesAcquirer_
virtual void doBeginLuminosityBlock_(LuminosityBlockPrincipal const &, ModuleCallingContext const *)
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
OutputModuleBase(ParameterSet const &pset)
virtual void doEndLuminosityBlock_(LuminosityBlockPrincipal const &, ModuleCallingContext const *)
void setModuleDescription(ModuleDescription const &md)
const ModuleDescription & moduleDescription() const
void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren)
boost::array< SelectedProducts, NumBranchTypes > SelectedProductsForBranchType
BranchChildren const & branchChildren() const
void doRespondToCloseInputFile(FileBlock const &fb)
virtual SharedResourcesAcquirer createAcquirer()
void doRespondToOpenInputFile(FileBlock const &fb)
std::string const & processName() const
static void fillDescriptions(ConfigurationDescriptions &descriptions)
virtual void write(EventPrincipal const &e, ModuleCallingContext const *)=0
bool doEndRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *)
OutputModuleBase & operator=(OutputModuleBase const &)=delete
static const std::string & baseType()
void doOpenFile(FileBlock const &fb)
virtual void writeLuminosityBlock(LuminosityBlockPrincipal const &, ModuleCallingContext const *)=0
virtual void postForkReacquireResources(unsigned int, unsigned int)
BranchIDLists const * origBranchIDLists_
bool doBeginLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *)
virtual bool shouldWeCloseFile() const
Ask the OutputModule if we should end the current file.
void doCloseFile()
Tell the OutputModule that is must end the current file.
static void fillDescription(ParameterSetDescription &desc)
virtual bool isFileOpen() const
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
preg
Definition: Schedule.cc:369
void updateBranchParents(EventPrincipal const &ep)
ProductSelector productSelector_
detail::TriggerResultsBasedEventSelector selectors_
ParameterSetID selector_config_id_
bool doEndLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *)
std::map< BranchID, std::set< ParentageID > > BranchParents