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 #include "boost/shared_ptr.hpp"
36 
37 #include <map>
38 #include <memory>
39 #include <set>
40 #include <string>
41 #include <vector>
42 
43 namespace edm {
44 
45  class HistoryAppender;
46  class ProductHolderIndexHelper;
47 
49  bool operator()(boost::shared_ptr<ProductHolderBase> const& iObj) { return bool(iObj);}
50  };
51 
52  class Principal : public EDProductGetter {
53  public:
54  typedef std::vector<boost::shared_ptr<ProductHolderBase> > ProductHolderCollection;
55  typedef boost::filter_iterator<FilledProductPtr, ProductHolderCollection::const_iterator> const_iterator;
58  typedef std::vector<BasicHandle> BasicHandleVec;
60 
61  typedef boost::shared_ptr<ProductHolderBase> SharedProductPtr;
63 
64  Principal(boost::shared_ptr<ProductRegistry const> reg,
65  boost::shared_ptr<ProductHolderIndexHelper const> productLookup,
66  ProcessConfiguration const& pc,
67  BranchType bt,
68  HistoryAppender* historyAppender);
69 
70  virtual ~Principal();
71 
73 
75 
76  void addScheduledProduct(boost::shared_ptr<ConstBranchDescription> bd);
77 
78  void addSourceProduct(boost::shared_ptr<ConstBranchDescription> bd);
79 
80  void addInputProduct(boost::shared_ptr<ConstBranchDescription> bd);
81 
82  void addUnscheduledProduct(boost::shared_ptr<ConstBranchDescription> bd);
83 
84  void addAliasedProduct(boost::shared_ptr<ConstBranchDescription> bd);
85 
87 
88  void clearPrincipal();
89 
90  void deleteProduct(BranchID const& id);
91 
92  EDProductGetter const* prodGetter() const {return this;}
93 
94  OutputHandle getForOutput(BranchID const& bid, bool getProd) const;
95 
96  // Return a BasicHandle to the product which:
97  // 1. matches the given label, instance, and process
98  // (if process if empty gets the match from the most recent process)
99  // 2. If kindOfType is PRODUCT, then the type of the product matches typeID
100  // 3. If kindOfType is ELEMENT
101  // a. the product is a sequence,
102  // b. the sequence has the nested type 'value_type'
103  // c. typeID is the same as or a public base of
104  // this value_type,
105 
106  BasicHandle getByLabel(KindOfType kindOfType,
107  TypeID const& typeID,
108  InputTag const& inputTag) const;
109 
110  BasicHandle getByLabel(KindOfType kindOfType,
111  TypeID const& typeID,
112  std::string const& label,
113  std::string const& instance,
114  std::string const& process) const;
115 
116  BasicHandle getByToken(KindOfType kindOfType,
117  TypeID const& typeID,
119  bool skipCurrentProcess,
120  bool& ambiguous) const;
121 
122  void getManyByType(TypeID const& typeID,
123  BasicHandleVec& results) const;
124 
126  return *processHistoryPtr_;
127  }
128 
130  return processHistoryID_;
131  }
132 
134 
135  ProductRegistry const& productRegistry() const {return *preg_;}
136 
138 
139  // merge Principals containing different products.
140  void recombine(Principal& other, std::vector<BranchID> const& bids);
141 
142  size_t size() const;
143 
144  // These iterators skip over any null shared pointers
145  const_iterator begin() const {return boost::make_filter_iterator<FilledProductPtr>(productHolders_.begin(), productHolders_.end());}
146  const_iterator end() const {return boost::make_filter_iterator<FilledProductPtr>(productHolders_.end(), productHolders_.end());}
147 
148  Provenance getProvenance(BranchID const& bid) const;
149 
150  void getAllProvenance(std::vector<Provenance const*>& provenances) const;
151 
152  BranchType const& branchType() const {return branchType_;}
153 
154  DelayedReader* reader() const {return reader_;}
155 
157  bool resolveProd,
158  bool fillOnDemand) const;
159 
160  ProductData const* findProductByTag(TypeID const& typeID, InputTag const& tag) const;
161 
162  // Make my DelayedReader get the EDProduct for a ProductHolder or
163  // trigger unscheduled execution if required. The ProductHolder is
164  // a cache, and so can be modified through the const reference.
165  // We do not change the *number* of products through this call, and so
166  // *this is const.
167  void resolveProduct(ProductHolderBase const& phb, bool fillOnDemand) const {resolveProduct_(phb, fillOnDemand);}
168 
169  virtual bool unscheduledFill(std::string const& moduleLabel) const = 0;
170 
171  std::vector<unsigned int> const& lookupProcessOrder() const { return lookupProcessOrder_; }
172 
174  bool resolveProd,
175  bool fillOnDemand) const;
176 
177  bool isComplete() const {return isComplete_();}
178 
179  protected:
180 
181  // ----- Add a new ProductHolder
182  // *this takes ownership of the ProductHolder, which in turn owns its
183  // data.
184  void addProduct_(std::auto_ptr<ProductHolderBase> phb);
185  void addProductOrThrow(std::auto_ptr<ProductHolderBase> phb);
188 
189  // throws if the pointed to product is already in the Principal.
190  void checkUniquenessAndType(WrapperOwningHolder const& prod, ProductHolderBase const* productHolder) const;
191 
192  void putOrMerge(WrapperOwningHolder const& prod, ProductHolderBase const* productHolder) const;
193 
194  void putOrMerge(WrapperOwningHolder const& prod, ProductProvenance& prov, ProductHolderBase* productHolder);
195 
196  private:
197  virtual WrapperHolder getIt(ProductID const&) const;
198 
199  void findProducts(std::vector<ProductHolderBase const*> const& holders,
200  TypeID const& typeID,
201  BasicHandleVec& results) const;
202 
203  ProductData const* findProductByLabel(KindOfType kindOfType,
204  TypeID const& typeID,
205  InputTag const& inputTag) const;
206 
207  ProductData const* findProductByLabel(KindOfType kindOfType,
208  TypeID const& typeID,
209  std::string const& label,
210  std::string const& instance,
211  std::string const& process) const;
212 
213  // defaults to no-op unless overridden in derived class.
214  virtual void resolveProduct_(ProductHolderBase const&, bool /*fillOnDemand*/) const {}
215 
216  virtual bool isComplete_() const {return true;}
217 
219 
221 
223 
224  // A vector of product holders.
225  ProductHolderCollection productHolders_; // products and provenances are persistent
226 
227  // Pointer to the product registry. There is one entry in the registry
228  // for each EDProduct in the event.
229  boost::shared_ptr<ProductRegistry const> preg_;
230  boost::shared_ptr<ProductHolderIndexHelper const> productLookup_;
231 
232  std::vector<unsigned int> lookupProcessOrder_;
234 
235  // Pointer to the 'source' that will be used to obtain EDProducts
236  // from the persistent store. This 'source' is owned by the input source.
238 
239  // Used to check for duplicates. The same product instance must not be in more than one product holder
240  mutable std::set<void const*> productPtrs_;
241 
243 
244  // In use cases where the new process should not be appended to
245  // input ProcessHistory, the following pointer should be null.
246  // The Principal does not own this object.
248 
250  };
251 
252  template <typename PROD>
253  inline
254  boost::shared_ptr<Wrapper<PROD> const>
255  getProductByTag(Principal const& ep, InputTag const& tag) {
256  TypeID tid = TypeID(typeid(PROD));
257  ProductData const* result = ep.findProductByTag(tid, tag);
258 
259  if(result->getInterface() &&
260  (!(result->getInterface()->dynamicTypeInfo() == typeid(PROD)))) {
262  }
263  return boost::static_pointer_cast<Wrapper<PROD> const>(result->wrapper_);
264  }
265 }
266 #endif
BranchType branchType_
Definition: Principal.h:242
collection_type::const_iterator const_iterator
void resolveProduct(ProductHolderBase const &phb, bool fillOnDemand) const
Definition: Principal.h:167
ProductRegistry const & productRegistry() const
Definition: Principal.h:135
void clearPrincipal()
Definition: Principal.cc:280
boost::shared_ptr< Wrapper< PROD > const > getProductByTag(Principal const &ep, InputTag const &tag)
Definition: Principal.h:255
size_t size() const
Definition: Principal.cc:214
DelayedReader * reader_
Definition: Principal.h:237
std::string ProcessName
Definition: Principal.h:62
WrapperInterfaceBase const * getInterface() const
Definition: ProductData.h:25
void addUnscheduledProduct(boost::shared_ptr< ConstBranchDescription > bd)
Definition: Principal.cc:264
static const ProcessHistory emptyProcessHistory_
Definition: Principal.h:249
HistoryAppender * historyAppender_
Definition: Principal.h:247
ConstProductPtr getProductByIndex(ProductHolderIndex const &oid, bool resolveProd, bool fillOnDemand) const
Definition: Principal.cc:408
std::vector< boost::shared_ptr< ProductHolderBase > > ProductHolderCollection
Definition: Principal.h:54
void putOrMerge(WrapperOwningHolder const &prod, ProductHolderBase const *productHolder) const
Definition: Principal.cc:761
const_iterator end() const
Definition: Principal.h:146
static PFTauRenderPlugin instance
bool isComplete() const
Definition: Principal.h:177
ConstProductPtr getProductHolder(BranchID const &oid, bool resolveProd, bool fillOnDemand) const
Definition: Principal.cc:399
ProcessHistoryID processHistoryID_
Definition: Principal.h:220
virtual bool isComplete_() const
Definition: Principal.h:216
void getAllProvenance(std::vector< Provenance const * > &provenances) const
Definition: Principal.cc:713
void checkUniquenessAndType(WrapperOwningHolder const &prod, ProductHolderBase const *productHolder) const
Definition: Principal.cc:746
void addScheduledProduct(boost::shared_ptr< ConstBranchDescription > bd)
Definition: Principal.cc:246
void getManyByType(TypeID const &typeID, BasicHandleVec &results) const
Definition: Principal.cc:472
boost::shared_ptr< ProductRegistry const > preg_
Definition: Principal.h:229
std::type_info const & dynamicTypeInfo() const
ProcessHistory const * processHistoryPtr_
Definition: Principal.h:218
Principal(boost::shared_ptr< ProductRegistry const > reg, boost::shared_ptr< ProductHolderIndexHelper const > productLookup, ProcessConfiguration const &pc, BranchType bt, HistoryAppender *historyAppender)
Definition: Principal.cc:103
unsigned int ProductHolderIndex
boost::shared_ptr< ProductHolderBase > SharedProductPtr
Definition: Principal.h:61
uint16_t size_type
ProcessHistory const & processHistory() const
Definition: Principal.h:125
BranchType
Definition: BranchType.h:11
void addInputProduct(boost::shared_ptr< ConstBranchDescription > bd)
Definition: Principal.cc:258
std::vector< unsigned int > lookupProcessOrder_
Definition: Principal.h:232
void throwConvertTypeError(std::type_info const &expected, std::type_info const &actual)
void findProducts(std::vector< ProductHolderBase const * > const &holders, TypeID const &typeID, BasicHandleVec &results) const
Definition: Principal.cc:537
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:129
BasicHandle getByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag) const
Definition: Principal.cc:421
boost::shared_ptr< ProductHolderIndexHelper const > productLookup_
Definition: Principal.h:230
BranchType const & branchType() const
Definition: Principal.h:152
std::vector< unsigned int > const & lookupProcessOrder() const
Definition: Principal.h:171
ProductHolderCollection productHolders_
Definition: Principal.h:225
void addProduct_(std::auto_ptr< ProductHolderBase > phb)
Definition: Principal.cc:368
BasicHandle getByToken(KindOfType kindOfType, TypeID const &typeID, ProductHolderIndex index, bool skipCurrentProcess, bool &ambiguous) const
Definition: Principal.cc:451
tuple result
Definition: query.py:137
ProcessHistoryID orderProcessHistoryID_
Definition: Principal.h:233
boost::shared_ptr< void const > wrapper_
Definition: ProductData.h:50
void addAliasedProduct(boost::shared_ptr< ConstBranchDescription > bd)
Definition: Principal.cc:270
OutputHandle getForOutput(BranchID const &bid, bool getProd) const
Definition: Principal.cc:673
ProcessConfiguration const & processConfiguration() const
Definition: Principal.h:133
std::set< void const * > productPtrs_
Definition: Principal.h:240
DelayedReader * reader() const
Definition: Principal.h:154
virtual ~Principal()
Definition: Principal.cc:207
ProductHolderCollection::size_type size_type
Definition: Principal.h:59
ProcessHistory::const_iterator ProcessNameConstIterator
Definition: Principal.h:56
ProductData const * findProductByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag) const
Definition: Principal.cc:581
const_iterator begin() const
Definition: Principal.h:145
virtual WrapperHolder getIt(ProductID const &) const
Definition: Principal.cc:740
bool operator()(boost::shared_ptr< ProductHolderBase > const &iObj)
Definition: Principal.h:49
virtual void resolveProduct_(ProductHolderBase const &, bool) const
Definition: Principal.h:214
void addProductOrThrow(std::auto_ptr< ProductHolderBase > phb)
Definition: Principal.cc:382
boost::filter_iterator< FilledProductPtr, ProductHolderCollection::const_iterator > const_iterator
Definition: Principal.h:55
ProductHolderBase const * ConstProductPtr
Definition: Principal.h:57
virtual bool unscheduledFill(std::string const &moduleLabel) const =0
bool adjustToNewProductRegistry(ProductRegistry const &reg)
Definition: Principal.cc:229
#define PROD(A, B)
ProductData const * findProductByTag(TypeID const &typeID, InputTag const &tag) const
Definition: Principal.cc:661
void fillPrincipal(ProcessHistoryID const &hist, DelayedReader *reader)
Definition: Principal.cc:303
void adjustIndexesAfterProductRegistryAddition()
Definition: Principal.cc:785
void addSourceProduct(boost::shared_ptr< ConstBranchDescription > bd)
Definition: Principal.cc:252
tuple process
Definition: LaserDQM_cfg.py:3
EDProductGetter const * prodGetter() const
Definition: Principal.h:92
Provenance getProvenance(BranchID const &bid) const
Definition: Principal.cc:691
void recombine(Principal &other, std::vector< BranchID > const &bids)
Definition: Principal.cc:727
ProcessConfiguration const * processConfiguration_
Definition: Principal.h:222
std::vector< BasicHandle > BasicHandleVec
Definition: Principal.h:58
ProductHolderBase * getExistingProduct(BranchID const &branchID)
Definition: Principal.cc:353
ProductHolderIndexHelper const & productLookup() const
Definition: Principal.h:137
void deleteProduct(BranchID const &id)
Definition: Principal.cc:291