Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-22 01:53:27

0001 #ifndef FWCore_Framework_ESSourceDataProxyBase_h
0002 #define FWCore_Framework_ESSourceDataProxyBase_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Framework
0006 // Class  :     ESSourceDataProxyBase
0007 //
0008 /**\class ESSourceDataProxyBase ESSourceDataProxyBase.h "FWCore/Framework/interface/ESSourceDataProxyBase.h"
0009 
0010  Description: Base class for DataProxies for ESSources that can be specialized based on concurrency needs
0011 
0012  Usage:
0013     The ESSourceDataProxyBase 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/DataProxy.h"
0029 #include "FWCore/Framework/interface/EventSetupRecordDetails.h"
0030 #include "FWCore/Concurrency/interface/WaitingTaskList.h"
0031 
0032 // forward declarations
0033 
0034 namespace edm::eventsetup {
0035   class ESSourceDataProxyBase : public DataProxy {
0036   public:
0037     ESSourceDataProxyBase() : m_prefetching{false} {}
0038 
0039   protected:
0040     void invalidateCache() override {
0041       m_waitingList.reset();
0042       m_prefetching = false;
0043     }
0044     void invalidateTransientCache() override {}
0045 
0046     virtual void prefetch(edm::eventsetup::DataKey const& iKey, EventSetupRecordDetails) = 0;
0047 
0048     //Should call from prefetchAsyncImpl
0049     template <typename ASYNC, typename GUARD>
0050     void prefetchAsyncImplTemplate(ASYNC iAsync,
0051                                    GUARD iGuardFactory,
0052                                    edm::WaitingTaskHolder iTask,
0053                                    edm::eventsetup::EventSetupRecordImpl const& iRecord,
0054                                    edm::eventsetup::DataKey const& iKey,
0055                                    edm::ESParentContext const& iContext) {
0056       auto group = iTask.group();
0057       if (needToPrefetch(std::move(iTask))) {
0058         iAsync(*group, [this, iGuardFactory, &iRecord, iKey, iContext]() {
0059           try {
0060             guardPrefetch(iGuardFactory, iRecord, iKey, iContext);
0061             m_waitingList.doneWaiting(std::exception_ptr{});
0062           } catch (...) {
0063             m_waitingList.doneWaiting(std::current_exception());
0064           }
0065         });
0066       }
0067     }
0068 
0069   private:
0070     template <typename GUARD>
0071     void guardPrefetch(GUARD iGuardFactory,
0072                        edm::eventsetup::EventSetupRecordImpl const& iES,
0073                        edm::eventsetup::DataKey const& iKey,
0074                        edm::ESParentContext const& iContext) {
0075       [[maybe_unused]] auto guard = iGuardFactory();
0076       doPrefetchAndSignals(iES, iKey, iContext);
0077     }
0078 
0079     bool needToPrefetch(edm::WaitingTaskHolder iTask);
0080 
0081     void doPrefetchAndSignals(edm::eventsetup::EventSetupRecordImpl const&,
0082                               edm::eventsetup::DataKey const& iKey,
0083                               edm::ESParentContext const&);
0084 
0085     // ---------- member data --------------------------------
0086 
0087     edm::WaitingTaskList m_waitingList;
0088     std::atomic<bool> m_prefetching;
0089   };
0090 }  // namespace edm::eventsetup
0091 #endif