CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/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 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/ServiceRegistry/interface/ServiceMakerBase.h"
00026 #include "FWCore/ServiceRegistry/interface/ServiceWrapper.h"
00027 #include "FWCore/ServiceRegistry/interface/ServicesManager.h"
00028 #include "FWCore/ServiceRegistry/interface/ServicePluginFactory.h"
00029 #include "FWCore/ParameterSet/interface/ParameterSetDescriptionFillerPluginFactory.h"
00030 
00031 // forward declarations
00032 
00033 namespace edm {
00034    class ParameterSet;
00035    class ActivityRegistry;
00036 
00037    
00038    namespace serviceregistry {
00039       
00040       template<class T, class TConcrete >
00041       struct MakerBase {
00042          typedef T interface_t;
00043          typedef TConcrete concrete_t;
00044       };
00045       
00046       template< class T, class TConcrete = T>
00047          struct AllArgsMaker : public MakerBase<T,TConcrete> {
00048          
00049          std::auto_ptr<T> make(const edm::ParameterSet& iPS,
00050                                edm::ActivityRegistry& iAR) const 
00051          {
00052             return std::auto_ptr<T>(new TConcrete(iPS, iAR));
00053          }
00054       };
00055 
00056       template< class T, class TConcrete = T>
00057       struct ParameterSetMaker : public MakerBase<T,TConcrete> {
00058          std::auto_ptr<T> make(const edm::ParameterSet& iPS,
00059                                edm::ActivityRegistry& /* iAR */) const 
00060          {
00061             return std::auto_ptr<T>(new TConcrete(iPS));
00062          }
00063       };
00064 
00065       template< class T, class TConcrete = T>
00066       struct NoArgsMaker : public MakerBase<T,TConcrete> {
00067          std::auto_ptr<T> make(const edm::ParameterSet& /* iPS */,
00068                                edm::ActivityRegistry& /* iAR */) const 
00069          {
00070             return std::auto_ptr<T>(new TConcrete());
00071          }
00072       };
00073       
00074       
00075       template< class T, class TMaker = AllArgsMaker<T> >
00076       class ServiceMaker : public ServiceMakerBase
00077       {
00078 
00079 public:
00080          ServiceMaker() {}
00081          //virtual ~ServiceMaker();
00082          
00083          // ---------- const member functions ---------------------
00084          virtual const std::type_info& serviceType() const { return typeid(T); }
00085          
00086          virtual bool make(const edm::ParameterSet& iPS,
00087                            edm::ActivityRegistry& iAR,
00088                            ServicesManager& oSM) const 
00089          {
00090             TMaker maker;
00091             std::auto_ptr<T> pService(maker.make(iPS, iAR));
00092             boost::shared_ptr<ServiceWrapper<T> > ptr(new ServiceWrapper<T>(pService));
00093             return oSM.put(ptr);
00094          }
00095          
00096          virtual bool saveConfiguration() const
00097          {
00098             return ServiceMakerBase::testSaveConfiguration(static_cast<typename TMaker::concrete_t const *>(0));
00099          }
00100 
00101          // ---------- static member functions --------------------
00102          
00103          // ---------- member functions ---------------------------
00104          
00105 private:
00106          ServiceMaker(const ServiceMaker&); // stop default
00107          
00108          const ServiceMaker& operator=(const ServiceMaker&); // stop default
00109                   
00110          // ---------- member data --------------------------------
00111          
00112       };
00113    }
00114 }
00115 
00116 
00117 #define DEFINE_FWK_SERVICE(type) \
00118 DEFINE_EDM_PLUGIN (edm::serviceregistry::ServicePluginFactory,edm::serviceregistry::ServiceMaker<type>,#type); \
00119 DEFINE_DESC_FILLER_FOR_SERVICES(type, type)
00120 
00121 #define DEFINE_FWK_SERVICE_MAKER(concrete,maker) \
00122 typedef edm::serviceregistry::ServiceMaker<maker::interface_t,maker> concrete ## _ ## _t; \
00123 DEFINE_EDM_PLUGIN (edm::serviceregistry::ServicePluginFactory, concrete ## _ ##  _t ,#concrete); \
00124 typedef maker::concrete_t concrete ## _ ## _ ## _t; \
00125 DEFINE_DESC_FILLER_FOR_SERVICES(concrete, concrete ## _ ## _ ## _t)
00126 
00127 #endif