CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/FWCore/ServiceRegistry/interface/ServiceMaker.h

Go to the documentation of this file.
00001 #ifndef FWCore_ServiceRegistry_ServiceMaker_h
00002 #define FWCore_ServiceRegistry_ServiceMaker_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     ServiceRegistry
00006 // Class  :     ServiceMaker
00007 //
00016 //
00017 // Original Author:  Chris Jones
00018 //         Created:  Mon Sep  5 13:33:00 EDT 2005
00019 //
00020 
00021 // user include files
00022 #include "FWCore/ParameterSet/interface/ParameterSetDescriptionFillerPluginFactory.h"
00023 #include "FWCore/ServiceRegistry/interface/ServiceMakerBase.h"
00024 #include "FWCore/ServiceRegistry/interface/ServicePluginFactory.h"
00025 #include "FWCore/ServiceRegistry/interface/ServiceWrapper.h"
00026 #include "FWCore/ServiceRegistry/interface/ServicesManager.h"
00027 
00028 // system include files
00029 #include <memory>
00030 #include <typeinfo>
00031 
00032 // forward declarations
00033 
00034 namespace edm {
00035    class ActivityRegistry;
00036    class ParameterSet;
00037 
00038    namespace serviceregistry {
00039 
00040       template<typename T, typename TConcrete>
00041       struct MakerBase {
00042          typedef T interface_t;
00043          typedef TConcrete concrete_t;
00044       };
00045 
00046       template<typename T, typename TConcrete = T>
00047          struct AllArgsMaker : public MakerBase<T, TConcrete> {
00048 
00049          std::auto_ptr<T> make(ParameterSet const& iPS,
00050                                ActivityRegistry& iAR) const {
00051             return std::auto_ptr<T>(new TConcrete(iPS, iAR));
00052          }
00053       };
00054 
00055       template<typename T, typename TConcrete = T>
00056       struct ParameterSetMaker : public MakerBase<T, TConcrete> {
00057          std::auto_ptr<T> make(ParameterSet const& iPS,
00058                                ActivityRegistry& /* iAR */) const {
00059             return std::auto_ptr<T>(new TConcrete(iPS));
00060          }
00061       };
00062 
00063       template<typename T, typename TConcrete = T>
00064       struct NoArgsMaker : public MakerBase<T, TConcrete> {
00065          std::auto_ptr<T> make(ParameterSet const& /* iPS */,
00066                                ActivityRegistry& /* iAR */) const {
00067             return std::auto_ptr<T>(new TConcrete());
00068          }
00069       };
00070 
00071       template<typename T, typename TMaker = AllArgsMaker<T> >
00072       class ServiceMaker : public ServiceMakerBase {
00073 
00074 public:
00075          ServiceMaker() {}
00076          //virtual ~ServiceMaker();
00077 
00078          // ---------- const member functions ---------------------
00079          virtual std::type_info const& serviceType() const { return typeid(T); }
00080 
00081          virtual bool make(ParameterSet const& iPS,
00082                            ActivityRegistry& iAR,
00083                            ServicesManager& oSM) const {
00084             TMaker maker;
00085             std::auto_ptr<T> pService(maker.make(iPS, iAR));
00086             boost::shared_ptr<ServiceWrapper<T> > ptr(new ServiceWrapper<T>(pService));
00087             return oSM.put(ptr);
00088          }
00089 
00090          virtual bool saveConfiguration() const {
00091             return ServiceMakerBase::testSaveConfiguration(static_cast<typename TMaker::concrete_t const*>(0));
00092          }
00093 
00094          virtual bool processWideService() const {
00095             return service::isProcessWideService(static_cast<typename TMaker::concrete_t const*>(0));
00096          }
00097 
00098          // ---------- static member functions --------------------
00099 
00100          // ---------- member functions ---------------------------
00101 
00102 private:
00103          ServiceMaker(ServiceMaker const&); // stop default
00104 
00105          ServiceMaker const& operator=(ServiceMaker const&); // stop default
00106 
00107          // ---------- member data --------------------------------
00108 
00109       };
00110    }
00111 }
00112 
00113 #define DEFINE_FWK_SERVICE(type) \
00114 DEFINE_EDM_PLUGIN (edm::serviceregistry::ServicePluginFactory, edm::serviceregistry::ServiceMaker<type>, #type); \
00115 DEFINE_DESC_FILLER_FOR_SERVICES(type, type)
00116 
00117 #define DEFINE_FWK_SERVICE_MAKER(concrete, maker) \
00118 typedef edm::serviceregistry::ServiceMaker<maker::interface_t, maker> concrete ## _ ## _t; \
00119 DEFINE_EDM_PLUGIN (edm::serviceregistry::ServicePluginFactory, concrete ## _ ##  _t , #concrete); \
00120 typedef maker::concrete_t concrete ## _ ## _ ## _t; \
00121 DEFINE_DESC_FILLER_FOR_SERVICES(concrete, concrete ## _ ## _ ## _t)
00122 
00123 #endif