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;
49 
51  bool operator()(std::shared_ptr<ProductHolderBase> const& iObj) { return bool(iObj);}
52  };
53 
54  class Principal : public EDProductGetter {
55  public:
56  typedef std::vector<std::shared_ptr<ProductHolderBase> > ProductHolderCollection;
57  typedef boost::filter_iterator<FilledProductPtr, ProductHolderCollection::const_iterator> const_iterator;
60  typedef std::vector<BasicHandle> BasicHandleVec;
62 
63  typedef std::shared_ptr<ProductHolderBase> SharedProductPtr;
65 
66  Principal(std::shared_ptr<ProductRegistry const> reg,
67  std::shared_ptr<ProductHolderIndexHelper const> productLookup,
68  ProcessConfiguration const& pc,
69  BranchType bt,
70  HistoryAppender* historyAppender);
71 
72  virtual ~Principal();
73 
75 
77 
78  void addScheduledProduct(std::shared_ptr<BranchDescription const> bd);
79 
80  void addSourceProduct(std::shared_ptr<BranchDescription const> bd);
81 
82  void addInputProduct(std::shared_ptr<BranchDescription const> bd);
83 
84  void addUnscheduledProduct(std::shared_ptr<BranchDescription const> bd);
85 
86  void addAliasedProduct(std::shared_ptr<BranchDescription const> bd);
87 
89 
90  void clearPrincipal();
91 
92  void deleteProduct(BranchID const& id);
93 
94  EDProductGetter const* prodGetter() const {return this;}
95 
96  OutputHandle getForOutput(BranchID const& bid, bool getProd, ModuleCallingContext const* mcc) const;
97 
98  // Return a BasicHandle to the product which:
99  // 1. matches the given label, instance, and process
100  // (if process if empty gets the match from the most recent process)
101  // 2. If kindOfType is PRODUCT, then the type of the product matches typeID
102  // 3. If kindOfType is ELEMENT
103  // a. the product is a sequence,
104  // b. the sequence has the nested type 'value_type'
105  // c. typeID is the same as or a public base of
106  // this value_type,
107 
108  BasicHandle getByLabel(KindOfType kindOfType,
109  TypeID const& typeID,
110  InputTag const& inputTag,
111  EDConsumerBase const* consumes,
113  ModuleCallingContext const* mcc) const;
114 
115  BasicHandle getByLabel(KindOfType kindOfType,
116  TypeID const& typeID,
117  std::string const& label,
118  std::string const& instance,
119  std::string const& process,
120  EDConsumerBase const* consumes,
122  ModuleCallingContext const* mcc) const;
123 
124  BasicHandle getByToken(KindOfType kindOfType,
125  TypeID const& typeID,
127  bool skipCurrentProcess,
128  bool& ambiguous,
130  ModuleCallingContext const* mcc) const;
131 
133  bool skipCurrentProcess,
134  ModuleCallingContext const* mcc) const;
135 
136  void getManyByType(TypeID const& typeID,
138  EDConsumerBase const* consumes,
140  ModuleCallingContext const* mcc) const;
141 
143  return *processHistoryPtr_;
144  }
145 
147  return processHistoryID_;
148  }
149 
151 
152  ProductRegistry const& productRegistry() const {return *preg_;}
153 
155 
156  // merge Principals containing different products.
157  void recombine(Principal& other, std::vector<BranchID> const& bids);
158 
159  size_t size() const;
160 
161  // These iterators skip over any null shared pointers
162  const_iterator begin() const {return boost::make_filter_iterator<FilledProductPtr>(productHolders_.begin(), productHolders_.end());}
163  const_iterator end() const {return boost::make_filter_iterator<FilledProductPtr>(productHolders_.end(), productHolders_.end());}
164 
165  Provenance getProvenance(BranchID const& bid,
166  ModuleCallingContext const* mcc) const;
167 
168  void getAllProvenance(std::vector<Provenance const*>& provenances) const;
169 
170  BranchType const& branchType() const {return branchType_;}
171 
172  //This will never return 0 so you can use 0 to mean unset
173  typedef unsigned long CacheIdentifier_t;
175 
176  DelayedReader* reader() const {return reader_;}
177 
179 
180  ProductData const* findProductByTag(TypeID const& typeID, InputTag const& tag, ModuleCallingContext const* mcc) const;
181 
182  // Make my DelayedReader get the EDProduct for a ProductHolder.
183  // The ProductHolder is a cache, and so can be modified through the const
184  // reference.
185  // We do not change the *number* of products through this call, and so
186  // *this is const.
187  void readFromSource(ProductHolderBase const& phb, ModuleCallingContext const* mcc) const {
188  readFromSource_(phb, mcc);
189  }
190 
191  virtual bool unscheduledFill(std::string const& moduleLabel,
193  ModuleCallingContext const* mcc) const = 0;
194 
195  std::vector<unsigned int> const& lookupProcessOrder() const { return lookupProcessOrder_; }
196 
198 
199  bool isComplete() const {return isComplete_();}
200 
201  protected:
202 
203  // ----- Add a new ProductHolder
204  // *this takes ownership of the ProductHolder, which in turn owns its
205  // data.
206  void addProduct_(std::auto_ptr<ProductHolderBase> phb);
207  void addProductOrThrow(std::auto_ptr<ProductHolderBase> phb);
210 
211  // throws if the pointed to product is already in the Principal.
212  void checkUniquenessAndType(WrapperBase const* prod, ProductHolderBase const* productHolder) const;
213 
214  void putOrMerge(std::unique_ptr<WrapperBase> prod, ProductHolderBase const* productHolder) const;
215 
216  void putOrMerge(std::unique_ptr<WrapperBase> prod, ProductProvenance& prov, ProductHolderBase* productHolder);
217 
218  private:
219 
220  virtual WrapperBase const* getIt(ProductID const&) const override;
221  virtual WrapperBase const* getThinnedProduct(ProductID const&, unsigned int&) const override;
222  virtual void getThinnedProducts(ProductID const&,
223  std::vector<WrapperBase const*>&,
224  std::vector<unsigned int>&) const override;
225 
226  void findProducts(std::vector<ProductHolderBase const*> const& holders,
227  TypeID const& typeID,
230  ModuleCallingContext const* mcc) const;
231 
232  ProductData const* findProductByLabel(KindOfType kindOfType,
233  TypeID const& typeID,
234  InputTag const& inputTag,
235  EDConsumerBase const* consumer,
237  ModuleCallingContext const* mcc) const;
238 
239  ProductData const* findProductByLabel(KindOfType kindOfType,
240  TypeID const& typeID,
241  std::string const& label,
242  std::string const& instance,
243  std::string const& process,
244  EDConsumerBase const* consumer,
246  ModuleCallingContext const* mcc) const;
247 
248  virtual void readFromSource_(ProductHolderBase const& /* phb */, ModuleCallingContext const* /* mcc */) const {}
249 
250  virtual bool isComplete_() const {return true;}
251 
252  std::shared_ptr<ProcessHistory const> processHistoryPtr_;
253 
255 
257 
258  // A vector of product holders.
259  ProductHolderCollection productHolders_; // products and provenances are persistent
260 
261  // Pointer to the product registry. There is one entry in the registry
262  // for each EDProduct in the event.
263  std::shared_ptr<ProductRegistry const> preg_;
264  std::shared_ptr<ProductHolderIndexHelper const> productLookup_;
265 
266  std::vector<unsigned int> lookupProcessOrder_;
268 
269  // Pointer to the 'source' that will be used to obtain EDProducts
270  // from the persistent store. This 'source' is owned by the input source.
272 
273  // Used to check for duplicates. The same product instance must not be in more than one product holder
274  mutable std::set<void const*> productPtrs_;
275 
277 
278  // In use cases where the new process should not be appended to
279  // input ProcessHistory, the following pointer should be null.
280  // The Principal does not own this object.
282 
284 
285  };
286 
287  template <typename PROD>
288  inline
289  std::shared_ptr<Wrapper<PROD> const>
290  getProductByTag(Principal const& ep, InputTag const& tag, ModuleCallingContext const* mcc) {
291  TypeID tid = TypeID(typeid(PROD));
292  ProductData const* result = ep.findProductByTag(tid, tag, mcc);
293  if(result == nullptr) {
294  return std::shared_ptr<Wrapper<PROD> const>();
295  }
296 
297  if(!(result->wrapper_->dynamicTypeInfo() == typeid(PROD))) {
298  handleimpl::throwConvertTypeError(typeid(PROD), result->wrapper_->dynamicTypeInfo());
299  }
300  return std::static_pointer_cast<Wrapper<PROD> const>(result->wrapper_);
301  }
302 }
303 #endif
BranchType branchType_
Definition: Principal.h:276
collection_type::const_iterator const_iterator
void putOrMerge(std::unique_ptr< WrapperBase > prod, ProductHolderBase const *productHolder) const
Definition: Principal.cc:852
ProductRegistry const & productRegistry() const
Definition: Principal.h:152
void clearPrincipal()
Definition: Principal.cc:319
virtual void getThinnedProducts(ProductID const &, std::vector< WrapperBase const * > &, std::vector< unsigned int > &) const override
Definition: Principal.cc:831
size_t size() const
Definition: Principal.cc:253
DelayedReader * reader_
Definition: Principal.h:271
std::string ProcessName
Definition: Principal.h:64
HistoryAppender * historyAppender_
Definition: Principal.h:281
ConstProductHolderPtr getProductHolder(BranchID const &oid) const
Definition: Principal.cc:454
std::vector< std::shared_ptr< ProductHolderBase > > ProductHolderCollection
Definition: Principal.h:56
std::shared_ptr< ProductHolderBase > SharedProductPtr
Definition: Principal.h:63
void readFromSource(ProductHolderBase const &phb, ModuleCallingContext const *mcc) const
Definition: Principal.h:187
std::shared_ptr< ProcessHistory const > processHistoryPtr_
Definition: Principal.h:252
const_iterator end() const
Definition: Principal.h:163
ProductHolderBase const * ConstProductHolderPtr
Definition: Principal.h:59
static PFTauRenderPlugin instance
virtual WrapperBase const * getThinnedProduct(ProductID const &, unsigned int &) const override
Definition: Principal.cc:825
bool isComplete() const
Definition: Principal.h:199
ProcessHistoryID processHistoryID_
Definition: Principal.h:254
virtual bool isComplete_() const
Definition: Principal.h:250
void getAllProvenance(std::vector< Provenance const * > &provenances) const
Definition: Principal.cc:792
Provenance getProvenance(BranchID const &bid, ModuleCallingContext const *mcc) const
Definition: Principal.cc:772
CacheIdentifier_t cacheIdentifier() const
Definition: Principal.h:174
unsigned int ProductHolderIndex
void addInputProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:297
bool operator()(std::shared_ptr< ProductHolderBase > const &iObj)
Definition: Principal.h:51
uint16_t size_type
ProcessHistory const & processHistory() const
Definition: Principal.h:142
BranchType
Definition: BranchType.h:11
virtual void readFromSource_(ProductHolderBase const &, ModuleCallingContext const *) const
Definition: Principal.h:248
std::vector< unsigned int > lookupProcessOrder_
Definition: Principal.h:266
void throwConvertTypeError(std::type_info const &expected, std::type_info const &actual)
BasicHandle getByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:470
BasicHandle getByToken(KindOfType kindOfType, TypeID const &typeID, ProductHolderIndex index, bool skipCurrentProcess, bool &ambiguous, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:506
void addScheduledProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:285
ProductData const * findProductByTag(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
Definition: Principal.cc:737
std::shared_ptr< Wrapper< PROD > const > getProductByTag(Principal const &ep, InputTag const &tag, ModuleCallingContext const *mcc)
Definition: Principal.h:290
ConstProductHolderPtr getProductHolderByIndex(ProductHolderIndex const &oid) const
Definition: Principal.cc:463
std::shared_ptr< ProductRegistry const > preg_
Definition: Principal.h:263
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:146
CacheIdentifier_t cacheIdentifier_
Definition: Principal.h:283
BranchType const & branchType() const
Definition: Principal.h:170
std::vector< unsigned int > const & lookupProcessOrder() const
Definition: Principal.h:195
ProductHolderCollection productHolders_
Definition: Principal.h:259
void addProduct_(std::auto_ptr< ProductHolderBase > phb)
Definition: Principal.cc:423
void checkUniquenessAndType(WrapperBase const *prod, ProductHolderBase const *productHolder) const
Definition: Principal.cc:838
void addSourceProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:291
tuple result
Definition: query.py:137
ProcessHistoryID orderProcessHistoryID_
Definition: Principal.h:267
std::shared_ptr< WrapperBase > wrapper_
Definition: ProductData.h:46
ProcessConfiguration const & processConfiguration() const
Definition: Principal.h:150
std::set< void const * > productPtrs_
Definition: Principal.h:274
std::shared_ptr< ProductHolderIndexHelper const > productLookup_
Definition: Principal.h:264
Principal(std::shared_ptr< ProductRegistry const > reg, std::shared_ptr< ProductHolderIndexHelper const > productLookup, ProcessConfiguration const &pc, BranchType bt, HistoryAppender *historyAppender)
Definition: Principal.cc:140
OutputHandle getForOutput(BranchID const &bid, bool getProd, ModuleCallingContext const *mcc) const
Definition: Principal.cc:749
DelayedReader * reader() const
Definition: Principal.h:176
virtual ~Principal()
Definition: Principal.cc:246
void prefetch(ProductHolderIndex index, bool skipCurrentProcess, ModuleCallingContext const *mcc) const
Definition: Principal.cc:529
ProductHolderCollection::size_type size_type
Definition: Principal.h:61
ProcessHistory::const_iterator ProcessNameConstIterator
Definition: Principal.h:58
void addUnscheduledProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:303
const_iterator begin() const
Definition: Principal.h:162
void findProducts(std::vector< ProductHolderBase const * > const &holders, TypeID const &typeID, BasicHandleVec &results, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:611
unsigned long CacheIdentifier_t
Definition: Principal.h:173
virtual WrapperBase const * getIt(ProductID const &) const override
Definition: Principal.cc:819
void addProductOrThrow(std::auto_ptr< ProductHolderBase > phb)
Definition: Principal.cc:437
boost::filter_iterator< FilledProductPtr, ProductHolderCollection::const_iterator > const_iterator
Definition: Principal.h:57
bool adjustToNewProductRegistry(ProductRegistry const &reg)
Definition: Principal.cc:268
ProductData const * findProductByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumer, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:642
#define PROD(A, B)
void adjustIndexesAfterProductRegistryAddition()
Definition: Principal.cc:876
tuple process
Definition: LaserDQM_cfg.py:3
void addAliasedProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:309
void fillPrincipal(ProcessHistoryID const &hist, ProcessHistoryRegistry const &phr, DelayedReader *reader)
Definition: Principal.cc:342
EDProductGetter const * prodGetter() const
Definition: Principal.h:94
void recombine(Principal &other, std::vector< BranchID > const &bids)
Definition: Principal.cc:806
ProcessConfiguration const * processConfiguration_
Definition: Principal.h:256
virtual bool unscheduledFill(std::string const &moduleLabel, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const =0
std::vector< BasicHandle > BasicHandleVec
Definition: Principal.h:60
void getManyByType(TypeID const &typeID, BasicHandleVec &results, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:539
ProductHolderBase * getExistingProduct(BranchID const &branchID)
Definition: Principal.cc:398
ProductHolderIndexHelper const & productLookup() const
Definition: Principal.h:154
void deleteProduct(BranchID const &id)
Definition: Principal.cc:330