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
35 
44 
45 // forward declarations
46 namespace edm {
47 
48  class ModuleCallingContext;
49  class PreallocationConfiguration;
50  class ActivityRegistry;
51  class ProductRegistry;
52  class ThinnedAssociationsHelper;
53 
54  template <typename T> class OutputModuleCommunicatorT;
55 
56  namespace maker {
57  template<typename T> class ModuleHolderT;
58  }
59 
60  namespace one {
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 
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 
95  bool wantAllEvents() const {return wantAllEvents_;}
96 
98 
100 
102  return moduleDescription_;
103  }
104  protected:
105 
106  ModuleDescription const& description() const;
107 
109 
111 
112  void doBeginJob();
113  void doEndJob();
114  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
116  ModuleCallingContext const*);
117  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
118  ModuleCallingContext const*);
119  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
120  ModuleCallingContext const*);
122  ModuleCallingContext const*);
124  ModuleCallingContext const*);
125 
126  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
127  bool anyProductProduced);
128 
129  void configure(OutputModuleDescription const& desc);
130 
131  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
133  }
134 
135  private:
136 
138  std::atomic<int> remainingEvents_;
139 
140  // TODO: Give OutputModule
141  // an interface (protected?) that supplies client code with the
142  // needed functionality *without* giving away implementation
143  // details ... don't just return a reference to keptProducts_, because
144  // we are looking to have the flexibility to change the
145  // implementation of keptProducts_ without modifying clients. When this
146  // change is made, we'll have a one-time-only task of modifying
147  // clients (classes derived from OutputModule) to use the
148  // newly-introduced interface.
149  // TODO: Consider using shared pointers here?
150 
151  // keptProducts_ are pointers to the BranchDescription objects describing
152  // the branches we are to write.
153  //
154  // We do not own the BranchDescriptions to which we point.
156  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
157 
162 
164  std::vector<detail::TriggerResultsBasedEventSelector> selectors_;
166  // ID of the ParameterSet that configured the event selector
167  // subsystem.
169 
170  // needed because of possible EDAliases.
171  // filled in only if key and value are different.
172  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
173  std::unique_ptr<BranchIDLists> branchIDLists_;
175 
176  std::unique_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
177  std::map<BranchID, bool> keepAssociation_;
178 
181 
182  //------------------------------------------------------------------
183  // private member functions
184  //------------------------------------------------------------------
185 
187 
188  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const*);
190  void doOpenFile(FileBlock const& fb);
194  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 
210 
211  // Do the end-of-file tasks; this is only called internally, after
212  // the appropriate tests have been done.
213  virtual void reallyCloseFile();
214 
215 
217  virtual bool shouldWeCloseFile() const {return false;}
218 
219  virtual void write(EventPrincipal const& e, ModuleCallingContext const*) = 0;
220  virtual void beginJob(){}
221  virtual void endJob(){}
222  virtual void writeLuminosityBlock(LuminosityBlockPrincipal const&, ModuleCallingContext const*) = 0;
223  virtual void writeRun(RunPrincipal const&, ModuleCallingContext const*) = 0;
224  virtual void openFile(FileBlock const&) {}
225  virtual bool isFileOpen() const { return true; }
226  virtual void reallyOpenFile() {}
227 
228  virtual void preForkReleaseResources();
229  virtual void postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/);
230 
231  virtual void doBeginRun_(RunPrincipal const&, ModuleCallingContext const*){}
232  virtual void doEndRun_(RunPrincipal const&, ModuleCallingContext const*){}
235  virtual void doRespondToOpenInputFile_(FileBlock const&) {}
236  virtual void doRespondToCloseInputFile_(FileBlock const&) {}
237 
238  void keepThisBranch(BranchDescription const& desc,
239  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
240  std::set<BranchID>& keptProductsInEvent);
241 
244  }
245 
246  bool limitReached() const {return remainingEvents_ == 0;}
247  };
248  }
249 }
250 #endif
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 *)
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 *)
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 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
bool prePrefetchSelection(StreamID id, EventPrincipal const &, ModuleCallingContext 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)
std::vector< detail::TriggerResultsBasedEventSelector > selectors_
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
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 doPreallocate(PreallocationConfiguration const &)
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
ProductSelector productSelector_
ParameterSetID selector_config_id_
BranchIDLists const * branchIDLists()
bool doEndLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *)
std::map< BranchID, bool > keepAssociation_