Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:46

0001 #ifndef FWCore_Framework_EventSetupRecordImplementation_h
0002 #define FWCore_Framework_EventSetupRecordImplementation_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Framework
0006 // Class  :     EventSetupRecordImplementation
0007 //
0008 /**\class EventSetupRecordImplementation EventSetupRecordImplementation.h FWCore/Framework/interface/EventSetupRecordImplementation.h
0009 
0010  Description: Help class which implements the necessary virtual methods for a new Record class
0011 
0012  Usage:
0013     This class handles implementing the necessary 'meta data' methods for a Record. To use the class, a new Record type should
0014  inherit from EventSetupRecordImplementation and pass itself as the argument to the template parameter. For example, for a
0015  Record named FooRcd, you would declare it like
0016 
0017       class FooRcd : public edm::eventsetup::EventSetupRecordImplementation< FooRcd > {};
0018 */
0019 //
0020 // Author:      Chris Jones
0021 // Created:     Fri Apr  1 16:50:49 EST 2005
0022 //
0023 
0024 // user include files
0025 
0026 #include "FWCore/Framework/interface/EventSetupRecord.h"
0027 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
0028 #include "FWCore/Framework/interface/ESTransientHandle.h"
0029 #include "FWCore/Framework/interface/data_default_record_trait.h"
0030 #include "FWCore/Utilities/interface/ESGetToken.h"
0031 
0032 // system include files
0033 
0034 // forward declarations
0035 namespace edm {
0036   namespace eventsetup {
0037     struct ComponentDescription;
0038 
0039     template <typename T>
0040     class EventSetupRecordImplementation : public EventSetupRecord {
0041     public:
0042       //virtual ~EventSetupRecordImplementation();
0043 
0044       // ---------- const member functions ---------------------
0045       EventSetupRecordKey key() const override { return EventSetupRecordKey::makeKey<T>(); }
0046 
0047       template <typename PRODUCT>
0048       ESHandle<PRODUCT> getHandle(ESGetToken<PRODUCT, T> const& iToken) const {
0049         return getHandleImpl<ESHandle>(iToken);
0050       }
0051 
0052       template <typename PRODUCT>
0053       ESHandle<PRODUCT> getHandle(ESGetToken<PRODUCT, edm::DefaultRecord> const& iToken) const {
0054         static_assert(std::is_same_v<T, eventsetup::default_record_t<ESHandle<PRODUCT>>>,
0055                       "The Record being used to retrieve the product is not the default record for the product type");
0056         return getHandleImpl<ESHandle>(iToken);
0057       }
0058 
0059       template <typename PRODUCT>
0060       ESTransientHandle<PRODUCT> getTransientHandle(ESGetToken<PRODUCT, T> const& iToken) const {
0061         return getHandleImpl<ESTransientHandle>(iToken);
0062       }
0063 
0064       template <typename PRODUCT>
0065       ESTransientHandle<PRODUCT> getTransientHandle(ESGetToken<PRODUCT, edm::DefaultRecord> const& iToken) const {
0066         static_assert(std::is_same_v<T, eventsetup::default_record_t<ESTransientHandle<PRODUCT>>>,
0067                       "The Record being used to retrieve the product is not the default record for the product type");
0068         return getHandleImpl<ESTransientHandle>(iToken);
0069       }
0070 
0071       using EventSetupRecord::get;
0072 
0073       template <typename PRODUCT>
0074       PRODUCT const& get(ESGetToken<PRODUCT, T> const& iToken) const {
0075         return *getHandleImpl<ESHandle>(iToken);
0076       }
0077       template <typename PRODUCT>
0078       PRODUCT const& get(ESGetToken<PRODUCT, T>& iToken) const {
0079         return *getHandleImpl<ESHandle>(const_cast<const ESGetToken<PRODUCT, T>&>(iToken));
0080       }
0081 
0082       template <typename PRODUCT>
0083       PRODUCT const& get(ESGetToken<PRODUCT, edm::DefaultRecord> const& iToken) const {
0084         static_assert(std::is_same_v<T, eventsetup::default_record_t<ESHandle<PRODUCT>>>,
0085                       "The Record being used to retrieve the product is not the default record for the product type");
0086         return *getHandleImpl<ESHandle>(iToken);
0087       }
0088       template <typename PRODUCT>
0089       PRODUCT const& get(ESGetToken<PRODUCT, edm::DefaultRecord>& iToken) const {
0090         return get(const_cast<const ESGetToken<PRODUCT, edm::DefaultRecord>&>(iToken));
0091       }
0092 
0093       // ---------- static member functions --------------------
0094       static EventSetupRecordKey keyForClass() { return EventSetupRecordKey::makeKey<T>(); }
0095 
0096       // ---------- member functions ---------------------------
0097 
0098     protected:
0099       EventSetupRecordImplementation() {}
0100 
0101     private:
0102       // ---------- member data --------------------------------
0103     };
0104   }  // namespace eventsetup
0105 }  // namespace edm
0106 
0107 #endif