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