File indexing completed on 2023-10-25 09:46:49
0001 #ifndef FWCore_Framework_ESSourceProductResolverBase_h
0002 #define FWCore_Framework_ESSourceProductResolverBase_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #include <atomic>
0026
0027
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
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
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
0087
0088 edm::WaitingTaskList m_waitingList;
0089 std::atomic<bool> m_prefetching;
0090 };
0091 }
0092 #endif