CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | Public Attributes | 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 (const Callback &)=delete
 
Callbackclone ()
 
ESProxyIndex const * getTokenIndices () const
 
template<class DataT >
void holdOntoPointer (DataT *iData)
 
callingContext_iProd ()), method_(iMethod), id_(iID), wasCalledForThisRecord_(false), decorator_(iDec
 
void newRecordComing ()
 
const Callbackoperator= (const Callback &)=delete
 
void prefetchAsync (WaitingTaskHolder iTask, EventSetupRecordImpl const *iRecord, EventSetupImpl const *iEventSetupImpl, ServiceToken const &token, ESParentContext const &iParent)
 
 producer_ (iProd)
 
template<class RemainingContainerT , class DataT , class ProductsT >
void setData (ProductsT &iProducts)
 
void storeReturnedValues (TReturn iReturn)
 
unsigned int transitionID () const
 

Public Attributes

 __pad0__: proxyData_{}
 

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

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

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

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
Callback* edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::clone ( void  )
inline
template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
ESProxyIndex const* edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::getTokenIndices ( ) const
inline
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
std::optional< std::vector< ESProxyIndex > > postMayGetProxies_
Definition: Callback.h:221
ESProxyIndex const * getTokenIndices() const
Definition: Callback.h:148
edm::propagate_const< T * > producer_
Definition: Callback.h:222
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
template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
callingContext_& edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::iProd ( )
inline

Definition at line 63 of file Callback.h.

67  {}
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
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
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(), 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;
113  auto task = edm::make_waiting_task(
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
std::atomic< bool > wasCalledForThisRecord_
Definition: Callback.h:228
tuple group
Definition: watchdog.py:82
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)
ESProxyIndex const * getTokenIndices() const
Definition: Callback.h:148
#define UNLIKELY(x)
Definition: Likely.h:21
edm::propagate_const< T * > producer_
Definition: Callback.h:222
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

Definition at line 151 of file Callback.h.

References edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::callingContext_, edm::EventSetupImpl::findImpl(), mps_fire::i, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::id_, dqmiodumpmetadata::n, edm::eventsetup::EventSetupRecordImpl::prefetchAsync(), and edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::producer_.

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

154  {
155  auto recs = producer_->getTokenRecordIndices(id_);
156  auto n = producer_->numberOfTokenIndices(id_);
157  for (size_t i = 0; i != n; ++i) {
158  auto rec = iImpl->findImpl(recs[i]);
159  if (rec) {
160  rec->prefetchAsync(task, proxies[i], iImpl, token, edm::ESParentContext{&callingContext_});
161  }
162  }
163  }
const unsigned int id_
Definition: Callback.h:227
ESModuleCallingContext callingContext_
Definition: Callback.h:223
edm::propagate_const< T * > producer_
Definition: Callback.h:222
template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::producer_ ( iProd  )
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
unsigned int transitionID() const
Definition: Callback.h:147
void doneWaiting(std::exception_ptr iPtr)
Signals that the resource is now available and tasks should be spawned.
edm::WaitingTaskList taskList_
Definition: Callback.h:224
std::optional< std::vector< ESProxyIndex > > postMayGetProxies_
Definition: Callback.h:221
ESProxyIndex const * getTokenIndices() const
Definition: Callback.h:148
auto wrap(F iFunc) -> decltype(iFunc())
edm::propagate_const< T * > producer_
Definition: Callback.h:222
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)
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  }
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

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

Definition at line 61 of file Callback.h.

template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
ESModuleCallingContext edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::callingContext_
private
template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
TDecorator edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::decorator_
private
template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
const unsigned int edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::id_
private
template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
method_type edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::method_
private
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
template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
edm::propagate_const<T*> edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::producer_
private
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
template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
edm::WaitingTaskList edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::taskList_
private
template<typename T , typename TReturn , typename TRecord , typename TDecorator = CallbackSimpleDecorator<TRecord>>
std::atomic<bool> edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::wasCalledForThisRecord_
private