Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:02

0001 #ifndef DataFormats_Provenance_ProductProvenanceLookup_h
0002 #define DataFormats_Provenance_ProductProvenanceLookup_h
0003 
0004 /*----------------------------------------------------------------------
0005   
0006 ProductProvenanceLookup: Gives access to the per event/lumi/run per product provenance.
0007 
0008 ----------------------------------------------------------------------*/
0009 #include "DataFormats/Provenance/interface/BranchID.h"
0010 #include "DataFormats/Provenance/interface/ProductProvenance.h"
0011 #include "FWCore/Utilities/interface/propagate_const.h"
0012 #include "FWCore/Utilities/interface/Likely.h"
0013 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0014 
0015 #include <vector>
0016 #include <memory>
0017 #include <set>
0018 #include <atomic>
0019 
0020 /*
0021  ProductProvenanceLookup
0022 */
0023 
0024 namespace edm {
0025   class ProductRegistry;
0026 
0027   class ProductProvenanceLookup {
0028   public:
0029     ProductProvenanceLookup();
0030     explicit ProductProvenanceLookup(edm::ProductRegistry const&);
0031     virtual ~ProductProvenanceLookup();
0032 
0033     ProductProvenanceLookup& operator=(ProductProvenanceLookup const&) = delete;
0034 
0035     ProductProvenance const* branchIDToProvenance(BranchID const& bid) const;
0036     void insertIntoSet(ProductProvenance provenanceProduct) const;
0037     ProductProvenance const* branchIDToProvenanceForProducedOnly(BranchID const& bid) const;
0038 
0039     void update(edm::ProductRegistry const&);
0040 
0041     class ProducedProvenanceInfo {
0042     public:
0043       ProducedProvenanceInfo(BranchID iBid) : provenance_{iBid}, isParentageSet_{false} {}
0044       ProducedProvenanceInfo(ProducedProvenanceInfo&& iOther)
0045           : provenance_{std::move(iOther.provenance_)},
0046             isParentageSet_{iOther.isParentageSet_.load(std::memory_order_acquire)} {}
0047       ProducedProvenanceInfo(ProducedProvenanceInfo const& iOther) : provenance_{iOther.provenance_.branchID()} {
0048         bool isSet = iOther.isParentageSet_.load(std::memory_order_acquire);
0049         if (isSet) {
0050           provenance_.set(iOther.provenance_.parentageID());
0051         }
0052         isParentageSet_.store(isSet, std::memory_order_release);
0053       }
0054 
0055       ProducedProvenanceInfo& operator=(ProducedProvenanceInfo&& iOther) {
0056         provenance_ = std::move(iOther.provenance_);
0057         isParentageSet_.store(iOther.isParentageSet_.load(std::memory_order_acquire), std::memory_order_release);
0058         return *this;
0059       }
0060       ProducedProvenanceInfo& operator=(ProducedProvenanceInfo const& iOther) {
0061         bool isSet = iOther.isParentageSet_.load(std::memory_order_acquire);
0062         if (isSet) {
0063           provenance_ = iOther.provenance_;
0064         } else {
0065           provenance_ = ProductProvenance(iOther.provenance_.branchID());
0066         }
0067         isParentageSet_.store(isSet, std::memory_order_release);
0068         return *this;
0069       }
0070 
0071       ProductProvenance const* productProvenance() const noexcept {
0072         if (LIKELY(isParentageSet())) {
0073           return &provenance_;
0074         }
0075         return nullptr;
0076       }
0077       BranchID branchID() const noexcept { return provenance_.branchID(); }
0078 
0079       bool isParentageSet() const noexcept { return isParentageSet_.load(std::memory_order_acquire); }
0080 
0081       void threadsafe_set(ParentageID id) const {
0082         provenance_.set(std::move(id));
0083         isParentageSet_.store(true, std::memory_order_release);
0084       }
0085 
0086       void resetParentage() { isParentageSet_.store(false, std::memory_order_release); }
0087 
0088     private:
0089       CMS_THREAD_GUARD(isParentageSet_) mutable ProductProvenance provenance_;
0090       mutable std::atomic<bool> isParentageSet_;
0091     };
0092 
0093   protected:
0094     virtual std::unique_ptr<const std::set<ProductProvenance>> readProvenance() const = 0;
0095     virtual const ProductProvenanceLookup* nextRetriever() const = 0;
0096 
0097     std::vector<ProducedProvenanceInfo> entryInfoSet_;
0098     mutable std::atomic<const std::set<ProductProvenance>*> readEntryInfoSet_;
0099     edm::propagate_const<ProductProvenanceLookup const*> parentProcessRetriever_;
0100 
0101   private:
0102     void setupEntryInfoSet(edm::ProductRegistry const&);
0103   };
0104 }  // namespace edm
0105 #endif