File indexing completed on 2024-05-11 03:34:12
0001 #ifndef Framework_CallbackProductResolver_h
0002 #define Framework_CallbackProductResolver_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #include <cassert>
0024 #include <memory>
0025
0026
0027 #include "FWCore/Framework/interface/ESProductResolver.h"
0028 #include "FWCore/Framework/interface/EventSetupRecord.h"
0029 #include "FWCore/Concurrency/interface/WaitingTaskList.h"
0030 #include "FWCore/Concurrency/interface/WaitingTaskHolder.h"
0031
0032 #include "FWCore/Framework/interface/produce_helpers.h"
0033 #include "FWCore/Utilities/interface/propagate_const.h"
0034
0035
0036 namespace edm::eventsetup {
0037
0038 template <class CallbackT, class RecordT, class DataT>
0039 class CallbackProductResolver final : public ESProductResolver {
0040 public:
0041 using smart_pointer_traits = produce::smart_pointer_traits<DataT>;
0042 using ValueType = typename smart_pointer_traits::type;
0043 using RecordType = RecordT;
0044
0045 CallbackProductResolver(std::shared_ptr<CallbackT>& iCallback) : callback_{iCallback} {
0046
0047
0048
0049 iCallback->holdOntoPointer(&data_);
0050 }
0051
0052 ~CallbackProductResolver() final {
0053 DataT* dummy(nullptr);
0054 callback_->holdOntoPointer(dummy);
0055 }
0056
0057 void prefetchAsyncImpl(WaitingTaskHolder iWaitTask,
0058 const EventSetupRecordImpl& iRecord,
0059 const DataKey&,
0060 EventSetupImpl const* iEventSetupImpl,
0061 ServiceToken const& iToken,
0062 edm::ESParentContext const& iParent) noexcept final {
0063 assert(iRecord.key() == RecordT::keyForClass());
0064 callback_->prefetchAsync(iWaitTask, &iRecord, iEventSetupImpl, iToken, iParent);
0065 }
0066
0067 void const* getAfterPrefetchImpl() const final { return smart_pointer_traits::getPointer(data_); }
0068
0069 void invalidateCache() override {
0070 data_ = DataT{};
0071 callback_->newRecordComing();
0072 }
0073
0074
0075 CallbackProductResolver(const CallbackProductResolver&) = delete;
0076 const CallbackProductResolver& operator=(const CallbackProductResolver&) = delete;
0077
0078 private:
0079 DataT data_{};
0080 edm::propagate_const<std::shared_ptr<CallbackT>> callback_;
0081 };
0082
0083 }
0084
0085 #endif