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_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 
41 
42 // forward declarations
43 namespace edm {
44 
45  class ModuleCallingContext;
46  class PreallocationConfiguration;
47  class ActivityRegistry;
48  class ProductRegistry;
49  class ThinnedAssociationsHelper;
50 
51  template <typename T> class OutputModuleCommunicatorT;
52 
53  namespace maker {
54  template<typename T> class ModuleHolderT;
55  }
56 
57  namespace global {
58 
60  public:
61  template <typename U> friend class edm::maker::ModuleHolderT;
62  template <typename T> friend class ::edm::WorkerT;
63  template <typename T> friend class ::edm::OutputModuleCommunicatorT;
65 
66  explicit OutputModuleBase(ParameterSet const& pset);
67  virtual ~OutputModuleBase();
68 
69  OutputModuleBase(OutputModuleBase const&) = delete; // Disallow copying and moving
70  OutputModuleBase& operator=(OutputModuleBase const&) = delete; // Disallow copying and moving
71 
74  int maxEvents() const {return maxEvents_;}
75 
78  int remainingEvents() const {return remainingEvents_;}
79 
80  bool selected(BranchDescription const& desc) const;
81 
83  std::string const& processName() const {return process_name_;}
85  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
86 
87  static void fillDescription(ParameterSetDescription & desc);
88  static void fillDescriptions(ConfigurationDescriptions& descriptions);
89  static const std::string& baseType();
91 
92  bool wantAllEvents() const {return wantAllEvents_;}
93 
95 
97 
99  return moduleDescription_;
100  }
101  protected:
102 
103  ModuleDescription const& description() const;
104 
106 
108 
109  void doBeginJob();
110  void doEndJob();
111 
112  void doBeginStream(StreamID id);
113  void doEndStream(StreamID id);
114  void doStreamBeginRun(StreamID id,
115  RunPrincipal& ep,
116  EventSetup const& c,
117  ModuleCallingContext const*);
118  void doStreamEndRun(StreamID id,
119  RunPrincipal& ep,
120  EventSetup const& c,
121  ModuleCallingContext const*);
124  EventSetup const& c,
125  ModuleCallingContext const*);
128  EventSetup const& c,
129  ModuleCallingContext const*);
130 
131  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
133  ModuleCallingContext const*);
134  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
135  ModuleCallingContext const*);
136  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
137  ModuleCallingContext const*);
139  ModuleCallingContext const*);
141  ModuleCallingContext const*);
142 
143  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
144  bool anyProductProduced);
145 
146  void configure(OutputModuleDescription const& desc);
147 
148  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
150  }
151 
152  private:
153 
155  std::atomic<int> remainingEvents_;
156 
157  // TODO: Give OutputModule
158  // an interface (protected?) that supplies client code with the
159  // needed functionality *without* giving away implementation
160  // details ... don't just return a reference to keptProducts_, because
161  // we are looking to have the flexibility to change the
162  // implementation of keptProducts_ without modifying clients. When this
163  // change is made, we'll have a one-time-only task of modifying
164  // clients (classes derived from OutputModule) to use the
165  // newly-introduced interface.
166  // TODO: Consider using shared pointers here?
167 
168  // keptProducts_ are pointers to the BranchDescription objects describing
169  // the branches we are to write.
170  //
171  // We do not own the BranchDescriptions to which we point.
173  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
174 
179 
181  std::vector<detail::TriggerResultsBasedEventSelector> selectors_;
183  // ID of the ParameterSet that configured the event selector
184  // subsystem.
186 
187  // needed because of possible EDAliases.
188  // filled in only if key and value are different.
189  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
190  std::unique_ptr<BranchIDLists> branchIDLists_;
192 
193  std::unique_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
194  std::map<BranchID, bool> keepAssociation_;
195 
196  //------------------------------------------------------------------
197  // private member functions
198  //------------------------------------------------------------------
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::global::OutputModuleBase>";}
211 
213  void doCloseFile();
214 
217  void maybeOpenFile();
218 
220 
222 
223  // Do the end-of-file tasks; this is only called internally, after
224  // the appropriate tests have been done.
225  virtual void reallyCloseFile();
226 
227 
229  virtual bool shouldWeCloseFile() const {return false;}
230 
231  virtual void write(EventPrincipal const& e, ModuleCallingContext const*) = 0;
232  virtual void beginJob(){}
233  virtual void endJob(){}
234  virtual void writeLuminosityBlock(LuminosityBlockPrincipal const&, ModuleCallingContext const*) = 0;
235  virtual void writeRun(RunPrincipal const&, ModuleCallingContext const*) = 0;
236  virtual void openFile(FileBlock const&) {}
237  virtual bool isFileOpen() const { return true; }
238  virtual void reallyOpenFile() {}
239 
240  virtual void preForkReleaseResources();
241  virtual void postForkReacquireResources(unsigned int /*iChildIndex*/, unsigned int /*iNumberOfChildren*/);
242 
243  virtual void preallocStreams(unsigned int){}
244  virtual void doBeginStream_(StreamID){}
245  virtual void doEndStream_(StreamID){}
246  virtual void doStreamBeginRun_(StreamID, Run const&, EventSetup const&){}
247  virtual void doStreamEndRun_(StreamID, Run const&, EventSetup const&){}
248  virtual void doStreamEndRunSummary_(StreamID, Run const&, EventSetup const&){}
252 
253  virtual void doBeginRun_(RunPrincipal const&, ModuleCallingContext const*){}
254  virtual void doBeginRunSummary_(Run const&, EventSetup const&){}
255  virtual void doEndRun_(RunPrincipal const&, ModuleCallingContext const*){}
256  virtual void doEndRunSummary_(Run const&, EventSetup const&){}
261  virtual void doRespondToOpenInputFile_(FileBlock const&) {}
262  virtual void doRespondToCloseInputFile_(FileBlock const&) {}
263 
264  void keepThisBranch(BranchDescription const& desc,
265  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
266  std::set<BranchID>& keptProductsInEvent);
267 
270  }
271 
272  bool limitReached() const {return remainingEvents_ == 0;}
273  };
274  }
275 }
276 #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_
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 &)
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
std::unique_ptr< BranchIDLists > branchIDLists_
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 *)
std::unique_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper_
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:369
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 *)