test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ServiceMaker.h
Go to the documentation of this file.
1 #ifndef FWCore_ServiceRegistry_ServiceMaker_h
2 #define FWCore_ServiceRegistry_ServiceMaker_h
3 // -*- C++ -*-
4 //
5 // Package: ServiceRegistry
6 // Class : ServiceMaker
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Mon Sep 5 13:33:00 EDT 2005
19 //
20 
21 // user include files
27 
28 // system include files
29 #include <memory>
30 #include <typeinfo>
31 
32 // forward declarations
33 
34 namespace edm {
35  class ActivityRegistry;
36  class ParameterSet;
37 
38  namespace serviceregistry {
39 
40  template<typename T, typename TConcrete>
41  struct MakerBase {
42  typedef T interface_t;
43  typedef TConcrete concrete_t;
44  };
45 
46  template<typename T, typename TConcrete = T>
47  struct AllArgsMaker : public MakerBase<T, TConcrete> {
48 
49  std::auto_ptr<T> make(ParameterSet const& iPS,
50  ActivityRegistry& iAR) const {
51  return std::auto_ptr<T>(new TConcrete(iPS, iAR));
52  }
53  };
54 
55  template<typename T, typename TConcrete = T>
56  struct ParameterSetMaker : public MakerBase<T, TConcrete> {
57  std::auto_ptr<T> make(ParameterSet const& iPS,
58  ActivityRegistry& /* iAR */) const {
59  return std::auto_ptr<T>(new TConcrete(iPS));
60  }
61  };
62 
63  template<typename T, typename TConcrete = T>
64  struct NoArgsMaker : public MakerBase<T, TConcrete> {
65  std::auto_ptr<T> make(ParameterSet const& /* iPS */,
66  ActivityRegistry& /* iAR */) const {
67  return std::auto_ptr<T>(new TConcrete());
68  }
69  };
70 
71  template<typename T, typename TMaker = AllArgsMaker<T> >
72  class ServiceMaker : public ServiceMakerBase {
73 
74 public:
76  //virtual ~ServiceMaker();
77 
78  // ---------- const member functions ---------------------
79  virtual std::type_info const& serviceType() const { return typeid(T); }
80 
81  virtual bool make(ParameterSet const& iPS,
82  ActivityRegistry& iAR,
83  ServicesManager& oSM) const {
84  TMaker maker;
85  std::auto_ptr<T> pService(maker.make(iPS, iAR));
86  auto ptr = std::make_shared<ServiceWrapper<T> >(pService);
87  return oSM.put(ptr);
88  }
89 
90  virtual bool saveConfiguration() const {
91  return ServiceMakerBase::testSaveConfiguration(static_cast<typename TMaker::concrete_t const*>(0));
92  }
93 
94  virtual bool processWideService() const {
95  return service::isProcessWideService(static_cast<typename TMaker::concrete_t const*>(0));
96  }
97 
98  // ---------- static member functions --------------------
99 
100  // ---------- member functions ---------------------------
101 
102 private:
103  ServiceMaker(ServiceMaker const&); // stop default
104 
105  ServiceMaker const& operator=(ServiceMaker const&); // stop default
106 
107  // ---------- member data --------------------------------
108 
109  };
110  }
111 }
112 
113 #define DEFINE_FWK_SERVICE(type) \
114 DEFINE_EDM_PLUGIN (edm::serviceregistry::ServicePluginFactory, edm::serviceregistry::ServiceMaker<type>, #type); \
115 DEFINE_DESC_FILLER_FOR_SERVICES(type, type)
116 
117 #define DEFINE_FWK_SERVICE_MAKER(concrete, maker) \
118 typedef edm::serviceregistry::ServiceMaker<maker::interface_t, maker> concrete ## _ ## _t; \
119 DEFINE_EDM_PLUGIN (edm::serviceregistry::ServicePluginFactory, concrete ## _ ## _t , #concrete); \
120 typedef maker::concrete_t concrete ## _ ## _ ## _t; \
121 DEFINE_DESC_FILLER_FOR_SERVICES(concrete, concrete ## _ ## _ ## _t)
122 
123 #endif
std::auto_ptr< T > make(ParameterSet const &, ActivityRegistry &) const
Definition: ServiceMaker.h:65
bool isProcessWideService(TFileService const *)
Definition: TFileService.h:99
std::auto_ptr< T > make(ParameterSet const &iPS, ActivityRegistry &) const
Definition: ServiceMaker.h:57
virtual bool saveConfiguration() const
Definition: ServiceMaker.h:90
bool testSaveConfiguration(SaveConfiguration const *) const
bool put(std::shared_ptr< ServiceWrapper< T > > iPtr)
returns false if put fails because a service of this type already exists
virtual bool processWideService() const
Definition: ServiceMaker.h:94
virtual std::type_info const & serviceType() const
Definition: ServiceMaker.h:79
virtual bool make(ParameterSet const &iPS, ActivityRegistry &iAR, ServicesManager &oSM) const
Definition: ServiceMaker.h:81
std::auto_ptr< T > make(ParameterSet const &iPS, ActivityRegistry &iAR) const
Definition: ServiceMaker.h:49
ServiceMaker const & operator=(ServiceMaker const &)
long double T