Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 ModuleTypeResolverMaker;
0038   class ServiceToken;
0039   class WaitingTaskHolder;
0040   class WaitingTaskList;
0041 
0042   namespace eventsetup {
0043 
0044     class ESProductResolverProvider;
0045     class EventSetupProvider;
0046 
0047     class ESProducerInfo {
0048     public:
0049       ESProducerInfo(ParameterSet* ps, std::shared_ptr<ESProductResolverProvider> const& pr)
0050           : pset_(ps), provider_(pr), subProcessIndexes_() {}
0051 
0052       ParameterSet const* pset() const { return pset_.get(); }
0053       ParameterSet* pset() { return pset_.get(); }
0054       std::shared_ptr<ESProductResolverProvider> const& provider() { return get_underlying(provider_); }
0055       ESProductResolverProvider const* providerGet() const { return provider_.get(); }
0056       std::vector<unsigned>& subProcessIndexes() { return subProcessIndexes_; }
0057       std::vector<unsigned> const& subProcessIndexes() const { return subProcessIndexes_; }
0058 
0059     private:
0060       edm::propagate_const<ParameterSet*> pset_;
0061       propagate_const<std::shared_ptr<ESProductResolverProvider>> provider_;
0062       std::vector<unsigned> subProcessIndexes_;
0063     };
0064 
0065     class ESSourceInfo {
0066     public:
0067       ESSourceInfo(ParameterSet const* ps, std::shared_ptr<EventSetupRecordIntervalFinder> const& fi)
0068           : pset_(ps), finder_(fi), subProcessIndexes_() {}
0069 
0070       ParameterSet const* pset() const { return pset_; }
0071       std::shared_ptr<EventSetupRecordIntervalFinder> const& finder() { return get_underlying(finder_); }
0072       EventSetupRecordIntervalFinder const* finderGet() const { return finder_.get(); }
0073       std::vector<unsigned>& subProcessIndexes() { return subProcessIndexes_; }
0074       std::vector<unsigned> const& subProcessIndexes() const { return subProcessIndexes_; }
0075 
0076     private:
0077       ParameterSet const* pset_;
0078       propagate_const<std::shared_ptr<EventSetupRecordIntervalFinder>> finder_;
0079       std::vector<unsigned> subProcessIndexes_;
0080     };
0081 
0082     class EventSetupsController {
0083     public:
0084       EventSetupsController();
0085       explicit EventSetupsController(ModuleTypeResolverMaker const* resolverMaker);
0086 
0087       EventSetupsController(EventSetupsController const&) = delete;
0088       EventSetupsController const& operator=(EventSetupsController const&) = delete;
0089 
0090       void endIOVsAsync(edm::WaitingTaskHolder iEndTask);
0091 
0092       std::shared_ptr<EventSetupProvider> makeProvider(ParameterSet&,
0093                                                        ActivityRegistry*,
0094                                                        ParameterSet const* eventSetupPset = nullptr,
0095                                                        unsigned int maxConcurrentIOVs = 0,
0096                                                        bool dumpOptions = false);
0097 
0098       // The main purpose of this function is to call eventSetupForInstanceAsync. It might
0099       // be called immediately or we might need to wait until all the currently active
0100       // IOVs end. If there is an exception, then a signal is emitted and the exception
0101       // is propagated.
0102       void runOrQueueEventSetupForInstanceAsync(IOVSyncValue const&,
0103                                                 WaitingTaskHolder& taskToStartAfterIOVInit,
0104                                                 WaitingTaskList& endIOVWaitingTasks,
0105                                                 std::vector<std::shared_ptr<const EventSetupImpl>>&,
0106                                                 edm::SerialTaskQueue& queueWhichWaitsForIOVsToFinish,
0107                                                 ActivityRegistry*,
0108                                                 ServiceToken const&,
0109                                                 bool iForceCacheClear = false);
0110 
0111       // Pass in an IOVSyncValue to let the EventSetup system know which run and lumi
0112       // need to be processed and prepare IOVs for it (also could be a time or only a run).
0113       // Pass in a WaitingTaskHolder that allows the EventSetup to communicate when all
0114       // the IOVs are ready to process this IOVSyncValue. Note this preparation is often
0115       // done in asynchronous tasks and the function might return before all the preparation
0116       // is complete.
0117       // Pass in endIOVWaitingTasks, additions to this WaitingTaskList allow the lumi or
0118       // run to notify the EventSetup system when a lumi or run transition is done and no
0119       // longer needs its EventSetup IOVs.
0120       // Pass in a vector of EventSetupImpl that gets filled and is used to give clients
0121       // of EventSetup access to the EventSetup system such that for each record the IOV
0122       // associated with this IOVSyncValue will be used. The first element of the vector
0123       // is for the top level process and each additional element corresponds to a SubProcess.
0124       void eventSetupForInstanceAsync(IOVSyncValue const&,
0125                                       WaitingTaskHolder const& taskToStartAfterIOVInit,
0126                                       WaitingTaskList& endIOVWaitingTasks,
0127                                       std::vector<std::shared_ptr<const EventSetupImpl>>&);
0128 
0129       bool doWeNeedToWaitForIOVsToFinish(IOVSyncValue const&) const;
0130 
0131       void forceCacheClear();
0132 
0133       std::shared_ptr<ESProductResolverProvider> getESProducerAndRegisterProcess(ParameterSet const& pset,
0134                                                                                  unsigned subProcessIndex);
0135       void putESProducer(ParameterSet& pset,
0136                          std::shared_ptr<ESProductResolverProvider> const& component,
0137                          unsigned subProcessIndex);
0138 
0139       std::shared_ptr<EventSetupRecordIntervalFinder> getESSourceAndRegisterProcess(ParameterSet const& pset,
0140                                                                                     unsigned subProcessIndex);
0141       void putESSource(ParameterSet const& pset,
0142                        std::shared_ptr<EventSetupRecordIntervalFinder> const& component,
0143                        unsigned subProcessIndex);
0144 
0145       void finishConfiguration();
0146       void clearComponents();
0147 
0148       unsigned indexOfNextProcess() const { return providers_.size(); }
0149 
0150       void lookForMatches(ParameterSetID const& psetID,
0151                           unsigned subProcessIndex,
0152                           unsigned precedingProcessIndex,
0153                           bool& firstProcessWithThisPSet,
0154                           bool& precedingHasMatchingPSet) const;
0155 
0156       bool isFirstMatch(ParameterSetID const& psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const;
0157 
0158       bool isLastMatch(ParameterSetID const& psetID, unsigned subProcessIndex, unsigned precedingProcessIndex) const;
0159 
0160       bool isMatchingESSource(ParameterSetID const& psetID,
0161                               unsigned subProcessIndex,
0162                               unsigned precedingProcessIndex) const;
0163 
0164       bool isMatchingESProducer(ParameterSetID const& psetID,
0165                                 unsigned subProcessIndex,
0166                                 unsigned precedingProcessIndex) const;
0167 
0168       ParameterSet& getESProducerPSet(ParameterSetID const& psetID, unsigned subProcessIndex);
0169 
0170       std::vector<propagate_const<std::shared_ptr<EventSetupProvider>>> const& providers() const { return providers_; }
0171 
0172       std::multimap<ParameterSetID, ESProducerInfo> const& esproducers() const { return esproducers_; }
0173 
0174       std::multimap<ParameterSetID, ESSourceInfo> const& essources() const { return essources_; }
0175 
0176       bool hasNonconcurrentFinder() const { return hasNonconcurrentFinder_; }
0177       bool mustFinishConfiguration() const { return mustFinishConfiguration_; }
0178 
0179     private:
0180       void checkESProducerSharing();
0181       void initializeEventSetupRecordIOVQueues();
0182 
0183       // ---------- member data --------------------------------
0184       std::vector<propagate_const<std::shared_ptr<EventSetupProvider>>> providers_;
0185       NumberOfConcurrentIOVs numberOfConcurrentIOVs_;
0186 
0187       // This data member is intentionally declared after providers_
0188       // It is important that this is destroyed first.
0189       std::vector<propagate_const<std::unique_ptr<EventSetupRecordIOVQueue>>> eventSetupRecordIOVQueues_;
0190 
0191       // The following two multimaps have one entry for each unique
0192       // ParameterSet. The ESProducerInfo or ESSourceInfo object
0193       // contains a list of the processes that use that ParameterSet
0194       // (0 for the top level process, then the SubProcesses are
0195       // identified by counting their execution order starting at 1).
0196       // There can be multiple entries for a single ParameterSetID because
0197       // of a difference in untracked parameters. These are only
0198       // used during initialization.  The Info objects also contain
0199       // a pointer to the full validated ParameterSet and a shared_ptr
0200       // to the component.
0201       std::multimap<ParameterSetID, ESProducerInfo> esproducers_;
0202       std::multimap<ParameterSetID, ESSourceInfo> essources_;
0203 
0204       ModuleTypeResolverMaker const* typeResolverMaker_ = nullptr;
0205 
0206       bool hasNonconcurrentFinder_ = false;
0207       bool mustFinishConfiguration_ = true;
0208     };
0209 
0210     void synchronousEventSetupForInstance(IOVSyncValue const& syncValue,
0211                                           oneapi::tbb::task_group& iGroup,
0212                                           eventsetup::EventSetupsController& espController);
0213   }  // namespace eventsetup
0214 }  // namespace edm
0215 #endif