Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-14 03:16:31

0001 // -*- C++ -*-
0002 #ifndef FWCore_Framework_EventSetupRecordProvider_h
0003 #define FWCore_Framework_EventSetupRecordProvider_h
0004 //
0005 // Package:     Framework
0006 // Class  :     EventSetupRecordProvider
0007 //
0008 /**\class edm::eventsetup::EventSetupRecordProvider
0009 
0010  Description: Coordinates all EventSetupDataProviders with the same 'interval of validity'
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Author:      Chris Jones
0018 // Created:     Fri Mar 25 19:02:23 EST 2005
0019 //
0020 
0021 // user include files
0022 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
0023 #include "FWCore/Framework/interface/EventSetupRecordImpl.h"
0024 #include "FWCore/Framework/interface/ValidityInterval.h"
0025 #include "FWCore/Utilities/interface/get_underlying_safe.h"
0026 #include "FWCore/Utilities/interface/propagate_const.h"
0027 
0028 // system include files
0029 #include <map>
0030 #include <memory>
0031 #include <set>
0032 #include <unordered_set>
0033 #include <vector>
0034 
0035 // forward declarations
0036 namespace edm {
0037   class ActivityRegistry;
0038   class EventSetupImpl;
0039   class EventSetupRecordIntervalFinder;
0040 
0041   namespace eventsetup {
0042     struct ComponentDescription;
0043     class DataKey;
0044     class ESProductResolverProvider;
0045     class ESRecordsToProductResolverIndices;
0046     class EventSetupProvider;
0047     class EventSetupRecordImpl;
0048     class ParameterSetIDHolder;
0049 
0050     class EventSetupRecordProvider {
0051     public:
0052       enum class IntervalStatus { NotInitializedForSyncValue, Invalid, NewInterval, UpdateIntervalEnd, SameInterval };
0053 
0054       using DataToPreferredProviderMap = std::map<DataKey, ComponentDescription>;
0055 
0056       EventSetupRecordProvider(EventSetupRecordKey const& iKey,
0057                                ActivityRegistry const*,
0058                                unsigned int nConcurrentIOVs = 1);
0059 
0060       EventSetupRecordProvider(EventSetupRecordProvider const&) = delete;
0061       EventSetupRecordProvider const& operator=(EventSetupRecordProvider const&) = delete;
0062 
0063       // ---------- const member functions ---------------------
0064 
0065       unsigned int nConcurrentIOVs() const { return nConcurrentIOVs_; }
0066 
0067       ValidityInterval const& validityInterval() const { return validityInterval_; }
0068       EventSetupRecordKey const& key() const { return key_; }
0069 
0070       // Returns a reference for the first of the allowed concurrent IOVs.
0071       // There is always at least one IOV allowed. Intended for cases where
0072       // you only need one of them and don't care which one you get.
0073       EventSetupRecordImpl const& firstRecordImpl() const;
0074 
0075       ///Returns the list of Records the provided Record depends on (usually none)
0076       std::set<EventSetupRecordKey> dependentRecords() const;
0077 
0078       ///return information on which ESProductResolverProviders are supplying information
0079       std::set<ComponentDescription> resolverProviderDescriptions() const;
0080 
0081       /// The available DataKeys in the Record. The order can be used to request the data by index
0082       std::vector<DataKey> registeredDataKeys() const;
0083 
0084       std::vector<ComponentDescription const*> componentsForRegisteredDataKeys() const;
0085       std::vector<unsigned int> produceMethodIDsForRegisteredDataKeys() const;
0086 
0087       // ---------- member functions ---------------------------
0088 
0089       ///returns the first matching ESProductResolverProvider or a 'null' if not found
0090       std::shared_ptr<ESProductResolverProvider> resolverProvider(ComponentDescription const&);
0091 
0092       ///returns the first matching ESProductResolverProvider or a 'null' if not found
0093       std::shared_ptr<ESProductResolverProvider> resolverProvider(ParameterSetIDHolder const&);
0094 
0095       void resetProductResolverProvider(ParameterSetIDHolder const&, std::shared_ptr<ESProductResolverProvider> const&);
0096 
0097       void add(std::shared_ptr<ESProductResolverProvider>);
0098       ///For now, only use one finder
0099       void addFinder(std::shared_ptr<EventSetupRecordIntervalFinder>);
0100 
0101       ///Intended for use only in unit tests
0102       void setValidityInterval_forTesting(ValidityInterval const&);
0103 
0104       /** This function is called when an IOV is started up by the asynchronous task assigned to start IOVs.
0105        *  This is the point where we know the value of iovIndex, so we know which EventSetupRecordImpl
0106        *  object will be used. We set a pointer to it. In the EventSetupRecordImpl we set the cacheIdentifier
0107        *  and validity interval. We also set the pointer in the EventSetupImpl to the EventSetupRecordImpl here.
0108        */
0109       void initializeForNewIOV(unsigned int iovIndex, unsigned long long cacheIdentifier);
0110 
0111       /** This function is called when we do not need to start a new IOV for a record and syncValue.
0112        *  If a new EventSetupImpl was created, then this will set its pointer to the EventSetupRecordImpl.
0113        *  This is also the place where the validity interval will be updated in the special case
0114        *  where the beginning of the interval did not change but the end changed so it is not treated
0115        *  as a new IOV.
0116        */
0117       void continueIOV(bool newEventSetupImpl);
0118 
0119       /** The asynchronous task called when an IOV ends calls this function. It clears the caches
0120        *  of the ESProductResolver's.
0121        */
0122       void endIOV(unsigned int iovIndex);
0123 
0124       /** Set a flag each time the EventSetupProvider starts initializing with a new sync value.
0125        *  setValidityIntervalFor can be called multiple times because of dependent records.
0126        *  Using this flag allows setValidityIntervalFor to avoid duplicating its work on the same
0127        *  syncValue.
0128        */
0129       void initializeForNewSyncValue();
0130 
0131       bool doWeNeedToWaitForIOVsToFinish(IOVSyncValue const&) const;
0132 
0133       /** Sets the validity interval for this sync value and returns true if we have a valid
0134        *  interval for sync value. Also sets the interval status.
0135        */
0136       bool setValidityIntervalFor(IOVSyncValue const&);
0137 
0138       bool newIntervalForAnySubProcess() const { return newIntervalForAnySubProcess_; }
0139       void setNewIntervalForAnySubProcess(bool value) { newIntervalForAnySubProcess_ = value; }
0140 
0141       ///If the provided Record depends on other Records, here are the dependent Providers
0142       void setDependentProviders(std::vector<std::shared_ptr<EventSetupRecordProvider>> const&);
0143 
0144       /**In the case of a conflict, sets what Provider to call.  This must be called after
0145          all providers have been added.  An empty map is acceptable. */
0146       void usePreferred(DataToPreferredProviderMap const&);
0147 
0148       ///This will clear the cache's of all the Resolvers so that next time they are called they will run
0149       void resetResolvers();
0150 
0151       std::shared_ptr<EventSetupRecordIntervalFinder const> finder() const { return get_underlying_safe(finder_); }
0152       std::shared_ptr<EventSetupRecordIntervalFinder>& finder() { return get_underlying_safe(finder_); }
0153 
0154       void getReferencedESProducers(
0155           std::map<EventSetupRecordKey, std::vector<ComponentDescription const*>>& referencedESProducers) const;
0156 
0157       void fillReferencedDataKeys(std::map<DataKey, ComponentDescription const*>& referencedDataKeys) const;
0158 
0159       void resetRecordToResolverPointers(DataToPreferredProviderMap const& iMap);
0160 
0161       void setEventSetupImpl(EventSetupImpl* value) { eventSetupImpl_ = value; }
0162 
0163       IntervalStatus intervalStatus() const { return intervalStatus_; }
0164 
0165       void fillAllESProductResolverProviders(std::vector<ESProductResolverProvider const*>&,
0166                                              std::unordered_set<unsigned int>& componentIDs) const;
0167 
0168       void updateLookup(ESRecordsToProductResolverIndices const&);
0169 
0170     protected:
0171       void addResolversToRecordHelper(edm::propagate_const<std::shared_ptr<ESProductResolverProvider>>& dpp,
0172                                       DataToPreferredProviderMap const& mp) {
0173         addResolversToRecord(get_underlying_safe(dpp), mp);
0174       }
0175       void addResolversToRecord(std::shared_ptr<ESProductResolverProvider>, DataToPreferredProviderMap const&);
0176 
0177       std::shared_ptr<EventSetupRecordIntervalFinder> swapFinder(std::shared_ptr<EventSetupRecordIntervalFinder> iNew) {
0178         std::swap(iNew, finder());
0179         return iNew;
0180       }
0181 
0182     private:
0183       // ---------- member data --------------------------------
0184       const EventSetupRecordKey key_;
0185 
0186       // This holds the interval most recently initialized with a call to
0187       // eventSetupForInstance. A particular EventSetupRecordImpl in flight
0188       // might contain an older interval.
0189       ValidityInterval validityInterval_;
0190 
0191       EventSetupImpl* eventSetupImpl_ = nullptr;
0192 
0193       std::vector<EventSetupRecordImpl> recordImpls_;
0194       EventSetupRecordImpl const* recordImpl_ = nullptr;
0195 
0196       edm::propagate_const<std::shared_ptr<EventSetupRecordIntervalFinder>> finder_;
0197       std::vector<edm::propagate_const<std::shared_ptr<ESProductResolverProvider>>> providers_;
0198       std::unique_ptr<std::vector<edm::propagate_const<std::shared_ptr<EventSetupRecordIntervalFinder>>>>
0199           multipleFinders_;
0200 
0201       const unsigned int nConcurrentIOVs_;
0202       IntervalStatus intervalStatus_ = IntervalStatus::NotInitializedForSyncValue;
0203       bool newIntervalForAnySubProcess_ = false;
0204       bool hasNonconcurrentFinder_ = false;
0205     };
0206   }  // namespace eventsetup
0207 }  // namespace edm
0208 #endif