CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
edm::ESProductHost< Product, RecordTypes > Class Template Referencefinal

#include <ESProductHost.h>

Inheritance diagram for edm::ESProductHost< Product, RecordTypes >:

Public Member Functions

template<typename... Args>
 ESProductHost (Args &&... args)
 
template<typename RecordType , typename ContainingRecordType , typename FUNC >
void ifRecordChanges (ContainingRecordType const &containingRecord, FUNC func)
 

Static Public Member Functions

template<typename U >
static constexpr std::size_t index ()
 
template<std::size_t I, typename U , typename TST , typename... M>
static constexpr std::size_t indexLoop ()
 
static constexpr std::size_t numberOfRecordTypes ()
 

Private Attributes

std::vector< unsigned long long > cacheIDs_
 

Detailed Description

template<typename Product, typename... RecordTypes>
class edm::ESProductHost< Product, RecordTypes >

Description: Helps an ESProducer produce an ESProduct that has complex dependences on multiple record types. In particular, it helps it manage what is executed in the produce function based on which records changed and which did not.

This was designed as a replacement for the EventSetup "dependsOn" functionality and is needed in some cases where the "dependsOn" callbacks would not work well when processing multiple IOVs concurrently.

Usage:

An ESProducer class would use this class.

  1. Add to the ESProducer header

    include "FWCore/Framework/interface/ESProductHost.h" include "FWCore/Utilities/interface/ReusableObjectHolder.h"

  2. Assume the following only for purposes of this usage example (the actual types in your case would be different). If the produced function was defined as follows:
    std::shared_ptr<ESTestDataB> produce(ESTestRecordB const&);
    

and assume there is some special dependence on ESTestRecordC and ESTestRecordD.

  1. Then you would add a data member to the ESProducer similar to the following:
    using HostType = edm::ESProductHost<ESTestDataB,
                                        ESTestRecordC,
                                        ESTestRecordD>;
    
    edm::ReusableObjectHolder<HostType> holder_;
    
  2. Then the produce function would be defined something similar to this:

    std::shared_ptr<ESTestDataB> ESTestProducerBUsingHost::produce(ESTestRecordB const& record) {
    
      auto host = holder_.makeOrGet([]() {
        return new HostType;
      });
    
      host->ifRecordChanges<ESTestRecordC>(record,
                                           [this, h=host.get()](auto const& rec) {
    

    Do whatever special needs to be done only when record C changes (If you are using this class to replace a dependsOn callback, you could call the function that dependsOn used as a callback here) });

    host->ifRecordChanges<ESTestRecordD>(record, [this, h=host.get()](auto const& rec) { Do whatever special needs to be done only when record D changes });

    ... repeat for as many record types as you need.

Definition at line 93 of file ESProductHost.h.

Constructor & Destructor Documentation

◆ ESProductHost()

template<typename Product , typename... RecordTypes>
template<typename... Args>
edm::ESProductHost< Product, RecordTypes >::ESProductHost ( Args &&...  args)
inline

Definition at line 96 of file ESProductHost.h.

96 : Product(std::forward<Args>(args)...), cacheIDs_(numberOfRecordTypes(), 0) {}
std::vector< unsigned long long > cacheIDs_
static constexpr std::size_t numberOfRecordTypes()

Member Function Documentation

◆ ifRecordChanges()

template<typename Product , typename... RecordTypes>
template<typename RecordType , typename ContainingRecordType , typename FUNC >
void edm::ESProductHost< Product, RecordTypes >::ifRecordChanges ( ContainingRecordType const &  containingRecord,
FUNC  func 
)
inline

Definition at line 103 of file ESProductHost.h.

References edm::ESProductHost< Product, RecordTypes >::cacheIDs_, EcalMonitorTask_cff::func, and AlCaHarvesting_cff::record.

103  {
104  RecordType const& record = containingRecord.template getRecord<RecordType>();
105  unsigned long long cacheIdentifier = record.cacheIdentifier();
106  std::size_t iRecord = index<RecordType>();
107  if (cacheIdentifier != cacheIDs_[iRecord]) {
108  cacheIDs_[iRecord] = cacheIdentifier;
109  func(record);
110  }
111  }
std::vector< unsigned long long > cacheIDs_

◆ index()

template<typename Product , typename... RecordTypes>
template<typename U >
static constexpr std::size_t edm::ESProductHost< Product, RecordTypes >::index ( )
inlinestatic

Definition at line 129 of file ESProductHost.h.

References edm::ESProductHost< Product, RecordTypes >::indexLoop(), edm::ESProductHost< Product, RecordTypes >::numberOfRecordTypes(), and mitigatedMETSequence_cff::U.

129  {
130  static_assert(numberOfRecordTypes() > 0, "no record types in ESProductHost");
131  return indexLoop<0, U, RecordTypes...>();
132  }
static constexpr std::size_t indexLoop()
static constexpr std::size_t numberOfRecordTypes()

◆ indexLoop()

template<typename Product , typename... RecordTypes>
template<std::size_t I, typename U , typename TST , typename... M>
static constexpr std::size_t edm::ESProductHost< Product, RecordTypes >::indexLoop ( )
inlinestatic

Definition at line 135 of file ESProductHost.h.

References ALPAKA_ACCELERATOR_NAMESPACE::brokenline::constexpr(), Exhume::I, edm::ESProductHost< Product, RecordTypes >::numberOfRecordTypes(), and mitigatedMETSequence_cff::U.

Referenced by edm::ESProductHost< Product, RecordTypes >::index().

135  {
136  if constexpr (std::is_same_v<U, TST>) {
137  return I;
138  } else {
139  static_assert(I + 1 < numberOfRecordTypes(), "unknown record type passed to ESProductHost::index");
140  return indexLoop<I + 1, U, M...>();
141  }
142  }
static constexpr std::size_t indexLoop()
const std::complex< double > I
Definition: I.h:8
static constexpr std::size_t numberOfRecordTypes()

◆ numberOfRecordTypes()

template<typename Product , typename... RecordTypes>
static constexpr std::size_t edm::ESProductHost< Product, RecordTypes >::numberOfRecordTypes ( )
inlinestatic

Definition at line 120 of file ESProductHost.h.

Referenced by edm::ESProductHost< Product, RecordTypes >::index(), and edm::ESProductHost< Product, RecordTypes >::indexLoop().

120 { return sizeof...(RecordTypes); }

Member Data Documentation

◆ cacheIDs_

template<typename Product , typename... RecordTypes>
std::vector<unsigned long long> edm::ESProductHost< Product, RecordTypes >::cacheIDs_
private