MayConsumeChooser

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#ifndef FWCore_Framework_es_impl_MayConsumeChooser_h
#define FWCore_Framework_es_impl_MayConsumeChooser_h
// -*- C++ -*-
//
// Package:     FWCore/Framework
// Class  :     MayConsumeChooser
//
/**\class MayConsumeChooser MayConsumeChooser.h "MayConsumeChooser.h"

 Description: Handles calling the user's function to choose which product to get

 Usage:
    This is used by the mayConsumes ability of an ESProducer.

*/
//
// Original Author:  Chris Jones
//         Created:  Thu, 19 Sep 2019 15:29:50 GMT
//

// system include files
#include <type_traits>

// user include files
#include "FWCore/Framework/interface/es_impl/MayConsumeChooserBase.h"
#include "FWCore/Framework/interface/DataKey.h"
#include "FWCore/Framework/interface/EventSetupRecordKey.h"
#include "FWCore/Utilities/interface/ESGetToken.h"

// forward declarations

namespace edm::eventsetup::impl {
  template <typename RECBASE, typename PRODUCT, typename RCD, typename FUNC, typename PTAG>
  class MayConsumeChooser : public MayConsumeChooserBase<RECBASE> {
  public:
    using Record_t = typename PTAG::Record;
    using GetType_t = typename PTAG::Type;

    MayConsumeChooser(FUNC&& iFunc) : func_(std::forward<FUNC>(iFunc)) {}

    // ---------- const member functions ---------------------
    ESResolverIndex makeChoice(RECBASE const& iRecord) const final {
      return func_(this->tagGetter(), iRecord.getTransientHandle(token_));
    }

    EventSetupRecordKey recordKey() const noexcept final { return EventSetupRecordKey::makeKey<RCD>(); }
    TypeTag productType() const noexcept final { return DataKey::makeTypeTag<PRODUCT>(); }

    // ---------- static member functions --------------------

    // ---------- member functions ---------------------------
    edm::ESGetToken<GetType_t, Record_t>& token() { return token_; }

  private:
    // ---------- member data --------------------------------
    edm::ESGetToken<GetType_t, Record_t> token_;
    FUNC func_;
  };
}  // namespace edm::eventsetup::impl

#endif