CMS 3D CMS Logo

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 
29 // user include files
34 
44 
45 // forward declarations
46 namespace edm {
47 
48  class ModuleCallingContext;
49  class PreallocationConfiguration;
50  class ActivityRegistry;
51  class ProductRegistry;
52  class ThinnedAssociationsHelper;
53  class SubProcessParentageHelper;
54  class WaitingTask;
55 
56  template <typename T> class OutputModuleCommunicatorT;
57 
58  namespace maker {
59  template<typename T> class ModuleHolderT;
60  }
61 
62  namespace one {
63 
65  public:
66  template <typename U> friend class edm::maker::ModuleHolderT;
67  template <typename T> friend class ::edm::WorkerT;
68  template <typename T> friend class ::edm::OutputModuleCommunicatorT;
70 
71  explicit OutputModuleBase(ParameterSet const& pset);
72  ~OutputModuleBase() override;
73 
74  OutputModuleBase(OutputModuleBase const&) = delete; // Disallow copying and moving
75  OutputModuleBase& operator=(OutputModuleBase const&) = delete; // Disallow copying and moving
76 
79  int maxEvents() const {return maxEvents_;}
80 
83  int remainingEvents() const {return remainingEvents_;}
84 
85  bool selected(BranchDescription const& desc) const;
86 
87  void selectProducts(ProductRegistry const& preg, ThinnedAssociationsHelper const&);
88  std::string const& processName() const {return process_name_;}
89  SelectedProductsForBranchType const& keptProducts() const {return keptProducts_;}
90  std::array<bool, NumBranchTypes> const& hasNewlyDroppedBranch() const {return hasNewlyDroppedBranch_;}
91 
92  static void fillDescription(ParameterSetDescription & desc);
93  static void fillDescriptions(ConfigurationDescriptions& descriptions);
94  static const std::string& baseType();
95  static void prevalidate(ConfigurationDescriptions& );
96 
97  //Output modules always need writeRun and writeLumi to be called
98  virtual bool wantsGlobalRuns() const = 0;
99  virtual bool wantsGlobalLuminosityBlocks() const = 0;
100  bool wantsStreamRuns() const {return false;}
101  bool wantsStreamLuminosityBlocks() const {return false;};
102 
103  SerialTaskQueue* globalRunsQueue() { return &runQueue_;}
104  SerialTaskQueue* globalLuminosityBlocksQueue() { return &luminosityBlockQueue_;}
106  return resourcesAcquirer_;
107  }
108 
109  bool wantAllEvents() const {return wantAllEvents_;}
110 
111  BranchIDLists const* branchIDLists();
112 
113  ThinnedAssociationsHelper const* thinnedAssociationsHelper() const;
114 
116  return subProcessParentageHelper_;
117  }
118 
120  return moduleDescription_;
121  }
122  protected:
123 
124  ModuleDescription const& description() const;
125 
126  ParameterSetID selectorConfig() const { return selector_config_id_; }
127 
128  void doPreallocate(PreallocationConfiguration const&);
129 
130  void doBeginJob();
131  void doEndJob();
132  bool doEvent(EventPrincipal const& ep, EventSetup const& c,
134  ModuleCallingContext const*);
135  bool doBeginRun(RunPrincipal const& rp, EventSetup const& c,
136  ModuleCallingContext const*);
137  bool doEndRun(RunPrincipal const& rp, EventSetup const& c,
138  ModuleCallingContext const*);
139  bool doBeginLuminosityBlock(LuminosityBlockPrincipal const& lbp, EventSetup const& c,
140  ModuleCallingContext const*);
141  bool doEndLuminosityBlock(LuminosityBlockPrincipal const& lbp, EventSetup const& c,
142  ModuleCallingContext const*);
143 
144  void setEventSelectionInfo(std::map<std::string, std::vector<std::pair<std::string, int> > > const& outputModulePathPositions,
145  bool anyProductProduced);
146 
147  void configure(OutputModuleDescription const& desc);
148 
149  std::map<BranchID::value_type, BranchID::value_type> const& droppedBranchIDToKeptBranchID() {
150  return droppedBranchIDToKeptBranchID_;
151  }
152 
153  private:
154 
156  std::atomic<int> remainingEvents_;
157 
158  // TODO: Give OutputModule
159  // an interface (protected?) that supplies client code with the
160  // needed functionality *without* giving away implementation
161  // details ... don't just return a reference to keptProducts_, because
162  // we are looking to have the flexibility to change the
163  // implementation of keptProducts_ without modifying clients. When this
164  // change is made, we'll have a one-time-only task of modifying
165  // clients (classes derived from OutputModule) to use the
166  // newly-introduced interface.
167  // TODO: Consider using shared pointers here?
168 
169  // keptProducts_ are pointers to the BranchDescription objects describing
170  // the branches we are to write.
171  //
172  // We do not own the BranchDescriptions to which we point.
174  std::array<bool, NumBranchTypes> hasNewlyDroppedBranch_;
175 
180 
182  std::vector<detail::TriggerResultsBasedEventSelector> selectors_;
184  // ID of the ParameterSet that configured the event selector
185  // subsystem.
187 
188  // needed because of possible EDAliases.
189  // filled in only if key and value are different.
190  std::map<BranchID::value_type, BranchID::value_type> droppedBranchIDToKeptBranchID_;
193 
195 
197  std::map<BranchID, bool> keepAssociation_;
198 
202 
203  //------------------------------------------------------------------
204  // private member functions
205  //------------------------------------------------------------------
206 
207  virtual SharedResourcesAcquirer createAcquirer();
208 
209  void doWriteRun(RunPrincipal const& rp, ModuleCallingContext const*);
210  void doWriteLuminosityBlock(LuminosityBlockPrincipal const& lbp, ModuleCallingContext const*);
211  void doOpenFile(FileBlock const& fb);
212  void doRespondToOpenInputFile(FileBlock const& fb);
213  void doRespondToCloseInputFile(FileBlock const& fb);
216 
217  std::string workerType() const {return "WorkerT<edm::one::OutputModuleBase>";}
218 
220  void doCloseFile();
221 
223 
224  bool needToRunSelection() const;
225  std::vector<ProductResolverIndexAndSkipBit> productsUsedBySelection() const;
226  bool prePrefetchSelection(StreamID id, EventPrincipal const&, ModuleCallingContext const*);
227 
228  // Do the end-of-file tasks; this is only called internally, after
229  // the appropriate tests have been done.
230  virtual void reallyCloseFile();
231 
232 
234  virtual bool shouldWeCloseFile() const {return false;}
235 
236  virtual void write(EventForOutput const&) = 0;
237  virtual void preActionBeforeRunEventAsync(WaitingTask* iTask, ModuleCallingContext const& iModuleCallingContext, Principal const& iPrincipal) const {}
238 
239  virtual void beginJob(){}
240  virtual void endJob(){}
241  virtual void writeLuminosityBlock(LuminosityBlockForOutput const&) = 0;
242  virtual void writeRun(RunForOutput const&) = 0;
243  virtual void openFile(FileBlock const&) {}
244  virtual bool isFileOpen() const { return true; }
245 
246  virtual void doBeginRun_(RunForOutput const&){}
247  virtual void doEndRun_(RunForOutput const& ){}
250  virtual void doRespondToOpenInputFile_(FileBlock const&) {}
251  virtual void doRespondToCloseInputFile_(FileBlock const&) {}
252 
253  bool hasAcquire() const { return false; }
254  bool hasAccumulator() const { return false; }
255 
256  void keepThisBranch(BranchDescription const& desc,
257  std::map<BranchID, BranchDescription const*>& trueBranchIDToKeptBranchDesc,
258  std::set<BranchID>& keptProductsInEvent);
259 
261  moduleDescription_ = md;
262  }
263 
264  bool limitReached() const {return remainingEvents_ == 0;}
265  };
266  }
267 }
268 #endif
SubProcessParentageHelper const * subProcessParentageHelper() const
SharedResourcesAcquirer & sharedResourcesAcquirer()
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
SelectedProductsForBranchType keptProducts_
ModuleDescription moduleDescription_
std::array< SelectedProducts, NumBranchTypes > SelectedProductsForBranchType
SubProcessParentageHelper const * subProcessParentageHelper_
virtual void preActionBeforeRunEventAsync(WaitingTask *iTask, ModuleCallingContext const &iModuleCallingContext, Principal const &iPrincipal) const
void registerProductsAndCallbacks(OutputModuleBase const *, ProductRegistry const *)
SerialTaskQueue luminosityBlockQueue_
ParameterSetID selectorConfig() const
virtual void doBeginLuminosityBlock_(LuminosityBlockForOutput const &)
ProductSelectorRules productSelectorRules_
virtual void doRespondToCloseInputFile_(FileBlock const &)
virtual void doRespondToOpenInputFile_(FileBlock const &)
virtual void openFile(FileBlock const &)
virtual void doEndRun_(RunForOutput const &)
std::atomic< int > remainingEvents_
bool wantsStreamLuminosityBlocks() const
std::map< BranchID::value_type, BranchID::value_type > const & droppedBranchIDToKeptBranchID()
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
SelectedProductsForBranchType const & keptProducts() const
SerialTaskQueue * globalRunsQueue()
std::string workerType() const
edm::propagate_const< std::unique_ptr< ThinnedAssociationsHelper > > thinnedAssociationsHelper_
std::array< bool, NumBranchTypes > const & hasNewlyDroppedBranch() const
SharedResourcesAcquirer resourcesAcquirer_
SerialTaskQueue * globalLuminosityBlocksQueue()
std::array< bool, NumBranchTypes > hasNewlyDroppedBranch_
std::vector< detail::TriggerResultsBasedEventSelector > selectors_
void setModuleDescription(ModuleDescription const &md)
const ModuleDescription & moduleDescription() const
virtual void doEndLuminosityBlock_(LuminosityBlockForOutput const &)
void doRegisterThinnedAssociations(ProductRegistry const &, ThinnedAssociationsHelper &)
std::string const & processName() const
virtual void doBeginRun_(RunForOutput const &)
HLT enums.
BranchIDLists const * origBranchIDLists_
virtual bool shouldWeCloseFile() const
Ask the OutputModule if we should end the current file.
def write(self, setup)
virtual bool isFileOpen() const
std::map< BranchID::value_type, BranchID::value_type > droppedBranchIDToKeptBranchID_
ProductSelector productSelector_
ParameterSetID selector_config_id_
edm::propagate_const< std::unique_ptr< BranchIDLists > > branchIDLists_
std::map< BranchID, bool > keepAssociation_