CMS 3D CMS Logo

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 ProductResolver, which
10 contains an EDProduct and its associated Provenance, along with
11 ancillary transient information regarding the two. ProductResolvers are handled
12 through shared pointers.
13 
14 The Principal returns BasicHandle, rather than a shared
15 pointer to a ProductResolver, 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 MergeableRunProductMetadata;
45  class ModuleCallingContext;
46  class ProcessHistoryRegistry;
47  class ProductResolverIndexHelper;
48  class EDConsumerBase;
50  class InputProductResolver;
51  class WaitingTask;
53 
55  bool operator()(propagate_const<std::shared_ptr<ProductResolverBase>> const& iObj) { return bool(iObj);}
56  };
57 
58  class Principal : public EDProductGetter {
59  public:
60  typedef std::vector<propagate_const<std::shared_ptr<ProductResolverBase>> > ProductResolverCollection;
61  typedef boost::filter_iterator<FilledProductPtr, ProductResolverCollection::const_iterator> const_iterator;
62  typedef boost::filter_iterator<FilledProductPtr, ProductResolverCollection::iterator> iterator;
65  typedef std::vector<BasicHandle> BasicHandleVec;
67 
68  typedef std::shared_ptr<ProductResolverBase> SharedProductPtr;
70 
71  Principal(std::shared_ptr<ProductRegistry const> reg,
72  std::shared_ptr<ProductResolverIndexHelper const> productLookup,
73  ProcessConfiguration const& pc,
74  BranchType bt,
75  HistoryAppender* historyAppender,
76  bool isForPrimaryProcess = true);
77 
78  ~Principal() override;
79 
80  bool adjustToNewProductRegistry(ProductRegistry const& reg);
81 
82  void adjustIndexesAfterProductRegistryAddition();
83 
84  void fillPrincipal(ProcessHistoryID const& hist, ProcessHistoryRegistry const& phr, DelayedReader* reader);
85 
86  void clearPrincipal();
87 
88  void setupUnscheduled(UnscheduledConfigurator const&);
89 
90  void deleteProduct(BranchID const& id) const;
91 
92  EDProductGetter const* prodGetter() const {return this;}
93 
94  // Return a BasicHandle to the product which:
95  // 1. matches the given label, instance, and process
96  // (if process if empty gets the match from the most recent process)
97  // 2. If kindOfType is PRODUCT, then the type of the product matches typeID
98  // 3. If kindOfType is ELEMENT
99  // a. the product is a sequence,
100  // b. the sequence has the nested type 'value_type'
101  // c. typeID is the same as or a public base of
102  // this value_type,
103 
104  BasicHandle getByLabel(KindOfType kindOfType,
105  TypeID const& typeID,
106  InputTag const& inputTag,
107  EDConsumerBase const* consumes,
109  ModuleCallingContext const* mcc) const;
110 
111  BasicHandle getByLabel(KindOfType kindOfType,
112  TypeID const& typeID,
113  std::string const& label,
114  std::string const& instance,
115  std::string const& process,
116  EDConsumerBase const* consumes,
118  ModuleCallingContext const* mcc) const;
119 
120  BasicHandle getByToken(KindOfType kindOfType,
121  TypeID const& typeID,
123  bool skipCurrentProcess,
124  bool& ambiguous,
126  ModuleCallingContext const* mcc) const;
127 
128  void prefetchAsync(WaitingTask* waitTask,
129  ProductResolverIndex index,
130  bool skipCurrentProcess,
131  ServiceToken const& token,
132  ModuleCallingContext const* mcc) const;
133 
134  void getManyByType(TypeID const& typeID,
135  BasicHandleVec& results,
136  EDConsumerBase const* consumes,
138  ModuleCallingContext const* mcc) const;
139 
141  return *processHistoryPtr_;
142  }
143 
145  return processHistoryID_;
146  }
147 
148  ProcessConfiguration const& processConfiguration() const {return *processConfiguration_;}
149 
150  ProductRegistry const& productRegistry() const {return *preg_;}
151 
152  ProductResolverIndexHelper const& productLookup() const {return *productLookup_;}
153 
154  // merge Principals containing different products.
155  void recombine(Principal& other, std::vector<BranchID> const& bids);
156 
158  return const_cast<ProductResolverBase*>( const_cast<const Principal*>(this)->getProductResolver(oid));
159  }
160 
161  size_t size() const;
162 
163  // These iterators skip over any null shared pointers
164  const_iterator begin() const {return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.begin(), productResolvers_.end());}
165  const_iterator end() const {return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.end(), productResolvers_.end());}
166 
167  iterator begin() {return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.begin(), productResolvers_.end());}
168  iterator end() {return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.end(), productResolvers_.end());}
169 
170  Provenance getProvenance(BranchID const& bid,
171  ModuleCallingContext const* mcc) const;
172 
173  void getAllProvenance(std::vector<Provenance const*>& provenances) const;
174 
175  void getAllStableProvenance(std::vector<StableProvenance const*>& provenances) const;
176 
177  BranchType const& branchType() const {return branchType_;}
178 
179  //This will never return 0 so you can use 0 to mean unset
180  typedef unsigned long CacheIdentifier_t;
181  CacheIdentifier_t cacheIdentifier() const {return cacheIdentifier_;}
182 
183  DelayedReader* reader() const {return reader_;}
184 
185  ConstProductResolverPtr getProductResolver(BranchID const& oid) const;
186 
187  ProductData const* findProductByTag(TypeID const& typeID, InputTag const& tag, ModuleCallingContext const* mcc) const;
188 
189  void readAllFromSourceAndMergeImmediately(MergeableRunProductMetadata const* mergeableRunProductMetadata = nullptr);
190 
191  std::vector<unsigned int> const& lookupProcessOrder() const { return lookupProcessOrder_; }
192 
193  ConstProductResolverPtr getProductResolverByIndex(ProductResolverIndex const& oid) const;
194 
195  protected:
196 
197  // ----- Add a new ProductResolver
198  // *this takes ownership of the ProductResolver, which in turn owns its
199  // data.
200  void addProduct_(std::unique_ptr<ProductResolverBase> phb);
201  void addProductOrThrow(std::unique_ptr<ProductResolverBase> phb);
202  ProductResolverBase* getExistingProduct(BranchID const& branchID);
203  ProductResolverBase const* getExistingProduct(BranchID const& branchID) const;
204  ProductResolverBase const* getExistingProduct(ProductResolverBase const& phb) const;
205 
206  void putOrMerge(BranchDescription const& bd, std::unique_ptr<WrapperBase> edp) const;
207 
208  //F must take an argument of type ProductResolverBase*
209  template <typename F>
210  void applyToResolvers( F iFunc) {
211  for(auto& resolver: productResolvers_) {
212  iFunc(resolver.get());
213  }
214  }
215 
216  private:
217 
218  void addScheduledProduct(std::shared_ptr<BranchDescription const> bd);
219  void addSourceProduct(std::shared_ptr<BranchDescription const> bd);
220  void addInputProduct(std::shared_ptr<BranchDescription const> bd);
221  void addUnscheduledProduct(std::shared_ptr<BranchDescription const> bd);
222  void addAliasedProduct(std::shared_ptr<BranchDescription const> bd);
223  void addParentProcessProduct(std::shared_ptr<BranchDescription const> bd);
224 
225 
226  WrapperBase const* getIt(ProductID const&) const override;
227  WrapperBase const* getThinnedProduct(ProductID const&, unsigned int&) const override;
228  void getThinnedProducts(ProductID const&,
229  std::vector<WrapperBase const*>&,
230  std::vector<unsigned int>&) const override;
231 
232  void findProducts(std::vector<ProductResolverBase const*> const& holders,
233  TypeID const& typeID,
234  BasicHandleVec& results,
236  ModuleCallingContext const* mcc) const;
237 
238  ProductData const* findProductByLabel(KindOfType kindOfType,
239  TypeID const& typeID,
240  InputTag const& inputTag,
241  EDConsumerBase const* consumer,
243  ModuleCallingContext const* mcc) const;
244 
245  ProductData const* findProductByLabel(KindOfType kindOfType,
246  TypeID const& typeID,
247  std::string const& label,
248  std::string const& instance,
249  std::string const& process,
250  EDConsumerBase const* consumer,
252  ModuleCallingContext const* mcc) const;
253 
254  void putOrMerge(std::unique_ptr<WrapperBase> prod, ProductResolverBase const* productResolver) const;
255 
256  std::shared_ptr<ProcessHistory const> processHistoryPtr_;
257 
260 
262 
263  // A vector of product holders.
264  ProductResolverCollection productResolvers_; // products and provenances are persistent
265 
266  // Pointer to the product registry. There is one entry in the registry
267  // for each EDProduct in the event.
268  std::shared_ptr<ProductRegistry const> preg_;
269  std::shared_ptr<ProductResolverIndexHelper const> productLookup_;
270 
271  std::vector<unsigned int> lookupProcessOrder_;
273 
274  // Pointer to the 'source' that will be used to obtain EDProducts
275  // from the persistent store. This 'source' is owned by the input source.
277 
279 
280  // In use cases where the new process should not be appended to
281  // input ProcessHistory, the following pointer should be null.
282  // The Principal does not own this object.
284 
285  CacheIdentifier_t cacheIdentifier_;
286  };
287 
288  template <typename PROD>
289  inline
290  std::shared_ptr<Wrapper<PROD> const>
291  getProductByTag(Principal const& ep, InputTag const& tag, ModuleCallingContext const* mcc) {
292  TypeID tid = TypeID(typeid(PROD));
293  ProductData const* result = ep.findProductByTag(tid, tag, mcc);
294  if(result == nullptr) {
295  return std::shared_ptr<Wrapper<PROD> const>();
296  }
297 
298  if(!(result->wrapper()->dynamicTypeInfo() == typeid(PROD))) {
300  }
301  return std::static_pointer_cast<Wrapper<PROD> const>(result->sharedConstWrapper());
302  }
303 }
304 #endif
BranchType branchType_
Definition: Principal.h:278
size
Write out results.
collection_type::const_iterator const_iterator
ProductRegistry const & productRegistry() const
Definition: Principal.h:150
ProductResolverBase * getModifiableProductResolver(BranchID const &oid)
Definition: Principal.h:157
DelayedReader * reader_
Definition: Principal.h:276
std::string ProcessName
Definition: Principal.h:69
iterator begin()
Definition: Principal.h:167
ProcessHistoryID processHistoryIDBeforeConfig_
Definition: Principal.h:259
unsigned int ProductResolverIndex
ProductResolverCollection productResolvers_
Definition: Principal.h:264
std::type_info const & dynamicTypeInfo() const
Definition: WrapperBase.h:46
std::shared_ptr< ProcessHistory const > processHistoryPtr_
Definition: Principal.h:256
const_iterator end() const
Definition: Principal.h:165
static PFTauRenderPlugin instance
std::shared_ptr< ProductResolverBase > SharedProductPtr
Definition: Principal.h:68
ProcessHistoryID processHistoryID_
Definition: Principal.h:258
void applyToResolvers(F iFunc)
Definition: Principal.h:210
WrapperBase const * wrapper() const
Definition: ProductData.h:34
CacheIdentifier_t cacheIdentifier() const
Definition: Principal.h:181
bool operator()(propagate_const< std::shared_ptr< ProductResolverBase >> const &iObj)
Definition: Principal.h:55
edm::propagate_const< HistoryAppender * > historyAppender_
Definition: Principal.h:283
uint16_t size_type
ProcessHistory const & processHistory() const
Definition: Principal.h:140
BranchType
Definition: BranchType.h:11
boost::filter_iterator< FilledProductPtr, ProductResolverCollection::iterator > iterator
Definition: Principal.h:62
std::vector< unsigned int > lookupProcessOrder_
Definition: Principal.h:271
std::vector< propagate_const< std::shared_ptr< ProductResolverBase > > > ProductResolverCollection
Definition: Principal.h:60
void throwConvertTypeError(std::type_info const &expected, std::type_info const &actual)
ProductData const * findProductByTag(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
Definition: Principal.cc:785
T const * getThinnedProduct(RefCore const &ref, unsigned int &thinnedKey, EDProductGetter const *prodGetter)
Definition: RefCoreGet.h:129
std::shared_ptr< ProductResolverIndexHelper const > productLookup_
Definition: Principal.h:269
std::shared_ptr< Wrapper< PROD > const > getProductByTag(Principal const &ep, InputTag const &tag, ModuleCallingContext const *mcc)
Definition: Principal.h:291
std::shared_ptr< ProductRegistry const > preg_
Definition: Principal.h:268
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:144
CacheIdentifier_t cacheIdentifier_
Definition: Principal.h:285
BranchType const & branchType() const
Definition: Principal.h:177
std::vector< unsigned int > const & lookupProcessOrder() const
Definition: Principal.h:191
ProcessHistoryID orderProcessHistoryID_
Definition: Principal.h:272
ProcessConfiguration const & processConfiguration() const
Definition: Principal.h:148
DelayedReader * reader() const
Definition: Principal.h:183
ProcessHistory::const_iterator ProcessNameConstIterator
Definition: Principal.h:63
const_iterator begin() const
Definition: Principal.h:164
ProductResolverIndexHelper const & productLookup() const
Definition: Principal.h:152
ProductResolverBase const * ConstProductResolverPtr
Definition: Principal.h:64
iterator end()
Definition: Principal.h:168
HLT enums.
unsigned long CacheIdentifier_t
Definition: Principal.h:180
boost::filter_iterator< FilledProductPtr, ProductResolverCollection::const_iterator > const_iterator
Definition: Principal.h:61
#define PROD(A, B)
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
ProductResolverCollection::size_type size_type
Definition: Principal.h:66
EDProductGetter const * prodGetter() const
Definition: Principal.h:92
ProcessConfiguration const * processConfiguration_
Definition: Principal.h:261
std::shared_ptr< WrapperBase const > sharedConstWrapper() const
Definition: ProductData.h:37
std::vector< BasicHandle > BasicHandleVec
Definition: Principal.h:65