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  void connectTo(ProductResolverBase const&, Principal const*) final;
51 
53 
54  //Give AliasProductResolver access
55  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  void putOrMergeProduct_(std::unique_ptr<WrapperBase> prod) const final;
76  bool productUnavailable_() const final;
77  bool productResolved_() const final;
78  bool productWasDeleted_() const final;
79  bool productWasFetchedAndIsValid_( bool iSkipCurrentProcess) const final;
80 
82  void resetBranchDescription_(std::shared_ptr<BranchDescription const> bd) final {productData_.resetBranchDescription(bd);}
83  Provenance const* provenance_() const final {return &productData_.provenance();}
84 
85  std::string const& resolvedModuleLabel_() const final {return moduleLabel();}
86  void setProvenance_(ProductProvenanceRetriever const* provRetriever, ProcessHistory const& ph, ProductID const& pid) final;
87  void setProcessHistory_(ProcessHistory const& ph) final;
88  ProductProvenance const* productProvenancePtr_() const final;
89  bool singleProduct_() const 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  void setupUnscheduled(UnscheduledConfigurator const&) final;
104 
105  private:
106  bool isFromCurrentProcess() const final;
107 
108 
110  bool skipCurrentProcess,
112  ModuleCallingContext const* mcc) const override;
113  void prefetchAsync_(WaitingTask* waitTask,
114  Principal const& principal,
115  bool skipCurrentProcess,
116  ServiceToken const& token,
118  ModuleCallingContext const* mcc) const override;
119  void putProduct_(std::unique_ptr<WrapperBase> edp) const override;
120 
121  void retrieveAndMerge_(Principal const& principal) const override;
122 
123  bool unscheduledWasNotRun_() const final {return false;}
124 
125  void resetProductData_(bool deleteEarly) override;
126 
127  mutable std::atomic<bool> m_prefetchRequested;
129  UnscheduledAuxiliary const* aux_; //provides access to the delayedGet signals
130 
131 
132  };
133 
135  public:
136  ProducedProductResolver(std::shared_ptr<BranchDescription const> bd, ProductStatus iDefaultStatus) : DataManagingProductResolver(bd, iDefaultStatus) {assert(bd->produced());}
137 
138  protected:
139  void putProduct_(std::unique_ptr<WrapperBase> edp) const override;
140  private:
141  bool isFromCurrentProcess() const final;
142 
143  };
144 
146  public:
147  explicit PuttableProductResolver(std::shared_ptr<BranchDescription const> bd) : ProducedProductResolver(bd, ProductStatus::NotPut), worker_(nullptr), prefetchRequested_(false) {}
148 
149  void setupUnscheduled(UnscheduledConfigurator const&) final;
150 
151  private:
153  bool skipCurrentProcess,
155  ModuleCallingContext const* mcc) const override;
156  void prefetchAsync_(WaitingTask* waitTask,
157  Principal const& principal,
158  bool skipCurrentProcess,
159  ServiceToken const& token,
161  ModuleCallingContext const* mcc) const override;
162  bool unscheduledWasNotRun_() const override {return false;}
163 
164  void putProduct_(std::unique_ptr<WrapperBase> edp) const override;
165  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  void setupUnscheduled(UnscheduledConfigurator const&) final;
181 
182  private:
184  bool skipCurrentProcess,
186  ModuleCallingContext const* mcc) const override;
187  void prefetchAsync_(WaitingTask* waitTask,
188  Principal const& principal,
189  bool skipCurrentProcess,
190  ServiceToken const& token,
192  ModuleCallingContext const* mcc) const override;
193  bool unscheduledWasNotRun_() const override {return status() == ProductStatus::ResolveNotRun;}
194 
195  void resetProductData_(bool deleteEarly) override;
196 
200  mutable std::atomic<bool> prefetchRequested_;
201  };
202 
204  public:
206  explicit AliasProductResolver(std::shared_ptr<BranchDescription const> bd, ProducedProductResolver& realProduct) : ProductResolverBase(), realProduct_(realProduct), bd_(bd) {}
207 
208  void connectTo(ProductResolverBase const& iOther, Principal const* iParentPrincipal) final {
209  realProduct_.connectTo(iOther, iParentPrincipal );
210  };
211 
212  private:
214  bool skipCurrentProcess,
216  ModuleCallingContext const* mcc) const override {
217  return realProduct_.resolveProduct(principal, skipCurrentProcess, sra, mcc);}
218  void prefetchAsync_(WaitingTask* waitTask,
219  Principal const& principal,
220  bool skipCurrentProcess,
221  ServiceToken const& token,
223  ModuleCallingContext const* mcc) const override {
224  realProduct_.prefetchAsync(waitTask, principal, skipCurrentProcess, token, sra, mcc);
225  }
226  bool unscheduledWasNotRun_() const override {return realProduct_.unscheduledWasNotRun();}
227  bool productUnavailable_() const override {return realProduct_.productUnavailable();}
228  bool productResolved_() const final {
229  return realProduct_.productResolved(); }
230  bool productWasDeleted_() const override {return realProduct_.productWasDeleted();}
231  bool productWasFetchedAndIsValid_(bool iSkipCurrentProcess) const final {
232  return realProduct_.productWasFetchedAndIsValid(iSkipCurrentProcess);
233  }
234 
235  void putProduct_(std::unique_ptr<WrapperBase> edp) const override;
236  void putOrMergeProduct_(std::unique_ptr<WrapperBase> prod) const final;
237  BranchDescription const& branchDescription_() const override {return *bd_;}
238  void resetBranchDescription_(std::shared_ptr<BranchDescription const> bd) override {bd_ = bd;}
239  Provenance const* provenance_() const final { return realProduct_.provenance(); }
240 
241  std::string const& resolvedModuleLabel_() const override {return realProduct_.moduleLabel();}
242  void setProvenance_(ProductProvenanceRetriever const* provRetriever, ProcessHistory const& ph, ProductID const& pid) override;
243  void setProcessHistory_(ProcessHistory const& ph) override;
244  ProductProvenance const* productProvenancePtr_() const override;
245  void resetProductData_(bool deleteEarly) override;
246  bool singleProduct_() const override;
247 
249  std::shared_ptr<BranchDescription const> bd_;
250  };
251 
253  public:
255  explicit ParentProcessProductResolver(std::shared_ptr<BranchDescription const> bd) : ProductResolverBase(), realProduct_(nullptr), bd_(bd), provRetriever_(nullptr), parentPrincipal_(nullptr) {}
256 
257  void connectTo(ProductResolverBase const& iOther, Principal const* iParentPrincipal) final {
258  realProduct_ = &iOther;
259  parentPrincipal_ = iParentPrincipal;
260  };
261 
262  private:
264  bool skipCurrentProcess,
266  ModuleCallingContext const* mcc) const override {
267  skipCurrentProcess = false;
268  return realProduct_->resolveProduct(*parentPrincipal_, skipCurrentProcess, sra, mcc);
269  }
270  void prefetchAsync_(WaitingTask* waitTask,
271  Principal const& principal,
272  bool skipCurrentProcess,
273  ServiceToken const& token,
275  ModuleCallingContext const* mcc) const override {
276  skipCurrentProcess = false;
277  realProduct_->prefetchAsync( waitTask, *parentPrincipal_, skipCurrentProcess, token, sra, mcc);
278  }
279  bool unscheduledWasNotRun_() const override {
280  if (realProduct_) return realProduct_->unscheduledWasNotRun();
281  throwNullRealProduct();
282  return false;
283  }
284  bool productUnavailable_() const override {return realProduct_->productUnavailable();}
285  bool productResolved_() const final { return realProduct_->productResolved(); }
286  bool productWasDeleted_() const override {return realProduct_->productWasDeleted();}
287  bool productWasFetchedAndIsValid_(bool iSkipCurrentProcess) const override {
288  iSkipCurrentProcess = false;
289  return realProduct_->productWasFetchedAndIsValid(iSkipCurrentProcess);
290  }
291 
292  void putProduct_(std::unique_ptr<WrapperBase> edp) const override;
293  void putOrMergeProduct_(std::unique_ptr<WrapperBase> prod) const final;
294  BranchDescription const& branchDescription_() const override {return *bd_;}
295  void resetBranchDescription_(std::shared_ptr<BranchDescription const> bd) override {bd_ = bd;}
296  Provenance const* provenance_() const final {return realProduct_->provenance();
297  }
298  std::string const& resolvedModuleLabel_() const override {return realProduct_->moduleLabel();}
299  void setProvenance_(ProductProvenanceRetriever const* provRetriever, ProcessHistory const& ph, ProductID const& pid) override;
300  void setProcessHistory_(ProcessHistory const& ph) override;
301  ProductProvenance const* productProvenancePtr_() const override;
302  void resetProductData_(bool deleteEarly) override;
303  bool singleProduct_() const override;
304  void throwNullRealProduct() const;
305 
307  std::shared_ptr<BranchDescription const> bd_;
310  };
311 
313  public:
315  NoProcessProductResolver(std::vector<ProductResolverIndex> const& matchingHolders,
316  std::vector<bool> const& ambiguous, bool madeAtEnd);
317 
318  void connectTo(ProductResolverBase const& iOther, Principal const*) final ;
319 
320  void tryPrefetchResolverAsync(unsigned int iProcessingIndex,
321  Principal const& principal,
322  bool skipCurrentProcess,
324  ModuleCallingContext const* mcc,
325  ServiceToken token) const;
326 
327  bool dataValidFromResolver(unsigned int iProcessingIndex,
328  Principal const& principal,
329  bool iSkipCurrentProcess) const;
330 
331  void prefetchFailed(unsigned int iProcessingIndex,
332  Principal const& principal,
333  bool iSkipCurrentProcess,
334  std::exception_ptr iExceptPtr) const;
335  private:
336  unsigned int unsetIndexValue() const;
337  Resolution resolveProduct_(Principal const& principal,
338  bool skipCurrentProcess,
340  ModuleCallingContext const* mcc) const override;
341  void prefetchAsync_(WaitingTask* waitTask,
342  Principal const& principal,
343  bool skipCurrentProcess,
344  ServiceToken const& token,
346  ModuleCallingContext const* mcc) const override;
347  bool unscheduledWasNotRun_() const override;
348  bool productUnavailable_() const override;
349  bool productWasDeleted_() const override;
350  bool productResolved_() const final;
351  bool productWasFetchedAndIsValid_(bool iSkipCurrentProcess) const override;
352 
353  void putProduct_(std::unique_ptr<WrapperBase> edp) const override;
354  void putOrMergeProduct_(std::unique_ptr<WrapperBase> prod) const final;
355  BranchDescription const& branchDescription_() const override;
356  void resetBranchDescription_(std::shared_ptr<BranchDescription const> bd) override;
357  Provenance const* provenance_() const override;
358 
359  std::string const& resolvedModuleLabel_() const override {return moduleLabel();}
360  void setProvenance_(ProductProvenanceRetriever const* provRetriever, ProcessHistory const& ph, ProductID const& pid) override;
361  void setProcessHistory_(ProcessHistory const& ph) override;
362  ProductProvenance const* productProvenancePtr_() const override;
363  void resetProductData_(bool deleteEarly) override;
364  bool singleProduct_() const override;
365 
366  Resolution tryResolver(unsigned int index,
367  Principal const& principal,
368  bool skipCurrentProcess,
370  ModuleCallingContext const* mcc) const;
371 
372  void setCache(bool skipCurrentProcess, ProductResolverIndex index, std::exception_ptr exceptionPtr) const;
373 
374  std::vector<ProductResolverIndex> matchingHolders_;
375  std::vector<bool> ambiguous_;
378  mutable std::atomic<unsigned int> lastCheckIndex_;
379  mutable std::atomic<unsigned int> lastSkipCurrentCheckIndex_;
380  mutable std::atomic<bool> prefetchRequested_;
381  mutable std::atomic<bool> skippingPrefetchRequested_;
382  const bool madeAtEnd_;
383  };
384 
386  public:
389  ProductResolverBase(), realResolverIndex_(iChoice) {}
390 
391  void connectTo(ProductResolverBase const& iOther, Principal const*) final ;
392 
393  private:
395  bool skipCurrentProcess,
397  ModuleCallingContext const* mcc) const override;
398  void prefetchAsync_(WaitingTask* waitTask,
399  Principal const& principal,
400  bool skipCurrentProcess,
401  ServiceToken const& token,
403  ModuleCallingContext const* mcc) const override;
404  bool unscheduledWasNotRun_() const override;
405  bool productUnavailable_() const override;
406  bool productWasDeleted_() const override;
407  bool productResolved_() const final;
408  bool productWasFetchedAndIsValid_(bool iSkipCurrentProcess) const override;
409 
410  void putProduct_(std::unique_ptr<WrapperBase> edp) const override;
411  void putOrMergeProduct_(std::unique_ptr<WrapperBase> prod) const final;
412  BranchDescription const& branchDescription_() const override;
413  void resetBranchDescription_(std::shared_ptr<BranchDescription const> bd) override;
414  Provenance const* provenance_() const override;
415 
416  std::string const& resolvedModuleLabel_() const override {return moduleLabel();}
417  void setProvenance_(ProductProvenanceRetriever const* provRetriever, ProcessHistory const& ph, ProductID const& pid) override;
418  void setProcessHistory_(ProcessHistory const& ph) override;
419  ProductProvenance const* productProvenancePtr_() const override;
420  void resetProductData_(bool deleteEarly) override;
421  bool singleProduct_() const override;
422 
424  };
425 
426 }
427 
428 #endif
ProducedProductResolver & realProduct_
bool productResolved_() const final
Provenance const & provenance() const
Definition: ProductData.h:30
bool unscheduledWasNotRun_() const override
void connectTo(ProductResolverBase const &iOther, Principal const *iParentPrincipal) final
unsigned int ProductResolverIndex
std::shared_ptr< BranchDescription const > const & branchDescription() const
Definition: ProductData.h:26
void checkType(WrapperBase const &prod) const
ParentProcessProductResolver(std::shared_ptr< BranchDescription const > bd)
ProducedProductResolver::ProductStatus ProductStatus
std::string const & resolvedModuleLabel_() const override
ProductStatus const defaultStatus_
std::shared_ptr< BranchDescription const > bd_
bool productUnavailable_() const override
bool productWasFetchedAndIsValid_(bool iSkipCurrentProcess) const final
void resetProductData_(bool deleteEarly) override
UnscheduledProductResolver(std::shared_ptr< BranchDescription const > bd)
UnscheduledAuxiliary const * aux_
ProductStatus status() const
Provenance const * provenance_() const final
virtual void setupUnscheduled(UnscheduledConfigurator const &)
std::string const & resolvedModuleLabel_() const final
WaitingTaskList m_waitingTasks
virtual void putProduct_(std::unique_ptr< WrapperBase > edp) const =0
virtual void prefetchAsync_(WaitingTask *waitTask, Principal const &principal, bool skipCurrentProcess, ServiceToken const &token, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const =0
DataManagingProductResolver(std::shared_ptr< BranchDescription const > bd, ProductStatus iDefaultStatus)
Provenance const * provenance_() const final
#define nullptr
ProducedProductResolver(std::shared_ptr< BranchDescription const > bd, ProductStatus iDefaultStatus)
std::atomic< bool > prefetchRequested_
ProductProvenanceRetriever const * provRetriever_
Resolution resolveProduct_(Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
void connectTo(ProductResolverBase const &, Principal const *) final
void resetBranchDescription(std::shared_ptr< BranchDescription const > bd)
Definition: ProductData.cc:29
std::string const & resolvedModuleLabel_() const override
void resetBranchDescription_(std::shared_ptr< BranchDescription const > bd) override
bool productUnavailable_() const override
BranchDescription const & branchDescription_() const override
ProducedProductResolver::ProductStatus ProductStatus
UnscheduledAuxiliary const * aux_
def principal(options)
ProductResolverBase const * realProduct_
void connectTo(ProductResolverBase const &iOther, Principal const *iParentPrincipal) final
std::atomic< unsigned int > lastSkipCurrentCheckIndex_
InputProductResolver(std::shared_ptr< BranchDescription const > bd)
std::atomic< bool > prefetchRequested_
bool productWasDeleted_() const override
BranchDescription const & branchDescription_() const final
void resetBranchDescription_(std::shared_ptr< BranchDescription const > bd) override
void mergeProduct(std::unique_ptr< WrapperBase > edp) const
void putOrMergeProduct_(std::unique_ptr< WrapperBase > prod) const final
std::atomic< bool > prefetchRequested_
std::atomic< bool > m_prefetchRequested
std::atomic< unsigned int > lastCheckIndex_
bool unscheduledWasNotRun_() const override
void setProvenance_(ProductProvenanceRetriever const *provRetriever, ProcessHistory const &ph, ProductID const &pid) final
bool unscheduledWasNotRun_() const override
AliasProductResolver(std::shared_ptr< BranchDescription const > bd, ProducedProductResolver &realProduct)
ProducedProductResolver::ProductStatus ProductStatus
virtual bool isFromCurrentProcess() const =0
void setProduct(std::unique_ptr< WrapperBase > edp) const
std::atomic< bool > skippingPrefetchRequested_
std::atomic< ProductStatus > theStatus_
std::vector< bool > ambiguous_
Resolution resolveProductImpl(FUNC resolver) const
Resolution resolveProduct_(Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
bool unscheduledWasNotRun_() const override
virtual bool unscheduledWasNotRun_() const =0
ProductStatus defaultStatus() const
bool productWasFetchedAndIsValid_(bool iSkipCurrentProcess) const final
BranchDescription const & branchDescription_() const override
std::vector< ProductResolverIndex > matchingHolders_
HLT enums.
bool productWasFetchedAndIsValid_(bool iSkipCurrentProcess) const override
bool productWasDeleted_() const override
virtual void retrieveAndMerge_(Principal const &principal) const
void resetBranchDescription_(std::shared_ptr< BranchDescription const > bd) final
ProductProvenance const * productProvenancePtr_() const final
ProducedProductResolver::ProductStatus ProductStatus
void prefetchAsync_(WaitingTask *waitTask, Principal const &principal, bool skipCurrentProcess, ServiceToken const &token, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
ProductData const & getProductData() const
std::shared_ptr< BranchDescription const > bd_
void prefetchAsync_(WaitingTask *waitTask, Principal const &principal, bool skipCurrentProcess, ServiceToken const &token, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const override
std::string const & resolvedModuleLabel_() const override
bool unscheduledWasNotRun_() const final
PuttableProductResolver(std::shared_ptr< BranchDescription const > bd)
Provenance const * provenance_() const final
SingleChoiceNoProcessProductResolver(ProductResolverIndex iChoice)
virtual Resolution resolveProduct_(Principal const &principal, bool skipCurrentProcess, SharedResourcesAcquirer *sra, ModuleCallingContext const *mcc) const =0
void setProcessHistory_(ProcessHistory const &ph) final
std::string const & moduleLabel() const