CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 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 addAliasedProduct(std::shared_ptr<BranchDescription const> bd);
233  void addSwitchProducerProduct(std::shared_ptr<BranchDescription const> bd);
234  void addSwitchAliasProduct(std::shared_ptr<BranchDescription const> bd);
235  void addParentProcessProduct(std::shared_ptr<BranchDescription const> bd);
236 
237  WrapperBase const* getIt(ProductID const&) const override;
238  std::optional<std::tuple<WrapperBase const*, unsigned int>> getThinnedProduct(ProductID const&,
239  unsigned int) const override;
240  void getThinnedProducts(ProductID const&,
241  std::vector<WrapperBase const*>&,
242  std::vector<unsigned int>&) const override;
244  unsigned int key,
245  ProductID const& thinned) const override;
246 
247  void findProducts(std::vector<ProductResolverBase const*> const& holders,
248  TypeID const& typeID,
251  ModuleCallingContext const* mcc) const;
252 
253  ProductData const* findProductByLabel(KindOfType kindOfType,
254  TypeID const& typeID,
255  InputTag const& inputTag,
256  EDConsumerBase const* consumer,
258  ModuleCallingContext const* mcc) const;
259 
260  ProductData const* findProductByLabel(KindOfType kindOfType,
261  TypeID const& typeID,
262  std::string const& label,
263  std::string const& instance,
264  std::string const& process,
265  EDConsumerBase const* consumer,
267  ModuleCallingContext const* mcc) const;
268 
269  void put_(std::unique_ptr<WrapperBase> prod, ProductResolverBase const* productResolver) const;
270 
271  std::shared_ptr<ProcessHistory const> processHistoryPtr_;
272 
275 
277 
278  // A vector of product holders.
279  ProductResolverCollection productResolvers_; // products and provenances are persistent
280 
281  // Pointer to the product registry. There is one entry in the registry
282  // for each EDProduct in the event.
283  std::shared_ptr<ProductRegistry const> preg_;
284  std::shared_ptr<ProductResolverIndexHelper const> productLookup_;
285 
286  std::vector<unsigned int> lookupProcessOrder_;
288 
289  // Pointer to the 'source' that will be used to obtain EDProducts
290  // from the persistent store. This 'source' is owned by the input source.
292 
294 
295  // In use cases where the new process should not be appended to
296  // input ProcessHistory, the following pointer should be null.
297  // The Principal does not own this object.
299 
301  };
302 
303  template <typename PROD>
304  inline std::shared_ptr<Wrapper<PROD> const> getProductByTag(Principal const& ep,
305  InputTag const& tag,
306  ModuleCallingContext const* mcc) {
307  TypeID tid = TypeID(typeid(PROD));
308  ProductData const* result = ep.findProductByTag(tid, tag, mcc);
309  if (result == nullptr) {
310  return std::shared_ptr<Wrapper<PROD> const>();
311  }
312 
313  if (!(result->wrapper()->dynamicTypeInfo() == typeid(PROD))) {
315  }
316  return std::static_pointer_cast<Wrapper<PROD> const>(result->sharedConstWrapper());
317  }
318 } // namespace edm
319 #endif
BranchType branchType_
Definition: Principal.h:293
collection_type::const_iterator const_iterator
void fillPrincipal(DelayedReader *reader)
Definition: Principal.cc:402
ProductRegistry const & productRegistry() const
Definition: Principal.h:146
ProductResolverBase * getModifiableProductResolver(BranchID const &oid)
Definition: Principal.h:153
void clearPrincipal()
Definition: Principal.cc:382
void getThinnedProducts(ProductID const &, std::vector< WrapperBase const * > &, std::vector< unsigned int > &) const override
Definition: Principal.cc:912
size_t size() const
Definition: Principal.cc:303
DelayedReader * reader_
Definition: Principal.h:291
std::string ProcessName
Definition: Principal.h:67
iterator begin()
Definition: Principal.h:167
ProcessHistoryID processHistoryIDBeforeConfig_
Definition: Principal.h:274
void setupUnscheduled(UnscheduledConfigurator const &)
Definition: Principal.cc:398
unsigned int ProductResolverIndex
ProductResolverCollection productResolvers_
Definition: Principal.h:279
std::variant< unsigned int, detail::GetThinnedKeyFromExceptionFactory, std::monostate > OptionalThinnedKey
std::type_info const & dynamicTypeInfo() const
Definition: WrapperBase.h:42
std::shared_ptr< ProcessHistory const > processHistoryPtr_
Definition: Principal.h:271
const_iterator end() const
Definition: Principal.h:163
static PFTauRenderPlugin instance
std::shared_ptr< ProductResolverBase > SharedProductPtr
Definition: Principal.h:66
void addProduct_(std::unique_ptr< ProductResolverBase > phb)
Definition: Principal.cc:529
ProcessHistoryID processHistoryID_
Definition: Principal.h:273
dictionary results
ProductResolverBase * getExistingProduct(BranchID const &branchID)
Definition: Principal.cc:501
void getAllProvenance(std::vector< Provenance const * > &provenances) const
Definition: Principal.cc:862
void applyToResolvers(F iFunc)
Definition: Principal.h:217
void getAllStableProvenance(std::vector< StableProvenance const * > &provenances) const
Definition: Principal.cc:879
~Principal() override
Definition: Principal.cc:298
StableProvenance const & getStableProvenance(BranchID const &bid) const
Definition: Principal.cc:850
WrapperBase const * wrapper() const
Definition: ProductData.h:35
CacheIdentifier_t cacheIdentifier() const
Definition: Principal.h:185
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
bool operator()(propagate_const< std::shared_ptr< ProductResolverBase >> const &iObj)
Definition: Principal.h:53
edm::propagate_const< HistoryAppender * > historyAppender_
Definition: Principal.h:298
uint16_t size_type
ProcessHistory const & processHistory() const
Definition: Principal.h:140
BranchType
Definition: BranchType.h:11
tuple result
Definition: mps_fire.py:311
boost::filter_iterator< FilledProductPtr, ProductResolverCollection::iterator > iterator
Definition: Principal.h:60
void prefetchAsync(WaitingTaskHolder waitTask, ProductResolverIndex index, bool skipCurrentProcess, ServiceToken const &token, ModuleCallingContext const *mcc) const
Definition: Principal.cc:639
std::vector< unsigned int > lookupProcessOrder_
Definition: Principal.h:286
std::vector< propagate_const< std::shared_ptr< ProductResolverBase > > > ProductResolverCollection
Definition: Principal.h:58
char const * label
void throwConvertTypeError(std::type_info const &expected, std::type_info const &actual)
BasicHandle getByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:571
void addScheduledProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:331
ProductData const * findProductByTag(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
Definition: Principal.cc:827
std::shared_ptr< ProductResolverIndexHelper const > productLookup_
Definition: Principal.h:284
std::shared_ptr< Wrapper< PROD > const > getProductByTag(Principal const &ep, InputTag const &tag, ModuleCallingContext const *mcc)
Definition: Principal.h:304
void addProductOrThrow(std::unique_ptr< ProductResolverBase > phb)
Definition: Principal.cc:542
std::shared_ptr< ProductRegistry const > preg_
Definition: Principal.h:283
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:142
CacheIdentifier_t cacheIdentifier_
Definition: Principal.h:300
void addDelayedReaderInputProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:341
BranchType const & branchType() const
Definition: Principal.h:181
std::vector< unsigned int > const & lookupProcessOrder() const
Definition: Principal.h:197
void addSourceProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:336
ProcessHistoryID orderProcessHistoryID_
Definition: Principal.h:287
tuple key
prepare the HTCondor submission files and eventually submit them
virtual void changedIndexes_()
Definition: Principal.h:225
std::optional< std::tuple< WrapperBase const *, unsigned int > > getThinnedProduct(ProductID const &, unsigned int) const override
Definition: Principal.cc:906
void addParentProcessProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:377
ProcessConfiguration const & processConfiguration() const
Definition: Principal.h:144
__shared__ Hist hist
DelayedReader * reader() const
Definition: Principal.h:187
virtual unsigned int processBlockIndex(std::string const &processName) const
Definition: Principal.cc:567
ProcessHistory::const_iterator ProcessNameConstIterator
Definition: Principal.h:61
void addSwitchAliasProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:369
void addUnscheduledProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:349
const_iterator begin() const
Definition: Principal.h:160
ProductResolverIndexHelper const & productLookup() const
Definition: Principal.h:148
void addPutOnReadInputProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:345
ProductResolverBase const * ConstProductResolverPtr
Definition: Principal.h:62
iterator end()
Definition: Principal.h:170
void findProducts(std::vector< ProductResolverBase const * > const &holders, TypeID const &typeID, BasicHandleVec &results, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:719
void readAllFromSourceAndMergeImmediately(MergeableRunProductMetadata const *mergeableRunProductMetadata=nullptr)
Definition: Principal.cc:968
unsigned long CacheIdentifier_t
Definition: Principal.h:184
WrapperBase const * getIt(ProductID const &) const override
Definition: Principal.cc:901
boost::filter_iterator< FilledProductPtr, ProductResolverCollection::const_iterator > const_iterator
Definition: Principal.h:59
bool adjustToNewProductRegistry(ProductRegistry const &reg)
Definition: Principal.cc:315
ProductData const * findProductByLabel(KindOfType kindOfType, TypeID const &typeID, InputTag const &inputTag, EDConsumerBase const *consumer, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:744
#define PROD(A, B)
ConstProductResolverPtr getProductResolverByIndex(ProductResolverIndex const &oid) const
Definition: Principal.cc:562
void addSwitchProducerProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:361
ConstProductResolverPtr getProductResolver(BranchID const &oid) const
Definition: Principal.cc:554
Provenance const & getProvenance(BranchID const &bid) const
Definition: Principal.cc:837
void adjustIndexesAfterProductRegistryAddition()
Definition: Principal.cc:939
BasicHandle getByToken(KindOfType kindOfType, TypeID const &typeID, ProductResolverIndex index, bool skipCurrentProcess, bool &ambiguous, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:613
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:918
tuple process
Definition: LaserDQM_cfg.py:3
void addAliasedProduct(std::shared_ptr< BranchDescription const > bd)
Definition: Principal.cc:353
ProductResolverCollection::size_type size_type
Definition: Principal.h:64
EDProductGetter const * prodGetter() const
Definition: Principal.h:92
void recombine(Principal &other, std::vector< BranchID > const &bids)
Definition: Principal.cc:890
ProcessConfiguration const * processConfiguration_
Definition: Principal.h:276
std::shared_ptr< WrapperBase const > sharedConstWrapper() const
Definition: ProductData.h:37
std::vector< BasicHandle > BasicHandleVec
Definition: Principal.h:63
void getManyByType(TypeID const &typeID, BasicHandleVec &results, EDConsumerBase const *consumes, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const
Definition: Principal.cc:649
void deleteProduct(BranchID const &id) const
Definition: Principal.cc:392
void put_(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp) const
Definition: Principal.cc:927