CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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  std::unique_ptr<T> make(ParameterSet const& iPS, ActivityRegistry& iAR) const {
49  return std::make_unique<TConcrete>(iPS, iAR);
50  }
51  };
52 
53  template <typename T, typename TConcrete = T>
54  struct ParameterSetMaker : public MakerBase<T, TConcrete> {
55  std::unique_ptr<T> make(ParameterSet const& iPS, ActivityRegistry& /* iAR */) const {
56  return std::make_unique<TConcrete>(iPS);
57  }
58  };
59 
60  template <typename T, typename TConcrete = T>
61  struct NoArgsMaker : public MakerBase<T, TConcrete> {
62  std::unique_ptr<T> make(ParameterSet const& /* iPS */, ActivityRegistry& /* iAR */) const {
63  return std::make_unique<TConcrete>();
64  }
65  };
66 
67  template <typename T, typename TMaker = AllArgsMaker<T> >
68  class ServiceMaker : public ServiceMakerBase {
69  public:
71 
72  ServiceMaker(ServiceMaker const&) = delete;
73  ServiceMaker const& operator=(ServiceMaker const&) = delete;
74 
75  // ---------- const member functions ---------------------
76  std::type_info const& serviceType() const override { return typeid(T); }
77 
78  bool make(ParameterSet const& iPS, ActivityRegistry& iAR, ServicesManager& oSM) const override {
79  TMaker maker;
80  std::unique_ptr<T> pService(maker.make(iPS, iAR));
81  auto ptr = std::make_shared<ServiceWrapper<T> >(std::move(pService));
82  return oSM.put(ptr);
83  }
84 
85  bool saveConfiguration() const override {
86  return ServiceMakerBase::testSaveConfiguration(static_cast<typename TMaker::concrete_t const*>(nullptr));
87  }
88 
89  bool processWideService() const override {
90  return service::isProcessWideService(static_cast<typename TMaker::concrete_t const*>(nullptr));
91  }
92  };
93  } // namespace serviceregistry
94 } // namespace edm
95 
96 #define DEFINE_FWK_SERVICE(type) \
97  DEFINE_EDM_PLUGIN(edm::serviceregistry::ServicePluginFactory, edm::serviceregistry::ServiceMaker<type>, #type); \
98  DEFINE_DESC_FILLER_FOR_SERVICES(type, type)
99 
100 #define DEFINE_FWK_SERVICE_MAKER(concrete, maker) \
101  typedef edm::serviceregistry::ServiceMaker<maker::interface_t, maker> concrete##_##_t; \
102  DEFINE_EDM_PLUGIN(edm::serviceregistry::ServicePluginFactory, concrete##_##_t, #concrete); \
103  typedef maker::concrete_t concrete##_##_##_t; \
104  DEFINE_DESC_FILLER_FOR_SERVICES(concrete, concrete##_##_##_t)
105 
106 #endif
std::unique_ptr< T > make(ParameterSet const &iPS, ActivityRegistry &iAR) const
Definition: ServiceMaker.h:48
bool put(std::shared_ptr< ServiceWrapper< T >> iPtr)
returns false if put fails because a service of this type already exists
ServiceMaker const & operator=(ServiceMaker const &)=delete
bool isProcessWideService(TFileService const *)
Definition: TFileService.h:98
bool testSaveConfiguration(SaveConfiguration const *) const
std::unique_ptr< T > make(ParameterSet const &iPS, ActivityRegistry &) const
Definition: ServiceMaker.h:55
def move
Definition: eostools.py:511
std::type_info const & serviceType() const override
Definition: ServiceMaker.h:76
bool processWideService() const override
Definition: ServiceMaker.h:89
bool saveConfiguration() const override
Definition: ServiceMaker.h:85
long double T
std::unique_ptr< T > make(ParameterSet const &, ActivityRegistry &) const
Definition: ServiceMaker.h:62
bool make(ParameterSet const &iPS, ActivityRegistry &iAR, ServicesManager &oSM) const override
Definition: ServiceMaker.h:78