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 
135 
137 
139 
140  ProductRegistry const& productRegistry() const { return *preg_; }
141 
143 
144  // merge Principals containing different products.
145  void recombine(Principal& other, std::vector<BranchID> const& bids);
146 
148  return const_cast<ProductResolverBase*>(const_cast<const Principal*>(this)->getProductResolver(oid));
149  }
150 
151  size_t size() const;
152 
153  // These iterators skip over any null shared pointers
155  return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.begin(), productResolvers_.end());
156  }
157  const_iterator end() const {
158  return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.end(), productResolvers_.end());
159  }
160 
162  return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.begin(), productResolvers_.end());
163  }
165  return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.end(), productResolvers_.end());
166  }
167 
168  Provenance const& getProvenance(BranchID const& bid) const;
169  StableProvenance const& getStableProvenance(BranchID const& bid) const;
170 
171  void getAllProvenance(std::vector<Provenance const*>& provenances) const;
172 
173  void getAllStableProvenance(std::vector<StableProvenance const*>& provenances) const;
174 
175  BranchType const& branchType() const { return branchType_; }
176 
177  //This will never return 0 so you can use 0 to mean unset
178  typedef unsigned long CacheIdentifier_t;
180 
181  DelayedReader* reader() const { return reader_; }
182 
184 
185  ProductData const* findProductByTag(TypeID const& typeID,
186  InputTag const& tag,
187  ModuleCallingContext const* mcc) const;
188 
189  void readAllFromSourceAndMergeImmediately(MergeableRunProductMetadata const* mergeableRunProductMetadata = nullptr);
190 
191  std::vector<unsigned int> const& lookupProcessOrder() const { return lookupProcessOrder_; }
192 
194 
195  virtual unsigned int processBlockIndex(std::string const& processName) const;
196 
197  protected:
198  // ----- Add a new ProductResolver
199  // *this takes ownership of the ProductResolver, which in turn owns its
200  // data.
201  void addProduct_(std::unique_ptr<ProductResolverBase> phb);
202  void addProductOrThrow(std::unique_ptr<ProductResolverBase> phb);
204  ProductResolverBase const* getExistingProduct(BranchID const& branchID) const;
206 
207  void put_(BranchDescription const& bd, std::unique_ptr<WrapperBase> edp) const;
208 
209  //F must take an argument of type ProductResolverBase*
210  template <typename F>
211  void applyToResolvers(F iFunc) {
212  for (auto& resolver : productResolvers_) {
213  iFunc(resolver.get());
214  }
215  }
216 
217  private:
218  //called by adjustIndexesAfterProductRegistryAddition only if an index actually changed
219  virtual void changedIndexes_() {}
220 
221  void addScheduledProduct(std::shared_ptr<BranchDescription const> bd);
222  void addSourceProduct(std::shared_ptr<BranchDescription const> bd);
223  void addDelayedReaderInputProduct(std::shared_ptr<BranchDescription const> bd);
224  void addPutOnReadInputProduct(std::shared_ptr<BranchDescription const> bd);
225  void addUnscheduledProduct(std::shared_ptr<BranchDescription const> bd);
226  void addTransformProduct(std::shared_ptr<BranchDescription const> bd);
227  void addAliasedProduct(std::shared_ptr<BranchDescription const> bd);
228  void addSwitchProducerProduct(std::shared_ptr<BranchDescription const> bd);
229  void addSwitchAliasProduct(std::shared_ptr<BranchDescription const> bd);
230  void addParentProcessProduct(std::shared_ptr<BranchDescription const> bd);
231 
232  WrapperBase const* getIt(ProductID const&) const override;
233  std::optional<std::tuple<WrapperBase const*, unsigned int>> getThinnedProduct(ProductID const&,
234  unsigned int) const override;
235  void getThinnedProducts(ProductID const&,
236  std::vector<WrapperBase const*>&,
237  std::vector<unsigned int>&) const override;
239  unsigned int key,
240  ProductID const& thinned) const override;
241 
242  ProductData const* findProductByLabel(KindOfType kindOfType,
243  TypeID const& typeID,
244  InputTag const& inputTag,
245  EDConsumerBase const* consumer,
247  ModuleCallingContext const* mcc) const;
248 
249  ProductData const* findProductByLabel(KindOfType kindOfType,
250  TypeID const& typeID,
251  std::string const& label,
252  std::string const& instance,
253  std::string const& process,
254  EDConsumerBase const* consumer,
256  ModuleCallingContext const* mcc) const;
257 
258  void put_(std::unique_ptr<WrapperBase> prod, ProductResolverBase const* productResolver) const;
259 
260  std::shared_ptr<ProcessHistory const> processHistoryPtr_;
261 
264 
266 
267  // A vector of product holders.
268  ProductResolverCollection productResolvers_; // products and provenances are persistent
269 
270  // Pointer to the product registry. There is one entry in the registry
271  // for each EDProduct in the event.
272  std::shared_ptr<ProductRegistry const> preg_;
273  std::shared_ptr<ProductResolverIndexHelper const> productLookup_;
274 
275  std::vector<unsigned int> lookupProcessOrder_;
277 
278  // Pointer to the 'source' that will be used to obtain EDProducts
279  // from the persistent store. This 'source' is owned by the input source.
281 
283 
284  // In use cases where the new process should not be appended to
285  // input ProcessHistory, the following pointer should be null.
286  // The Principal does not own this object.
288 
290  };
291 
292  template <typename PROD>
293  inline std::shared_ptr<Wrapper<PROD> const> getProductByTag(Principal const& ep,
294  InputTag const& tag,
295  ModuleCallingContext const* mcc) {
296  TypeID tid = TypeID(typeid(PROD));
297  ProductData const* result = ep.findProductByTag(tid, tag, mcc);
298  if (result == nullptr) {
299  return std::shared_ptr<Wrapper<PROD> const>();
300  }
301 
302  if (!(result->wrapper()->dynamicTypeInfo() == typeid(PROD))) {
303  handleimpl::throwConvertTypeError(typeid(PROD), result->wrapper()->dynamicTypeInfo());
304  }
305  return std::static_pointer_cast<Wrapper<PROD> const>(result->sharedConstWrapper());
306  }
307 } // namespace edm
308 #endif
std::optional< std::tuple< WrapperBase const *, unsigned int > > getThinnedProduct(ProductID const &, unsigned int) const override
Definition: Principal.cc:840
BranchType branchType_
Definition: Principal.h:282
collection_type::const_iterator const_iterator
void fillPrincipal(DelayedReader *reader)
Definition: Principal.cc:403
ProductResolverBase * getModifiableProductResolver(BranchID const &oid)
Definition: Principal.h:147
void clearPrincipal()
Definition: Principal.cc:383
DelayedReader * reader_
Definition: Principal.h:280
std::string ProcessName
Definition: Principal.h:67
iterator begin()
Definition: Principal.h:161
void getAllProvenance(std::vector< Provenance const *> &provenances) const
Definition: Principal.cc:796
ProcessHistoryID processHistoryIDBeforeConfig_
Definition: Principal.h:263
void setupUnscheduled(UnscheduledConfigurator const &)
Definition: Principal.cc:399
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:614
ProductResolverCollection productResolvers_
Definition: Principal.h:268
std::variant< unsigned int, detail::GetThinnedKeyFromExceptionFactory, std::monostate > OptionalThinnedKey
std::shared_ptr< ProcessHistory const > processHistoryPtr_
Definition: Principal.h:260
std::vector< unsigned int > const & lookupProcessOrder() const
Definition: Principal.h:191
static PFTauRenderPlugin instance
ProductRegistry const & productRegistry() const
Definition: Principal.h:140
std::shared_ptr< ProductResolverBase > SharedProductPtr
Definition: Principal.h:66
void addProduct_(std::unique_ptr< ProductResolverBase > phb)
Definition: Principal.cc:530
StableProvenance const & getStableProvenance(BranchID const &bid) const
Definition: Principal.cc:784
ProcessHistoryID processHistoryID_
Definition: Principal.h:262
ProductResolverBase * getExistingProduct(BranchID const &branchID)
Definition: Principal.cc:502
void getThinnedProducts(ProductID const &, std::vector< WrapperBase const *> &, std::vector< unsigned int > &) const override
Definition: Principal.cc:846
void applyToResolvers(F iFunc)
Definition: Principal.h:211
~Principal() override
Definition: Principal.cc:295
void prefetchAsync(WaitingTaskHolder waitTask, ProductResolverIndex index, bool skipCurrentProcess, ServiceToken const &token, ModuleCallingContext const *mcc) const
Definition: Principal.cc:640
size_t size() const
Definition: Principal.cc:300
ProcessConfiguration const & processConfiguration() const
Definition: Principal.h:138
bool operator()(propagate_const< std::shared_ptr< ProductResolverBase >> const &iObj)
Definition: Principal.h:53
edm::propagate_const< HistoryAppender * > historyAppender_
Definition: Principal.h:287
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:115
CacheIdentifier_t cacheIdentifier() const
Definition: Principal.h:179
void addUnscheduledProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:346
uint16_t size_type
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:650
boost::filter_iterator< FilledProductPtr, ProductResolverCollection::iterator > iterator
Definition: Principal.h:60
void addAliasedProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:354
std::vector< unsigned int > lookupProcessOrder_
Definition: Principal.h:275
virtual unsigned int processBlockIndex(std::string const &processName) const
Definition: Principal.cc:568
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:835
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:273
std::shared_ptr< Wrapper< PROD > const > getProductByTag(Principal const &ep, InputTag const &tag, ModuleCallingContext const *mcc)
Definition: Principal.h:293
void addProductOrThrow(std::unique_ptr< ProductResolverBase > phb)
Definition: Principal.cc:543
std::shared_ptr< ProductRegistry const > preg_
Definition: Principal.h:272
CacheIdentifier_t cacheIdentifier_
Definition: Principal.h:289
BasicHandle getByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:572
void getAllStableProvenance(std::vector< StableProvenance const *> &provenances) const
Definition: Principal.cc:813
ProcessHistoryID orderProcessHistoryID_
Definition: Principal.h:276
virtual void changedIndexes_()
Definition: Principal.h:219
void addSourceProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:333
void addPutOnReadInputProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:342
void deleteProduct(BranchID const &id) const
Definition: Principal.cc:393
const_iterator begin() const
Definition: Principal.h:154
void addDelayedReaderInputProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:338
void put_(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp) const
Definition: Principal.cc:861
void addParentProcessProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:378
ProductData const * findProductByTag(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
Definition: Principal.cc:761
void addScheduledProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:328
ProcessHistory::const_iterator ProcessNameConstIterator
Definition: Principal.h:61
ProcessHistory const & processHistory() const
Definition: Principal.h:134
void addSwitchProducerProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:362
ProductResolverBase const * ConstProductResolverPtr
Definition: Principal.h:62
iterator end()
Definition: Principal.h:164
HLT enums.
void readAllFromSourceAndMergeImmediately(MergeableRunProductMetadata const *mergeableRunProductMetadata=nullptr)
Definition: Principal.cc:902
unsigned long CacheIdentifier_t
Definition: Principal.h:178
boost::filter_iterator< FilledProductPtr, ProductResolverCollection::const_iterator > const_iterator
Definition: Principal.h:59
bool adjustToNewProductRegistry(ProductRegistry const &reg)
Definition: Principal.cc:312
#define PROD(A, B)
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:136
Provenance const & getProvenance(BranchID const &bid) const
Definition: Principal.cc:771
void adjustIndexesAfterProductRegistryAddition()
Definition: Principal.cc:873
ProductResolverIndexHelper const & productLookup() const
Definition: Principal.h:142
void addTransformProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:350
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:852
ProductResolverCollection::size_type size_type
Definition: Principal.h:64
const_iterator end() const
Definition: Principal.h:157
void recombine(Principal &other, std::vector< BranchID > const &bids)
Definition: Principal.cc:824
ConstProductResolverPtr getProductResolverByIndex(ProductResolverIndex const &oid) const
Definition: Principal.cc:563
ProcessConfiguration const * processConfiguration_
Definition: Principal.h:265
void addSwitchAliasProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:370
std::vector< BasicHandle > BasicHandleVec
Definition: Principal.h:63
DelayedReader * reader() const
Definition: Principal.h:181
BranchType const & branchType() const
Definition: Principal.h:175
ConstProductResolverPtr getProductResolver(BranchID const &oid) const
Definition: Principal.cc:555