Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:00

0001 // -*- C++ -*-
0002 #ifndef FWCore_Framework_Callback_h
0003 #define FWCore_Framework_Callback_h
0004 //
0005 // Package:     Framework
0006 // Class  :     Callback
0007 //
0008 /**\class edm::eventsetup::Callback
0009 
0010  Description: Functional object used as the 'callback' for the CallbackESProductResolver
0011 
0012  Usage: Produces data objects for ESProducers in EventSetup system
0013 
0014 */
0015 //
0016 // Author:      Chris Jones
0017 // Created:     Sun Apr 17 14:30:24 EDT 2005
0018 //
0019 
0020 #include <memory>
0021 #include <utility>
0022 
0023 #include "oneapi/tbb/task_group.h"
0024 
0025 #include "FWCore/Concurrency/interface/WaitingTaskHolder.h"
0026 #include "FWCore/Framework/interface/CallbackBase.h"
0027 #include "FWCore/ServiceRegistry/interface/ESParentContext.h"
0028 #include "FWCore/ServiceRegistry/interface/ServiceToken.h"
0029 
0030 namespace edm {
0031 
0032   class EventSetupImpl;
0033 
0034   namespace eventsetup {
0035 
0036     class EventSetupRecordImpl;
0037 
0038     template <typename T,             //producer's type
0039               typename TProduceFunc,  //produce functor type
0040               typename TReturn,       //return type of the produce method
0041               typename TRecord,       //the record passed in as an argument
0042               typename TDecorator     //allows customization using pre/post calls
0043               = CallbackSimpleDecorator<TRecord>>
0044     class Callback : public CallbackBase<T, TProduceFunc, TReturn, TRecord, TDecorator> {
0045     public:
0046       using Base = CallbackBase<T, TProduceFunc, TReturn, TRecord, TDecorator>;
0047 
0048       Callback(T* iProd, TProduceFunc iProduceFunc, unsigned int iID, const TDecorator& iDec = TDecorator())
0049           : Callback(iProd, std::make_shared<TProduceFunc>(std::move(iProduceFunc)), iID, iDec) {}
0050 
0051       Callback* clone() {
0052         return new Callback(Base::producer(), Base::produceFunction(), Base::transitionID(), Base::decorator());
0053       }
0054 
0055       void prefetchAsync(WaitingTaskHolder iTask,
0056                          EventSetupRecordImpl const* iRecord,
0057                          EventSetupImpl const* iEventSetupImpl,
0058                          ServiceToken const& token,
0059                          ESParentContext const& iParent) {
0060         return Base::prefetchAsyncImpl(
0061             [this](auto&& group, auto&& token, auto&& record, auto&& es) {
0062               constexpr bool emitPostPrefetchingSignal = true;
0063               auto produceFunctor = [this](TRecord const& record) { return (*Base::produceFunction())(record); };
0064               return Base::makeProduceTask(
0065                   group, token, record, es, emitPostPrefetchingSignal, std::move(produceFunctor));
0066             },
0067             std::move(iTask),
0068             iRecord,
0069             iEventSetupImpl,
0070             token,
0071             iParent);
0072       }
0073 
0074     private:
0075       Callback(T* iProd,
0076                std::shared_ptr<TProduceFunc> iProduceFunc,
0077                unsigned int iID,
0078                const TDecorator& iDec = TDecorator())
0079           : Base(iProd, std::move(iProduceFunc), iID, iDec) {}
0080     };
0081   }  // namespace eventsetup
0082 }  // namespace edm
0083 #endif