Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-16 00:05:34

0001 #ifndef FWCore_Framework_EventSetupsController_h
0002 #define FWCore_Framework_EventSetupsController_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Framework
0006 // Class  :     EventSetupsController
0007 //
0008 /** \class edm::eventsetup::EventSetupsController
0009 
0010  Description: Manages a group of EventSetups which can share components
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Authors:  Chris Jones, David Dagenhart
0018 //          Created:  Wed Jan 12 14:30:42 CST 2011
0019 //
0020 
0021 #include "DataFormats/Provenance/interface/ParameterSetID.h"
0022 #include "FWCore/Framework/interface/EventSetupRecordIOVQueue.h"
0023 #include "FWCore/Framework/interface/NumberOfConcurrentIOVs.h"
0024 #include "FWCore/Utilities/interface/propagate_const.h"
0025 
0026 #include <map>
0027 #include <memory>
0028 #include <vector>
0029 
0030 namespace edm {
0031 
0032   class ActivityRegistry;
0033   class EventSetupImpl;
0034   class EventSetupRecordIntervalFinder;
0035   class ParameterSet;
0036   class IOVSyncValue;
0037   class ModuleTypeResolverBase;
0038   class WaitingTaskHolder;
0039   class WaitingTaskList;
0040 
0041   namespace eventsetup {
0042 
0043     class DataProxyProvider;
0044     class EventSetupProvider;
0045 
0046     class ESProducerInfo {
0047     public:
0048       ESProducerInfo(ParameterSet const* ps, std::shared_ptr<DataProxyProvider> const& pr)
0049           : pset_(ps), provider_(pr), subProcessIndexes_() {}
0050 
0051       ParameterSet const* pset() const { return pset_; }
0052       std::shared_ptr<DataProxyProvider> const& provider() { return get_underlying(provider_); }
0053       DataProxyProvider const* providerGet() const { return provider_.get(); }
0054       std::vector<unsigned>& subProcessIndexes() { return subProcessIndexes_; }
0055       std::vector<unsigned> const& subProcessIndexes() const { return subProcessIndexes_; }
0056 
0057     private:
0058       ParameterSet const* pset_;
0059       propagate_const<std::shared_ptr<DataProxyProvider>> provider_;
0060       std::vector<unsigned> subProcessIndexes_;
0061     };
0062 
0063     class ESSourceInfo {
0064     public:
0065       ESSourceInfo(ParameterSet const* ps, std::shared_ptr<EventSetupRecordIntervalFinder> const& fi)
0066           : pset_(ps), finder_(fi), subProcessIndexes_() {}
0067 
0068       ParameterSet const* pset() const { return pset_; }
0069       std::shared_ptr<EventSetupRecordIntervalFinder> const& finder() { return get_underlying(finder_); }
0070       EventSetupRecordIntervalFinder const* finderGet() const { return finder_.get(); }
0071       std::vector<unsigned>& subProcessIndexes() { return subProcessIndexes_; }
0072       std::vector<unsigned> const& subProcessIndexes() const { return subProcessIndexes_; }
0073 
0074     private:
0075       ParameterSet const* pset_;
0076       propagate_const<std::shared_ptr<EventSetupRecordIntervalFinder>> finder_;
0077       std::vector<unsigned> subProcessIndexes_;
0078     };
0079 
0080     class EventSetupsController {
0081     public:
0082       EventSetupsController();
0083       explicit EventSetupsController(ModuleTypeResolverBase const* resolver);
0084 
0085       EventSetupsController(EventSetupsController const&) = delete;
0086       EventSetupsController const& operator=(EventSetupsController const&) = delete;
0087 
0088       void endIOVsAsync(edm::WaitingTaskHolder iEndTask);
0089 
0090       std::shared_ptr<EventSetupProvider> makeProvider(ParameterSet&,
0091                                                        ActivityRegistry*,
0092                                                        ParameterSet const* eventSetupPset = nullptr,
0093                                                        unsigned int maxConcurrentIOVs = 0,
0094                                                        bool dumpOptions = false);
0095 
0096       // Pass in an IOVSyncValue to let the EventSetup system know which run and lumi
0097       // need to be processed and prepare IOVs for it (also could be a time or only a run).
0098       // Pass in a WaitingTaskHolder that allows the EventSetup to communicate when all
0099       // the IOVs are ready to process this IOVSyncValue. Note this preparation is often
0100       // done in asynchronous tasks and the function might return before all the preparation
0101       // is complete.
0102       // Pass in endIOVWaitingTasks, additions to this WaitingTaskList allow the lumi to notify
0103       // the EventSetup when the lumi is done and no longer needs its EventSetup IOVs.
0104       // Pass in a vector of EventSetupImpl that gets filled and is used to give clients
0105       // of EventSetup access to the EventSetup system such that for each record the IOV
0106       // associated with this IOVSyncValue will be used. The first element of the vector
0107       // is for the top level process and each additional element corresponds to a SubProcess.
0108       void eventSetupForInstanceAsync(IOVSyncValue const&,
0109                                       WaitingTaskHolder const& taskToStartAfterIOVInit,
0110                                       WaitingTaskList& endIOVWaitingTasks,
0111                                       std::vector<std::shared_ptr<const EventSetupImpl>>&);
0112 
0113       bool doWeNeedToWaitForIOVsToFinish(IOVSyncValue const&) const;
0114 
0115       void forceCacheClear();
0116 
0117       std::shared_ptr<DataProxyProvider> getESProducerAndRegisterProcess(ParameterSet const& pset,
0118                                                                          unsigned subProcessIndex);
0119       void putESProducer(ParameterSet const& pset,
0120                          std::shared_ptr<DataProxyProvider> const& component,
0121                          unsigned subProcessIndex);
0122 
0123       std::shared_ptr<EventSetupRecordIntervalFinder> getESSourceAndRegisterProcess(ParameterSet const& pset,
0124                                                                                     unsigned subProcessIndex);
0125       void putESSource(ParameterSet const& pset,
0126                        std::shared_ptr<EventSetupRecordIntervalFinder> const& component,
0127                        unsigned subProcessIndex);
0128 
0129       void finishConfiguration();
0130       void clearComponents();
0131 
0132       unsigned indexOfNextProcess() const { return providers_.size(); }
0133 
0134       void lookForMatches(ParameterSetID const& psetID,
0135                           unsigned subProcessIndex,
0136                           unsigned precedingProcessIndex,
0137                           bool& firstProcessWithThisPSet,
0138                           bool& precedingHasMatchingPSet) const;
0139 
0140       bool isFirstMatch(ParameterSetID const& psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const;
0141 
0142       bool isLastMatch(ParameterSetID const& psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const;
0143 
0144       bool isMatchingESSource(ParameterSetID const& psetID,
0145                               unsigned subProcessIndex,
0146                               unsigned precedingProcessIndex) const;
0147 
0148       bool isMatchingESProducer(ParameterSetID const& psetID,
0149                                 unsigned subProcessIndex,
0150                                 unsigned precedingProcessIndex) const;
0151 
0152       ParameterSet const* getESProducerPSet(ParameterSetID const& psetID, unsigned subProcessIndex) const;
0153 
0154       std::vector<propagate_const<std::shared_ptr<EventSetupProvider>>> const& providers() const { return providers_; }
0155 
0156       std::multimap<ParameterSetID, ESProducerInfo> const& esproducers() const { return esproducers_; }
0157 
0158       std::multimap<ParameterSetID, ESSourceInfo> const& essources() const { return essources_; }
0159 
0160       bool hasNonconcurrentFinder() const { return hasNonconcurrentFinder_; }
0161       bool mustFinishConfiguration() const { return mustFinishConfiguration_; }
0162 
0163     private:
0164       void checkESProducerSharing();
0165       void initializeEventSetupRecordIOVQueues();
0166 
0167       // ---------- member data --------------------------------
0168       std::vector<propagate_const<std::shared_ptr<EventSetupProvider>>> providers_;
0169       NumberOfConcurrentIOVs numberOfConcurrentIOVs_;
0170 
0171       // This data member is intentionally declared after providers_
0172       // It is important that this is destroyed first.
0173       std::vector<propagate_const<std::unique_ptr<EventSetupRecordIOVQueue>>> eventSetupRecordIOVQueues_;
0174 
0175       // The following two multimaps have one entry for each unique
0176       // ParameterSet. The ESProducerInfo or ESSourceInfo object
0177       // contains a list of the processes that use that ParameterSet
0178       // (0 for the top level process, then the SubProcesses are
0179       // identified by counting their execution order starting at 1).
0180       // There can be multiple entries for a single ParameterSetID because
0181       // of a difference in untracked parameters. These are only
0182       // used during initialization.  The Info objects also contain
0183       // a pointer to the full validated ParameterSet and a shared_ptr
0184       // to the component.
0185       std::multimap<ParameterSetID, ESProducerInfo> esproducers_;
0186       std::multimap<ParameterSetID, ESSourceInfo> essources_;
0187 
0188       ModuleTypeResolverBase const* typeResolver_ = nullptr;
0189 
0190       bool hasNonconcurrentFinder_ = false;
0191       bool mustFinishConfiguration_ = true;
0192     };
0193 
0194     void synchronousEventSetupForInstance(IOVSyncValue const& syncValue,
0195                                           oneapi::tbb::task_group& iGroup,
0196                                           eventsetup::EventSetupsController& espController);
0197   }  // namespace eventsetup
0198 }  // namespace edm
0199 #endif