CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 (const Callback &)=delete
 
 Callback (T *iProd, method_type iMethod, unsigned int iID, const TDecorator &iDec=TDecorator())
 
Callbackclone ()
 
ESProxyIndex const * getTokenIndices () const
 
template<class DataT >
void holdOntoPointer (DataT *iData)
 
void newRecordComing ()
 
const Callbackoperator= (const Callback &)=delete
 
void prefetchAsync (WaitingTask *iTask, EventSetupRecordImpl const *iRecord, EventSetupImpl const *iEventSetupImpl, ServiceToken const &token)
 
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 (WaitingTask *task, EventSetupImpl const *iImpl, ESProxyIndex const *proxies, edm::ServiceToken const &token) const
 
void runProducerAsync (std::exception_ptr const *iExcept, EventSetupRecordImpl const *iRecord, EventSetupImpl const *iEventSetupImpl, ServiceToken const &token)
 

Private Attributes

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 52 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 54 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 56 of file Callback.h.

57  : proxyData_{},
58  producer_(iProd),
59  method_(iMethod),
60  id_(iID),
62  decorator_(iDec) {}

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

◆ 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

◆ 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

◆ newRecordComing()

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

◆ 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 ( WaitingTask iTask,
EventSetupRecordImpl const *  iRecord,
EventSetupImpl const *  iEventSetupImpl,
ServiceToken const &  token 
)
inline

Definition at line 69 of file Callback.h.

72  {
73  bool expected = false;
74  auto doPrefetch = wasCalledForThisRecord_.compare_exchange_strong(expected, true);
75  taskList_.add(iTask);
76  if (doPrefetch) {
77  if UNLIKELY (producer_->hasMayConsumes()) {
78  //after prefetching need to do the mayGet
79  auto mayGetTask = edm::make_waiting_task(
80  tbb::task::allocate_root(), [this, iRecord, iEventSetupImpl, token](std::exception_ptr const* iExcept) {
81  if (iExcept) {
82  runProducerAsync(iExcept, iRecord, iEventSetupImpl, token);
83  return;
84  }
85  if (handleMayGet(iRecord, iEventSetupImpl)) {
86  auto runTask = edm::make_waiting_task(
87  tbb::task::allocate_root(),
88  [this, iRecord, iEventSetupImpl, token](std::exception_ptr const* iExcept) {
89  runProducerAsync(iExcept, iRecord, iEventSetupImpl, token);
90  });
91  prefetchNeededDataAsync(runTask, iEventSetupImpl, &((*postMayGetProxies_).front()), token);
92  } else {
93  runProducerAsync(iExcept, iRecord, iEventSetupImpl, token);
94  }
95  });
96 
97  //Get everything we can before knowing about the mayGets
98  prefetchNeededDataAsync(mayGetTask, iEventSetupImpl, getTokenIndices(), token);
99  } else {
101  tbb::task::allocate_root(), [this, iRecord, iEventSetupImpl, token](std::exception_ptr const* iExcept) {
102  runProducerAsync(iExcept, iRecord, iEventSetupImpl, token);
103  });
104  prefetchNeededDataAsync(task, iEventSetupImpl, getTokenIndices(), token);
105  }
106  }
107  }

