Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef Framework_ESProxyFactoryProducer_h
0002 #define Framework_ESProxyFactoryProducer_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Framework
0006 // Class  :     ESProxyFactoryProducer
0007 //
0008 /**\class ESProxyFactoryProducer ESProxyFactoryProducer.h FWCore/Framework/interface/ESProxyFactoryProducer.h
0009 
0010  Description: An EventSetup algorithmic Provider that manages Factories of Proxies
0011 
0012  Usage:
0013     This class is used when the algorithms in the EventSetup that are to be run on demand are encapsulated
0014   in edm::eventsetup::Proxy's.  This 'design pattern' is more flexible than having the algorithm embedded 
0015   directly in the Provider (see ESProducer for such an implemenation).
0016 
0017     Users inherit from this class and then call the 'registerFactory' method in their class' constructor
0018   in order to get their Proxies registered.  For most users, the already available templated Factory classes
0019   should suffice and therefore they should not need to create their own Factories.
0020 
0021 Example: register one Factory that creates a proxy that takes no arguments
0022 \code
0023    class FooProxy : public edm::eventsetup::DataProxy { ... };
0024    class FooProd : public edm::ESProxyFactoryProducer { ... };
0025 
0026    FooProd::FooProd(const edm::ParameterSet&) {
0027       typedef edm::eventsetup::ProxyFactoryTemplate<FooProxy> > TYPE;
0028       registerFactory(std::make_unique<TYPE>();
0029    };
0030    
0031 \endcode
0032 
0033 Example: register one Factory that creates a proxy that takes one argument
0034 \code
0035 class BarProxy : public edm::eventsetup::DataProxy { ...
0036    BarProxy(const edm::ParameterSet&) ;
0037    ... };
0038 class BarProd : public edm::ESProxyFactoryProducer { ... };
0039 
0040 BarProd::BarProd(const edm::ParameterSet& iPS) {
0041    typedef edm::eventsetup::ProxyArgumentFactoryTemplate<FooProxy, edm::ParmeterSet> TYPE;
0042    registerFactory(std::make_unique<TYPE>(iPS);
0043 };
0044 
0045 \endcode
0046 
0047 */
0048 //
0049 // Author:      Chris Jones
0050 // Created:     Thu Apr  7 17:14:58 CDT 2005
0051 //
0052 
0053 // system include files
0054 #include <map>
0055 #include <memory>
0056 #include <string>
0057 
0058 // user include files
0059 
0060 // forward declarations
0061 #include "FWCore/Framework/interface/DataProxyProvider.h"
0062 #include "FWCore/Utilities/interface/propagate_const.h"
0063 
0064 namespace edm {
0065   namespace eventsetup {
0066     class ProxyFactoryBase;
0067 
0068     struct FactoryInfo {
0069       FactoryInfo() : key_(), factory_() {}
0070       FactoryInfo(const DataKey& iKey, std::shared_ptr<ProxyFactoryBase> iFactory) : key_(iKey), factory_(iFactory) {}
0071       DataKey key_;
0072       edm::propagate_const<std::shared_ptr<ProxyFactoryBase>> factory_;
0073     };
0074   }  // namespace eventsetup
0075 
0076   class ESProxyFactoryProducer : public eventsetup::DataProxyProvider {
0077   public:
0078     ESProxyFactoryProducer();
0079 
0080     ESProxyFactoryProducer(const ESProxyFactoryProducer&) = delete;
0081     const ESProxyFactoryProducer& operator=(const ESProxyFactoryProducer&) = delete;
0082 
0083     ~ESProxyFactoryProducer() noexcept(false) override;
0084 
0085   protected:
0086     using EventSetupRecordKey = eventsetup::EventSetupRecordKey;
0087 
0088     KeyedProxiesVector registerProxies(const EventSetupRecordKey&, unsigned int iovIndex) override;
0089 
0090     /** \param iFactory unique_ptr holding a new instance of a Factory
0091          \param iLabel extra string label used to get data (optional)
0092          Producer takes ownership of the Factory and uses it create the appropriate
0093          Proxy which is then registered with the EventSetup.  If used, this method should
0094          be called in inheriting class' constructor.
0095       */
0096     template <class TFactory>
0097     void registerFactory(std::unique_ptr<TFactory> iFactory, const std::string& iLabel = std::string()) {
0098       std::unique_ptr<eventsetup::ProxyFactoryBase> temp(iFactory.release());
0099       registerFactoryWithKey(EventSetupRecordKey::makeKey<typename TFactory::RecordType>(), std::move(temp), iLabel);
0100     }
0101 
0102     virtual void registerFactoryWithKey(const EventSetupRecordKey& iRecord,
0103                                         std::unique_ptr<eventsetup::ProxyFactoryBase> iFactory,
0104                                         const std::string& iLabel = std::string());
0105 
0106   private:
0107     // ---------- member data --------------------------------
0108     std::multimap<EventSetupRecordKey, eventsetup::FactoryInfo> record2Factories_;
0109   };
0110 
0111 }  // namespace edm
0112 
0113 #endif