Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-29 04:38:01

0001 #ifndef FWCore_Framework_ProductResolverBase_h
0002 #define FWCore_Framework_ProductResolverBase_h
0003 
0004 /*----------------------------------------------------------------------
0005 
0006 ProductResolver: Class to handle access to a WrapperBase and its related information.
0007 
0008  [The class was formerly called Group and later ProductHolder]
0009 ----------------------------------------------------------------------*/
0010 
0011 #include "DataFormats/Common/interface/WrapperBase.h"
0012 #include "DataFormats/Common/interface/ProductData.h"
0013 #include "DataFormats/Provenance/interface/BranchDescription.h"
0014 #include "DataFormats/Provenance/interface/BranchID.h"
0015 #include "DataFormats/Provenance/interface/Provenance.h"
0016 #include "FWCore/Concurrency/interface/WaitingTaskHolder.h"
0017 #include "FWCore/Utilities/interface/ProductResolverIndex.h"
0018 #include "FWCore/Utilities/interface/TypeID.h"
0019 
0020 #include <memory>
0021 
0022 #include <string>
0023 
0024 namespace edm {
0025   class MergeableRunProductMetadata;
0026   class ProductProvenanceRetriever;
0027   class DelayedReader;
0028   class ModuleCallingContext;
0029   class SharedResourcesAcquirer;
0030   class Principal;
0031   class UnscheduledConfigurator;
0032   class ServiceToken;
0033 
0034   class ProductResolverBase {
0035   public:
0036     class Resolution {
0037     public:
0038       static std::uintptr_t constexpr kAmbiguityValue = 0x1;
0039       static std::uintptr_t constexpr kAmbiguityMask = std::numeric_limits<std::uintptr_t>::max() ^ kAmbiguityValue;
0040       explicit Resolution(ProductData const* iData) : m_data(iData) {}
0041 
0042       bool isAmbiguous() const { return reinterpret_cast<std::uintptr_t>(m_data) == kAmbiguityValue; }
0043 
0044       ProductData const* data() const {
0045         return reinterpret_cast<ProductData const*>(kAmbiguityMask & reinterpret_cast<std::uintptr_t>(m_data));
0046       }
0047 
0048       static Resolution makeAmbiguous() { return Resolution(reinterpret_cast<ProductData const*>(kAmbiguityValue)); }
0049 
0050     private:
0051       ProductData const* m_data;
0052     };
0053 
0054     ProductResolverBase();
0055     virtual ~ProductResolverBase();
0056 
0057     ProductResolverBase(ProductResolverBase const&) = delete;             // Disallow copying and moving
0058     ProductResolverBase& operator=(ProductResolverBase const&) = delete;  // Disallow copying and moving
0059 
0060     Resolution resolveProduct(Principal const& principal,
0061                               bool skipCurrentProcess,
0062                               SharedResourcesAcquirer* sra,
0063                               ModuleCallingContext const* mcc) const {
0064       return resolveProduct_(principal, skipCurrentProcess, sra, mcc);
0065     }
0066 
0067     /** oDataFetchedIsValid is allowed to be nullptr in which case no value will be assigned
0068      */
0069     void prefetchAsync(WaitingTaskHolder waitTask,
0070                        Principal const& principal,
0071                        bool skipCurrentProcess,
0072                        ServiceToken const& token,
0073                        SharedResourcesAcquirer* sra,
0074                        ModuleCallingContext const* mcc) const {
0075       return prefetchAsync_(waitTask, principal, skipCurrentProcess, token, sra, mcc);
0076     }
0077 
0078     void retrieveAndMerge(Principal const& principal,
0079                           MergeableRunProductMetadata const* mergeableRunProductMetadata) const {
0080       retrieveAndMerge_(principal, mergeableRunProductMetadata);
0081     }
0082     void resetProductData() { resetProductData_(false); }
0083 
0084     void unsafe_deleteProduct() const { const_cast<ProductResolverBase*>(this)->resetProductData_(true); }
0085 
0086     // product is not available (dropped or never created)
0087     bool productUnavailable() const { return productUnavailable_(); }
0088 
0089     // returns true if resolveProduct was already called for this product
0090     bool productResolved() const { return productResolved_(); }
0091 
0092     // provenance is currently available
0093     bool provenanceAvailable() const;
0094 
0095     // Only returns true if the module is unscheduled and was not run
0096     //   all other cases return false
0097     bool unscheduledWasNotRun() const { return unscheduledWasNotRun_(); }
0098 
0099     // Product was deleted early in order to save memory
0100     bool productWasDeleted() const { return productWasDeleted_(); }
0101 
0102     bool productWasFetchedAndIsValid(bool iSkipCurrentProcess) const {
0103       return productWasFetchedAndIsValid_(iSkipCurrentProcess);
0104     }
0105 
0106     // Retrieves pointer to the per event(lumi)(run) provenance.
0107     ProductProvenance const* productProvenancePtr() const { return productProvenancePtr_(); }
0108 
0109     // Retrieves a reference to the event independent provenance.
0110     BranchDescription const& branchDescription() const { return branchDescription_(); }
0111 
0112     // Retrieves a reference to the event independent provenance.
0113     bool singleProduct() const { return singleProduct_(); }
0114 
0115     // Sets the pointer to the event independent provenance.
0116     void resetBranchDescription(std::shared_ptr<BranchDescription const> bd) { resetBranchDescription_(bd); }
0117 
0118     // Retrieves a reference to the module label.
0119     std::string const& moduleLabel() const { return branchDescription().moduleLabel(); }
0120 
0121     // Same as moduleLabel except in the case of an AliasProductResolver, in which
0122     // case it resolves the module which actually produces the product and returns
0123     // its module label
0124     std::string const& resolvedModuleLabel() const { return resolvedModuleLabel_(); }
0125 
0126     // Retrieves a reference to the product instance name
0127     std::string const& productInstanceName() const { return branchDescription().productInstanceName(); }
0128 
0129     // Retrieves a reference to the process name
0130     std::string const& processName() const { return branchDescription().processName(); }
0131 
0132     // Retrieves pointer to a class containing both the event independent and the per even provenance.
0133     Provenance const* provenance() const;
0134 
0135     // Retrieves pointer to a class containing the event independent provenance.
0136     StableProvenance const* stableProvenance() const { return &provenance()->stable(); }
0137 
0138     // Initialize the mechanism to retrieve per event provenance
0139     void setProductProvenanceRetriever(ProductProvenanceRetriever const* provRetriever) {
0140       setProductProvenanceRetriever_(provRetriever);
0141     }
0142 
0143     // Initializes the ProductID
0144     void setProductID(ProductID const& pid) { setProductID_(pid); }
0145 
0146     // Initializes the portion of the provenance related to mergeable run products.
0147     void setMergeableRunProductMetadata(MergeableRunProductMetadata const* mrpm) {
0148       setMergeableRunProductMetadata_(mrpm);
0149     }
0150 
0151     // Write the product to the stream.
0152     void write(std::ostream& os) const;
0153 
0154     // Return the type of the product stored in this ProductResolver.
0155     // We are relying on the fact that Type instances are small, and
0156     // so we are free to copy them at will.
0157     TypeID productType() const;
0158 
0159     // Retrieves the product ID of the product.
0160     ProductID const& productID() const { return provenance()->productID(); }
0161 
0162     virtual void connectTo(ProductResolverBase const&, Principal const*) = 0;
0163     virtual void setupUnscheduled(UnscheduledConfigurator const&);
0164 
0165   private:
0166     virtual Resolution resolveProduct_(Principal const& principal,
0167                                        bool skipCurrentProcess,
0168                                        SharedResourcesAcquirer* sra,
0169                                        ModuleCallingContext const* mcc) const = 0;
0170     virtual void prefetchAsync_(WaitingTaskHolder waitTask,
0171                                 Principal const& principal,
0172                                 bool skipCurrentProcess,
0173                                 ServiceToken const& token,
0174                                 SharedResourcesAcquirer* sra,
0175                                 ModuleCallingContext const* mcc) const = 0;
0176 
0177     virtual void retrieveAndMerge_(Principal const& principal,
0178                                    MergeableRunProductMetadata const* mergeableRunProductMetadata) const;
0179 
0180     virtual bool unscheduledWasNotRun_() const = 0;
0181     virtual bool productUnavailable_() const = 0;
0182     virtual bool productResolved_() const = 0;
0183     virtual bool productWasDeleted_() const = 0;
0184     virtual bool productWasFetchedAndIsValid_(bool iSkipCurrentProcess) const = 0;
0185 
0186     virtual BranchDescription const& branchDescription_() const = 0;
0187     virtual void resetBranchDescription_(std::shared_ptr<BranchDescription const> bd) = 0;
0188     virtual Provenance const* provenance_() const = 0;
0189     virtual std::string const& resolvedModuleLabel_() const = 0;
0190     virtual void setProductProvenanceRetriever_(ProductProvenanceRetriever const* provRetriever) = 0;
0191     virtual void setProductID_(ProductID const& pid) = 0;
0192     virtual void setMergeableRunProductMetadata_(MergeableRunProductMetadata const*);
0193     virtual ProductProvenance const* productProvenancePtr_() const = 0;
0194     virtual void resetProductData_(bool deleteEarly) = 0;
0195     virtual bool singleProduct_() const = 0;
0196   };
0197 
0198   inline std::ostream& operator<<(std::ostream& os, ProductResolverBase const& phb) {
0199     phb.write(os);
0200     return os;
0201   }
0202 }  // namespace edm
0203 
0204 #endif