Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:03

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       template <typename PRODUCT>
0072       PRODUCT const& get(ESGetToken<PRODUCT, T> const& iToken) const {
0073         return *getHandleImpl<ESHandle>(iToken);
0074       }
0075       template <typename PRODUCT>
0076       PRODUCT const& get(ESGetToken<PRODUCT, T>& iToken) const {
0077         return *getHandleImpl<ESHandle>(const_cast<const ESGetToken<PRODUCT, T>&>(iToken));
0078       }
0079 
0080       template <typename PRODUCT>
0081       PRODUCT const& get(ESGetToken<PRODUCT, edm::DefaultRecord> const& iToken) const {
0082         static_assert(std::is_same_v<T, eventsetup::default_record_t<ESHandle<PRODUCT>>>,
0083                       "The Record being used to retrieve the product is not the default record for the product type");
0084         return *getHandleImpl<ESHandle>(iToken);
0085       }
0086       template <typename PRODUCT>
0087       PRODUCT const& get(ESGetToken<PRODUCT, edm::DefaultRecord>& iToken) const {
0088         return get(const_cast<const ESGetToken<PRODUCT, edm::DefaultRecord>&>(iToken));
0089       }
0090 
0091       // ---------- static member functions --------------------
0092       static EventSetupRecordKey keyForClass() { return EventSetupRecordKey::makeKey<T>(); }
0093 
0094       // ---------- member functions ---------------------------
0095 
0096     protected:
0097       EventSetupRecordImplementation() {}
0098 
0099     private:
0100       // ---------- member data --------------------------------
0101     };
0102   }  // namespace eventsetup
0103 }  // namespace edm
0104 
0105 #endif