Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:52

0001 #ifndef DataFormats_Common_ProductData_h
0002 #define DataFormats_Common_ProductData_h
0003 
0004 /*----------------------------------------------------------------------
0005 
0006 ProductData: A collection of information related to a single EDProduct. This
0007 is the storage unit of such information.
0008 
0009 ----------------------------------------------------------------------*/
0010 
0011 #include "DataFormats/Provenance/interface/Provenance.h"
0012 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0013 #include <memory>
0014 
0015 namespace edm {
0016   class BranchDescription;
0017   class MergeableRunProductMetadataBase;
0018   class WrapperBase;
0019 
0020   class ProductData {
0021   public:
0022     ProductData();
0023 
0024     explicit ProductData(std::shared_ptr<BranchDescription const> bd);
0025 
0026     // For use by FWLite
0027     ProductData(WrapperBase* product, Provenance const& prov);
0028 
0029     std::shared_ptr<BranchDescription const> const& branchDescription() const {
0030       return prov_.constBranchDescriptionPtr();
0031     }
0032 
0033     Provenance const& provenance() const { return prov_; }
0034 
0035     WrapperBase const* wrapper() const { return wrapper_.get(); }
0036     WrapperBase* unsafe_wrapper() const { return const_cast<WrapperBase*>(wrapper_.get()); }
0037     std::shared_ptr<WrapperBase const> sharedConstWrapper() const { return wrapper_; }
0038 
0039     void swap(ProductData& other) {
0040       std::swap(wrapper_, other.wrapper_);
0041       prov_.swap(other.prov_);
0042     }
0043 
0044     void setWrapper(std::unique_ptr<WrapperBase> iValue);
0045 
0046     //Not const thread-safe update
0047     void unsafe_setWrapper(std::unique_ptr<WrapperBase> iValue) const;
0048     void unsafe_setWrapper(std::shared_ptr<WrapperBase const> iValue) const;  // for SwitchProducer
0049 
0050     void resetBranchDescription(std::shared_ptr<BranchDescription const> bd);
0051 
0052     void resetProductData() { wrapper_.reset(); }
0053 
0054     void unsafe_resetProductData() const { wrapper_.reset(); }
0055 
0056     void setProvenance(ProductProvenanceLookup const* provRetriever) { prov_.setStore(provRetriever); }
0057 
0058     void setProductID(ProductID const& pid) { prov_.setProductID(pid); }
0059 
0060     void setMergeableRunProductMetadata(MergeableRunProductMetadataBase const* mrpm) {
0061       prov_.setMergeableRunProductMetadata(mrpm);
0062     }
0063 
0064     // NOTE: We should probably think hard about whether these
0065     // variables should be declared "mutable" as part of
0066     // the effort to make the Framework multithread capable ...
0067 
0068   private:
0069     // "non-const data" (updated every event).
0070     // The mutating function begin with 'unsafe_'
0071     CMS_SA_ALLOW mutable std::shared_ptr<WrapperBase const> wrapper_;
0072     Provenance prov_;
0073   };
0074 
0075   // Free swap function
0076   inline void swap(ProductData& a, ProductData& b) { a.swap(b); }
0077 }  // namespace edm
0078 #endif