CMS 3D CMS Logo

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::unique_ptr<T> make(ParameterSet const& iPS,
50  ActivityRegistry& iAR) const {
51  return std::make_unique<TConcrete>(iPS, iAR);
52  }
53  };
54 
55  template<typename T, typename TConcrete = T>
56  struct ParameterSetMaker : public MakerBase<T, TConcrete> {
57  std::unique_ptr<T> make(ParameterSet const& iPS,
58  ActivityRegistry& /* iAR */) const {
59  return std::make_unique<TConcrete>(iPS);
60  }
61  };
62 
63  template<typename T, typename TConcrete = T>
64  struct NoArgsMaker : public MakerBase<T, TConcrete> {
65  std::unique_ptr<T> make(ParameterSet const& /* iPS */,
66  ActivityRegistry& /* iAR */) const {
67  return std::make_unique<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  std::type_info const& serviceType() const override { return typeid(T); }
80 
81  bool make(ParameterSet const& iPS,
82  ActivityRegistry& iAR,
83  ServicesManager& oSM) const override {
84  TMaker maker;
85  std::unique_ptr<T> pService(maker.make(iPS, iAR));
86  auto ptr = std::make_shared<ServiceWrapper<T> >(std::move(pService));
87  return oSM.put(ptr);
88  }
89 
90  bool saveConfiguration() const override {
91  return ServiceMakerBase::testSaveConfiguration(static_cast<typename TMaker::concrete_t const*>(nullptr));
92  }
93 
94  bool processWideService() const override {
95  return service::isProcessWideService(static_cast<typename TMaker::concrete_t const*>(nullptr));
96  }
97 
98  // ---------- static member functions --------------------
99 
100  // ---------- member functions ---------------------------
101 
102 private:
103  ServiceMaker(ServiceMaker const&) = delete; // stop default
104 
105  ServiceMaker const& operator=(ServiceMaker const&) = delete; // 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::unique_ptr< T > make(ParameterSet const &iPS, ActivityRegistry &iAR) const
Definition: ServiceMaker.h:49
bool isProcessWideService(TFileService const *)
Definition: TFileService.h:99
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
std::unique_ptr< T > make(ParameterSet const &iPS, ActivityRegistry &) const
Definition: ServiceMaker.h:57
bool make(ParameterSet const &iPS, ActivityRegistry &iAR, ServicesManager &oSM) const override
Definition: ServiceMaker.h:81
bool processWideService() const override
Definition: ServiceMaker.h:94
bool saveConfiguration() const override
Definition: ServiceMaker.h:90
HLT enums.
long double T
std::unique_ptr< T > make(ParameterSet const &, ActivityRegistry &) const
Definition: ServiceMaker.h:65
def move(src, dest)
Definition: eostools.py:511
std::type_info const & serviceType() const override
Definition: ServiceMaker.h:79