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 <memory>
24 #include <string>
25 #include <vector>
26 #include <map>
27 #include <atomic>
28 #include <mutex>
29 
30 // user include files
37 
46 
47 // forward declarations
48 namespace edm {
49 
50  class ModuleCallingContext;
51  class PreallocationConfiguration;
52  class ActivityRegistry;
53  class ProductRegistry;
54  class ThinnedAssociationsHelper;
55 
56  template <typename T> class OutputModuleCommunicatorT;
57 
58  namespace maker {
59  template<typename T> class ModuleHolderT;
60  }
61 
62  namespace one {
63 
65 
67  public:
68  template <typename U> friend class edm::maker::ModuleHolderT;
69  template <typename T> friend class ::edm::WorkerT;
70  template <typename T> friend class ::edm::OutputModuleCommunicatorT;
72 
73  explicit OutputModuleBase(ParameterSet const& pset);
74  virtual ~OutputModuleBase();
75 
76  OutputModuleBase(OutputModuleBase const&) = delete; // Disallow copying and moving
77  OutputModuleBase& operator=(OutputModuleBase const&) = delete; // Disallow copying and moving
78 
81  int maxEvents() const {return maxEvents_;}
82 
85  int remainingEvents() const {return remainingEvents_;}
86 
87  bool selected(BranchDescription const& desc) const;
88 
90  std::string const& processName() const {return process_name_;}
92  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
93 
94  static void fillDescription(ParameterSetDescription & desc);
95  static void fillDescriptions(ConfigurationDescriptions& descriptions);
96  static const std::string& baseType();
98 
100 
101  bool wantAllEvents() const {return wantAllEvents_;}
102 
103  BranchIDLists const* branchIDLists() const;
104 
106 
108  return moduleDescription_;
109  }
110  protected:
111 
113 
114  ModuleDescription const& description() const;
115 
117 
119 
120  void doBeginJob();
121  void doEndJob();
122  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
124  ModuleCallingContext const*);
125  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
126  ModuleCallingContext const*);
127  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
128  ModuleCallingContext const*);
130  ModuleCallingContext const*);
132  ModuleCallingContext const*);
133 
134  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
135  bool anyProductProduced);
136 
137  void configure(OutputModuleDescription const& desc);
138 
139  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
141  }
142 
143  private:
144 
146  std::atomic<int> remainingEvents_;
147 
148  // TODO: Give OutputModule
149  // an interface (protected?) that supplies client code with the
150  // needed functionality *without* giving away implementation
151  // details ... don't just return a reference to keptProducts_, because
152  // we are looking to have the flexibility to change the
153  // implementation of keptProducts_ without modifying clients. When this
154  // change is made, we'll have a one-time-only task of modifying
155  // clients (classes derived from OutputModule) to use the
156  // newly-introduced interface.
157  // TODO: Consider using shared pointers here?
158 
159  // keptProducts_ are pointers to the BranchDescription objects describing
160  // the branches we are to write.
161  //
162  // We do not own the BranchDescriptions to which we point.
164  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
165 
170 
173  // ID of the ParameterSet that configured the event selector
174  // subsystem.
176 
177  // needed because of possible EDAliases.
178  // filled in only if key and value are different.
179  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
180  std::unique_ptr<BranchIDLists> branchIDLists_;
182 
183  std::unique_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
184  std::map<BranchID, bool> keepAssociation_;
185 
186  typedef std::map<BranchID, std::set<ParentageID> > BranchParents;
188 
190 
193 
194  //------------------------------------------------------------------
195  // private member functions
196  //------------------------------------------------------------------
197 
199 
200  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const*);
202  void doOpenFile(FileBlock const& fb);
206  void doPostForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren);
209 
210  std::string workerType() const {return "WorkerT<edm::one::OutputModuleBase>";}
211 
213  void doCloseFile();
214 
217  void maybeOpenFile();
218 
220 
221 
222  // Do the end-of-file tasks; this is only called internally, after
223  // the appropriate tests have been done.
224  virtual void reallyCloseFile();
225 
226 
228  virtual bool shouldWeCloseFile() const {return false;}
229 
230  virtual void write(EventPrincipal const& e, ModuleCallingContext const*) = 0;
231  virtual void beginJob(){}
232  virtual void endJob(){}
233  virtual void writeLuminosityBlock(LuminosityBlockPrincipal const&, ModuleCallingContext const*) = 0;
234  virtual void writeRun(RunPrincipal const&, ModuleCallingContext const*) = 0;
235  virtual void openFile(FileBlock const&) {}
236  virtual bool isFileOpen() const { return true; }
237  virtual void reallyOpenFile() {}
238 
239  virtual void preForkReleaseResources();
240  virtual void postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/);
241 
242  virtual void doBeginRun_(RunPrincipal const&, ModuleCallingContext const*){}
243  virtual void doEndRun_(RunPrincipal const&, ModuleCallingContext const*){}
246  virtual void doRespondToOpenInputFile_(FileBlock const&) {}
247  virtual void doRespondToCloseInputFile_(FileBlock const&) {}
248 
249  void keepThisBranch(BranchDescription const& desc,
250  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
251  std::set<BranchID>& keptProductsInEvent);
252 
255  }
256 
257  void updateBranchParents(EventPrincipal const& ep);
258  void fillDependencyGraph();
259 
260  bool limitReached() const {return remainingEvents_ == 0;}
261  };
262  }
263 }
264 #endif
BranchIDLists const * branchIDLists() const
std::unique_ptr< BranchIDLists > branchIDLists_
ModuleDescription const & description() const
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
ThinnedAssociationsHelper const * thinnedAssociationsHelper() const
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 *)
void keepThisBranch(BranchDescription const &desc, std::map< BranchID, BranchDescription const * > &trueBranchIDToKeptBranchDesc, std::set< BranchID > &keptProductsInEvent)
virtual void doEndRun_(RunPrincipal const &, ModuleCallingContext const *)
bool doBeginRun(RunPrincipal const &rp, EventSetup const &c, ModuleCallingContext const *)
ParameterSetID selectorConfig() const
ProductSelectorRules productSelectorRules_
void selectProducts(ProductRegistry const &preg, ThinnedAssociationsHelper const &)
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::unique_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper_
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 doRegisterThinnedAssociations(ProductRegistry const &, ThinnedAssociationsHelper &)
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:370
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
std::map< BranchID, bool > keepAssociation_