File indexing completed on 2025-05-23 23:48:33
0001
0002 #ifndef FWCore_Framework_ESSourceProductResolverBase_h
0003 #define FWCore_Framework_ESSourceProductResolverBase_h
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #include <atomic>
0027
0028
0029 #include "FWCore/Framework/interface/ESProductResolver.h"
0030 #include "FWCore/Framework/interface/EventSetupRecordDetails.h"
0031 #include "FWCore/Concurrency/interface/WaitingTaskList.h"
0032 #include "FWCore/ServiceRegistry/interface/ESParentContext.h"
0033 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0034
0035
0036
0037 namespace edm::eventsetup {
0038 class ESSourceProductResolverBase : public ESProductResolver {
0039 public:
0040 ESSourceProductResolverBase() : m_prefetching{false} {}
0041
0042 protected:
0043 void invalidateCache() override {
0044 m_waitingList.reset();
0045 m_prefetching = false;
0046 }
0047 void invalidateTransientCache() override {}
0048
0049 virtual void prefetch(edm::eventsetup::DataKey const& iKey, EventSetupRecordDetails) = 0;
0050
0051
0052 template <typename ASYNC, typename GUARD>
0053 void prefetchAsyncImplTemplate(ASYNC iAsync,
0054 GUARD iGuardFactory,
0055 edm::WaitingTaskHolder iTask,
0056 edm::eventsetup::EventSetupRecordImpl const& iRecord,
0057 edm::eventsetup::DataKey const& iKey,
0058 edm::ESParentContext const& iContext) noexcept {
0059 auto group = iTask.group();
0060 if (needToPrefetch(std::move(iTask))) {
0061 iAsync(*group, [this, iGuardFactory, &iRecord, iKey, iContext]() {
0062 CMS_SA_ALLOW try {
0063 guardPrefetch(iGuardFactory, iRecord, iKey, iContext);
0064 m_waitingList.doneWaiting(std::exception_ptr{});
0065 } catch (...) {
0066 m_waitingList.doneWaiting(std::current_exception());
0067 }
0068 });
0069 }
0070 }
0071
0072 private:
0073 template <typename GUARD>
0074 void guardPrefetch(GUARD iGuardFactory,
0075 edm::eventsetup::EventSetupRecordImpl const& iES,
0076 edm::eventsetup::DataKey const& iKey,
0077 edm::ESParentContext const& iContext) {
0078 [[maybe_unused]] auto guard = iGuardFactory();
0079 doPrefetchAndSignals(iES, iKey, iContext);
0080 }
0081
0082 bool needToPrefetch(edm::WaitingTaskHolder iTask) noexcept;
0083
0084 void doPrefetchAndSignals(edm::eventsetup::EventSetupRecordImpl const&,
0085 edm::eventsetup::DataKey const& iKey,
0086 edm::ESParentContext const&);
0087
0088
0089
0090 edm::WaitingTaskList m_waitingList;
0091 std::atomic<bool> m_prefetching;
0092 };
0093 }
0094 #endif