Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:46:49

0001 #ifndef FWCore_Framework_ESSourceProductResolverBase_h
0002 #define FWCore_Framework_ESSourceProductResolverBase_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Framework
0006 // Class  :     ESSourceProductResolverBase
0007 //
0008 /**\class ESSourceProductResolverBase ESSourceProductResolverBase.h "FWCore/Framework/interface/ESSourceProductResolverBase.h"
0009 
0010  Description: Base class for DataProxies for ESSources that can be specialized based on concurrency needs
0011 
0012  Usage:
0013     The ESSourceProductResolverBase provides the bases for DataProxies needed for ESSources. It allows customization of synchronization needs via the use of template parameters.
0014 
0015     NOTE: if inheriting classes override `void invalidateCache()` they must be sure to call this classes
0016     implementation as part of the call.
0017 
0018 */
0019 //
0020 // Original Author:  Chris Jones
0021 //         Created:  14/05/2020
0022 //
0023 
0024 // system include files
0025 #include <atomic>
0026 
0027 // user include files
0028 #include "FWCore/Framework/interface/ESProductResolver.h"
0029 #include "FWCore/Framework/interface/EventSetupRecordDetails.h"
0030 #include "FWCore/Concurrency/interface/WaitingTaskList.h"
0031 #include "FWCore/ServiceRegistry/interface/ESParentContext.h"
0032 
0033 // forward declarations
0034 
0035 namespace edm::eventsetup {
0036   class ESSourceProductResolverBase : public ESProductResolver {
0037   public:
0038     ESSourceProductResolverBase() : m_prefetching{false} {}
0039 
0040   protected:
0041     void invalidateCache() override {
0042       m_waitingList.reset();
0043       m_prefetching = false;
0044     }
0045     void invalidateTransientCache() override {}
0046 
0047     virtual void prefetch(edm::eventsetup::DataKey const& iKey, EventSetupRecordDetails) = 0;
0048 
0049     //Should call from prefetchAsyncImpl
0050     template <typename ASYNC, typename GUARD>
0051     void prefetchAsyncImplTemplate(ASYNC iAsync,
0052                                    GUARD iGuardFactory,
0053                                    edm::WaitingTaskHolder iTask,
0054                                    edm::eventsetup::EventSetupRecordImpl const& iRecord,
0055                                    edm::eventsetup::DataKey const& iKey,
0056                                    edm::ESParentContext const& iContext) {
0057       auto group = iTask.group();
0058       if (needToPrefetch(std::move(iTask))) {
0059         iAsync(*group, [this, iGuardFactory, &iRecord, iKey, iContext]() {
0060           try {
0061             guardPrefetch(iGuardFactory, iRecord, iKey, iContext);
0062             m_waitingList.doneWaiting(std::exception_ptr{});
0063           } catch (...) {
0064             m_waitingList.doneWaiting(std::current_exception());
0065           }
0066         });
0067       }
0068     }
0069 
0070   private:
0071     template <typename GUARD>
0072     void guardPrefetch(GUARD iGuardFactory,
0073                        edm::eventsetup::EventSetupRecordImpl const& iES,
0074                        edm::eventsetup::DataKey const& iKey,
0075                        edm::ESParentContext const& iContext) {
0076       [[maybe_unused]] auto guard = iGuardFactory();
0077       doPrefetchAndSignals(iES, iKey, iContext);
0078     }
0079 
0080     bool needToPrefetch(edm::WaitingTaskHolder iTask);
0081 
0082     void doPrefetchAndSignals(edm::eventsetup::EventSetupRecordImpl const&,
0083                               edm::eventsetup::DataKey const& iKey,
0084                               edm::ESParentContext const&);
0085 
0086     // ---------- member data --------------------------------
0087 
0088     edm::WaitingTaskList m_waitingList;
0089     std::atomic<bool> m_prefetching;
0090   };
0091 }  // namespace edm::eventsetup
0092 #endif