Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-24 09:53:02

0001 #ifndef Framework_CallbackProxy_h
0002 #define Framework_CallbackProxy_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Framework
0006 // Class  :     CallbackProxy
0007 //
0008 /**\class CallbackProxy CallbackProxy.h FWCore/Framework/interface/CallbackProxy.h
0009 
0010  Description: A DataProxy which performs a callback when data is requested
0011 
0012  Usage:
0013     This class is primarily used by ESProducer to allow the EventSetup system
0014  to call a particular method of ESProducer where data is being requested.
0015 
0016 */
0017 //
0018 // Author:      Chris Jones
0019 // Created:     Fri Apr  8 11:50:21 CDT 2005
0020 //
0021 
0022 // system include files
0023 #include <cassert>
0024 #include <memory>
0025 
0026 // user include files
0027 #include "FWCore/Framework/interface/DataProxy.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 // forward declarations
0036 namespace edm::eventsetup {
0037 
0038   template <class CallbackT, class RecordT, class DataT>
0039   class CallbackProxy final : public DataProxy {
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     CallbackProxy(std::shared_ptr<CallbackT>& iCallback) : callback_{iCallback} {
0046       //The callback fills the data directly.  This is done so that the callback does not have to
0047       //  hold onto a temporary copy of the result of the callback since the callback is allowed
0048       //  to return multiple items where only one item is needed by this Proxy
0049       iCallback->holdOntoPointer(&data_);
0050     }
0051 
0052     ~CallbackProxy() 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) 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     // Delete copy operations
0075     CallbackProxy(const CallbackProxy&) = delete;
0076     const CallbackProxy& operator=(const CallbackProxy&) = delete;
0077 
0078   private:
0079     DataT data_{};
0080     edm::propagate_const<std::shared_ptr<CallbackT>> callback_;
0081   };
0082 
0083 }  // namespace edm::eventsetup
0084 
0085 #endif