CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Principal.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_Principal_h
2 #define FWCore_Framework_Principal_h
3 
4 /*----------------------------------------------------------------------
5 
6 Principal: This is the implementation of the classes responsible
7 for management of EDProducts. It is not seen by reconstruction code.
8 
9 The major internal component of the Principal is the ProductHolder, which
10 contains an EDProduct and its associated Provenance, along with
11 ancillary transient information regarding the two. ProductHolders are handled
12 through shared pointers.
13 
14 The Principal returns BasicHandle, rather than a shared
15 pointer to a ProductHolder, when queried.
16 
17 (Historical note: prior to April 2007 this class was named DataBlockImpl)
18 
19 ----------------------------------------------------------------------*/
32 
33 #include "boost/iterator/filter_iterator.hpp"
34 
35 #include <map>
36 #include <memory>
37 #include <set>
38 #include <string>
39 #include <vector>
40 
41 namespace edm {
42 
43  class HistoryAppender;
44  class ModuleCallingContext;
45  class ProcessHistoryRegistry;
46  class ProductHolderIndexHelper;
47  class EDConsumerBase;
48 
50  bool operator()(std::shared_ptr<ProductHolderBase> const& iObj) { return bool(iObj);}
51  };
52 
53  class Principal : public EDProductGetter {
54  public:
55  typedef std::vector<std::shared_ptr<ProductHolderBase> > ProductHolderCollection;
56  typedef boost::filter_iterator<FilledProductPtr, ProductHolderCollection::const_iterator> const_iterator;
59  typedef std::vector<BasicHandle> BasicHandleVec;
61 
62  typedef std::shared_ptr<ProductHolderBase> SharedProductPtr;
64 
65  Principal(std::shared_ptr<ProductRegistry const> reg,
66  std::shared_ptr<ProductHolderIndexHelper const> productLookup,
67  ProcessConfiguration const& pc,
68  BranchType bt,
69  HistoryAppender* historyAppender);
70 
71  virtual ~Principal();
72 
74 
76 
77  void addScheduledProduct(std::shared_ptr<BranchDescription const> bd);
78 
79  void addSourceProduct(std::shared_ptr<BranchDescription const> bd);
80 
81  void addInputProduct(std::shared_ptr<BranchDescription const> bd);
82 
83  void addUnscheduledProduct(std::shared_ptr<BranchDescription const> bd);
84 
85  void addAliasedProduct(std::shared_ptr<BranchDescription const> bd);
86 
88 
89  void clearPrincipal();
90 
91  void deleteProduct(BranchID const& id);
92 
93  EDProductGetter const* prodGetter() const {return this;}
94 
95  OutputHandle getForOutput(BranchID const& bid, bool getProd, ModuleCallingContext const* mcc) const;
96 
97  // Return a BasicHandle to the product which:
98  // 1. matches the given label, instance, and process
99  // (if process if empty gets the match from the most recent process)
100  // 2. If kindOfType is PRODUCT, then the type of the product matches typeID
101  // 3. If kindOfType is ELEMENT
102  // a. the product is a sequence,
103  // b. the sequence has the nested type 'value_type'
104  // c. typeID is the same as or a public base of
105  // this value_type,
106 
107  BasicHandle getByLabel(KindOfType kindOfType,
108  TypeID const& typeID,
109  InputTag const& inputTag,
110  EDConsumerBase const* consumes,
111  ModuleCallingContext const* mcc) const;
112 
113  BasicHandle getByLabel(KindOfType kindOfType,
114  TypeID const& typeID,
115  std::string const& label,
116  std::string const& instance,
117  std::string const& process,
118  EDConsumerBase const* consumes,
119  ModuleCallingContext const* mcc) const;
120 
121  BasicHandle getByToken(KindOfType kindOfType,
122  TypeID const& typeID,
124  bool skipCurrentProcess,
125  bool& ambiguous,
126  ModuleCallingContext const* mcc) const;
127 
129  bool skipCurrentProcess,
130  ModuleCallingContext const* mcc) const;
131 
132  void getManyByType(TypeID const& typeID,
134  EDConsumerBase const* consumes,
135  ModuleCallingContext const* mcc) const;
136 
138  return *processHistoryPtr_;
139  }
140 
142  return processHistoryID_;
143  }
144 
146 
147  ProductRegistry const& productRegistry() const {return *preg_;}
148 
150 
151  // merge Principals containing different products.
152  void recombine(Principal& other, std::vector<BranchID> const& bids);
153 
154  size_t size() const;
155 
156  // These iterators skip over any null shared pointers
157  const_iterator begin() const {return boost::make_filter_iterator<FilledProductPtr>(productHolders_.begin(), productHolders_.end());}
158  const_iterator end() const {return boost::make_filter_iterator<FilledProductPtr>(productHolders_.end(), productHolders_.end());}
159 
160  Provenance getProvenance(BranchID const& bid,
161  ModuleCallingContext const* mcc) const;
162 
163  void getAllProvenance(std::vector<Provenance const*>& provenances) const;
164 
165  BranchType const& branchType() const {return branchType_;}
166 
167  //This will never return 0 so you can use 0 to mean unset
168  typedef unsigned long CacheIdentifier_t;
170 
171  DelayedReader* reader() const {return reader_;}
172 
174 
175  ProductData const* findProductByTag(TypeID const& typeID, InputTag const& tag, ModuleCallingContext const* mcc) const;
176 
177  // Make my DelayedReader get the EDProduct for a ProductHolder.
178  // The ProductHolder is a cache, and so can be modified through the const
179  // reference.
180  // We do not change the *number* of products through this call, and so
181  // *this is const.
182  void readFromSource(ProductHolderBase const& phb, ModuleCallingContext const* mcc) const {
183  readFromSource_(phb, mcc);
184  }
185 
186  virtual bool unscheduledFill(std::string const& moduleLabel,
187  ModuleCallingContext const* mcc) const = 0;
188 
189  std::vector<unsigned int> const& lookupProcessOrder() const { return lookupProcessOrder_; }
190 
192 
193  bool isComplete() const {return isComplete_();}
194 
195  protected:
196 
197  // ----- Add a new ProductHolder
198  // *this takes ownership of the ProductHolder, which in turn owns its
199  // data.
200  void addProduct_(std::auto_ptr<ProductHolderBase> phb);
201  void addProductOrThrow(std::auto_ptr<ProductHolderBase> phb);
204 
205  // throws if the pointed to product is already in the Principal.
206  void checkUniquenessAndType(WrapperBase const* prod, ProductHolderBase const* productHolder) const;
207 
208  void putOrMerge(std::unique_ptr<WrapperBase> prod, ProductHolderBase const* productHolder) const;
209 
210  void putOrMerge(std::unique_ptr<WrapperBase> prod, ProductProvenance& prov, ProductHolderBase* productHolder);
211 
212  private:
213 
214  virtual WrapperBase const* getIt(ProductID const&) const override;
215  virtual WrapperBase const* getThinnedProduct(ProductID const&, unsigned int&) const override;
216  virtual void getThinnedProducts(ProductID const&,
217  std::vector<WrapperBase const*>&,
218  std::vector<unsigned int>&) const override;
219 
220  void findProducts(std::vector<ProductHolderBase const*> const& holders,
221  TypeID const& typeID,
223  ModuleCallingContext const* mcc) const;
224 
225  ProductData const* findProductByLabel(KindOfType kindOfType,
226  TypeID const& typeID,
227  InputTag const& inputTag,
228  EDConsumerBase const* consumer,
229  ModuleCallingContext const* mcc) const;
230 
231  ProductData const* findProductByLabel(KindOfType kindOfType,
232  TypeID const& typeID,
233  std::string const& label,
234  std::string const& instance,
235  std::string const& process,
236  EDConsumerBase const* consumer,
237  ModuleCallingContext const* mcc) const;
238 
239  virtual void readFromSource_(ProductHolderBase const& /* phb */, ModuleCallingContext const* /* mcc */) const {}
240 
241  virtual bool isComplete_() const {return true;}
242 
243  std::shared_ptr<ProcessHistory const> processHistoryPtr_;
244 
246 
248 
249  // A vector of product holders.
250  ProductHolderCollection productHolders_; // products and provenances are persistent
251 
252  // Pointer to the product registry. There is one entry in the registry
253  // for each EDProduct in the event.
254  std::shared_ptr<ProductRegistry const> preg_;
255  std::shared_ptr<ProductHolderIndexHelper const> productLookup_;
256 
257  std::vector<unsigned int> lookupProcessOrder_;
259 
260  // Pointer to the 'source' that will be used to obtain EDProducts
261  // from the persistent store. This 'source' is owned by the input source.
263 
264  // Used to check for duplicates. The same product instance must not be in more than one product holder
265  mutable std::set<void const*> productPtrs_;
266 
268 
269  // In use cases where the new process should not be appended to
270  // input ProcessHistory, the following pointer should be null.
271  // The Principal does not own this object.
273 
275 
276  };
277 
278  template <typename PROD>
279  inline
280  std::shared_ptr<Wrapper<PROD> const>
281  getProductByTag(Principal const& ep, InputTag const& tag, ModuleCallingContext const* mcc) {
282  TypeID tid = TypeID(typeid(PROD));
283  ProductData const* result = ep.findProductByTag(tid, tag, mcc);
284  if(result == nullptr) {
285  return std::shared_ptr<Wrapper<PROD> const>();
286  }
287 
288  if(!(result->wrapper_->dynamicTypeInfo() == typeid(PROD))) {
289  handleimpl::throwConvertTypeError(typeid(PROD), result->wrapper_->dynamicTypeInfo());
290  }
291  return std::static_pointer_cast<Wrapper<PROD> const>(result->wrapper_);
292  }
293 }
294 #endif
BranchType branchType_
Definition: Principal.h:267
collection_type::const_iterator const_iterator
void putOrMerge(std::unique_ptr< WrapperBase > prod, ProductHolderBase const *productHolder) const
Definition: Principal.cc:839
ProductRegistry const & productRegistry() const
Definition: Principal.h:147
void clearPrincipal()
Definition: Principal.cc:314
virtual void getThinnedProducts(ProductID const &, std::vector< WrapperBase const * > &, std::vector< unsigned int > &) const override
Definition: Principal.cc:818
size_t size() const
Definition: Principal.cc:248
DelayedReader * reader_
Definition: Principal.h:262
std::string ProcessName
Definition: Principal.h:63
HistoryAppender * historyAppender_
Definition: Principal.h:272
ConstProductHolderPtr getProductHolder(BranchID const &oid) const
Definition: Principal.cc:449
std::vector< std::shared_ptr< ProductHolderBase > > ProductHolderCollection
Definition: Principal.h:55
std::shared_ptr< ProductHolderBase > SharedProductPtr
Definition: Principal.h:62
void readFromSource(ProductHolderBase const &phb, ModuleCallingContext const *mcc) const
Definition: Principal.h:182
std::shared_ptr< ProcessHistory const > processHistoryPtr_
Definition: Principal.h:243
const_iterator end() const
Definition: Principal.h:158
ProductHolderBase const * ConstProductHolderPtr
Definition: Principal.h:58
static PFTauRenderPlugin instance
virtual WrapperBase const * getThinnedProduct(ProductID const &, unsigned int &) const override
Definition: Principal.cc:812
bool isComplete() const
Definition: Principal.h:193
ProcessHistoryID processHistoryID_
Definition: Principal.h:245
virtual bool isComplete_() const
Definition: Principal.h:241
void getAllProvenance(std::vector< Provenance const * > &provenances) const
Definition: Principal.cc:779
Provenance getProvenance(BranchID const &bid, ModuleCallingContext const *mcc) const
Definition: Principal.cc:759
void getManyByType(TypeID const &typeID, BasicHandleVec &results, EDConsumerBase const *consumes, ModuleCallingContext const *mcc) const
Definition: Principal.cc:531
CacheIdentifier_t cacheIdentifier() const
Definition: Principal.h:169
unsigned int ProductHolderIndex
void addInputProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:292
bool operator()(std::shared_ptr< ProductHolderBase > const &iObj)
Definition: Principal.h:50
uint16_t size_type
ProcessHistory const & processHistory() const
Definition: Principal.h:137
BranchType
Definition: BranchType.h:11
virtual void readFromSource_(ProductHolderBase const &, ModuleCallingContext const *) const
Definition: Principal.h:239
std::vector< unsigned int > lookupProcessOrder_
Definition: Principal.h:257
void throwConvertTypeError(std::type_info const &expected, std::type_info const &actual)
virtual bool unscheduledFill(std::string const &moduleLabel, ModuleCallingContext const *mcc) const =0
BasicHandle getByToken(KindOfType kindOfType, TypeID const &typeID, ProductHolderIndex index, bool skipCurrentProcess, bool &ambiguous, ModuleCallingContext const *mcc) const
Definition: Principal.cc:499
void addScheduledProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:280
ProductData const * findProductByTag(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
Definition: Principal.cc:725
std::shared_ptr< Wrapper< PROD > const > getProductByTag(Principal const &ep, InputTag const &tag, ModuleCallingContext const *mcc)
Definition: Principal.h:281
ConstProductHolderPtr getProductHolderByIndex(ProductHolderIndex const &oid) const
Definition: Principal.cc:458
std::shared_ptr< ProductRegistry const > preg_
Definition: Principal.h:254
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:141
ProductData const * findProductByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumer, ModuleCallingContext const *mcc) const
Definition: Principal.cc:632
CacheIdentifier_t cacheIdentifier_
Definition: Principal.h:274
BranchType const & branchType() const
Definition: Principal.h:165
std::vector< unsigned int > const & lookupProcessOrder() const
Definition: Principal.h:189
ProductHolderCollection productHolders_
Definition: Principal.h:250
void addProduct_(std::auto_ptr< ProductHolderBase > phb)
Definition: Principal.cc:418
void checkUniquenessAndType(WrapperBase const *prod, ProductHolderBase const *productHolder) const
Definition: Principal.cc:825
void addSourceProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:286
tuple result
Definition: query.py:137
ProcessHistoryID orderProcessHistoryID_
Definition: Principal.h:258
void findProducts(std::vector< ProductHolderBase const * > const &holders, TypeID const &typeID, BasicHandleVec &results, ModuleCallingContext const *mcc) const
Definition: Principal.cc:602
std::shared_ptr< WrapperBase > wrapper_
Definition: ProductData.h:46
ProcessConfiguration const & processConfiguration() const
Definition: Principal.h:145
std::set< void const * > productPtrs_
Definition: Principal.h:265
std::shared_ptr< ProductHolderIndexHelper const > productLookup_
Definition: Principal.h:255
Principal(std::shared_ptr< ProductRegistry const > reg, std::shared_ptr< ProductHolderIndexHelper const > productLookup, ProcessConfiguration const &pc, BranchType bt, HistoryAppender *historyAppender)
Definition: Principal.cc:135
OutputHandle getForOutput(BranchID const &bid, bool getProd, ModuleCallingContext const *mcc) const
Definition: Principal.cc:736
DelayedReader * reader() const
Definition: Principal.h:171
virtual ~Principal()
Definition: Principal.cc:241
void prefetch(ProductHolderIndex index, bool skipCurrentProcess, ModuleCallingContext const *mcc) const
Definition: Principal.cc:521
ProductHolderCollection::size_type size_type
Definition: Principal.h:60
ProcessHistory::const_iterator ProcessNameConstIterator
Definition: Principal.h:57
void addUnscheduledProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:298
const_iterator begin() const
Definition: Principal.h:157
unsigned long CacheIdentifier_t
Definition: Principal.h:168
virtual WrapperBase const * getIt(ProductID const &) const override
Definition: Principal.cc:806
void addProductOrThrow(std::auto_ptr< ProductHolderBase > phb)
Definition: Principal.cc:432
boost::filter_iterator< FilledProductPtr, ProductHolderCollection::const_iterator > const_iterator
Definition: Principal.h:56
bool adjustToNewProductRegistry(ProductRegistry const &reg)
Definition: Principal.cc:263
#define PROD(A, B)
void adjustIndexesAfterProductRegistryAddition()
Definition: Principal.cc:863
BasicHandle getByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumes, ModuleCallingContext const *mcc) const
Definition: Principal.cc:465
tuple process
Definition: LaserDQM_cfg.py:3
void addAliasedProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:304
void fillPrincipal(ProcessHistoryID const &hist, ProcessHistoryRegistry const &phr, DelayedReader *reader)
Definition: Principal.cc:337
EDProductGetter const * prodGetter() const
Definition: Principal.h:93
void recombine(Principal &other, std::vector< BranchID > const &bids)
Definition: Principal.cc:793
ProcessConfiguration const * processConfiguration_
Definition: Principal.h:247
std::vector< BasicHandle > BasicHandleVec
Definition: Principal.h:59
ProductHolderBase * getExistingProduct(BranchID const &branchID)
Definition: Principal.cc:393
ProductHolderIndexHelper const & productLookup() const
Definition: Principal.h:149
void deleteProduct(BranchID const &id)
Definition: Principal.cc:325