Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:46

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