test
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 ----------------------------------------------------------------------*/
33 
34 #include "boost/iterator/filter_iterator.hpp"
35 
36 #include <map>
37 #include <memory>
38 #include <set>
39 #include <string>
40 #include <vector>
41 
42 namespace edm {
43 
44  class HistoryAppender;
45  class ModuleCallingContext;
46  class ProcessHistoryRegistry;
47  class ProductHolderIndexHelper;
48  class EDConsumerBase;
50 
52  bool operator()(propagate_const<std::shared_ptr<ProductHolderBase>> const& iObj) { return bool(iObj);}
53  };
54 
55  class Principal : public EDProductGetter {
56  public:
57  typedef std::vector<propagate_const<std::shared_ptr<ProductHolderBase>> > ProductHolderCollection;
58  typedef boost::filter_iterator<FilledProductPtr, ProductHolderCollection::const_iterator> const_iterator;
59  typedef boost::filter_iterator<FilledProductPtr, ProductHolderCollection::iterator> iterator;
62  typedef std::vector<BasicHandle> BasicHandleVec;
64 
65  typedef std::shared_ptr<ProductHolderBase> SharedProductPtr;
67 
68  Principal(std::shared_ptr<ProductRegistry const> reg,
69  std::shared_ptr<ProductHolderIndexHelper const> productLookup,
70  ProcessConfiguration const& pc,
71  BranchType bt,
72  HistoryAppender* historyAppender);
73 
74  virtual ~Principal();
75 
77 
79 
80  void addScheduledProduct(std::shared_ptr<BranchDescription const> bd);
81 
82  void addSourceProduct(std::shared_ptr<BranchDescription const> bd);
83 
84  void addInputProduct(std::shared_ptr<BranchDescription const> bd);
85 
86  void addUnscheduledProduct(std::shared_ptr<BranchDescription const> bd);
87 
88  void addAliasedProduct(std::shared_ptr<BranchDescription const> bd);
89 
91 
92  void clearPrincipal();
93 
94  void deleteProduct(BranchID const& id) const;
95 
96  EDProductGetter const* prodGetter() const {return this;}
97 
98  OutputHandle getForOutput(BranchID const& bid, bool getProd, ModuleCallingContext const* mcc) const;
99 
100  // Return a BasicHandle to the product which:
101  // 1. matches the given label, instance, and process
102  // (if process if empty gets the match from the most recent process)
103  // 2. If kindOfType is PRODUCT, then the type of the product matches typeID
104  // 3. If kindOfType is ELEMENT
105  // a. the product is a sequence,
106  // b. the sequence has the nested type 'value_type'
107  // c. typeID is the same as or a public base of
108  // this value_type,
109 
110  BasicHandle getByLabel(KindOfType kindOfType,
111  TypeID const& typeID,
112  InputTag const& inputTag,
113  EDConsumerBase const* consumes,
115  ModuleCallingContext const* mcc) const;
116 
117  BasicHandle getByLabel(KindOfType kindOfType,
118  TypeID const& typeID,
119  std::string const& label,
120  std::string const& instance,
121  std::string const& process,
122  EDConsumerBase const* consumes,
124  ModuleCallingContext const* mcc) const;
125 
126  BasicHandle getByToken(KindOfType kindOfType,
127  TypeID const& typeID,
129  bool skipCurrentProcess,
130  bool& ambiguous,
132  ModuleCallingContext const* mcc) const;
133 
135  bool skipCurrentProcess,
136  ModuleCallingContext const* mcc) const;
137 
138  void getManyByType(TypeID const& typeID,
140  EDConsumerBase const* consumes,
142  ModuleCallingContext const* mcc) const;
143 
145  return *processHistoryPtr_;
146  }
147 
149  return processHistoryID_;
150  }
151 
153 
154  ProductRegistry const& productRegistry() const {return *preg_;}
155 
157 
158  // merge Principals containing different products.
159  void recombine(Principal& other, std::vector<BranchID> const& bids);
160 
162  return const_cast<ProductHolderBase*>( const_cast<const Principal*>(this)->getProductHolder(oid));
163  }
164 
165  size_t size() const;
166 
167  // These iterators skip over any null shared pointers
168  const_iterator begin() const {return boost::make_filter_iterator<FilledProductPtr>(productHolders_.begin(), productHolders_.end());}
169  const_iterator end() const {return boost::make_filter_iterator<FilledProductPtr>(productHolders_.end(), productHolders_.end());}
170 
171  iterator begin() {return boost::make_filter_iterator<FilledProductPtr>(productHolders_.begin(), productHolders_.end());}
172  iterator end() {return boost::make_filter_iterator<FilledProductPtr>(productHolders_.end(), productHolders_.end());}
173 
174  Provenance getProvenance(BranchID const& bid,
175  ModuleCallingContext const* mcc) const;
176 
177  void getAllProvenance(std::vector<Provenance const*>& provenances) const;
178 
179  BranchType const& branchType() const {return branchType_;}
180 
181  //This will never return 0 so you can use 0 to mean unset
182  typedef unsigned long CacheIdentifier_t;
184 
185  DelayedReader* reader() const {return reader_;}
186 
188 
189  ProductData const* findProductByTag(TypeID const& typeID, InputTag const& tag, ModuleCallingContext const* mcc) const;
190 
191  // Make my DelayedReader get the EDProduct for a ProductHolder.
192  // The ProductHolder is a cache, and so can be modified through the const
193  // reference.
194  // We do not change the *number* of products through this call, and so
195  // *this is const.
196  void readFromSource(ProductHolderBase const& phb, ModuleCallingContext const* mcc) const {
197  readFromSource_(phb, mcc);
198  }
199 
201 
202  virtual bool unscheduledFill(std::string const& moduleLabel,
204  ModuleCallingContext const* mcc) const = 0;
205 
206  std::vector<unsigned int> const& lookupProcessOrder() const { return lookupProcessOrder_; }
207 
209 
210  bool isComplete() const {return isComplete_();}
211 
212  protected:
213 
214  // ----- Add a new ProductHolder
215  // *this takes ownership of the ProductHolder, which in turn owns its
216  // data.
217  void addProduct_(std::unique_ptr<ProductHolderBase> phb);
218  void addProductOrThrow(std::unique_ptr<ProductHolderBase> phb);
220  ProductHolderBase const* getExistingProduct(BranchID const& branchID) const;
221  ProductHolderBase const* getExistingProduct(ProductHolderBase const& phb) const;
222 
223  // throws if the pointed to product is already in the Principal.
224  void checkUniquenessAndType(WrapperBase const* prod, ProductHolderBase const* productHolder) const;
225 
226  void putOrMerge(BranchDescription const& bd, std::unique_ptr<WrapperBase> edp) const;
227 
228  private:
229 
230  virtual WrapperBase const* getIt(ProductID const&) const override;
231  virtual WrapperBase const* getThinnedProduct(ProductID const&, unsigned int&) const override;
232  virtual void getThinnedProducts(ProductID const&,
233  std::vector<WrapperBase const*>&,
234  std::vector<unsigned int>&) const override;
235 
236  void findProducts(std::vector<ProductHolderBase const*> const& holders,
237  TypeID const& typeID,
240  ModuleCallingContext const* mcc) const;
241 
242  ProductData const* findProductByLabel(KindOfType kindOfType,
243  TypeID const& typeID,
244  InputTag const& inputTag,
245  EDConsumerBase const* consumer,
247  ModuleCallingContext const* mcc) const;
248 
249  ProductData const* findProductByLabel(KindOfType kindOfType,
250  TypeID const& typeID,
251  std::string const& label,
252  std::string const& instance,
253  std::string const& process,
254  EDConsumerBase const* consumer,
256  ModuleCallingContext const* mcc) const;
257 
258  virtual void readFromSource_(ProductHolderBase const& /* phb */, ModuleCallingContext const* /* mcc */) const {}
259 
261 
262  virtual bool isComplete_() const {return true;}
263 
264  void putOrMerge(std::unique_ptr<WrapperBase> prod, ProductHolderBase const* productHolder) const;
265 
266  std::shared_ptr<ProcessHistory const> processHistoryPtr_;
267 
269 
271 
272  // A vector of product holders.
273  ProductHolderCollection productHolders_; // products and provenances are persistent
274 
275  // Pointer to the product registry. There is one entry in the registry
276  // for each EDProduct in the event.
277  std::shared_ptr<ProductRegistry const> preg_;
278  std::shared_ptr<ProductHolderIndexHelper const> productLookup_;
279 
280  std::vector<unsigned int> lookupProcessOrder_;
282 
283  // Pointer to the 'source' that will be used to obtain EDProducts
284  // from the persistent store. This 'source' is owned by the input source.
286 
287  // Used to check for duplicates. The same product instance must not be in more than one product holder
288  mutable std::set<void const*> productPtrs_;
289 
291 
292  // In use cases where the new process should not be appended to
293  // input ProcessHistory, the following pointer should be null.
294  // The Principal does not own this object.
296 
298 
299  };
300 
301  template <typename PROD>
302  inline
303  std::shared_ptr<Wrapper<PROD> const>
304  getProductByTag(Principal const& ep, InputTag const& tag, ModuleCallingContext const* mcc) {
305  TypeID tid = TypeID(typeid(PROD));
306  ProductData const* result = ep.findProductByTag(tid, tag, mcc);
307  if(result == nullptr) {
308  return std::shared_ptr<Wrapper<PROD> const>();
309  }
310 
311  if(!(result->wrapper()->dynamicTypeInfo() == typeid(PROD))) {
313  }
314  return std::static_pointer_cast<Wrapper<PROD> const>(result->sharedConstWrapper());
315  }
316 }
317 #endif
BranchType branchType_
Definition: Principal.h:290
collection_type::const_iterator const_iterator
ProductRegistry const & productRegistry() const
Definition: Principal.h:154
void clearPrincipal()
Definition: Principal.cc:321
virtual void getThinnedProducts(ProductID const &, std::vector< WrapperBase const * > &, std::vector< unsigned int > &) const override
Definition: Principal.cc:836
size_t size() const
Definition: Principal.cc:255
DelayedReader * reader_
Definition: Principal.h:285
std::string ProcessName
Definition: Principal.h:66
iterator begin()
Definition: Principal.h:171
ConstProductHolderPtr getProductHolder(BranchID const &oid) const
Definition: Principal.cc:460
std::shared_ptr< ProductHolderBase > SharedProductPtr
Definition: Principal.h:65
std::type_info const & dynamicTypeInfo() const
Definition: WrapperBase.h:38
void readFromSource(ProductHolderBase const &phb, ModuleCallingContext const *mcc) const
Definition: Principal.h:196
std::shared_ptr< ProcessHistory const > processHistoryPtr_
Definition: Principal.h:266
void resolveProductImmediately(ProductHolderBase &phb)
Definition: Principal.cc:915
const_iterator end() const
Definition: Principal.h:169
ProductHolderBase const * ConstProductHolderPtr
Definition: Principal.h:61
static PFTauRenderPlugin instance
virtual WrapperBase const * getThinnedProduct(ProductID const &, unsigned int &) const override
Definition: Principal.cc:830
bool isComplete() const
Definition: Principal.h:210
ProcessHistoryID processHistoryID_
Definition: Principal.h:268
virtual bool isComplete_() const
Definition: Principal.h:262
void getAllProvenance(std::vector< Provenance const * > &provenances) const
Definition: Principal.cc:798
Provenance getProvenance(BranchID const &bid, ModuleCallingContext const *mcc) const
Definition: Principal.cc:778
WrapperBase const * wrapper() const
Definition: ProductData.h:32
ProductHolderBase * getModifiableProductHolder(BranchID const &oid)
Definition: Principal.h:161
CacheIdentifier_t cacheIdentifier() const
Definition: Principal.h:183
unsigned int ProductHolderIndex
void addInputProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:299
edm::propagate_const< HistoryAppender * > historyAppender_
Definition: Principal.h:295
uint16_t size_type
ProcessHistory const & processHistory() const
Definition: Principal.h:144
BranchType
Definition: BranchType.h:11
virtual void readFromSource_(ProductHolderBase const &, ModuleCallingContext const *) const
Definition: Principal.h:258
tuple result
Definition: mps_fire.py:83
void readAllFromSourceAndMergeImmediately()
Definition: Principal.cc:904
std::vector< unsigned int > lookupProcessOrder_
Definition: Principal.h:280
std::vector< propagate_const< std::shared_ptr< ProductHolderBase > > > ProductHolderCollection
Definition: Principal.h:57
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:476
BasicHandle getByToken(KindOfType kindOfType, TypeID const &typeID, ProductHolderIndex index, bool skipCurrentProcess, bool &ambiguous, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:512
void addScheduledProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:287
ProductData const * findProductByTag(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
Definition: Principal.cc:743
std::shared_ptr< Wrapper< PROD > const > getProductByTag(Principal const &ep, InputTag const &tag, ModuleCallingContext const *mcc)
Definition: Principal.h:304
ConstProductHolderPtr getProductHolderByIndex(ProductHolderIndex const &oid) const
Definition: Principal.cc:469
std::shared_ptr< ProductRegistry const > preg_
Definition: Principal.h:277
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:148
CacheIdentifier_t cacheIdentifier_
Definition: Principal.h:297
BranchType const & branchType() const
Definition: Principal.h:179
std::vector< unsigned int > const & lookupProcessOrder() const
Definition: Principal.h:206
ProductHolderCollection productHolders_
Definition: Principal.h:273
void putOrMerge(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp) const
Definition: Principal.cc:869
void checkUniquenessAndType(WrapperBase const *prod, ProductHolderBase const *productHolder) const
Definition: Principal.cc:843
void addSourceProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:293
tuple results
Definition: mps_update.py:44
ProcessHistoryID orderProcessHistoryID_
Definition: Principal.h:281
ProcessConfiguration const & processConfiguration() const
Definition: Principal.h:152
std::set< void const * > productPtrs_
Definition: Principal.h:288
std::shared_ptr< ProductHolderIndexHelper const > productLookup_
Definition: Principal.h:278
Principal(std::shared_ptr< ProductRegistry const > reg, std::shared_ptr< ProductHolderIndexHelper const > productLookup, ProcessConfiguration const &pc, BranchType bt, HistoryAppender *historyAppender)
Definition: Principal.cc:142
OutputHandle getForOutput(BranchID const &bid, bool getProd, ModuleCallingContext const *mcc) const
Definition: Principal.cc:755
DelayedReader * reader() const
Definition: Principal.h:185
virtual ~Principal()
Definition: Principal.cc:248
void prefetch(ProductHolderIndex index, bool skipCurrentProcess, ModuleCallingContext const *mcc) const
Definition: Principal.cc:535
ProductHolderCollection::size_type size_type
Definition: Principal.h:63
ProcessHistory::const_iterator ProcessNameConstIterator
Definition: Principal.h:60
void addUnscheduledProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:305
bool operator()(propagate_const< std::shared_ptr< ProductHolderBase >> const &iObj)
Definition: Principal.h:52
const_iterator begin() const
Definition: Principal.h:168
void addProduct_(std::unique_ptr< ProductHolderBase > phb)
Definition: Principal.cc:429
iterator end()
Definition: Principal.h:172
void findProducts(std::vector< ProductHolderBase const * > const &holders, TypeID const &typeID, BasicHandleVec &results, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:617
void addProductOrThrow(std::unique_ptr< ProductHolderBase > phb)
Definition: Principal.cc:443
unsigned long CacheIdentifier_t
Definition: Principal.h:182
virtual WrapperBase const * getIt(ProductID const &) const override
Definition: Principal.cc:824
boost::filter_iterator< FilledProductPtr, ProductHolderCollection::const_iterator > const_iterator
Definition: Principal.h:58
bool adjustToNewProductRegistry(ProductRegistry const &reg)
Definition: Principal.cc:270
ProductData const * findProductByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumer, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:648
#define PROD(A, B)
void adjustIndexesAfterProductRegistryAddition()
Definition: Principal.cc:883
tuple process
Definition: LaserDQM_cfg.py:3
void addAliasedProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:311
void fillPrincipal(ProcessHistoryID const &hist, ProcessHistoryRegistry const &phr, DelayedReader *reader)
Definition: Principal.cc:344
EDProductGetter const * prodGetter() const
Definition: Principal.h:96
void recombine(Principal &other, std::vector< BranchID > const &bids)
Definition: Principal.cc:812
ProcessConfiguration const * processConfiguration_
Definition: Principal.h:270
boost::filter_iterator< FilledProductPtr, ProductHolderCollection::iterator > iterator
Definition: Principal.h:59
virtual bool unscheduledFill(std::string const &moduleLabel, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const =0
std::shared_ptr< WrapperBase const > sharedConstWrapper() const
Definition: ProductData.h:35
std::vector< BasicHandle > BasicHandleVec
Definition: Principal.h:62
void getManyByType(TypeID const &typeID, BasicHandleVec &results, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:545
ProductHolderBase * getExistingProduct(BranchID const &branchID)
Definition: Principal.cc:400
void deleteProduct(BranchID const &id) const
Definition: Principal.cc:332
ProductHolderIndexHelper const & productLookup() const
Definition: Principal.h:156