test
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 
45 
46 // forward declarations
47 namespace edm {
48 
49  class ModuleCallingContext;
50  class PreallocationConfiguration;
51  class ActivityRegistry;
52  class ProductRegistry;
53  class ThinnedAssociationsHelper;
54 
55  template <typename T> class OutputModuleCommunicatorT;
56 
57  namespace maker {
58  template<typename T> class ModuleHolderT;
59  }
60 
61  namespace one {
62 
64  public:
65  template <typename U> friend class edm::maker::ModuleHolderT;
66  template <typename T> friend class ::edm::WorkerT;
67  template <typename T> friend class ::edm::OutputModuleCommunicatorT;
69 
70  explicit OutputModuleBase(ParameterSet const& pset);
71  virtual ~OutputModuleBase();
72 
73  OutputModuleBase(OutputModuleBase const&) = delete; // Disallow copying and moving
74  OutputModuleBase& operator=(OutputModuleBase const&) = delete; // Disallow copying and moving
75 
78  int maxEvents() const {return maxEvents_;}
79 
82  int remainingEvents() const {return remainingEvents_;}
83 
84  bool selected(BranchDescription const& desc) const;
85 
87  std::string const& processName() const {return process_name_;}
89  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
90 
91  static void fillDescription(ParameterSetDescription & desc);
92  static void fillDescriptions(ConfigurationDescriptions& descriptions);
93  static const std::string& baseType();
95 
96  bool wantAllEvents() const {return wantAllEvents_;}
97 
99 
101 
103  return moduleDescription_;
104  }
105  protected:
106 
107  ModuleDescription const& description() const;
108 
110 
112 
113  void doBeginJob();
114  void doEndJob();
115  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
117  ModuleCallingContext const*);
118  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
119  ModuleCallingContext const*);
120  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
121  ModuleCallingContext const*);
123  ModuleCallingContext const*);
125  ModuleCallingContext const*);
126 
127  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
128  bool anyProductProduced);
129 
130  void configure(OutputModuleDescription const& desc);
131 
132  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
134  }
135 
136  private:
137 
139  std::atomic<int> remainingEvents_;
140 
141  // TODO: Give OutputModule
142  // an interface (protected?) that supplies client code with the
143  // needed functionality *without* giving away implementation
144  // details ... don't just return a reference to keptProducts_, because
145  // we are looking to have the flexibility to change the
146  // implementation of keptProducts_ without modifying clients. When this
147  // change is made, we'll have a one-time-only task of modifying
148  // clients (classes derived from OutputModule) to use the
149  // newly-introduced interface.
150  // TODO: Consider using shared pointers here?
151 
152  // keptProducts_ are pointers to the BranchDescription objects describing
153  // the branches we are to write.
154  //
155  // We do not own the BranchDescriptions to which we point.
157  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
158 
163 
165  std::vector<detail::TriggerResultsBasedEventSelector> selectors_;
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_;
176 
177 
179  std::map<BranchID, bool> keepAssociation_;
180 
183 
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);
199 
200  std::string workerType() const {return "WorkerT<edm::one::OutputModuleBase>";}
201 
203  void doCloseFile();
204 
207  void maybeOpenFile();
208 
210 
212 
213  // Do the end-of-file tasks; this is only called internally, after
214  // the appropriate tests have been done.
215  virtual void reallyCloseFile();
216 
217 
219  virtual bool shouldWeCloseFile() const {return false;}
220 
221  virtual void write(EventPrincipal const& e, ModuleCallingContext const*) = 0;
222  virtual void beginJob(){}
223  virtual void endJob(){}
224  virtual void writeLuminosityBlock(LuminosityBlockPrincipal const&, ModuleCallingContext const*) = 0;
225  virtual void writeRun(RunPrincipal const&, ModuleCallingContext const*) = 0;
226  virtual void openFile(FileBlock const&) {}
227  virtual bool isFileOpen() const { return true; }
228  virtual void reallyOpenFile() {}
229 
230  virtual void preForkReleaseResources();
231  virtual void postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/);
232 
233  virtual void doBeginRun_(RunPrincipal const&, ModuleCallingContext const*){}
234  virtual void doEndRun_(RunPrincipal const&, ModuleCallingContext const*){}
237  virtual void doRespondToOpenInputFile_(FileBlock const&) {}
238  virtual void doRespondToCloseInputFile_(FileBlock const&) {}
239 
240  void keepThisBranch(BranchDescription const& desc,
241  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
242  std::set<BranchID>& keptProductsInEvent);
243 
245  moduleDescription_ = md;
246  }
247 
248  bool limitReached() const {return remainingEvents_ == 0;}
249  };
250  }
251 }
252 #endif
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 *)
edm::propagate_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:374
ProductSelector productSelector_
ParameterSetID selector_config_id_
edm::propagate_const< std::unique_ptr< BranchIDLists > > branchIDLists_
BranchIDLists const * branchIDLists()
bool doEndLuminosityBlock(LuminosityBlockPrincipal const &lbp, EventSetup const &c, ModuleCallingContext const *)
std::map< BranchID, bool > keepAssociation_