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 ----------------------------------------------------------------------*/
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 MergeableRunProductMetadata;
46  class ModuleCallingContext;
47  class ProductResolverIndexHelper;
48  class EDConsumerBase;
51 
53  bool operator()(propagate_const<std::shared_ptr<ProductResolverBase>> const& iObj) { return bool(iObj); }
54  };
55 
56  class Principal : public EDProductGetter {
57  public:
58  typedef std::vector<propagate_const<std::shared_ptr<ProductResolverBase>>> ProductResolverCollection;
59  typedef boost::filter_iterator<FilledProductPtr, ProductResolverCollection::const_iterator> const_iterator;
60  typedef boost::filter_iterator<FilledProductPtr, ProductResolverCollection::iterator> iterator;
63  typedef std::vector<BasicHandle> BasicHandleVec;
65 
66  typedef std::shared_ptr<ProductResolverBase> SharedProductPtr;
68 
69  Principal(std::shared_ptr<ProductRegistry const> reg,
70  std::shared_ptr<ProductResolverIndexHelper const> productLookup,
71  ProcessConfiguration const& pc,
72  BranchType bt,
73  HistoryAppender* historyAppender,
74  bool isForPrimaryProcess = true);
75 
76  ~Principal() override;
77 
79 
81 
84  void fillPrincipal(std::string const& processNameOfBlock, DelayedReader* reader);
85 
86  void clearPrincipal();
87 
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(WaitingTaskHolder waitTask,
130  bool skipCurrentProcess,
131  ServiceToken const& token,
132  ModuleCallingContext const* mcc) const;
133 
134  void getManyByType(TypeID const& typeID,
136  EDConsumerBase const* consumes,
138  ModuleCallingContext const* mcc) const;
139 
141 
143 
145 
146  ProductRegistry const& productRegistry() const { return *preg_; }
147 
149 
150  // merge Principals containing different products.
151  void recombine(Principal& other, std::vector<BranchID> const& bids);
152 
154  return const_cast<ProductResolverBase*>(const_cast<const Principal*>(this)->getProductResolver(oid));
155  }
156 
157  size_t size() const;
158 
159  // These iterators skip over any null shared pointers
161  return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.begin(), productResolvers_.end());
162  }
163  const_iterator end() const {
164  return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.end(), productResolvers_.end());
165  }
166 
168  return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.begin(), productResolvers_.end());
169  }
171  return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.end(), productResolvers_.end());
172  }
173 
174  Provenance const& getProvenance(BranchID const& bid) const;
175  StableProvenance const& getStableProvenance(BranchID const& bid) const;
176 
177  void getAllProvenance(std::vector<Provenance const*>& provenances) const;
178 
179  void getAllStableProvenance(std::vector<StableProvenance const*>& provenances) const;
180 
181  BranchType const& branchType() const { return branchType_; }
182 
183  //This will never return 0 so you can use 0 to mean unset
184  typedef unsigned long CacheIdentifier_t;
186 
187  DelayedReader* reader() const { return reader_; }
188 
190 
191  ProductData const* findProductByTag(TypeID const& typeID,
192  InputTag const& tag,
193  ModuleCallingContext const* mcc) const;
194 
195  void readAllFromSourceAndMergeImmediately(MergeableRunProductMetadata const* mergeableRunProductMetadata = nullptr);
196 
197  std::vector<unsigned int> const& lookupProcessOrder() const { return lookupProcessOrder_; }
198 
200 
201  virtual unsigned int processBlockIndex(std::string const& processName) const;
202 
203  protected:
204  // ----- Add a new ProductResolver
205  // *this takes ownership of the ProductResolver, which in turn owns its
206  // data.
207  void addProduct_(std::unique_ptr<ProductResolverBase> phb);
208  void addProductOrThrow(std::unique_ptr<ProductResolverBase> phb);
210  ProductResolverBase const* getExistingProduct(BranchID const& branchID) const;
212 
213  void put_(BranchDescription const& bd, std::unique_ptr<WrapperBase> edp) const;
214 
215  //F must take an argument of type ProductResolverBase*
216  template <typename F>
217  void applyToResolvers(F iFunc) {
218  for (auto& resolver : productResolvers_) {
219  iFunc(resolver.get());
220  }
221  }
222 
223  private:
224  //called by adjustIndexesAfterProductRegistryAddition only if an index actually changed
225  virtual void changedIndexes_() {}
226 
227  void addScheduledProduct(std::shared_ptr<BranchDescription const> bd);
228  void addSourceProduct(std::shared_ptr<BranchDescription const> bd);
229  void addDelayedReaderInputProduct(std::shared_ptr<BranchDescription const> bd);
230  void addPutOnReadInputProduct(std::shared_ptr<BranchDescription const> bd);
231  void addUnscheduledProduct(std::shared_ptr<BranchDescription const> bd);
232  void addTransformProduct(std::shared_ptr<BranchDescription const> bd);
233  void addAliasedProduct(std::shared_ptr<BranchDescription const> bd);
234  void addSwitchProducerProduct(std::shared_ptr<BranchDescription const> bd);
235  void addSwitchAliasProduct(std::shared_ptr<BranchDescription const> bd);
236  void addParentProcessProduct(std::shared_ptr<BranchDescription const> bd);
237 
238  WrapperBase const* getIt(ProductID const&) const override;
239  std::optional<std::tuple<WrapperBase const*, unsigned int>> getThinnedProduct(ProductID const&,
240  unsigned int) const override;
241  void getThinnedProducts(ProductID const&,
242  std::vector<WrapperBase const*>&,
243  std::vector<unsigned int>&) const override;
245  unsigned int key,
246  ProductID const& thinned) const override;
247 
248  void findProducts(std::vector<ProductResolverBase const*> const& holders,
249  TypeID const& typeID,
252  ModuleCallingContext const* mcc) const;
253 
254  ProductData const* findProductByLabel(KindOfType kindOfType,
255  TypeID const& typeID,
256  InputTag const& inputTag,
257  EDConsumerBase const* consumer,
259  ModuleCallingContext const* mcc) const;
260 
261  ProductData const* findProductByLabel(KindOfType kindOfType,
262  TypeID const& typeID,
263  std::string const& label,
264  std::string const& instance,
265  std::string const& process,
266  EDConsumerBase const* consumer,
268  ModuleCallingContext const* mcc) const;
269 
270  void put_(std::unique_ptr<WrapperBase> prod, ProductResolverBase const* productResolver) const;
271 
272  std::shared_ptr<ProcessHistory const> processHistoryPtr_;
273 
276 
278 
279  // A vector of product holders.
280  ProductResolverCollection productResolvers_; // products and provenances are persistent
281 
282  // Pointer to the product registry. There is one entry in the registry
283  // for each EDProduct in the event.
284  std::shared_ptr<ProductRegistry const> preg_;
285  std::shared_ptr<ProductResolverIndexHelper const> productLookup_;
286 
287  std::vector<unsigned int> lookupProcessOrder_;
289 
290  // Pointer to the 'source' that will be used to obtain EDProducts
291  // from the persistent store. This 'source' is owned by the input source.
293 
295 
296  // In use cases where the new process should not be appended to
297  // input ProcessHistory, the following pointer should be null.
298  // The Principal does not own this object.
300 
302  };
303 
304  template <typename PROD>
305  inline std::shared_ptr<Wrapper<PROD> const> getProductByTag(Principal const& ep,
306  InputTag const& tag,
307  ModuleCallingContext const* mcc) {
308  TypeID tid = TypeID(typeid(PROD));
309  ProductData const* result = ep.findProductByTag(tid, tag, mcc);
310  if (result == nullptr) {
311  return std::shared_ptr<Wrapper<PROD> const>();
312  }
313 
314  if (!(result->wrapper()->dynamicTypeInfo() == typeid(PROD))) {
315  handleimpl::throwConvertTypeError(typeid(PROD), result->wrapper()->dynamicTypeInfo());
316  }
317  return std::static_pointer_cast<Wrapper<PROD> const>(result->sharedConstWrapper());
318  }
319 } // namespace edm
320 #endif
std::optional< std::tuple< WrapperBase const *, unsigned int > > getThinnedProduct(ProductID const &, unsigned int) const override
Definition: Principal.cc:942
BranchType branchType_
Definition: Principal.h:294
void findProducts(std::vector< ProductResolverBase const *> const &holders, TypeID const &typeID, BasicHandleVec &results, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:727
collection_type::const_iterator const_iterator
void fillPrincipal(DelayedReader *reader)
Definition: Principal.cc:410
ProductResolverBase * getModifiableProductResolver(BranchID const &oid)
Definition: Principal.h:153
void clearPrincipal()
Definition: Principal.cc:390
DelayedReader * reader_
Definition: Principal.h:292
std::string ProcessName
Definition: Principal.h:67
iterator begin()
Definition: Principal.h:167
void getAllProvenance(std::vector< Provenance const *> &provenances) const
Definition: Principal.cc:898
ProcessHistoryID processHistoryIDBeforeConfig_
Definition: Principal.h:275
void setupUnscheduled(UnscheduledConfigurator const &)
Definition: Principal.cc:406
unsigned int ProductResolverIndex
BasicHandle getByToken(KindOfType kindOfType, TypeID const &typeID, ProductResolverIndex index, bool skipCurrentProcess, bool &ambiguous, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:621
ProductResolverCollection productResolvers_
Definition: Principal.h:280
std::variant< unsigned int, detail::GetThinnedKeyFromExceptionFactory, std::monostate > OptionalThinnedKey
std::shared_ptr< ProcessHistory const > processHistoryPtr_
Definition: Principal.h:272
std::vector< unsigned int > const & lookupProcessOrder() const
Definition: Principal.h:197
static PFTauRenderPlugin instance
ProductRegistry const & productRegistry() const
Definition: Principal.h:146
std::shared_ptr< ProductResolverBase > SharedProductPtr
Definition: Principal.h:66
void addProduct_(std::unique_ptr< ProductResolverBase > phb)
Definition: Principal.cc:537
StableProvenance const & getStableProvenance(BranchID const &bid) const
Definition: Principal.cc:886
ProcessHistoryID processHistoryID_
Definition: Principal.h:274
ProductResolverBase * getExistingProduct(BranchID const &branchID)
Definition: Principal.cc:509
void getThinnedProducts(ProductID const &, std::vector< WrapperBase const *> &, std::vector< unsigned int > &) const override
Definition: Principal.cc:948
void applyToResolvers(F iFunc)
Definition: Principal.h:217
~Principal() override
Definition: Principal.cc:302
void prefetchAsync(WaitingTaskHolder waitTask, ProductResolverIndex index, bool skipCurrentProcess, ServiceToken const &token, ModuleCallingContext const *mcc) const
Definition: Principal.cc:647
size_t size() const
Definition: Principal.cc:307
ProcessConfiguration const & processConfiguration() const
Definition: Principal.h:144
bool operator()(propagate_const< std::shared_ptr< ProductResolverBase >> const &iObj)
Definition: Principal.h:53
edm::propagate_const< HistoryAppender * > historyAppender_
Definition: Principal.h:299
Principal(std::shared_ptr< ProductRegistry const > reg, std::shared_ptr< ProductResolverIndexHelper const > productLookup, ProcessConfiguration const &pc, BranchType bt, HistoryAppender *historyAppender, bool isForPrimaryProcess=true)
Definition: Principal.cc:122
CacheIdentifier_t cacheIdentifier() const
Definition: Principal.h:185
void addUnscheduledProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:353
uint16_t size_type
void getManyByType(TypeID const &typeID, BasicHandleVec &results, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:657
BranchType
Definition: BranchType.h:11
ProductData const * findProductByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumer, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:752
boost::filter_iterator< FilledProductPtr, ProductResolverCollection::iterator > iterator
Definition: Principal.h:60
void addAliasedProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:361
std::vector< unsigned int > lookupProcessOrder_
Definition: Principal.h:287
virtual unsigned int processBlockIndex(std::string const &processName) const
Definition: Principal.cc:575
std::vector< propagate_const< std::shared_ptr< ProductResolverBase > > > ProductResolverCollection
Definition: Principal.h:58
char const * label
WrapperBase const * getIt(ProductID const &) const override
Definition: Principal.cc:937
void throwConvertTypeError(std::type_info const &expected, std::type_info const &actual)
EDProductGetter const * prodGetter() const
Definition: Principal.h:92
std::shared_ptr< ProductResolverIndexHelper const > productLookup_
Definition: Principal.h:285
std::shared_ptr< Wrapper< PROD > const > getProductByTag(Principal const &ep, InputTag const &tag, ModuleCallingContext const *mcc)
Definition: Principal.h:305
void addProductOrThrow(std::unique_ptr< ProductResolverBase > phb)
Definition: Principal.cc:550
std::shared_ptr< ProductRegistry const > preg_
Definition: Principal.h:284
CacheIdentifier_t cacheIdentifier_
Definition: Principal.h:301
BasicHandle getByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:579
void getAllStableProvenance(std::vector< StableProvenance const *> &provenances) const
Definition: Principal.cc:915
ProcessHistoryID orderProcessHistoryID_
Definition: Principal.h:288
virtual void changedIndexes_()
Definition: Principal.h:225
void addSourceProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:340
void addPutOnReadInputProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:349
void deleteProduct(BranchID const &id) const
Definition: Principal.cc:400
const_iterator begin() const
Definition: Principal.h:160
void addDelayedReaderInputProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:345
void put_(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp) const
Definition: Principal.cc:963
void addParentProcessProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:385
ProductData const * findProductByTag(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
Definition: Principal.cc:863
void addScheduledProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:335
ProcessHistory::const_iterator ProcessNameConstIterator
Definition: Principal.h:61
ProcessHistory const & processHistory() const
Definition: Principal.h:140
void addSwitchProducerProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:369
ProductResolverBase const * ConstProductResolverPtr
Definition: Principal.h:62
iterator end()
Definition: Principal.h:170
HLT enums.
void readAllFromSourceAndMergeImmediately(MergeableRunProductMetadata const *mergeableRunProductMetadata=nullptr)
Definition: Principal.cc:1004
unsigned long CacheIdentifier_t
Definition: Principal.h:184
boost::filter_iterator< FilledProductPtr, ProductResolverCollection::const_iterator > const_iterator
Definition: Principal.h:59
bool adjustToNewProductRegistry(ProductRegistry const &reg)
Definition: Principal.cc:319
#define PROD(A, B)
results
Definition: mysort.py:8
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:142
Provenance const & getProvenance(BranchID const &bid) const
Definition: Principal.cc:873
void adjustIndexesAfterProductRegistryAddition()
Definition: Principal.cc:975
ProductResolverIndexHelper const & productLookup() const
Definition: Principal.h:148
void addTransformProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:357
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
OptionalThinnedKey getThinnedKeyFrom(ProductID const &parent, unsigned int key, ProductID const &thinned) const override
Definition: Principal.cc:954
ProductResolverCollection::size_type size_type
Definition: Principal.h:64
const_iterator end() const
Definition: Principal.h:163
void recombine(Principal &other, std::vector< BranchID > const &bids)
Definition: Principal.cc:926
ConstProductResolverPtr getProductResolverByIndex(ProductResolverIndex const &oid) const
Definition: Principal.cc:570
ProcessConfiguration const * processConfiguration_
Definition: Principal.h:277
void addSwitchAliasProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:377
std::vector< BasicHandle > BasicHandleVec
Definition: Principal.h:63
DelayedReader * reader() const
Definition: Principal.h:187
BranchType const & branchType() const
Definition: Principal.h:181
ConstProductResolverPtr getProductResolver(BranchID const &oid) const
Definition: Principal.cc:562