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