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 >
constexpr static std::size_t index ()
 
template<std::size_t I, typename U , typename TST , typename... M>
constexpr static std::size_t indexLoop ()
 
constexpr static 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) {}

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.

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  }

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

◆ index()

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

Definition at line 129 of file ESProductHost.h.

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

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

Referenced by BeautifulSoup.PageElement::insert().

◆ indexLoop()

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

Definition at line 135 of file ESProductHost.h.

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  }

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

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

◆ numberOfRecordTypes()

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

Definition at line 120 of file ESProductHost.h.

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

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

Member Data Documentation

◆ cacheIDs_

template<typename Product , typename... RecordTypes>
std::vector<unsigned long long> edm::ESProductHost< Product, RecordTypes >::cacheIDs_
private
writedatasetfile.args
args
Definition: writedatasetfile.py:18
edm::ESProductHost::numberOfRecordTypes
constexpr static std::size_t numberOfRecordTypes()
Definition: ESProductHost.h:120
Exhume::I
const std::complex< double > I
Definition: I.h:8
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::ESProductHost::cacheIDs_
std::vector< unsigned long long > cacheIDs_
Definition: ESProductHost.h:149
AlCaHarvesting_cff.record
record
Definition: AlCaHarvesting_cff.py:42
TrackCollections2monitor_cff.func
func
Definition: TrackCollections2monitor_cff.py:359
edm::ESProductHost::indexLoop
constexpr static std::size_t indexLoop()
Definition: ESProductHost.h:135