Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:56

0001 #ifndef FWCore_Framework_es_impl_MayConsumeChooser_h
0002 #define FWCore_Framework_es_impl_MayConsumeChooser_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Framework
0006 // Class  :     MayConsumeChooser
0007 //
0008 /**\class MayConsumeChooser MayConsumeChooser.h "MayConsumeChooser.h"
0009 
0010  Description: Handles calling the user's function to choose which product to get
0011 
0012  Usage:
0013     This is used by the mayConsumes ability of an ESProducer.
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Thu, 19 Sep 2019 15:29:50 GMT
0019 //
0020 
0021 // system include files
0022 #include <type_traits>
0023 
0024 // user include files
0025 #include "FWCore/Framework/interface/es_impl/MayConsumeChooserBase.h"
0026 #include "FWCore/Framework/interface/DataKey.h"
0027 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
0028 #include "FWCore/Utilities/interface/ESGetToken.h"
0029 
0030 // forward declarations
0031 
0032 namespace edm::eventsetup::impl {
0033   template <typename RECBASE, typename PRODUCT, typename RCD, typename FUNC, typename PTAG>
0034   class MayConsumeChooser : public MayConsumeChooserBase<RECBASE> {
0035   public:
0036     using Record_t = typename PTAG::Record;
0037     using GetType_t = typename PTAG::Type;
0038 
0039     MayConsumeChooser(FUNC&& iFunc) : func_(std::forward<FUNC>(iFunc)) {}
0040 
0041     // ---------- const member functions ---------------------
0042     ESResolverIndex makeChoice(RECBASE const& iRecord) const final {
0043       return func_(this->tagGetter(), iRecord.getTransientHandle(token_));
0044     }
0045 
0046     EventSetupRecordKey recordKey() const noexcept final { return EventSetupRecordKey::makeKey<RCD>(); }
0047     TypeTag productType() const noexcept final { return DataKey::makeTypeTag<PRODUCT>(); }
0048 
0049     // ---------- static member functions --------------------
0050 
0051     // ---------- member functions ---------------------------
0052     edm::ESGetToken<GetType_t, Record_t>& token() { return token_; }
0053 
0054   private:
0055     // ---------- member data --------------------------------
0056     edm::ESGetToken<GetType_t, Record_t> token_;
0057     FUNC func_;
0058   };
0059 }  // namespace edm::eventsetup::impl
0060 
0061 #endif