References edm::WaitingTaskList::add(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::getTokenIndices(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::handleMayGet(), edm::make_waiting_task(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::prefetchNeededDataAsync(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::producer_, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::runProducerAsync(), TrackValidation_cff::task, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::taskList_, unpackBuffers-CaloStage2::token, UNLIKELY, and edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::wasCalledForThisRecord_.

◆ prefetchNeededDataAsync()

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

Definition at line 138 of file Callback.h.

141  {
143  auto recs = producer_->getTokenRecordIndices(id_);
144  auto n = producer_->numberOfTokenIndices(id_);
145  for (size_t i = 0; i != n; ++i) {
146  auto rec = iImpl->findImpl(recs[i]);
147  if (rec) {
148  rec->prefetchAsync(task, proxies[i], iImpl, token);
149  }
150  }
151  }

References edm::EventSetupImpl::findImpl(), h, mps_fire::i, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::id_, dqmiodumpmetadata::n, edm::eventsetup::EventSetupRecordImpl::prefetchAsync(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::producer_, TrackValidation_cff::task, and unpackBuffers-CaloStage2::token.

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

◆ runProducerAsync()

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

Definition at line 161 of file Callback.h.

164  {
165  if (iExcept) {
166  //The cache held by the CallbackProxy was already set to invalid at the beginning of the IOV
167  taskList_.doneWaiting(*iExcept);
168  return;
169  }
170  producer_->queue().push([this, iRecord, iEventSetupImpl, token]() {
171  std::exception_ptr exceptPtr;
172  try {
173  convertException::wrap([this, iRecord, iEventSetupImpl, token] {
174  auto proxies = getTokenIndices();
175  if (postMayGetProxies_) {
176  proxies = &((*postMayGetProxies_).front());
177  }
178  TRecord rec;
179  rec.setImpl(iRecord, transitionID(), proxies, iEventSetupImpl, true);
181  decorator_.pre(rec);
183  decorator_.post(rec);
184  });
185  } catch (cms::Exception& iException) {
186  auto const& description = producer_->description();
187  std::ostringstream ost;
188  ost << "Running EventSetup component " << description.type_ << "/'" << description.label_;
189  iException.addContext(ost.str());
190  exceptPtr = std::current_exception();
191  }
192  taskList_.doneWaiting(exceptPtr);
193  });
194  }

References cms::Exception::addContext(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::decorator_, edmLumisInFiles::description, edm::WaitingTaskList::doneWaiting(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::getTokenIndices(), edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::method_, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::postMayGetProxies_, edm::eventsetup::Callback< T, TReturn, TRecord, TDecorator >::producer_, 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().

◆ 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 120 of file Callback.h.

120  {
121  DataT* temp = reinterpret_cast<DataT*>(proxyData_[produce::find_index<TReturn, DataT>::value]);
122  if (nullptr != temp) {
123  moveFromTo(iProducts, *temp);
124  }
125  if constexpr (not std::is_same_v<produce::Null, RemainingContainerT>) {
126  setData<typename RemainingContainerT::head_type, typename RemainingContainerT::tail_type>(iProducts);
127  }
128  }

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

◆ 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 114 of file Callback.h.

114  {
116  setData<typename type::head_type, typename type::tail_type>(iReturn);
117  }

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

◆ 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

◆ 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
edm::eventsetup::produce::product_traits::type
T type
Definition: produce_helpers.h:58
edm::eventsetup::Callback::storeReturnedValues
void storeReturnedValues(TReturn iReturn)
Definition: Callback.h:114
mps_fire.i
i
Definition: mps_fire.py:428
edm::eventsetup::Callback::producer_
edm::propagate_const< T * > producer_
Definition: Callback.h:198
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
cms::Exception::addContext
void addContext(std::string const &context)
Definition: Exception.cc:165
edm::eventsetup::Callback::id_
const unsigned int id_
Definition: Callback.h:202
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
edmLumisInFiles.description
description
Definition: edmLumisInFiles.py:11
edm::WaitingTaskList::add
void add(WaitingTask *)
Adds task to the waiting list.
Definition: WaitingTaskList.cc:90
edm::eventsetup::Callback::handleMayGet
bool handleMayGet(EventSetupRecordImpl const *iRecord, EventSetupImpl const *iEventSetupImpl)
Definition: Callback.h:153
edm::propagate_const::get
constexpr element_type const * get() const
Definition: propagate_const.h:64
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::eventsetup::Callback::transitionID
unsigned int transitionID() const
Definition: Callback.h:134
edm::WaitingTaskList::reset
void reset()
Resets access to the resource so that added tasks will wait.
Definition: WaitingTaskList.cc:52
edm::eventsetup::Callback::decorator_
TDecorator decorator_
Definition: Callback.h:204
UNLIKELY
#define UNLIKELY(x)
Definition: Likely.h:21
edm::eventsetup::Callback::proxyData_
std::array< void *, produce::size< TReturn >::value > proxyData_
Definition: Callback.h:196
edm::convertException::wrap
auto wrap(F iFunc) -> decltype(iFunc())
Definition: ConvertException.h:19
TrackValidation_cff.task
task
Definition: TrackValidation_cff.py:252
edm::WaitingTaskList::doneWaiting
void doneWaiting(std::exception_ptr iPtr)
Signals that the resource is now available and tasks should be spawned.
Definition: WaitingTaskList.cc:170
WaitingTaskHolder
edm::make_waiting_task
FunctorWaitingTask< F > * make_waiting_task(ALLOC &&iAlloc, F f)
Definition: WaitingTask.h:87
edm::eventsetup::Callback::Callback
Callback(T *iProd, method_type iMethod, unsigned int iID, const TDecorator &iDec=TDecorator())
Definition: Callback.h:56
edm::eventsetup::Callback::getTokenIndices
ESProxyIndex const * getTokenIndices() const
Definition: Callback.h:135
edm::eventsetup::Callback::prefetchNeededDataAsync
void prefetchNeededDataAsync(WaitingTask *task, EventSetupImpl const *iImpl, ESProxyIndex const *proxies, edm::ServiceToken const &token) const
Definition: Callback.h:138
edm::eventsetup::Callback::taskList_
edm::WaitingTaskList taskList_
Definition: Callback.h:199
edm::ServiceRegistry::Operate
friend class Operate
Definition: ServiceRegistry.h:54
edm::eventsetup::Callback::wasCalledForThisRecord_
std::atomic< bool > wasCalledForThisRecord_
Definition: Callback.h:203
edm::eventsetup::Callback::runProducerAsync
void runProducerAsync(std::exception_ptr const *iExcept, EventSetupRecordImpl const *iRecord, EventSetupImpl const *iEventSetupImpl, ServiceToken const &token)
Definition: Callback.h:161
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
edm::eventsetup::Callback::postMayGetProxies_
std::optional< std::vector< ESProxyIndex > > postMayGetProxies_
Definition: Callback.h:197
edm::eventsetup::produce::find_index::value
constexpr static int value
Definition: produce_helpers.h:128
edm::eventsetup::Callback::method_
method_type method_
Definition: Callback.h:200
cms::Exception
Definition: Exception.h:70
edm::eventsetup::moveFromTo
void moveFromTo(FromT &iFrom, ToT &iTo)
Definition: produce_helpers.h:33
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:318