CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator > Class Template Reference

#include <Callback.h>

Public Types

using method_type = TReturn(T ::*)(const TRecord &)
 

Public Member Functions

 Callback (T *iProd, method_type iMethod, unsigned int iID, const TDecorator &iDec=TDecorator())
 
 Callback (const Callback &)=delete
 
Callbackclone ()
 
ESProxyIndex const * getTokenIndices () const
 
template<class DataT >
void holdOntoPointer (DataT *iData)
 
void newRecordComing ()
 
const Callbackoperator= (const Callback &)=delete
 
void prefetchAsync (WaitingTaskHolder iTask, EventSetupRecordImpl const *iRecord, EventSetupImpl const *iEventSetupImpl, ServiceToken const &token, ESParentContext const &iParent)
 
template<class RemainingContainerT , class DataT , class ProductsT >
void setData (ProductsT &iProducts)
 
void storeReturnedValues (TReturn iReturn)
 
unsigned int transitionID () const
 

Private Member Functions

bool handleMayGet (EventSetupRecordImpl const *iRecord, EventSetupImpl const *iEventSetupImpl)
 
void prefetchNeededDataAsync (WaitingTaskHolder task, EventSetupImpl const *iImpl, ESProxyIndex const *proxies, edm::ServiceToken const &token) const
 
void runProducerAsync (oneapi::tbb::task_group *iGroup, std::exception_ptr const *iExcept, EventSetupRecordImpl const *iRecord, EventSetupImpl const *iEventSetupImpl, ServiceToken const &token)
 

Private Attributes

ESModuleCallingContext callingContext_
 
TDecorator decorator_
 
const unsigned int id_
 
method_type method_
 
std::optional< std::vector< ESProxyIndex > > postMayGetProxies_
 
edm::propagate_const< T * > producer_
 
std::array< void *, produce::size< TReturn >::value > proxyData_
 
edm::WaitingTaskList taskList_
 
std::atomic< bool > wasCalledForThisRecord_
 

Detailed Description

template<typename T, typename TReturn, typename TRecord, typename TDecorator = CallbackSimpleDecorator<TRecord>>
class edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >

Description: Functional object used as the 'callback' for the CallbackProxy

Usage: <usage>

Definition at line 56 of file Callback.h.

Member Typedef Documentation

◆ method_type

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
using edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::method_type = TReturn (T ::*)(const TRecord&)

Definition at line 58 of file Callback.h.

Constructor & Destructor Documentation

◆ Callback() [1/2]

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::Callback ( T iProd,
method_type  iMethod,
unsigned int  iID,
const TDecorator &  iDec = TDecorator() 
)
inline

Definition at line 60 of file Callback.h.

Referenced by edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::clone().

61  : proxyData_{},
62  producer_(iProd),
63  callingContext_(&iProd->description()),
64  method_(iMethod),
65  id_(iID),
67  decorator_(iDec) {}
const unsigned int id_
Definition: Callback.h:227
ESModuleCallingContext callingContext_
Definition: Callback.h:223
std::array< void *, produce::size< TReturn >::value > proxyData_
Definition: Callback.h:220
std::atomic< bool > wasCalledForThisRecord_
Definition: Callback.h:228
edm::propagate_const< T * > producer_
Definition: Callback.h:222

◆ Callback() [2/2]

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::Callback ( const Callback< T, TReturn, TRecord, TDecorator > &  )
delete

Member Function Documentation

◆ clone()

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
Callback* edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::clone ( void  )
inline

◆ getTokenIndices()

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
ESProxyIndex const* edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::getTokenIndices ( ) const
inline

◆ handleMayGet()

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
bool edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::handleMayGet ( EventSetupRecordImpl const *  iRecord,
EventSetupImpl const *  iEventSetupImpl 
)
inlineprivate

Definition at line 165 of file Callback.h.

References edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::callingContext_, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::getTokenIndices(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::id_, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::postMayGetProxies_, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::producer_, and edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::transitionID().

Referenced by edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::prefetchAsync().

165  {
166  //Handle mayGets
167  TRecord rec;
169  rec.setImpl(iRecord, transitionID(), getTokenIndices(), iEventSetupImpl, &pc);
170  postMayGetProxies_ = producer_->updateFromMayConsumes(id_, rec);
171  return static_cast<bool>(postMayGetProxies_);
172  }
const unsigned int id_
Definition: Callback.h:227
ESModuleCallingContext callingContext_
Definition: Callback.h:223
unsigned int transitionID() const
Definition: Callback.h:147
ESProxyIndex const * getTokenIndices() const
Definition: Callback.h:148
std::optional< std::vector< ESProxyIndex > > postMayGetProxies_
Definition: Callback.h:221
edm::propagate_const< T * > producer_
Definition: Callback.h:222

◆ holdOntoPointer()

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
template<class DataT >
void edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::holdOntoPointer ( DataT *  iData)
inline

Definition at line 123 of file Callback.h.

References edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::proxyData_.

123  {
125  }
std::array< void *, produce::size< TReturn >::value > proxyData_
Definition: Callback.h:220

◆ newRecordComing()

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
void edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::newRecordComing ( )
inline

Definition at line 142 of file Callback.h.

References edm::WaitingTaskList::reset(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::taskList_, and edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::wasCalledForThisRecord_.

142  {
143  wasCalledForThisRecord_ = false;
144  taskList_.reset();
145  }
void reset()
Resets access to the resource so that added tasks will wait.
std::atomic< bool > wasCalledForThisRecord_
Definition: Callback.h:228
edm::WaitingTaskList taskList_
Definition: Callback.h:224

◆ operator=()

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
const Callback& edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::operator= ( const Callback< T, TReturn, TRecord, TDecorator > &  )
delete

◆ prefetchAsync()

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
void edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::prefetchAsync ( WaitingTaskHolder  iTask,
EventSetupRecordImpl const *  iRecord,
EventSetupImpl const *  iEventSetupImpl,
ServiceToken const &  token,
ESParentContext const &  iParent 
)
inline

Definition at line 74 of file Callback.h.

References edm::eventsetup::EventSetupRecordImpl::activityRegistry(), edm::WaitingTaskList::add(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::callingContext_, edm::signalslot::Signal< T >::emit(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::getTokenIndices(), edm::WaitingTaskHolder::group(), watchdog::group, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::handleMayGet(), edm::eventsetup::EventSetupRecordImpl::key(), edm::ESModuleCallingContext::kPrefetching, edm::ServiceWeakToken::lock(), edm::make_waiting_task(), edm::ActivityRegistry::preESModulePrefetchingSignal_, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::prefetchNeededDataAsync(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::producer_, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::runProducerAsync(), edm::ESModuleCallingContext::setContext(), TrackValidation_cff::task, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::taskList_, unpackBuffers-CaloStage2::token, UNLIKELY, and edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::wasCalledForThisRecord_.

78  {
79  bool expected = false;
80  auto doPrefetch = wasCalledForThisRecord_.compare_exchange_strong(expected, true);
81  taskList_.add(iTask);
82  auto group = iTask.group();
83  if (doPrefetch) {
85  iRecord->activityRegistry()->preESModulePrefetchingSignal_.emit(iRecord->key(), callingContext_);
86  if UNLIKELY (producer_->hasMayConsumes()) {
87  //after prefetching need to do the mayGet
88  ServiceWeakToken weakToken = token;
89  auto mayGetTask = edm::make_waiting_task(
90  [this, iRecord, iEventSetupImpl, weakToken, group](std::exception_ptr const* iExcept) {
91  if (iExcept) {
92  runProducerAsync(group, iExcept, iRecord, iEventSetupImpl, weakToken.lock());
93  return;
94  }
95  if (handleMayGet(iRecord, iEventSetupImpl)) {
96  auto runTask = edm::make_waiting_task(
97  [this, group, iRecord, iEventSetupImpl, weakToken](std::exception_ptr const* iExcept) {
98  runProducerAsync(group, iExcept, iRecord, iEventSetupImpl, weakToken.lock());
99  });
101  iEventSetupImpl,
102  &((*postMayGetProxies_).front()),
103  weakToken.lock());
104  } else {
105  runProducerAsync(group, iExcept, iRecord, iEventSetupImpl, weakToken.lock());
106  }
107  });
108 
109  //Get everything we can before knowing about the mayGets
110  prefetchNeededDataAsync(WaitingTaskHolder(*group, mayGetTask), iEventSetupImpl, getTokenIndices(), token);
111  } else {
112  ServiceWeakToken weakToken = token;
114  [this, group, iRecord, iEventSetupImpl, weakToken](std::exception_ptr const* iExcept) {
115  runProducerAsync(group, iExcept, iRecord, iEventSetupImpl, weakToken.lock());
116  });
118  }
119  }
120  }
void prefetchNeededDataAsync(WaitingTaskHolder task, EventSetupImpl const *iImpl, ESProxyIndex const *proxies, edm::ServiceToken const &token) const
Definition: Callback.h:151
ESModuleCallingContext callingContext_
Definition: Callback.h:223
bool handleMayGet(EventSetupRecordImpl const *iRecord, EventSetupImpl const *iEventSetupImpl)
Definition: Callback.h:165
void add(oneapi::tbb::task_group *, WaitingTask *)
Adds task to the waiting list.
FunctorWaitingTask< F > * make_waiting_task(F f)
Definition: WaitingTask.h:101
ESProxyIndex const * getTokenIndices() const
Definition: Callback.h:148
std::atomic< bool > wasCalledForThisRecord_
Definition: Callback.h:228
edm::WaitingTaskList taskList_
Definition: Callback.h:224
void runProducerAsync(oneapi::tbb::task_group *iGroup, std::exception_ptr const *iExcept, EventSetupRecordImpl const *iRecord, EventSetupImpl const *iEventSetupImpl, ServiceToken const &token)
Definition: Callback.h:174
void setContext(State state, ESParentContext const &parent)
#define UNLIKELY(x)
Definition: Likely.h:21
edm::propagate_const< T * > producer_
Definition: Callback.h:222

◆ prefetchNeededDataAsync()

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
void edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::prefetchNeededDataAsync ( WaitingTaskHolder  task,
EventSetupImpl const *  iImpl,
ESProxyIndex const *  proxies,
edm::ServiceToken const &  token 
) const
inlineprivate

◆ runProducerAsync()

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
void edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::runProducerAsync ( oneapi::tbb::task_group *  iGroup,
std::exception_ptr const *  iExcept,
EventSetupRecordImpl const *  iRecord,
EventSetupImpl const *  iEventSetupImpl,
ServiceToken const &  token 
)
inlineprivate

Definition at line 174 of file Callback.h.

References edm::eventsetup::EventSetupRecordImpl::activityRegistry(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::callingContext_, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::decorator_, edm::WaitingTaskList::doneWaiting(), edm::signalslot::Signal< T >::emit(), edm::exceptionContext(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::getTokenIndices(), edm::eventsetup::EventSetupRecordImpl::key(), edm::ESModuleCallingContext::kRunning, edm::ServiceWeakToken::lock(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::method_, edm::ActivityRegistry::postESModulePrefetchingSignal_, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::postMayGetProxies_, edm::ActivityRegistry::preESModuleSignal_, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::producer_, edm::ESModuleCallingContext::setState(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::storeReturnedValues(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::taskList_, unpackBuffers-CaloStage2::token, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::transitionID(), and edm::convertException::wrap().

Referenced by edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::prefetchAsync().

178  {
179  if (iExcept) {
180  //The cache held by the CallbackProxy was already set to invalid at the beginning of the IOV
181  taskList_.doneWaiting(*iExcept);
182  return;
183  }
184  iRecord->activityRegistry()->postESModulePrefetchingSignal_.emit(iRecord->key(), callingContext_);
185  ServiceWeakToken weakToken = token;
186  producer_->queue().push(*iGroup, [this, iRecord, iEventSetupImpl, weakToken]() {
188  std::exception_ptr exceptPtr;
189  try {
190  convertException::wrap([this, iRecord, iEventSetupImpl, weakToken] {
191  auto proxies = getTokenIndices();
192  if (postMayGetProxies_) {
193  proxies = &((*postMayGetProxies_).front());
194  }
195  TRecord rec;
197  rec.setImpl(iRecord, transitionID(), proxies, iEventSetupImpl, &pc);
198  ServiceRegistry::Operate operate(weakToken.lock());
199  iRecord->activityRegistry()->preESModuleSignal_.emit(iRecord->key(), callingContext_);
200  struct EndGuard {
201  EndGuard(EventSetupRecordImpl const* iRecord, ESModuleCallingContext const& iContext)
202  : record_{iRecord}, context_{iContext} {}
203  ~EndGuard() { record_->activityRegistry()->postESModuleSignal_.emit(record_->key(), context_); }
204  EventSetupRecordImpl const* record_;
205  ESModuleCallingContext const& context_;
206  };
207  EndGuard guard(iRecord, callingContext_);
208  decorator_.pre(rec);
210  decorator_.post(rec);
211  });
212  } catch (cms::Exception& iException) {
214  exceptPtr = std::current_exception();
215  }
216  taskList_.doneWaiting(exceptPtr);
217  });
218  }
void storeReturnedValues(TReturn iReturn)
Definition: Callback.h:127
void exceptionContext(cms::Exception &, ESModuleCallingContext const &)
ESModuleCallingContext callingContext_
Definition: Callback.h:223
void doneWaiting(std::exception_ptr iPtr)
Signals that the resource is now available and tasks should be spawned.
unsigned int transitionID() const
Definition: Callback.h:147
ESProxyIndex const * getTokenIndices() const
Definition: Callback.h:148
edm::WaitingTaskList taskList_
Definition: Callback.h:224
std::optional< std::vector< ESProxyIndex > > postMayGetProxies_
Definition: Callback.h:221
auto wrap(F iFunc) -> decltype(iFunc())
edm::propagate_const< T * > producer_
Definition: Callback.h:222

◆ setData()

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
template<class RemainingContainerT , class DataT , class ProductsT >
void edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::setData ( ProductsT &  iProducts)
inline

Definition at line 133 of file Callback.h.

References edm::eventsetup::moveFromTo(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::proxyData_, and groupFilesInBlocks::temp.

133  {
134  DataT* temp = reinterpret_cast<DataT*>(proxyData_[produce::find_index<TReturn, DataT>::value]);
135  if (nullptr != temp) {
136  moveFromTo(iProducts, *temp);
137  }
138  if constexpr (not std::is_same_v<produce::Null, RemainingContainerT>) {
139  setData<typename RemainingContainerT::head_type, typename RemainingContainerT::tail_type>(iProducts);
140  }
141  }
std::array< void *, produce::size< TReturn >::value > proxyData_
Definition: Callback.h:220
void moveFromTo(FromT &iFrom, ToT &iTo)

◆ storeReturnedValues()

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
void edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::storeReturnedValues ( TReturn  iReturn)
inline

Definition at line 127 of file Callback.h.

Referenced by edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::runProducerAsync().

127  {
129  setData<typename type::head_type, typename type::tail_type>(iReturn);
130  }

◆ transitionID()

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
unsigned int edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::transitionID ( ) const
inline

Member Data Documentation

◆ callingContext_

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
ESModuleCallingContext edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::callingContext_
private

◆ decorator_

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
TDecorator edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::decorator_
private

◆ id_

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
const unsigned int edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::id_
private

◆ method_

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
method_type edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::method_
private

◆ postMayGetProxies_

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
std::optional<std::vector<ESProxyIndex> > edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::postMayGetProxies_
private

◆ producer_

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
edm::propagate_const<T*> edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::producer_
private

◆ proxyData_

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
std::array<void*, produce::size<TReturn>::value> edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::proxyData_
private

◆ taskList_

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
edm::WaitingTaskList edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::taskList_
private

◆ wasCalledForThisRecord_

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
std::atomic<bool> edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::wasCalledForThisRecord_
private