CMS 3D CMS Logo

ProductResolvers.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_ProductResolvers_h
2 #define FWCore_Framework_ProductResolvers_h
3 
4 /*----------------------------------------------------------------------
5 
6 ProductResolver: A collection of information related to a single WrapperBase or
7 a set of related EDProducts. This is the storage unit of such information.
8 
9 ----------------------------------------------------------------------*/
19 
20 #include <memory>
21 #include <atomic>
22 
23 #include <string>
24 
25 namespace edm {
26  class ProductProvenanceRetriever;
27  class DelayedReader;
28  class ModuleCallingContext;
30  class Principal;
32  class Worker;
33  class ServiceToken;
34 
36  public:
37  enum class ProductStatus {
38  ProductSet,
39  NotPut,
43  };
44 
45  DataManagingProductResolver(std::shared_ptr<BranchDescription const> bd,ProductStatus iDefaultStatus): ProductResolverBase(),
46  productData_(bd),
47  theStatus_(iDefaultStatus),
48  defaultStatus_(iDefaultStatus){}
49 
50  virtual void connectTo(ProductResolverBase const&, Principal const*) override final;
51 
53 
54  //Give AliasProductResolver access
55  virtual void resetProductData_(bool deleteEarly) override;
56 
57  protected:
58  void setProduct(std::unique_ptr<WrapperBase> edp) const;
59  ProductStatus status() const { return theStatus_;}
62  //Handle the boilerplate code needed for resolveProduct_
63  template <bool callResolver, typename FUNC>
64  Resolution resolveProductImpl( FUNC resolver) const;
65 
66  private:
67 
68  void throwProductDeletedException() const;
69  void checkType(WrapperBase const& prod) const;
70  ProductData const& getProductData() const {return productData_;}
71  virtual bool isFromCurrentProcess() const = 0;
72  // merges the product with the pre-existing product
73  void mergeProduct(std::unique_ptr<WrapperBase> edp) const;
74 
75  virtual void putOrMergeProduct_(std::unique_ptr<WrapperBase> prod) const override final;
76  virtual bool productUnavailable_() const override final;
77  virtual bool productResolved_() const override final;
78  virtual bool productWasDeleted_() const override final;
79  virtual bool productWasFetchedAndIsValid_( bool iSkipCurrentProcess) const override final;
80 
81  virtual BranchDescription const& branchDescription_() const override final {return *getProductData().branchDescription();}
82  virtual void resetBranchDescription_(std::shared_ptr<BranchDescription const> bd) override final {productData_.resetBranchDescription(bd);}
83  virtual Provenance const* provenance_() const override final {return &productData_.provenance();}
84 
85  virtual std::string const& resolvedModuleLabel_() const override final {return moduleLabel();}
86  virtual void setProvenance_(ProductProvenanceRetriever const* provRetriever, ProcessHistory const& ph, ProductID const& pid) override final;
87  virtual void setProcessHistory_(ProcessHistory const& ph) override final;
88  virtual ProductProvenance const* productProvenancePtr_() const override final;
89  virtual bool singleProduct_() const override final;
90 
92  mutable std::atomic<ProductStatus> theStatus_;
94  };
95 
97  public:
98  explicit InputProductResolver(std::shared_ptr<BranchDescription const> bd) :
100  m_prefetchRequested{ false },
101  aux_{nullptr} {}
102 
103  virtual void setupUnscheduled(UnscheduledConfigurator const&) override final;
104 
105  private:
106  virtual bool isFromCurrentProcess() const override final;
107 
108 
110  bool skipCurrentProcess,
112  ModuleCallingContext const* mcc) const override;
113  virtual void prefetchAsync_(WaitingTask* waitTask,
114  Principal const& principal,
115  bool skipCurrentProcess,
117  ModuleCallingContext const* mcc) const override;
118  virtual void putProduct_(std::unique_ptr<WrapperBase> edp) const override;
119 
120  virtual void retrieveAndMerge_(Principal const& principal) const override;
121 
122  virtual bool unscheduledWasNotRun_() const override final {return false;}
123 
124  virtual void resetProductData_(bool deleteEarly) override;
125 
126  mutable std::atomic<bool> m_prefetchRequested;
128  UnscheduledAuxiliary const* aux_; //provides access to the delayedGet signals
129 
130 
131  };
132 
134  public:
135  ProducedProductResolver(std::shared_ptr<BranchDescription const> bd, ProductStatus iDefaultStatus) : DataManagingProductResolver(bd, iDefaultStatus) {assert(bd->produced());}
136 
137  virtual void resetFailedFromThisProcess() override;
138 
139  protected:
140  virtual void putProduct_(std::unique_ptr<WrapperBase> edp) const override;
141  private:
142  virtual bool isFromCurrentProcess() const override final;
143 
144  };
145 
147  public:
148  explicit PuttableProductResolver(std::shared_ptr<BranchDescription const> bd) : ProducedProductResolver(bd, ProductStatus::NotPut), worker_(nullptr), prefetchRequested_(false) {}
149 
150  virtual void setupUnscheduled(UnscheduledConfigurator const&) override final;
151 
152  private:
154  bool skipCurrentProcess,
156  ModuleCallingContext const* mcc) const override;
157  virtual void prefetchAsync_(WaitingTask* waitTask,
158  Principal const& principal,
159  bool skipCurrentProcess,
161  ModuleCallingContext const* mcc) const override;
162  virtual bool unscheduledWasNotRun_() const override {return false;}
163 
164  virtual void putProduct_(std::unique_ptr<WrapperBase> edp) const override;
165  virtual void resetProductData_(bool deleteEarly) override;
166 
169  mutable std::atomic<bool> prefetchRequested_;
170 
171  };
172 
174  public:
175  explicit UnscheduledProductResolver(std::shared_ptr<BranchDescription const> bd) :
177  aux_(nullptr),
178  prefetchRequested_(false){}
179 
180  virtual void setupUnscheduled(UnscheduledConfigurator const&) override final;
181 
182  private:
184  bool skipCurrentProcess,
186  ModuleCallingContext const* mcc) const override;
187  virtual void prefetchAsync_(WaitingTask* waitTask,
188  Principal const& principal,
189  bool skipCurrentProcess,
191  ModuleCallingContext const* mcc) const override;
192  virtual bool unscheduledWasNotRun_() const override {return status() == ProductStatus::ResolveNotRun;}
193 
194  virtual void resetProductData_(bool deleteEarly) override;
195 
199  mutable std::atomic<bool> prefetchRequested_;
200  };
201 
203  public:
205  explicit AliasProductResolver(std::shared_ptr<BranchDescription const> bd, ProducedProductResolver& realProduct) : ProductResolverBase(), realProduct_(realProduct), bd_(bd) {}
206 
207  virtual void connectTo(ProductResolverBase const& iOther, Principal const* iParentPrincipal) override final {
208  realProduct_.connectTo(iOther, iParentPrincipal );
209  };
210 
211  private:
213  bool skipCurrentProcess,
215  ModuleCallingContext const* mcc) const override {
216  return realProduct_.resolveProduct(principal, skipCurrentProcess, sra, mcc);}
217  virtual void prefetchAsync_(WaitingTask* waitTask,
218  Principal const& principal,
219  bool skipCurrentProcess,
221  ModuleCallingContext const* mcc) const override {
222  realProduct_.prefetchAsync(waitTask, principal, skipCurrentProcess, sra, mcc);
223  }
224  virtual bool unscheduledWasNotRun_() const override {return realProduct_.unscheduledWasNotRun();}
225  virtual bool productUnavailable_() const override {return realProduct_.productUnavailable();}
226  virtual bool productResolved_() const override final {
227  return realProduct_.productResolved(); }
228  virtual bool productWasDeleted_() const override {return realProduct_.productWasDeleted();}
229  virtual bool productWasFetchedAndIsValid_(bool iSkipCurrentProcess) const override final {
230  return realProduct_.productWasFetchedAndIsValid(iSkipCurrentProcess);
231  }
232 
233  virtual void putProduct_(std::unique_ptr<WrapperBase> edp) const override;
234  virtual void putOrMergeProduct_(std::unique_ptr<WrapperBase> prod) const override final;
235  virtual BranchDescription const& branchDescription_() const override {return *bd_;}
236  virtual void resetBranchDescription_(std::shared_ptr<BranchDescription const> bd) override {bd_ = bd;}
237  virtual Provenance const* provenance_() const override final { return realProduct_.provenance(); }
238 
239  virtual std::string const& resolvedModuleLabel_() const override {return realProduct_.moduleLabel();}
240  virtual void setProvenance_(ProductProvenanceRetriever const* provRetriever, ProcessHistory const& ph, ProductID const& pid) override;
241  virtual void setProcessHistory_(ProcessHistory const& ph) override;
242  virtual ProductProvenance const* productProvenancePtr_() const override;
243  virtual void resetProductData_(bool deleteEarly) override;
244  virtual bool singleProduct_() const override;
245 
247  std::shared_ptr<BranchDescription const> bd_;
248  };
249 
251  public:
253  explicit ParentProcessProductResolver(std::shared_ptr<BranchDescription const> bd) : ProductResolverBase(), realProduct_(nullptr), bd_(bd), provRetriever_(nullptr), parentPrincipal_(nullptr) {}
254 
255  virtual void connectTo(ProductResolverBase const& iOther, Principal const* iParentPrincipal) override final {
256  realProduct_ = &iOther;
257  parentPrincipal_ = iParentPrincipal;
258  };
259 
260  private:
262  bool skipCurrentProcess,
264  ModuleCallingContext const* mcc) const override {return realProduct_->resolveProduct(*parentPrincipal_, skipCurrentProcess, sra, mcc);}
265  virtual void prefetchAsync_(WaitingTask* waitTask,
266  Principal const& principal,
267  bool skipCurrentProcess,
269  ModuleCallingContext const* mcc) const override {
270  realProduct_->prefetchAsync( waitTask, *parentPrincipal_, skipCurrentProcess, sra, mcc);
271  }
272  virtual bool unscheduledWasNotRun_() const override {
273  if (realProduct_) return realProduct_->unscheduledWasNotRun();
274  throwNullRealProduct();
275  return false;
276  }
277  virtual bool productUnavailable_() const override {return realProduct_->productUnavailable();}
278  virtual bool productResolved_() const override final { return realProduct_->productResolved(); }
279  virtual bool productWasDeleted_() const override {return realProduct_->productWasDeleted();}
280  virtual bool productWasFetchedAndIsValid_(bool iSkipCurrentProcess) const override {
281  return realProduct_->productWasFetchedAndIsValid(iSkipCurrentProcess); }
282 
283  virtual void putProduct_(std::unique_ptr<WrapperBase> edp) const override;
284  virtual void putOrMergeProduct_(std::unique_ptr<WrapperBase> prod) const override final;
285  virtual BranchDescription const& branchDescription_() const override {return *bd_;}
286  virtual void resetBranchDescription_(std::shared_ptr<BranchDescription const> bd) override {bd_ = bd;}
287  virtual Provenance const* provenance_() const override final {return realProduct_->provenance();
288  }
289  virtual std::string const& resolvedModuleLabel_() const override {return realProduct_->moduleLabel();}
290  virtual void setProvenance_(ProductProvenanceRetriever const* provRetriever, ProcessHistory const& ph, ProductID const& pid) override;
291  virtual void setProcessHistory_(ProcessHistory const& ph) override;
292  virtual ProductProvenance const* productProvenancePtr_() const override;
293  virtual void resetProductData_(bool deleteEarly) override;
294  virtual bool singleProduct_() const override;
295  void throwNullRealProduct() const;
296 
298  std::shared_ptr<BranchDescription const> bd_;
301  };
302 
304  public:
306  NoProcessProductResolver(std::vector<ProductResolverIndex> const& matchingHolders,
307  std::vector<bool> const& ambiguous);
308 
309  virtual void connectTo(ProductResolverBase const& iOther, Principal const*) override final ;
310 
311  void tryPrefetchResolverAsync(unsigned int iProcessingIndex,
312  Principal const& principal,
313  bool skipCurrentProcess,
315  ModuleCallingContext const* mcc,
316  ServiceToken token) const;
317 
318  bool dataValidFromResolver(unsigned int iProcessingIndex,
319  Principal const& principal,
320  bool iSkipCurrentProcess) const;
321 
322  void prefetchFailed(unsigned int iProcessingIndex,
323  Principal const& principal,
324  bool iSkipCurrentProcess,
325  std::exception_ptr iExceptPtr) const;
326  private:
327  unsigned int unsetIndexValue() const;
328  virtual Resolution resolveProduct_(Principal const& principal,
329  bool skipCurrentProcess,
331  ModuleCallingContext const* mcc) const override;
332  virtual void prefetchAsync_(WaitingTask* waitTask,
333  Principal const& principal,
334  bool skipCurrentProcess,
336  ModuleCallingContext const* mcc) const override;
337  virtual bool unscheduledWasNotRun_() const override;
338  virtual bool productUnavailable_() const override;
339  virtual bool productWasDeleted_() const override;
340  virtual bool productResolved_() const override final;
341  virtual bool productWasFetchedAndIsValid_(bool iSkipCurrentProcess) const override;
342 
343  virtual void putProduct_(std::unique_ptr<WrapperBase> edp) const override;
344  virtual void putOrMergeProduct_(std::unique_ptr<WrapperBase> prod) const override final;
345  virtual BranchDescription const& branchDescription_() const override;
346  virtual void resetBranchDescription_(std::shared_ptr<BranchDescription const> bd) override;
347  virtual Provenance const* provenance_() const override;
348 
349  virtual std::string const& resolvedModuleLabel_() const override {return moduleLabel();}
350  virtual void setProvenance_(ProductProvenanceRetriever const* provRetriever, ProcessHistory const& ph, ProductID const& pid) override;
351  virtual void setProcessHistory_(ProcessHistory const& ph) override;
352  virtual ProductProvenance const* productProvenancePtr_() const override;
353  virtual void resetProductData_(bool deleteEarly) override;
354  virtual bool singleProduct_() const override;
355 
356  Resolution tryResolver(unsigned int index,
357  Principal const& principal,
358  bool skipCurrentProcess,
360  ModuleCallingContext const* mcc) const;
361 
362  void setCache(bool skipCurrentProcess, ProductResolverIndex index, std::exception_ptr exceptionPtr) const;
363 
364  std::vector<ProductResolverIndex> matchingHolders_;
365  std::vector<bool> ambiguous_;
368  mutable std::atomic<unsigned int> lastCheckIndex_;
369  mutable std::atomic<unsigned int> lastSkipCurrentCheckIndex_;
370  mutable std::atomic<bool> prefetchRequested_;
371  mutable std::atomic<bool> skippingPrefetchRequested_;
372  mutable std::atomic<bool> recheckedAtEnd_;
373  };
374 
376  public:
379  ProductResolverBase(), realResolverIndex_(iChoice) {}
380 
381  virtual void connectTo(ProductResolverBase const& iOther, Principal const*) override final ;
382 
383  private:
385  bool skipCurrentProcess,
387  ModuleCallingContext const* mcc) const override;
388  virtual void prefetchAsync_(WaitingTask* waitTask,
389  Principal const& principal,
390  bool skipCurrentProcess,
392  ModuleCallingContext const* mcc) const override;
393  virtual bool unscheduledWasNotRun_() const override;
394  virtual bool productUnavailable_() const override;
395  virtual bool productWasDeleted_() const override;
396  virtual bool productResolved_() const override final;
397  virtual bool productWasFetchedAndIsValid_(bool iSkipCurrentProcess) const override;
398 
399  virtual void putProduct_(std::unique_ptr<WrapperBase> edp) const override;
400  virtual void putOrMergeProduct_(std::unique_ptr<WrapperBase> prod) const override final;
401  virtual BranchDescription const& branchDescription_() const override;
402  virtual void resetBranchDescription_(std::shared_ptr<BranchDescription const> bd) override;
403  virtual Provenance const* provenance_() const override;
404 
405  virtual std::string const& resolvedModuleLabel_() const override {return moduleLabel();}
406  virtual void setProvenance_(ProductProvenanceRetriever const* provRetriever, ProcessHistory const& ph, ProductID const& pid) override;
407  virtual void setProcessHistory_(ProcessHistory const& ph) override;
408  virtual ProductProvenance const* productProvenancePtr_() const override;
409  virtual void resetProductData_(bool deleteEarly) override;
410  virtual bool singleProduct_() const override;
411 
413  };
414 
415 }
416 
417 #endif
virtual bool productResolved_() const override final
ProducedProductResolver & realProduct_
Provenance const & provenance() const
Definition: ProductData.h:30
virtual void connectTo(ProductResolverBase const &iOther, Principal const *iParentPrincipal) override final
virtual Provenance const * provenance_() const override final
unsigned int ProductResolverIndex
virtual std::string const & resolvedModuleLabel_() const override final
std::shared_ptr< BranchDescription const > const & branchDescription() const
Definition: ProductData.h:26
virtual bool productUnavailable_() const override final
virtual Resolution resolveProduct_(Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
void checkType(WrapperBase const &prod) const
virtual std::string const & resolvedModuleLabel_() const override
ParentProcessProductResolver(std::shared_ptr< BranchDescription const > bd)
ProducedProductResolver::ProductStatus ProductStatus
virtual void resetBranchDescription_(std::shared_ptr< BranchDescription const > bd) override final
ProductStatus const defaultStatus_
std::shared_ptr< BranchDescription const > bd_
virtual bool unscheduledWasNotRun_() const override
virtual void resetProductData_(bool deleteEarly) override
UnscheduledProductResolver(std::shared_ptr< BranchDescription const > bd)
UnscheduledAuxiliary const * aux_
virtual bool productWasFetchedAndIsValid_(bool iSkipCurrentProcess) const override
ProductStatus status() const
virtual void setupUnscheduled(UnscheduledConfigurator const &)
WaitingTaskList m_waitingTasks
virtual void putProduct_(std::unique_ptr< WrapperBase > edp) const =0
virtual bool productWasFetchedAndIsValid_(bool iSkipCurrentProcess) const override final
virtual void resetBranchDescription_(std::shared_ptr< BranchDescription const > bd) override
DataManagingProductResolver(std::shared_ptr< BranchDescription const > bd, ProductStatus iDefaultStatus)
virtual bool productWasDeleted_() const override final
virtual bool productWasDeleted_() const override
#define nullptr
ProducedProductResolver(std::shared_ptr< BranchDescription const > bd, ProductStatus iDefaultStatus)
std::atomic< bool > prefetchRequested_
virtual std::string const & resolvedModuleLabel_() const override
ProductProvenanceRetriever const * provRetriever_
virtual BranchDescription const & branchDescription_() const override final
virtual Resolution resolveProduct_(Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
virtual bool productUnavailable_() const override
void resetBranchDescription(std::shared_ptr< BranchDescription const > bd)
Definition: ProductData.cc:29
virtual bool unscheduledWasNotRun_() const override
virtual Provenance const * provenance_() const override final
ProducedProductResolver::ProductStatus ProductStatus
virtual Provenance const * provenance_() const override final
UnscheduledAuxiliary const * aux_
virtual void setProcessHistory_(ProcessHistory const &ph) override final
def principal(options)
ProductResolverBase const * realProduct_
virtual std::string const & resolvedModuleLabel_() const override
std::atomic< unsigned int > lastSkipCurrentCheckIndex_
InputProductResolver(std::shared_ptr< BranchDescription const > bd)
virtual bool productResolved_() const override final
virtual void resetFailedFromThisProcess()
std::atomic< bool > prefetchRequested_
virtual BranchDescription const & branchDescription_() const override
void mergeProduct(std::unique_ptr< WrapperBase > edp) const
std::atomic< bool > prefetchRequested_
std::atomic< bool > m_prefetchRequested
std::atomic< unsigned int > lastCheckIndex_
virtual void prefetchAsync_(WaitingTask *waitTask, Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const =0
AliasProductResolver(std::shared_ptr< BranchDescription const > bd, ProducedProductResolver &realProduct)
ProducedProductResolver::ProductStatus ProductStatus
virtual void setProvenance_(ProductProvenanceRetriever const *provRetriever, ProcessHistory const &ph, ProductID const &pid) override final
virtual bool isFromCurrentProcess() const =0
virtual ProductProvenance const * productProvenancePtr_() const override final
void setProduct(std::unique_ptr< WrapperBase > edp) const
virtual BranchDescription const & branchDescription_() const override
std::atomic< bool > skippingPrefetchRequested_
std::atomic< ProductStatus > theStatus_
virtual bool singleProduct_() const override final
std::vector< bool > ambiguous_
Resolution resolveProductImpl(FUNC resolver) const
virtual bool productUnavailable_() const override
virtual bool unscheduledWasNotRun_() const override final
virtual bool unscheduledWasNotRun_() const =0
virtual bool unscheduledWasNotRun_() const override
ProductStatus defaultStatus() const
virtual void prefetchAsync_(WaitingTask *waitTask, Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
std::vector< ProductResolverIndex > matchingHolders_
HLT enums.
virtual void retrieveAndMerge_(Principal const &principal) const
virtual void putOrMergeProduct_(std::unique_ptr< WrapperBase > prod) const override final
virtual void connectTo(ProductResolverBase const &iOther, Principal const *iParentPrincipal) override final
virtual void resetBranchDescription_(std::shared_ptr< BranchDescription const > bd) override
ProducedProductResolver::ProductStatus ProductStatus
ProductData const & getProductData() const
std::shared_ptr< BranchDescription const > bd_
virtual bool unscheduledWasNotRun_() const override
virtual bool productWasFetchedAndIsValid_(bool iSkipCurrentProcess) const override final
PuttableProductResolver(std::shared_ptr< BranchDescription const > bd)
SingleChoiceNoProcessProductResolver(ProductResolverIndex iChoice)
virtual bool productWasDeleted_() const override
virtual Resolution resolveProduct_(Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const =0
std::atomic< bool > recheckedAtEnd_
virtual void prefetchAsync_(WaitingTask *waitTask, Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
std::string const & moduleLabel() const
virtual bool productResolved_() const override final
virtual void connectTo(ProductResolverBase const &, Principal const *) override final